private void Execute(string query, params object[] parameters) { Sqlite3Statement statement = null; try { Result r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_prepare_v2(Handle, query, out statement).ToString()); if (r != Result.OK && r != Result.Done && r != Result.Row) { throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r)); } BindData(statement, parameters); r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_step(statement).ToString()); if (r != Result.OK && r != Result.Done && r != Result.Row) { throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r)); } } finally { if (statement != null) { Sqlite3.sqlite3_finalize(statement); } } }
private Sqlite3Statement ExecuteQuery(string query, params object[] parameters) { Sqlite3Statement statement; Result r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_prepare_v2(Handle, query, out statement).ToString()); if (r != Result.OK && r != Result.Done && r != Result.Row) { throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r)); } BindData(statement, parameters); return(statement); }
/// <summary> /// Sets up SQLite database. /// </summary> private void SetupSQLiteEventStore() { this.DBfileFullPath = System.IO.Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, dbFileName); string vacuumCommand = "PRAGMA auto_vacuum = 1"; string sqlCommand = string.Format(CultureInfo.InvariantCulture, "CREATE TABLE IF NOT EXISTS {0} ({1} TEXT NOT NULL,{2} TEXT NOT NULL UNIQUE,{3} TEXT NOT NULL, {4} INTEGER NOT NULL DEFAULT 0 )", TABLE_NAME, EVENT_COLUMN_NAME, EVENT_ID_COLUMN_NAME, MA_APP_ID_COLUMN_NAME, EVENT_DELIVERY_ATTEMPT_COUNT_COLUMN_NAME); var r = Sqlite3.sqlite3_open(this.DBfileFullPath, out Handle); if (r != Sqlite3.SQLITE_OK) { throw Sqlite3Exception.New((Result)Enum.Parse(typeof(Result), r.ToString()), string.Format("Could not open database file: {0} ({1})", this.DBfileFullPath, r)); } lock (_lock) { Execute(vacuumCommand); Execute(sqlCommand); } }