MCPcopy Create free account
hub / github.com/duckdb/duckdb / getTableSchema

Function getTableSchema

tools/shell/shell.cpp:1061–1076  ·  view source on GitHub ↗

** Lookup the schema for a table using the information schema. */

Source from the content-addressed store, hash-verified

1059** Lookup the schema for a table using the information schema.
1060*/
1061static string getTableSchema(duckdb::Connection &con, const char *zTable) {
1062 string zSchema;
1063 auto zSql = StringUtil::Format("SELECT table_schema FROM information_schema.tables "
1064 "WHERE table_name = %s AND table_type='BASE TABLE' "
1065 "ORDER BY (table_schema='main') DESC LIMIT 1",
1066 SQLString(zTable));
1067
1068 auto query_result = con.Query(zSql);
1069 if (query_result->HasError()) {
1070 return zSchema;
1071 }
1072 for (auto &row : *query_result) {
1073 zSchema = row.GetValue<string>(0);
1074 }
1075 return zSchema;
1076}
1077
1078/*
1079** Build a qualified name: schema.table

Callers 1

RunSchemaDumpQueryMethod · 0.85

Calls 3

SQLStringClass · 0.85
QueryMethod · 0.45
HasErrorMethod · 0.45

Tested by

no test coverage detected