Esempio n. 1
0
            public void commit()
            {
                checkThread(); checkConnection();

                if (inTransaction)
                {
                    sqlite3_stmt statement = null;
                    string       tail      = null;
                    int          rc        = Sqlite3.sqlite3_prepare(this.db, "COMMIT", -1, ref statement, ref tail);
                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        throw GetSqliteError(this.db, null);
                    }

                    rc = Util.Step(statement);
                    if (rc == Sqlite3.SQLITE_DONE)
                    {
                        this.inTransaction = false;
                    }
                    else
                    {
                        throw GetSqliteError(this.db, statement);
                    }

                    rc = Sqlite3.sqlite3_finalize(statement);
                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        GetSqliteError(this.db, null);
                    }
                }
            }
Esempio n. 2
0
            internal void begin()
            {
                sqlite3_stmt statement = null;
                string       tail      = null;
                int          rc        = Sqlite3.sqlite3_prepare(this.db, this.begin_statement, -1, ref statement, ref tail);

                if (rc != Sqlite3.SQLITE_OK)
                {
                    throw GetSqliteError(this.db, statement);
                }

                rc = Util.Step(statement);
                if (rc == Sqlite3.SQLITE_DONE)
                {
                    this.inTransaction = true;
                }
                else
                {
                    throw GetSqliteError(this.db, statement);
                }

                rc = Sqlite3.sqlite3_finalize(statement);
                if (rc != Sqlite3.SQLITE_OK)
                {
                    GetSqliteError(this.db, null);
                }
            }
Esempio n. 3
0
            public void rollback()
            {
                checkThread(); checkConnection();

                if (inTransaction)
                {
                    doAllStatements(AllStatmentsAction.Reset);

                    sqlite3_stmt statement = null;
                    string       tail      = null;
                    int          rc        = Sqlite3.sqlite3_prepare(this.db, "ROLLBACK", -1, ref statement, ref tail);
                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        throw GetSqliteError(this.db, null);
                    }

                    rc = Util.Step(statement);
                    if (rc == Sqlite3.SQLITE_DONE)
                    {
                        this.inTransaction = false;
                    }
                    else
                    {
                        throw GetSqliteError(this.db, statement);
                    }

                    rc = Sqlite3.sqlite3_finalize(statement);
                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        GetSqliteError(this.db, null);
                    }
                }
            }
Esempio n. 4
0
            public Cursor executescript(string operation)
            {
                connection.checkThread(); connection.checkConnection();

                this.connection.commit();

                sqlite3_stmt statement           = null;
                string       script              = operation;
                bool         statement_completed = false;

                while (true)
                {
                    if (Sqlite3.sqlite3_complete(operation) == 0)
                    {
                        break;
                    }
                    statement_completed = true;

                    int rc = Sqlite3.sqlite3_prepare(this.connection.db,
                                                     operation,
                                                     -1,
                                                     ref statement,
                                                     ref script);

                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        throw GetSqliteError(this.connection.db, null);
                    }

                    /* execute statement, and ignore results of SELECT statements */
                    rc = Sqlite3.SQLITE_ROW;
                    while (rc == Sqlite3.SQLITE_ROW)
                    {
                        rc = Sqlite3.sqlite3_step(statement);
                    }

                    if (rc != Sqlite3.SQLITE_DONE)
                    {
                        Sqlite3.sqlite3_finalize(statement);
                        throw GetSqliteError(this.connection.db, null);
                    }

                    rc = Sqlite3.sqlite3_finalize(statement);
                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        throw GetSqliteError(this.connection.db, null);
                    }
                }

                if (!statement_completed)
                {
                    throw MakeProgrammingError("you did not provide a complete SQL statement");
                }

                return(this);
            }
Esempio n. 5
0
        public static int BindBlob(Sqlite3Statement stmt, int index, byte[] val, int n, IntPtr free)
        {
#if USE_WP8_NATIVE_SQLITE
            return(Sqlite3.sqlite3_bind_blob(stmt, index, val, n));
#elif USE_SQLITEPCL_RAW
            return(Sqlite3.sqlite3_bind_blob(stmt, index, val));
#else
            return(Sqlite3.sqlite3_bind_blob(stmt, index, val, n, null));
#endif
        }
Esempio n. 6
0
        private Statement(Sqlite3.sqlite3 db, sqlite3_stmt stmt, string operation, string tail)
        {
            this.uniqueid = Guid.NewGuid();

            this.db = db;
            this.sql = operation;

            this.st = stmt;
            this.Tail = tail;
        }
