MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / shellFakeSchema

Function shellFakeSchema

modules/dasSQLITE/sqlite/shell.c:1016–1058  ·  view source on GitHub ↗

** Construct a fake object name and column list to describe the structure ** of the view, virtual table, or table valued function zSchema.zName. */

Source from the content-addressed store, hash-verified

1014** of the view, virtual table, or table valued function zSchema.zName.
1015*/
1016static char *shellFakeSchema(
1017 sqlite3 *db, /* The database connection containing the vtab */
1018 const char *zSchema, /* Schema of the database holding the vtab */
1019 const char *zName /* The name of the virtual table */
1020){
1021 sqlite3_stmt *pStmt = 0;
1022 char *zSql;
1023 ShellText s;
1024 char cQuote;
1025 char *zDiv = "(";
1026 int nRow = 0;
1027
1028 zSql = sqlite3_mprintf("PRAGMA \"%w\".table_info=%Q;",
1029 zSchema ? zSchema : "main", zName);
1030 shell_check_oom(zSql);
1031 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
1032 sqlite3_free(zSql);
1033 initText(&s);
1034 if( zSchema ){
1035 cQuote = quoteChar(zSchema);
1036 if( cQuote && sqlite3_stricmp(zSchema,"temp")==0 ) cQuote = 0;
1037 appendText(&s, zSchema, cQuote);
1038 appendText(&s, ".", 0);
1039 }
1040 cQuote = quoteChar(zName);
1041 appendText(&s, zName, cQuote);
1042 while( sqlite3_step(pStmt)==SQLITE_ROW ){
1043 const char *zCol = (const char*)sqlite3_column_text(pStmt, 1);
1044 nRow++;
1045 appendText(&s, zDiv, 0);
1046 zDiv = ",";
1047 if( zCol==0 ) zCol = "";
1048 cQuote = quoteChar(zCol);
1049 appendText(&s, zCol, cQuote);
1050 }
1051 appendText(&s, ")", 0);
1052 sqlite3_finalize(pStmt);
1053 if( nRow==0 ){
1054 freeText(&s);
1055 s.z = 0;
1056 }
1057 return s.z;
1058}
1059
1060/*
1061** SQL function: shell_module_schema(X)

Callers 2

shellModuleSchemaFunction · 0.85
shellAddSchemaNameFunction · 0.85

Calls 5

shell_check_oomFunction · 0.85
initTextFunction · 0.85
quoteCharFunction · 0.85
appendTextFunction · 0.85
freeTextFunction · 0.85

Tested by

no test coverage detected