MCPcopy Create free account
hub / github.com/erans/pgsqlite / register_catalog_functions

Function register_catalog_functions

src/functions/catalog_functions.rs:5–51  ·  view source on GitHub ↗

Register PostgreSQL catalog-related functions

(conn: &Connection)

Source from the content-addressed store, hash-verified

3
4/// Register PostgreSQL catalog-related functions
5pub fn register_catalog_functions(conn: &Connection) -> Result<()> {
6 debug!("Registering catalog functions");
7
8 // pg_table_is_visible(oid) - checks if table is in search path
9 // For SQLite, all tables are visible
10 conn.create_scalar_function(
11 "pg_table_is_visible",
12 1,
13 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
14 |ctx| {
15 // Accept either integer or text OID
16 // Try to get as i64 first, if that fails try as string and parse
17 let _oid = match ctx.get::<i64>(0) {
18 Ok(oid) => oid,
19 Err(_) => {
20 // Try as string
21 let oid_str: String = ctx.get(0)?;
22 oid_str.parse::<i64>().unwrap_or(0)
23 }
24 };
25 // In SQLite, all tables are visible
26 // Return 1 for true (SQLite boolean convention)
27 Ok(1i32)
28 },
29 )?;
30
31 // Note: SQLite doesn't support schema-qualified function names,
32 // so we handle pg_catalog.pg_table_is_visible through query rewriting
33
34 // regclass type cast function
35 conn.create_scalar_function(
36 "regclass",
37 1,
38 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
39 |ctx| {
40 let table_name: String = ctx.get(0)?;
41
42 // Look up table OID from pg_class view
43 // For now, just generate a consistent OID
44 let oid = generate_table_oid(&table_name);
45 Ok(oid)
46 },
47 )?;
48
49 debug!("Catalog functions registered successfully");
50 Ok(())
51}
52
53// Generate a stable OID from table name
54fn generate_table_oid(name: &str) -> i32 {

Callers 3

test_pg_table_is_visibleFunction · 0.85
test_regclass_castFunction · 0.85
register_all_functionsFunction · 0.85

Calls 2

generate_table_oidFunction · 0.70
getMethod · 0.45

Tested by 2

test_pg_table_is_visibleFunction · 0.68
test_regclass_castFunction · 0.68