Esempio n. 7
0
        private Statement(Sqlite3.sqlite3 db, sqlite3_stmt stmt, string operation, string tail)
        {
            this.uniqueid = Guid.NewGuid();

            this.db  = db;
            this.sql = operation;

            this.st   = stmt;
            this.Tail = tail;
        }
Esempio n. 8
0
        public static int BindText(Sqlite3Statement stmt, int index, string val, int n, IntPtr free)
        {
#if USE_WP8_NATIVE_SQLITE
            return(Sqlite3.sqlite3_bind_text(stmt, index, val, n));
#elif USE_SQLITEPCL_RAW
            return(Sqlite3.sqlite3_bind_text(stmt, index, val));
#else
            return(Sqlite3.sqlite3_bind_text(stmt, index, val, n, null));
#endif
        }
        public static int sqlite3_prepare(
            SqliteConnectionHandle connection, string sql, int sqlLength,
            out SqliteStatementHandle statement, out string remainingSql)
        {
            Community.CsharpSqlite.Sqlite3.Vdbe stmt = null;
            string remSql = null;
            var    result = Community.CsharpSqlite.Sqlite3.sqlite3_prepare(connection.Handle, sql, sqlLength, ref stmt, ref remSql);

            statement    = new SqliteStatementHandle(stmt);
            remainingSql = remSql;
            return(result);
        }
Esempio n. 10
0
        public int SqliteFinalize()
        {
            int rc = Sqlite3.SQLITE_OK;

            if (this.st != null)
            {
                rc      = Sqlite3.sqlite3_finalize(this.st);
                this.st = null;
            }

            this.in_use = false;

            return(rc);
        }
 private void Dispose(bool disposing)
 {
     if (Statement != NullStatement)
     {
         try
         {
             SQLite3.Finalize(Statement);
         }
         finally
         {
             Statement  = NullStatement;
             Connection = null;
         }
     }
 }
Esempio n. 12
0
        public static Sqlite3Statement Prepare2(Sqlite3DatabaseHandle db, string query)
        {
            Sqlite3Statement stmt = default(Sqlite3Statement);

#if USE_WP8_NATIVE_SQLITE || USE_SQLITEPCL_RAW
            var r = Sqlite3.sqlite3_prepare_v2(db, query, out stmt);
#else
            stmt = new Sqlite3Statement();
            var r = Sqlite3.sqlite3_prepare_v2(db, query, -1, ref stmt, 0);
#endif
            if (r != 0)
            {
                throw SQLiteException.New((Result)r, GetErrmsg(db));
            }
            return(stmt);
        }
Esempio n. 13
0
        internal int Recompile(CodeContext context, object parameters)
        {
            sqlite3_stmt new_st = null;
            string       tail   = null;

            int rc = Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref new_st, ref tail);

            if (rc == Sqlite3.SQLITE_OK)
            {
                Statement new_stmt = new Statement(this.st.db, new_st, this.sql, tail);
                new_stmt.BindParameters(context, parameters);

                Sqlite3.sqlite3_finalize(this.st);
                this.st = new_st;
            }

            return(rc);
        }
Esempio n. 14
0
        public Statement(PythonSQLite.Connection connection, string operation)
        {
            this.uniqueid = Guid.NewGuid();

            this.db = connection.db;
            this.sql = operation;

            this.st = null;
            string tail = null;
            if(Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */)
            {
                Sqlite3.sqlite3_finalize(st);
                this.st = null;
                throw PythonSQLite.GetSqliteError(this.db, null);
            }

            this.Tail = tail;
        }
Esempio n. 15
0
        void BindAll(Sqlite3Statement stmt)
        {
            int nextIdx = 1;

            foreach (var b in _bindings)
            {
                if (b.Name != null)
                {
                    b.Index = SQLite3.BindParameterIndex(stmt, b.Name);
                }
                else
                {
                    b.Index = nextIdx++;
                }

                BindParameter(stmt, b.Index, b.Value, _conn.StoreDateTimeAsTicks);
            }
        }
