Ejemplo n.º 1
0
        public int ExecuteNonQuery()
        {
            if (_conn.Trace)
            {
                Debug.WriteLine("Executing: " + this);
            }

            var r    = SQLite3.Result.OK;
            var stmt = Prepare();

            r = SQLite3.Step(stmt);
            Finalize(stmt);
            if (r == SQLite3.Result.Done)
            {
                int rowsAffected = SQLite3.Changes(_conn.Handle);
                return(rowsAffected);
            }
            else if (r == SQLite3.Result.Error)
            {
                string msg = SQLite3.GetErrmsg(_conn.Handle);
                throw SQLiteException.New(r, msg);
            }
            else
            {
                throw SQLiteException.New(r, r.ToString());
            }
        }
Ejemplo n.º 2
0
        public static IntPtr Prepare2(IntPtr db, string query)
        {
            IntPtr stmt;
            var    r = Prepare2(db, query, query.Length, out stmt, IntPtr.Zero);

            if (r != Result.OK)
            {
                throw SQLiteException.New(r, GetErrmsg(db));
            }
            return(stmt);
        }
Ejemplo n.º 3
0
        public static Sqlite3.Vdbe Prepare2(Sqlite3.sqlite3 db, string query)
        {
            Sqlite3.Vdbe stmt = new Sqlite3.Vdbe();
            var          r    = Sqlite3.sqlite3_prepare_v2(db, query, System.Text.UTF8Encoding.UTF8.GetByteCount(query), ref stmt, 0);

            if (r != 0)
            {
                throw SQLiteException.New((Result)r, GetErrmsg(db));
            }
            return(stmt);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new SQLiteCommand given the command text with arguments. Place a '?'
 /// in the command text for each of the arguments.
 /// </summary>
 /// <param name="cmdText">
 /// The fully escaped SQL.
 /// </param>
 /// <param name="args">
 /// Arguments to substitute for the occurences of '?' in the command text.
 /// </param>
 /// <returns>
 /// A <see cref="SQLiteCommand"/>
 /// </returns>
 public SQLiteCommand CreateCommand(string cmdText, params object[] ps)
 {
     if (!_open)
     {
         throw SQLiteException.New(SQLite3.Result.Error, "Cannot create commands from unopened database");
     }
     else
     {
         var cmd = NewCommand();
         cmd.CommandText = cmdText;
         foreach (var o in ps)
         {
             cmd.Bind(o);
         }
         return(cmd);
     }
 }
        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());
            }
        }