/* ** Retrieve the current rowid. */ static int schemaRowid(sqlite3_vtab_cursor cur, out sqlite_int64 pRowid) { schema_cursor pCur = (schema_cursor)cur; pRowid = pCur.rowid; return(SQLITE_OK); }
/* ** Close a schema table cursor. */ static int schemaClose(ref sqlite3_vtab_cursor cur) { schema_cursor pCur = (schema_cursor)cur; sqlite3_finalize(pCur.pDbList); sqlite3_finalize(pCur.pTableList); sqlite3_finalize(pCur.pColumnList); //sqlite3_free( pCur ); cur = null;// return(SQLITE_OK); }
/* ** Open a new cursor on the schema table. */ static int schemaOpen(sqlite3_vtab pVTab, out sqlite3_vtab_cursor ppCursor) { int rc = SQLITE_NOMEM; schema_cursor pCur; pCur = new schema_cursor();//pCur = sqlite3_malloc(sizeof(schema_cursor)); //if ( pCur != null ) //{ //memset(pCur, 0, sizeof(schema_cursor)); ppCursor = (sqlite3_vtab_cursor)pCur; rc = SQLITE_OK; //} return(rc); }
/* ** Reset a schema table cursor. */ static int schemaFilter( sqlite3_vtab_cursor pVtabCursor, int idxNum, string idxStr, int argc, sqlite3_value[] argv ) { int rc; schema_vtab pVtab = (schema_vtab)(pVtabCursor.pVtab); schema_cursor pCur = (schema_cursor)pVtabCursor; pCur.rowid = 0; finalize(ref pCur.pTableList); finalize(ref pCur.pColumnList); finalize(ref pCur.pDbList); rc = sqlite3_prepare(pVtab.db, "PRAGMA database_list", -1, ref pCur.pDbList, 0); return(rc == SQLITE_OK ? schemaNext(pVtabCursor) : rc); }
/* ** Retrieve a column of data. */ static int schemaColumn(sqlite3_vtab_cursor cur, sqlite3_context ctx, int i) { schema_cursor pCur = (schema_cursor)cur; switch (i) { case 0: sqlite3_result_value(ctx, sqlite3_column_value(pCur.pDbList, 1)); break; case 1: sqlite3_result_value(ctx, sqlite3_column_value(pCur.pTableList, 0)); break; default: sqlite3_result_value(ctx, sqlite3_column_value(pCur.pColumnList, i - 2)); break; } return(SQLITE_OK); }
/* ** Advance the cursor to the next row. */ static int schemaNext(sqlite3_vtab_cursor cur) { int rc = SQLITE_OK; schema_cursor pCur = (schema_cursor)cur; schema_vtab pVtab = (schema_vtab)(cur.pVtab); string zSql = null; while (null == pCur.pColumnList || SQLITE_ROW != sqlite3_step(pCur.pColumnList)) { if (SQLITE_OK != (rc = finalize(ref pCur.pColumnList))) { goto next_exit; } while (null == pCur.pTableList || SQLITE_ROW != sqlite3_step(pCur.pTableList)) { if (SQLITE_OK != (rc = finalize(ref pCur.pTableList))) { goto next_exit; } Debug.Assert(pCur.pDbList != null); while (SQLITE_ROW != sqlite3_step(pCur.pDbList)) { rc = finalize(ref pCur.pDbList); goto next_exit; } /* Set zSql to the SQL to pull the list of tables from the ** sqlite_master (or sqlite_temp_master) table of the database ** identfied by the row pointed to by the SQL statement pCur.pDbList ** (iterating through a "PRAGMA database_list;" statement). */ if (sqlite3_column_int(pCur.pDbList, 0) == 1) { zSql = sqlite3_mprintf( "SELECT name FROM sqlite_temp_master WHERE type='table'" ); } else { sqlite3_stmt pDbList = pCur.pDbList; zSql = sqlite3_mprintf( "SELECT name FROM %Q.sqlite_master WHERE type='table'", sqlite3_column_text(pDbList, 1) ); } //if( !zSql ){ // rc = SQLITE_NOMEM; // goto next_exit; //} rc = sqlite3_prepare(pVtab.db, zSql, -1, ref pCur.pTableList, 0); //sqlite3_free(zSql); if (rc != SQLITE_OK) { goto next_exit; } } /* Set zSql to the SQL to the table_info pragma for the table currently ** identified by the rows pointed to by statements pCur.pDbList and ** pCur.pTableList. */ zSql = sqlite3_mprintf("PRAGMA %Q.table_info(%Q)", sqlite3_column_text(pCur.pDbList, 1), sqlite3_column_text(pCur.pTableList, 0) ); //if( !Sql ){ // rc = SQLITE_NOMEM; // goto next_exit; //} rc = sqlite3_prepare(pVtab.db, zSql, -1, ref pCur.pColumnList, 0); //sqlite3_free(zSql); if (rc != SQLITE_OK) { goto next_exit; } } pCur.rowid++; next_exit: /* TODO: Handle rc */ return(rc); }
static int schemaEof(sqlite3_vtab_cursor cur) { schema_cursor pCur = (schema_cursor)cur; return(pCur.pDbList != null ? 0 : 1); }
/* ** Open a new cursor on the schema table. */ static int schemaOpen( sqlite3_vtab pVTab, out sqlite3_vtab_cursor ppCursor ) { int rc = SQLITE_NOMEM; schema_cursor pCur; pCur = new schema_cursor();//pCur = sqlite3_malloc(sizeof(schema_cursor)); //if ( pCur != null ) //{ //memset(pCur, 0, sizeof(schema_cursor)); ppCursor = (sqlite3_vtab_cursor)pCur; rc = SQLITE_OK; //} return rc; }