Esempio n. 16
0
        public Statement(PythonSQLite.Connection connection, string operation)
        {
            this.uniqueid = Guid.NewGuid();

            this.db  = connection.db;
            this.sql = operation;

            this.st = null;
            string tail = null;

            if (Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */)
            {
                Sqlite3.sqlite3_finalize(st);
                this.st = null;
                throw PythonSQLite.GetSqliteError(this.db, null);
            }

            this.Tail = tail;
        }
        public int ExecuteNonQuery(object[] source)
        {
            if (Connection.Trace)
            {
                Debug.WriteLine("Executing: " + CommandText);
            }

            var r = SQLite3.Result.OK;

            if (!Initialized)
            {
                Statement   = Prepare();
                Initialized = true;
            }

            //bind the values.
            if (source != null)
            {
                for (int i = 0; i < source.Length; i++)
                {
                    SQLiteCommand.BindParameter(Statement, i + 1, source[i], Connection.StoreDateTimeAsTicks);
                }
            }
            r = SQLite3.Step(Statement);

            if (r == SQLite3.Result.Done)
            {
                int rowsAffected = SQLite3.Changes(Connection.Handle);
                SQLite3.Reset(Statement);
                return(rowsAffected);
            }
            else if (r == SQLite3.Result.Error)
            {
                string msg = SQLite3.GetErrmsg(Connection.Handle);
                SQLite3.Reset(Statement);
                throw SQLiteException.New(r, msg);
            }
            else
            {
                SQLite3.Reset(Statement);
                throw SQLiteException.New(r, r.ToString());
            }
        }
Esempio n. 18
0
 public static byte[] ColumnByteArray(Sqlite3Statement stmt, int index)
 {
     return(ColumnBlob(stmt, index));
 }
Esempio n. 19
0
 public static string ColumnString(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_text(stmt, index));
 }
Esempio n. 20
0
 public static int ColumnBytes(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_bytes(stmt, index));
 }
Esempio n. 21
0
 public static int BindDouble(Sqlite3Statement stmt, int index, double val)
 {
     return(Sqlite3.sqlite3_bind_double(stmt, index, val));
 }
Esempio n. 22
0
        internal int Recompile(CodeContext context, object parameters)
        {
            sqlite3_stmt new_st = null;
            string tail = null;

            int rc = Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref new_st, ref tail);
            if(rc == Sqlite3.SQLITE_OK)
            {
                Statement new_stmt = new Statement(this.st.db, new_st, this.sql, tail);
                new_stmt.BindParameters(context, parameters);

                Sqlite3.sqlite3_finalize(this.st);
                this.st = new_st;
            }

            return rc;
        }
Esempio n. 23
0
 public static long ColumnInt64(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_int64(stmt, index));
 }
Esempio n. 24
0
 public static int ColumnInt(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_int(stmt, index));
 }
Esempio n. 25
0
 public static ColType ColumnType(Sqlite3Statement stmt, int index)
 {
     return((ColType)Sqlite3.sqlite3_column_type(stmt, index));
 }
Esempio n. 26
0
 public static Result Finalize(Sqlite3Statement stmt)
 {
     return((Result)Sqlite3.sqlite3_finalize(stmt));
 }
Esempio n. 27
0
 public BBSQLStatement()
 {
     stmt = null;
     sqlite = null;
 }
Esempio n. 28
0
 public static int BindParameterIndex(Sqlite3Statement stmt, string name)
 {
     return(Sqlite3.sqlite3_bind_parameter_index(stmt, name));
 }
Esempio n. 29
0
 public static int BindNull(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_bind_null(stmt, index));
 }
Esempio n. 30
0
 public static double ColumnDouble(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_double(stmt, index));
 }
Esempio n. 31
0
        public int SqliteFinalize()
        {
            int rc = Sqlite3.SQLITE_OK;

            if(this.st != null)
            {
                rc = Sqlite3.sqlite3_finalize(this.st);
                this.st = null;
            }

            this.in_use = false;

            return rc;
        }
Esempio n. 32
0
 public static byte[] ColumnBlob(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_blob(stmt, index));
 }
Esempio n. 33
0
 public static string ColumnName16(Sqlite3Statement stmt, int index)
 {
     return(Sqlite3.sqlite3_column_name(stmt, index));
 }
Esempio n. 34
0
 public static int BindInt64(Sqlite3Statement stmt, int index, long val)
 {
     return(Sqlite3.sqlite3_bind_int64(stmt, index, val));
 }
Esempio n. 35
0
 public static int ColumnCount(Sqlite3Statement stmt)
 {
     return(Sqlite3.sqlite3_column_count(stmt));
 }
Esempio n. 36
0
 public void Dispose()
 {
     if( stmt != null )
     {
         int ret = Community.CsharpSqlite.Sqlite3.sqlite3_finalize(stmt);
         stmt = null;
     }
 }