Handle information_schema.tables query
(&self, query: &str, session_id: &Uuid)
| 2637 | |
| 2638 | /// Handle information_schema.tables query |
| 2639 | async fn handle_information_schema_tables_query(&self, query: &str, session_id: &Uuid) -> Result<DbResponse, PgSqliteError> { |
| 2640 | debug!("Handling information_schema.tables query: {}", query); |
| 2641 | |
| 2642 | // Check if this is a simple table_name only query |
| 2643 | if query.contains("SELECT table_name") && !query.contains("table_catalog") { |
| 2644 | // Simple query - just return table names |
| 2645 | let tables_query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__pgsqlite_%' ORDER BY name"; |
| 2646 | |
| 2647 | return self.connection_manager.execute_with_session(session_id, |conn| { |
| 2648 | let mut stmt = conn.prepare(tables_query)?; |
| 2649 | let rows: Result<Vec<_>, _> = stmt.query_map([], |row| { |
| 2650 | let table_name: String = row.get(0)?; |
| 2651 | Ok(vec![Some(table_name.into_bytes())]) |
| 2652 | })?.collect(); |
| 2653 | |
| 2654 | Ok(DbResponse { |
| 2655 | columns: vec!["table_name".to_string()], |
| 2656 | rows: rows?, |
| 2657 | rows_affected: 0, |
| 2658 | }) |
| 2659 | }); |
| 2660 | } |
| 2661 | |
| 2662 | // Full information_schema.tables query |
| 2663 | let tables_query = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__pgsqlite_%' ORDER BY name"; |
| 2664 | |
| 2665 | self.connection_manager.execute_with_session(session_id, |conn| { |
| 2666 | let mut stmt = conn.prepare(tables_query)?; |
| 2667 | let rows: Result<Vec<_>, _> = stmt.query_map([], |row| { |
| 2668 | let table_name: String = row.get(0)?; |
| 2669 | // Return full information_schema.tables row |
| 2670 | Ok(vec![ |
| 2671 | Some("main".to_string().into_bytes()), // table_catalog |
| 2672 | Some("public".to_string().into_bytes()), // table_schema |
| 2673 | Some(table_name.into_bytes()), // table_name |
| 2674 | Some("BASE TABLE".to_string().into_bytes()), // table_type |
| 2675 | None, // self_referencing_column_name |
| 2676 | None, // reference_generation |
| 2677 | None, // user_defined_type_catalog |
| 2678 | None, // user_defined_type_schema |
| 2679 | None, // user_defined_type_name |
| 2680 | None, // is_insertable_into |
| 2681 | None, // is_typed |
| 2682 | None, // commit_action |
| 2683 | ]) |
| 2684 | })?.collect(); |
| 2685 | |
| 2686 | Ok(DbResponse { |
| 2687 | columns: vec![ |
| 2688 | "table_catalog".to_string(), |
| 2689 | "table_schema".to_string(), |
| 2690 | "table_name".to_string(), |
| 2691 | "table_type".to_string(), |
| 2692 | "self_referencing_column_name".to_string(), |
| 2693 | "reference_generation".to_string(), |
| 2694 | "user_defined_type_catalog".to_string(), |
| 2695 | "user_defined_type_schema".to_string(), |
| 2696 | "user_defined_type_name".to_string(), |
no test coverage detected