odbc_api/catalog/
columns.rs1use crate::{
2 CursorImpl, Error, Nullable, TruncationInfo,
3 buffers::{FetchRow, FetchRowMember as _},
4 handles::{AsStatementRef, SqlText, Statement, StatementRef},
5 parameter::VarCharArray,
6};
7
8#[derive(Clone, Copy, Default)]
19pub struct ColumnsRow {
20 pub catalog: VarCharArray<128>,
22 pub schema: VarCharArray<128>,
24 pub table: VarCharArray<255>,
26 pub column_name: VarCharArray<255>,
28 pub data_type: i16,
30 pub type_name: VarCharArray<256>,
32 pub column_size: Nullable<i32>,
35 pub buffer_length: Nullable<i32>,
37 pub decimal_digits: Nullable<i16>,
39 pub num_prec_radix: Nullable<i16>,
41 pub nullable: i16,
43 pub remarks: VarCharArray<1024>,
45 pub column_default: VarCharArray<4000>,
47 pub sql_data_type: i16,
50 pub sql_datetime_sub: Nullable<i16>,
53 pub char_octet_length: Nullable<i32>,
56 pub ordinal_position: i32,
59 pub is_nullable: VarCharArray<4>,
62}
63
64unsafe impl FetchRow for ColumnsRow {
65 unsafe fn bind_columns_to_cursor(&mut self, mut cursor: StatementRef<'_>) -> Result<(), Error> {
66 unsafe {
67 self.catalog.bind_to_col(1, &mut cursor)?;
68 self.schema.bind_to_col(2, &mut cursor)?;
69 self.table.bind_to_col(3, &mut cursor)?;
70 self.column_name.bind_to_col(4, &mut cursor)?;
71 self.data_type.bind_to_col(5, &mut cursor)?;
72 self.type_name.bind_to_col(6, &mut cursor)?;
73 self.column_size.bind_to_col(7, &mut cursor)?;
74 self.buffer_length.bind_to_col(8, &mut cursor)?;
75 self.decimal_digits.bind_to_col(9, &mut cursor)?;
76 self.num_prec_radix.bind_to_col(10, &mut cursor)?;
77 self.nullable.bind_to_col(11, &mut cursor)?;
78 self.remarks.bind_to_col(12, &mut cursor)?;
79 self.column_default.bind_to_col(13, &mut cursor)?;
80 self.sql_data_type.bind_to_col(14, &mut cursor)?;
81 self.sql_datetime_sub.bind_to_col(15, &mut cursor)?;
82 self.char_octet_length.bind_to_col(16, &mut cursor)?;
83 self.ordinal_position.bind_to_col(17, &mut cursor)?;
84 self.is_nullable.bind_to_col(18, &mut cursor)?;
85 Ok(())
86 }
87 }
88
89 fn find_truncation(&self) -> Option<TruncationInfo> {
90 if let Some(t) = self.catalog.find_truncation(0) {
91 return Some(t);
92 }
93 if let Some(t) = self.schema.find_truncation(1) {
94 return Some(t);
95 }
96 if let Some(t) = self.table.find_truncation(2) {
97 return Some(t);
98 }
99 if let Some(t) = self.column_name.find_truncation(3) {
100 return Some(t);
101 }
102 if let Some(t) = self.data_type.find_truncation(4) {
103 return Some(t);
104 }
105 if let Some(t) = self.type_name.find_truncation(5) {
106 return Some(t);
107 }
108 if let Some(t) = self.column_size.find_truncation(6) {
109 return Some(t);
110 }
111 if let Some(t) = self.buffer_length.find_truncation(7) {
112 return Some(t);
113 }
114 if let Some(t) = self.decimal_digits.find_truncation(8) {
115 return Some(t);
116 }
117 if let Some(t) = self.num_prec_radix.find_truncation(9) {
118 return Some(t);
119 }
120 if let Some(t) = self.nullable.find_truncation(10) {
121 return Some(t);
122 }
123 if let Some(t) = self.remarks.find_truncation(11) {
124 return Some(t);
125 }
126 if let Some(t) = self.column_default.find_truncation(12) {
127 return Some(t);
128 }
129 if let Some(t) = self.sql_data_type.find_truncation(13) {
130 return Some(t);
131 }
132 if let Some(t) = self.sql_datetime_sub.find_truncation(14) {
133 return Some(t);
134 }
135 if let Some(t) = self.char_octet_length.find_truncation(15) {
136 return Some(t);
137 }
138 if let Some(t) = self.ordinal_position.find_truncation(16) {
139 return Some(t);
140 }
141 if let Some(t) = self.is_nullable.find_truncation(17) {
142 return Some(t);
143 }
144 None
145 }
146}
147
148pub fn execute_columns<S>(
149 mut statement: S,
150 catalog_name: &SqlText,
151 schema_name: &SqlText,
152 table_name: &SqlText,
153 column_name: &SqlText,
154) -> Result<CursorImpl<S>, Error>
155where
156 S: AsStatementRef,
157{
158 let mut stmt = statement.as_stmt_ref();
159
160 stmt.columns(catalog_name, schema_name, table_name, column_name)
161 .into_result(&stmt)?;
162
163 debug_assert_ne!(stmt.num_result_cols().unwrap(), 0);
165
166 let cursor = unsafe { CursorImpl::new(statement) };
168 Ok(cursor)
169}