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

Function sqlite3_expert_new

modules/dasSQLITE/sqlite/shell.c:12024–12080  ·  view source on GitHub ↗

** Allocate a new sqlite3expert object. */

Source from the content-addressed store, hash-verified

12022** Allocate a new sqlite3expert object.
12023*/
12024sqlite3expert *sqlite3_expert_new(sqlite3 *db, char **pzErrmsg){
12025 int rc = SQLITE_OK;
12026 sqlite3expert *pNew;
12027
12028 pNew = (sqlite3expert*)idxMalloc(&rc, sizeof(sqlite3expert));
12029
12030 /* Open two in-memory databases to work with. The "vtab database" (dbv)
12031 ** will contain a virtual table corresponding to each real table in
12032 ** the user database schema, and a copy of each view. It is used to
12033 ** collect information regarding the WHERE, ORDER BY and other clauses
12034 ** of the user's query.
12035 */
12036 if( rc==SQLITE_OK ){
12037 pNew->db = db;
12038 pNew->iSample = 100;
12039 rc = sqlite3_open(":memory:", &pNew->dbv);
12040 }
12041 if( rc==SQLITE_OK ){
12042 rc = sqlite3_open(":memory:", &pNew->dbm);
12043 if( rc==SQLITE_OK ){
12044 sqlite3_db_config(pNew->dbm, SQLITE_DBCONFIG_TRIGGER_EQP, 1, (int*)0);
12045 }
12046 }
12047
12048
12049 /* Copy the entire schema of database [db] into [dbm]. */
12050 if( rc==SQLITE_OK ){
12051 sqlite3_stmt *pSql = 0;
12052 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
12053 "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
12054 " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
12055 );
12056 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
12057 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
12058 if( zSql ) rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
12059 }
12060 idxFinalize(&rc, pSql);
12061 }
12062
12063 /* Create the vtab schema */
12064 if( rc==SQLITE_OK ){
12065 rc = idxCreateVtabSchema(pNew, pzErrmsg);
12066 }
12067
12068 /* Register the auth callback with dbv */
12069 if( rc==SQLITE_OK ){
12070 sqlite3_set_authorizer(pNew->dbv, idxAuthCallback, (void*)pNew);
12071 }
12072
12073 /* If an error has occurred, free the new object and reutrn NULL. Otherwise,
12074 ** return the new sqlite3expert handle. */
12075 if( rc!=SQLITE_OK ){
12076 sqlite3_expert_destroy(pNew);
12077 pNew = 0;
12078 }
12079 return pNew;
12080}
12081

Callers 1

expertDotCommandFunction · 0.85

Calls 6

idxMallocFunction · 0.85
idxPrintfPrepareStmtFunction · 0.85
sqlite3_execFunction · 0.85
idxFinalizeFunction · 0.85
idxCreateVtabSchemaFunction · 0.85
sqlite3_expert_destroyFunction · 0.85

Tested by

no test coverage detected