public int ExecuteNonQuery() { if (this._conn.Trace) { Console.WriteLine("Executing: " + this); } var r = SQLite3.Result.OK; var stmt = this.Prepare(); r = SQLite3.Step(stmt); this.Finalize(stmt); if (r == SQLite3.Result.Done) { int rowsAffected = SQLite3.Changes(this._conn.Handle); return(rowsAffected); } else if (r == SQLite3.Result.Error) { string msg = SQLite3.GetErrmsg(this._conn.Handle); throw SQLiteException.New(r, msg); } else { throw SQLiteException.New(r, r.ToString()); } }
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); }
/// <summary> /// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath. /// </summary> /// <param name="databasePath"> /// Specifies the path to the database file. /// </param> public SQLiteConnection(string databasePath) { this.DatabasePath = databasePath; IntPtr handle; var r = SQLite3.Open(this.DatabasePath, out handle); this.Handle = handle; if (r != SQLite3.Result.OK) { throw SQLiteException.New(r, "Could not open database file: " + this.DatabasePath); } this.open = true; this.BusyTimeout = TimeSpan.FromSeconds(0.1); }
/// <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 (!this.open) { throw SQLiteException.New(SQLite3.Result.Error, "Cannot create commands from unopened database"); } else { var cmd = new SQLiteCommand(this); cmd.CommandText = cmdText; foreach (var o in ps) { cmd.Bind(o); } return(cmd); } }
public int ExecuteNonQuery(object[] source) { if (this.Connection.Trace) { Console.WriteLine("Executing: " + this.CommandText); } var r = SQLite3.Result.OK; if (!this.Initialized) { this.Statement = this.Prepare(); this.Initialized = true; } //bind the values. if (source != null) { for (int i = 0; i < source.Length; i++) { SQLiteCommand.BindParameter(this.Statement, i + 1, source[i]); } } r = SQLite3.Step(this.Statement); if (r == SQLite3.Result.Done) { int rowsAffected = SQLite3.Changes(this.Connection.Handle); SQLite3.Reset(this.Statement); return(rowsAffected); } else if (r == SQLite3.Result.Error) { string msg = SQLite3.GetErrmsg(this.Connection.Handle); SQLite3.Reset(this.Statement); throw SQLiteException.New(r, msg); } else { SQLite3.Reset(this.Statement); throw SQLiteException.New(r, r.ToString()); } }