Register PostgreSQL system information functions
(conn: &Connection)
| 3 | |
| 4 | /// Register PostgreSQL system information functions |
| 5 | pub fn register_system_functions(conn: &Connection) -> Result<()> { |
| 6 | debug!("Registering system functions"); |
| 7 | |
| 8 | // version() - Returns PostgreSQL version string |
| 9 | conn.create_scalar_function( |
| 10 | "version", |
| 11 | 0, |
| 12 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 13 | |_ctx| { |
| 14 | // Return a PostgreSQL-compatible version string |
| 15 | // This format is what SQLAlchemy expects to parse |
| 16 | Ok(format!("PostgreSQL 16.0 (pgsqlite {}) on x86_64-pc-linux-gnu, compiled by rustc, 64-bit", |
| 17 | env!("CARGO_PKG_VERSION"))) |
| 18 | }, |
| 19 | )?; |
| 20 | |
| 21 | // current_database() - Returns the current database name |
| 22 | conn.create_scalar_function( |
| 23 | "current_database", |
| 24 | 0, |
| 25 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 26 | |_ctx| { |
| 27 | // In SQLite, we'll return "main" as the database name |
| 28 | Ok("main".to_string()) |
| 29 | }, |
| 30 | )?; |
| 31 | |
| 32 | // current_schema() - Returns the current schema name |
| 33 | conn.create_scalar_function( |
| 34 | "current_schema", |
| 35 | 0, |
| 36 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 37 | |_ctx| { |
| 38 | // SQLite doesn't have schemas, return "public" for PostgreSQL compatibility |
| 39 | Ok("public".to_string()) |
| 40 | }, |
| 41 | )?; |
| 42 | |
| 43 | // current_schemas(include_implicit) - Returns array of schemas in search path |
| 44 | conn.create_scalar_function( |
| 45 | "current_schemas", |
| 46 | 1, |
| 47 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 48 | |ctx| { |
| 49 | let include_implicit: bool = ctx.get(0)?; |
| 50 | if include_implicit { |
| 51 | // Include system schemas |
| 52 | Ok(r#"["pg_catalog","public"]"#.to_string()) |
| 53 | } else { |
| 54 | // Just user schemas |
| 55 | Ok(r#"["public"]"#.to_string()) |
| 56 | } |
| 57 | }, |
| 58 | )?; |
| 59 | |
| 60 | // current_user() - Returns the current user name |
| 61 | conn.create_scalar_function( |
| 62 | "current_user", |