()
| 138 | |
| 139 | #[tokio::test] |
| 140 | async fn test_information_schema_columns_basic() { |
| 141 | let _ = env_logger::builder().is_test(true).try_init(); |
| 142 | |
| 143 | let server = common::setup_test_server_with_init(|db| { |
| 144 | Box::pin(async move { |
| 145 | // Create a test table with various column types |
| 146 | db.execute(r#" |
| 147 | CREATE TABLE test_table ( |
| 148 | id INTEGER PRIMARY KEY, |
| 149 | name VARCHAR(100) NOT NULL, |
| 150 | age INT, |
| 151 | salary DECIMAL(10,2), |
| 152 | is_active BOOLEAN DEFAULT true, |
| 153 | created_at TIMESTAMP |
| 154 | ) |
| 155 | "#).await?; |
| 156 | Ok(()) |
| 157 | }) |
| 158 | }).await; |
| 159 | let client = &server.client; |
| 160 | |
| 161 | // Query information_schema.columns |
| 162 | let rows = client.query( |
| 163 | "SELECT table_name, column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_name = 'test_table' ORDER BY ordinal_position", |
| 164 | &[] |
| 165 | ).await.unwrap(); |
| 166 | |
| 167 | // Verify we got the expected number of columns |
| 168 | assert_eq!(rows.len(), 6, "Should have 6 columns"); |
| 169 | |
| 170 | // Check that we get the expected column names and types |
| 171 | let mut found_columns = std::collections::HashSet::new(); |
| 172 | for row in &rows { |
| 173 | let table_name: &str = row.get(0); |
| 174 | let column_name: &str = row.get(1); |
| 175 | let data_type: &str = row.get(2); |
| 176 | let is_nullable: &str = row.get(3); |
| 177 | |
| 178 | assert_eq!(table_name, "test_table"); |
| 179 | found_columns.insert(column_name.to_string()); |
| 180 | |
| 181 | match column_name { |
| 182 | "id" => { |
| 183 | assert_eq!(data_type, "integer"); |
| 184 | assert_eq!(is_nullable, "NO"); // PRIMARY KEY is NOT NULL |
| 185 | }, |
| 186 | "name" => { |
| 187 | assert_eq!(data_type, "character varying"); |
| 188 | assert_eq!(is_nullable, "NO"); // Explicitly NOT NULL |
| 189 | }, |
| 190 | "age" => { |
| 191 | assert_eq!(data_type, "integer"); |
| 192 | assert_eq!(is_nullable, "YES"); |
| 193 | }, |
| 194 | "salary" => { |
| 195 | assert_eq!(data_type, "numeric"); |
| 196 | assert_eq!(is_nullable, "YES"); |
| 197 | }, |
nothing calls this directly
no test coverage detected