public bool SetMapReduce(Mapper mapBlock, Reducer reduceBlock, string version) { System.Diagnostics.Debug.Assert((mapBlock != null)); System.Diagnostics.Debug.Assert((version != null)); this.mapBlock = mapBlock; this.reduceBlock = reduceBlock; if (!database.Open()) { return(false); } // Update the version column in the database. This is a little weird looking // because we want to // avoid modifying the database if the version didn't change, and because the // row might not exist yet. SQLiteStorageEngine storageEngine = this.database.GetDatabase(); // Older Android doesnt have reliable insert or ignore, will to 2 step // FIXME review need for change to execSQL, manual call to changes() string sql = "SELECT name, version FROM views WHERE name=?"; string[] args = new string[] { name }; Cursor cursor = null; try { cursor = storageEngine.RawQuery(sql, args); if (!cursor.MoveToNext()) { // no such record, so insert ContentValues insertValues = new ContentValues(); insertValues.Put("name", name); insertValues.Put("version", version); storageEngine.Insert("views", null, insertValues); return(true); } ContentValues updateValues = new ContentValues(); updateValues.Put("version", version); updateValues.Put("lastSequence", 0); string[] whereArgs = new string[] { name, version }; int rowsAffected = storageEngine.Update("views", updateValues, "name=? AND version!=?" , whereArgs); return(rowsAffected > 0); } catch (SQLException e) { Log.E(Log.TagView, "Error setting map block", e); return(false); } finally { if (cursor != null) { cursor.Close(); } } }
/// <exception cref="Couchbase.Lite.Storage.SQLException"></exception> public static byte[] ByteArrayResultForQuery(SQLiteStorageEngine database, string query, string[] args) { byte[] result = null; Cursor cursor = database.RawQuery(query, args); if (cursor.MoveToNext()) { result = cursor.GetBlob(0); } return(result); }