Пример #1
0
        /*
        ** 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);
        }
Пример #2
0
        /*
        ** Table constructor for the schema module.
        */
        static int schemaCreate(
            sqlite3 db,
            object pAux,
            int argc,
            string[] argv,
            out sqlite3_vtab ppVtab,
            out string pzErr
            )
        {
            int         rc    = SQLITE_NOMEM;
            schema_vtab pVtab = new schema_vtab();//sqlite3_malloc(sizeof(schema_vtab));

            if (pVtab != null)
            {
                //memset(pVtab, 0, sizeof(schema_vtab));
                pVtab.db = db;
#if !SQLITE_OMIT_VIRTUALTABLE
                rc = sqlite3_declare_vtab(db, SCHEMA);
#endif
            }
            ppVtab = (sqlite3_vtab)pVtab;
            pzErr  = "";
            return(rc);
        }
Пример #3
0
        /*
        ** 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);
        }
    /*
    ** Table constructor for the schema module.
    */
    static int schemaCreate(
      sqlite3 db,
      object pAux,
      int argc,
      string[] argv,
      out sqlite3_vtab ppVtab,
      out string pzErr
    )
    {
      int rc = SQLITE_NOMEM;
      schema_vtab pVtab = new schema_vtab();//sqlite3_malloc(sizeof(schema_vtab));
      if ( pVtab != null )
      {
        //memset(pVtab, 0, sizeof(schema_vtab));
        pVtab.db = db;
#if !SQLITE_OMIT_VIRTUALTABLE
        rc = sqlite3_declare_vtab( db, SCHEMA );
#endif
      }
      ppVtab = (sqlite3_vtab)pVtab;
      pzErr = "";
      return rc;
    }