(
framed: &mut Framed<T, crate::protocol::PostgresCodec>,
db: &Arc<DbHandler>,
session: &Arc<SessionState>,
query: &str,
)
| 5452 | } |
| 5453 | |
| 5454 | async fn execute_ddl<T>( |
| 5455 | framed: &mut Framed<T, crate::protocol::PostgresCodec>, |
| 5456 | db: &Arc<DbHandler>, |
| 5457 | session: &Arc<SessionState>, |
| 5458 | query: &str, |
| 5459 | ) -> Result<(), PgSqliteError> |
| 5460 | where |
| 5461 | T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin, |
| 5462 | { |
| 5463 | use crate::ddl::EnumDdlHandler; |
| 5464 | |
| 5465 | // Check if this is an ENUM DDL statement first |
| 5466 | if EnumDdlHandler::is_enum_ddl(query) { |
| 5467 | // ENUM DDL needs special handling through direct SQL execution |
| 5468 | // Parse and execute the ENUM DDL as SQL statements |
| 5469 | let enum_error = PgSqliteError::Protocol( |
| 5470 | "ENUM DDL is not supported in the current per-session connection mode. \ |
| 5471 | Please create ENUMs before establishing connections.".to_string() |
| 5472 | ); |
| 5473 | return Err(enum_error); |
| 5474 | } |
| 5475 | |
| 5476 | // Handle CREATE TABLE translation |
| 5477 | if query_starts_with_ignore_case(query, "CREATE TABLE") { |
| 5478 | // Use translator with connection for ENUM support |
| 5479 | let (sqlite_sql, type_mappings, enum_columns, array_columns) = db.with_session_connection(&session.id, |conn| { |
| 5480 | let result = crate::translator::CreateTableTranslator::translate_with_connection_full(query, Some(conn)) |
| 5481 | .map_err(|e| rusqlite::Error::SqliteFailure( |
| 5482 | rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR), |
| 5483 | Some(format!("CREATE TABLE translation failed: {e}")) |
| 5484 | ))?; |
| 5485 | |
| 5486 | Ok((result.sql, result.type_mappings, result.enum_columns, result.array_columns)) |
| 5487 | }).await |
| 5488 | .map_err(|e| PgSqliteError::Protocol(format!("Failed to translate CREATE TABLE: {e}")))?; |
| 5489 | |
| 5490 | // Execute the translated CREATE TABLE |
| 5491 | let cached_conn = Self::get_or_cache_connection(session, db).await; |
| 5492 | db.execute_with_session_cached(&sqlite_sql, &session.id, cached_conn.as_ref()).await?; |
| 5493 | |
| 5494 | // Store the type mappings if we have any |
| 5495 | debug!("Type mappings count: {}", type_mappings.len()); |
| 5496 | if !type_mappings.is_empty() { |
| 5497 | // Extract table name from query |
| 5498 | if let Some(table_name) = extract_table_name_from_create(query) { |
| 5499 | // Initialize the metadata table if it doesn't exist |
| 5500 | let init_query = "CREATE TABLE IF NOT EXISTS __pgsqlite_schema ( |
| 5501 | table_name TEXT NOT NULL, |
| 5502 | column_name TEXT NOT NULL, |
| 5503 | pg_type TEXT NOT NULL, |
| 5504 | sqlite_type TEXT NOT NULL, |
| 5505 | PRIMARY KEY (table_name, column_name) |
| 5506 | )"; |
| 5507 | let cached_conn = Self::get_or_cache_connection(session, db).await; |
| 5508 | let _ = db.execute_with_session_cached(init_query, &session.id, cached_conn.as_ref()).await; |
| 5509 | |
| 5510 | // Store each type mapping and numeric constraints |
| 5511 | for (full_column, type_mapping) in type_mappings { |
nothing calls this directly
no test coverage detected