コード例 #1
0
    public bool Step()
    {
        switch (Sqlite3.sqlite3_step(vm))
        {
        case Sqlite3.SQLITE_DONE: return(false);

        case Sqlite3.SQLITE_ROW:
        {
            int columnCount = Sqlite3.sqlite3_column_count(vm);
            columnNames = new string[columnCount];
            columnTypes = new int[columnCount];

            try
            {
                // reads columns one by one
                for (int i = 0; i < columnCount; i++)
                {
                    columnNames[i] = Sqlite3.sqlite3_column_name(vm, i);
                    columnTypes[i] = Sqlite3.sqlite3_column_type(vm, i);
                }
            }
            catch
            {
                throw new Exception("SQLite fail to read column's names and types! error: " + Sqlite3.sqlite3_errmsg(db));
            }

            return(true);
        }
        }
        throw new Exception("SQLite step fail! error: " + Sqlite3.sqlite3_errmsg(db));
    }
コード例 #2
0
    public void Reset()
    {
        bindIndex = 1;

        if (Sqlite3.sqlite3_reset(vm) != Sqlite3.SQLITE_OK)
        {
            throw new Exception("Error with sqlite3_reset!");
        }
        ;
    }
コード例 #3
0
    public byte[] GetBlob(string field)
    {
        int i = GetFieldIndex(field);

        if (Sqlite3.SQLITE_BLOB == columnTypes[i])
        {
            return(Sqlite3.sqlite3_column_blob(vm, i));
        }

        throw new Exception("SQLite wrong field type (expecting byte[]) : " + field);
    }
コード例 #4
0
    public float GetFloat(string field)
    {
        int i = GetFieldIndex(field);

        if (Sqlite3.SQLITE_FLOAT == columnTypes[i])
        {
            return((float)Sqlite3.sqlite3_column_double(vm, i));
        }

        throw new Exception("SQLite wrong field type (expecting Double) : " + field);
    }
コード例 #5
0
    public DateTime GetDateTime(string field)
    {
        int i = GetFieldIndex(field);

        if (Sqlite3.SQLITE_INTEGER == columnTypes[i])
        {
            return(DateTime.FromBinary(Sqlite3.sqlite3_column_int64(vm, i)));
        }

        throw new Exception("SQLite wrong field type (expecting Integer) : " + field);
    }
コード例 #6
0
    public long GetLong(string field)
    {
        int i = GetFieldIndex(field);

        if (Sqlite3.SQLITE_INTEGER == columnTypes[i])
        {
            return(Sqlite3.sqlite3_column_int64(vm, i));
        }

        throw new Exception("SQLite wrong field type (expecting Integer) : " + field);
    }
コード例 #7
0
 public void BindNullAt(int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_null(vm, bindAt) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind null error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
コード例 #8
0
 public void BindAt(DateTime time, int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_int64(vm, bindAt, time.ToBinary()) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind double with error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
コード例 #9
0
 public void BindAt(double real, int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_double(vm, bindAt, real) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind double with error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
コード例 #10
0
 public void BindAt(long integer, int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_int64(vm, bindAt, integer) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind long with error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
コード例 #11
0
    public string GetString(string field)
    {
        int i = GetFieldIndex(field);

        if (Sqlite3.SQLITE_TEXT == columnTypes [i])
        {
            return(Sqlite3.sqlite3_column_text16(vm, i));
        }
        else if (Sqlite3.SQLITE_NULL == columnTypes [i])
        {
            return(null);
        }

        throw new Exception("SQLite wrong field type (expecting String) : " + field);
    }
コード例 #12
0
    public void Release()
    {
        SqlDb.UnregisterQuery(this);

        if (Sqlite3.sqlite3_reset(vm) != Sqlite3.SQLITE_OK)
        {
            throw new Exception("Error with sqlite3_reset!");
        }
        ;

        if (Sqlite3.sqlite3_finalize(vm) != Sqlite3.SQLITE_OK)
        {
            throw new Exception("Error with sqlite3_finalize!");
        }
        ;
    }
コード例 #13
0
 public void BindAt(string str, int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_text16(vm, bindAt, str, -1,
                     #if !SQLITE_NATIVE
                                     null
                     #else
                                     IntPtr.Zero
                     #endif
                                     ) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind string with error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
コード例 #14
0
 public SQLiteQuery(SQLiteDB sqliteDb, string query)
 {
     SqlDb     = sqliteDb;
     bindIndex = 1;
     db        = sqliteDb.Connection();
     if (Sqlite3.sqlite3_prepare16_v2(db, query, -1, ref vm,
                     #if !SQLITE_NATIVE
                                      0
                     #else
                                      IntPtr.Zero
                     #endif
                                      ) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("Error with prepare query! error:" + Sqlite3.sqlite3_errmsg(db));
     }
     ;
     SqlDb.RegisterQuery(this);
 }
コード例 #15
0
 public void BindAt(byte[] blob, int bindAt)
 {
     if (bindAt == -1)
     {
         bindAt = bindIndex++;
     }
     if (Sqlite3.sqlite3_bind_blob(vm, bindAt, blob, blob.Length,
                     #if !SQLITE_NATIVE
                                   null
                     #else
                                   IntPtr.Zero
                     #endif
                                   ) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("SQLite fail to bind blob with error: " + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }