private bool UpdateDatasetMetadataInternal(string identityId, DatasetMetadata metadata) { lock (sqlite_lock) { DatasetMetadata local = this.GetMetadataInternal(identityId, metadata.DatasetName); SQLiteStatement stmt = null; try { if (local == null) { stmt = db.Prepare(DatasetColumns.BuildInsert()); stmt.BindText(1, identityId); stmt.BindText(2, metadata.DatasetName); stmt.BindDateTime(3, metadata.CreationDate); stmt.BindDateTime(4, metadata.LastModifiedDate); stmt.BindInt(5, metadata.RecordCount); stmt.BindInt(6, metadata.StorageSizeBytes); stmt.BindInt(7, 0); stmt.BindInt(8, 0); stmt.BindText(9, null); stmt.Step(); } else { stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.DATASET_NAME, DatasetColumns.CREATION_TIMESTAMP, DatasetColumns.LAST_MODIFIED_TIMESTAMP, DatasetColumns.LAST_MODIFIED_BY, DatasetColumns.RECORD_COUNT, DatasetColumns.STORAGE_SIZE_BYTES }, DatasetColumns.IDENTITY_ID + " = @whereIdentityId AND " + DatasetColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindText(1, metadata.DatasetName); stmt.BindDateTime(2, metadata.CreationDate); stmt.BindDateTime(3, metadata.LastModifiedDate); stmt.BindText(4, metadata.LastModifiedBy); stmt.BindInt(5, metadata.RecordCount); stmt.BindInt(6, metadata.StorageSizeBytes); stmt.BindText(7, identityId); stmt.BindText(8, metadata.DatasetName); stmt.Step(); } return(true); } finally { stmt.FinalizeStm(); } } }
public JArray Retrieve(string soupName, params long[] soupEntryIds) { lock (smartlock) { DBHelper db = Database; string soupTableName = db.GetSoupTableName(soupName); var result = new JArray(); if (String.IsNullOrWhiteSpace(soupTableName)) { throw new SmartStoreException("Soup: " + soupName + " does not exist"); } using (SQLiteStatement statement = db.Query(soupTableName, new[] { SoupCol }, String.Empty, String.Empty, GetSoupEntryIdsPredicate(soupEntryIds))) { if (statement.DataCount > 0) { do { string raw = statement.GetText(statement.ColumnIndex(SoupCol)); result.Add(JObject.Parse(raw)); } while (statement.Step() == SQLiteResult.ROW); } } return(result); } }
public void CreateDataset(string identityId, string datasetName) { lock (sqlite_lock) { DatasetMetadata metadata = this.GetMetadataInternal(identityId, datasetName); if (metadata == null) { SQLiteStatement stmt = null; try { string query = DatasetColumns.BuildInsert( new string[] { DatasetColumns.IDENTITY_ID, DatasetColumns.DATASET_NAME, DatasetColumns.CREATION_TIMESTAMP, DatasetColumns.LAST_MODIFIED_TIMESTAMP }); stmt = db.Prepare(query); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.BindDateTime(3, DateTime.Now); stmt.BindDateTime(4, DateTime.Now); stmt.Step(); } finally { stmt.FinalizeStm(); } } } }
/// <summary> /// Run a query given by its query spec, only returning results from the selected page. /// </summary> /// <param name="querySpec"></param> /// <param name="pageIndex"></param> /// <returns></returns> public JArray Query(QuerySpec querySpec, int pageIndex) { lock (smartlock) { QuerySpec.SmartQueryType qt = querySpec.QueryType; var results = new JArray(); string sql = ConvertSmartSql(querySpec.SmartSql); int offsetRows = querySpec.PageSize * pageIndex; int numberRows = querySpec.PageSize; string limit = offsetRows + "," + numberRows; using (SQLiteStatement statement = DBHelper.GetInstance(DatabasePath) .LimitRawQuery(sql, limit, querySpec.getArgs())) { if (statement.DataCount > 0) { do { if (qt == QuerySpec.SmartQueryType.Smart) { results.Add(GetDataFromRow(statement)); } else { results.Add(JObject.Parse(GetObject(statement, 0).ToString())); } } while (statement.Step() == SQLiteResult.ROW); } statement.ResetAndClearBindings(); } return(results); } }
public void UpdateLastSyncCount(string identityId, string datasetName, long lastSyncCount) { lock (sqlite_lock) { SQLiteStatement stmt = null; try { stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.LAST_SYNC_COUNT, DatasetColumns.LAST_SYNC_TIMESTAMP }, RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " + RecordColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindInt(1, lastSyncCount); stmt.BindDateTime(2, DateTime.Now); stmt.BindText(3, identityId); stmt.BindText(4, datasetName); stmt.Step(); } finally { stmt.FinalizeStm(); } } }
public void UpdateLastModifiedTimestamp(string identityId, string datasetName) { lock (sqlite_lock) { SQLiteStatement stmt = null; try { stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.LAST_MODIFIED_TIMESTAMP }, DatasetColumns.IDENTITY_ID + " = @whereIdentityId AND " + DatasetColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindDateTime(1, DateTime.Now); stmt.BindText(2, identityId); stmt.BindText(3, datasetName); stmt.Step(); } finally { stmt.FinalizeStm(); } } }
/// <summary> /// Increments the delivery attempt. /// </summary> /// <returns>true</returns> /// <c>false</c> /// <param name="rowIds">Row identifiers.</param> public bool IncrementDeliveryAttempt(List <string> rowIds) { bool success = false; lock (_lock) { SQLiteStatement stmt = null; try { #if SQL_DEBUG DateTime _dbExecutionStartTime = DateTime.Now; #endif string ids = "'" + String.Join("', '", rowIds.ToArray()) + "'"; string query = String.Format("UPDATE " + TABLE_NAME + " SET " + EVENT_DELIVERY_ATTEMPT_COUNT_COLUMN_NAME + "= " + EVENT_DELIVERY_ATTEMPT_COUNT_COLUMN_NAME + "+1 WHERE " + EVENT_ID_COLUMN_NAME + " IN ({0})", ids); stmt = db.Prepare(query); stmt.Step(); success = true; #if SQL_DEBUG DateTime _dbExecutionEndTime = DateTime.Now; double totalSeconds = _dbExecutionEndTime.Subtract(_dbExecutionStartTime).TotalSeconds; AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "SQLiteEventStore", "Increment Operation completed on local store in " + totalSeconds + " seconds"); #endif } finally { if (stmt != null) { stmt.FinalizeStm(); } } } return(success); }
private void AddData_Click(object sender, RoutedEventArgs e) { /*string name = nameContact.Text;*/ message.Text = ""; string phone = phoneNumber.Text; string name = nameContact.Text; string select = @"Select * from Contact where phoneNumber = '" + phone + "';"; ISQLiteStatement dbState = (SQLiteStatement)conn.Prepare(select); while (dbState.Step() == SQLiteResult.ROW) { string nameContact = dbState["name"] as string; string phoneNumber = dbState["phoneNumber"] as string; items.Add(nameContact + " " + phoneNumber); listPhone.Add(phoneNumber); } foreach (string s in listPhone) { if (s != phone) { string sql = @"Insert into Contact (name, phoneNumber) values ('" + name + "', '" + phone + "' ); "; SQLiteStatement statment = (SQLiteStatement)conn.Prepare(sql); statment.Step(); } else { message.Text = "Số điện thoại đã tồn tại"; } } }
public void PurgeDataset(string identityId, string datasetName) { lock (sqlite_lock) { this.DeleteDataset(identityId, datasetName); SQLiteStatement stmt = null; try { stmt = db.Prepare( DatasetColumns.BuildDelete( DatasetColumns.IDENTITY_ID + " = @whereIdentityId AND " + DatasetColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.Step(); } finally { stmt.FinalizeStm(); } } }
public SQLiteResult Execute(string sql, out SQLiteStatement statement) { statement = _sqlConnection.Prepare(sql) as SQLiteStatement; if (statement != null) { return(statement.Step()); } return(SQLiteResult.ERROR); }
public void DeleteDataset(string identityId, string datasetName) { lock (sqlite_lock) { SQLiteStatement stmt = null; try { stmt = db.Prepare( RecordColumns.BuildDelete( RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " + RecordColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.Step(); stmt.FinalizeStm(); stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.LAST_MODIFIED_TIMESTAMP, DatasetColumns.LAST_SYNC_COUNT }, DatasetColumns.IDENTITY_ID + " = @whereIdentityId AND " + DatasetColumns.DATASET_NAME + " = @whereDatasetName" )); stmt.BindDateTime(1, DateTime.Now); stmt.BindInt(2, -1); stmt.BindText(3, identityId); stmt.BindText(4, datasetName); stmt.Step(); } finally { stmt.FinalizeStm(); } } }
public MainPage() { this.InitializeComponent(); SQLiteConnection conn = new SQLiteConnection("News.db"); string sql = @"CREATE TABLE IF NOT EXISTS Contact (Id Integer Primary Key AutoIncrement Not null , name varchar(255), phoneNumber varchar(255) );"; SQLiteStatement statment = (SQLiteStatement)conn.Prepare(sql); statment.Step(); }
public override void ChangeIdentityId(string oldIdentityId, string newIdentityId) { lock (SQLiteDatabase.SQLiteLock) { SQLiteStatement stmt = null; try { stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.IDENTITY_ID }, DatasetColumns.IDENTITY_ID + " = @whereIdentityId" )); stmt.BindText(1, newIdentityId); stmt.BindText(2, oldIdentityId); stmt.Step(); stmt.FinalizeStm(); stmt = db.Prepare( RecordColumns.BuildUpdate( new string[] { RecordColumns.IDENTITY_ID }, RecordColumns.IDENTITY_ID + " = @whereIdentityId" )); stmt.BindText(1, newIdentityId); stmt.BindText(2, oldIdentityId); stmt.Step(); } finally { stmt.FinalizeStm(); } } }
public MainPage() { this.InitializeComponent(); Articles = new ObservableCollection <Article>(); GetAR("tesla", "2021-02-18", "publishedAt", "20f0bc79a63947818867de418e5f4ab3"); SQLiteConnection conn = new SQLiteConnection("News.db"); string sql = @"CREATE TABLE IF NOT EXISTS News (Id Integer Primary Key AutoIncrement Not null , urlLink varchar(255) );"; SQLiteStatement statment = (SQLiteStatement)conn.Prepare(sql); statment.Step(); }
private static List <string> GetAllSoupNames(string databasePath) { lock (smartlock) { var soupNames = new List <string>(); DBHelper db = DBHelper.GetInstance(databasePath); using (SQLiteStatement stmt = db.Query(SoupNamesTable, new[] { SoupNameCol }, String.Empty, String.Empty, String.Empty)) { if (stmt.DataCount > 0) { do { soupNames.Add(stmt.GetText(0)); } while (stmt.Step() == SQLiteResult.ROW); } } return(soupNames); } }
private IEnumerable <Entry> GetEntries(int offset, int length, SQLiteStatement query, int bindOffset) { query.Bind(bindOffset + 1, length); query.Bind(bindOffset + 2, offset); while (query.Step()) { var id = query.ColumnInt(0); var type = (EntryType)query.ColumnInt(1); var connectionId = query.ColumnInt(2); var database = query.ColumnText(3); var start = query.ColumnText(4); var end = query.ColumnText(5); var text = query.ColumnText(6); var plan = query.ColumnText(7); var results = query.ColumnText(8); var startDate = DateTime.Parse(start, null, DateTimeStyles.RoundtripKind); var endDate = DateTime.Parse(end, null, DateTimeStyles.RoundtripKind); var resultsTable = JsonConvert.DeserializeObject <DataTable>(results); yield return(new Entry { Id = id, Parent = this, Type = type, Connection = connectionId, Database = database, Start = startDate, End = endDate, Text = text, Plan = plan, Results = resultsTable, }); } query.Reset(); }
protected IndexSpec[] GetIndexSpecsFromDb(String soupName) { SQLiteStatement statement = Query(SmartStore.SoupIndexMapTable, new[] { SmartStore.PathCol, SmartStore.ColumnNameCol, SmartStore.ColumnTypeCol }, null, null, SmartStore.SoupNamePredicate, soupName); if (statement.DataCount < 1) { throw new SmartStoreException(String.Format("{0} does not have any indices", soupName)); } var indexSpecs = new List <IndexSpec>(); do { String path = statement.GetText(SmartStore.PathCol); String columnName = statement.GetText(SmartStore.ColumnNameCol); var columnType = new SmartStoreType(statement.GetText(SmartStore.ColumnTypeCol)); indexSpecs.Add(new IndexSpec(path, columnType, columnName)); } while (statement.Step() == SQLiteResult.ROW); statement.ResetAndClearBindings(); return(indexSpecs.ToArray()); }
public void ChangeIdentityId(string oldIdentityId, string newIdentityId) { Debug.Log("Reparenting datasets from " + oldIdentityId + " to " + newIdentityId); GetCommonDatasetNames(oldIdentityId, newIdentityId); lock (sqlite_lock) { SQLiteStatement stmt = null; try { // if oldIdentityId is unknown, aka the dataset is created prior to // having a cognito id, just reparent datasets from unknown to // newIdentityId if (DatasetUtils.UNKNOWN_IDENTITY_ID == oldIdentityId) { HashSet <string> commonDatasetNames = GetCommonDatasetNames(oldIdentityId, newIdentityId); // append UNKNOWN to the name of all non unique datasets foreach (String oldDatasetName in commonDatasetNames) { stmt = db.Prepare("UPDATE " + TABLE_DATASETS + " SET " + DatasetColumns.DATASET_NAME + " = ?" + " WHERE " + DatasetColumns.IDENTITY_ID + " = ?" + " AND " + DatasetColumns.DATASET_NAME + " = ?" ); DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); string timestamp = ((DateTime.UtcNow - epoch).TotalSeconds).ToString(); stmt.BindText(1, oldDatasetName + "." + oldIdentityId + "-" + timestamp); stmt.BindText(2, oldIdentityId); stmt.BindText(3, oldDatasetName); stmt.Step(); stmt.FinalizeStm(); stmt = db.Prepare("UPDATE " + TABLE_RECORDS + " SET " + RecordColumns.DATASET_NAME + " = ?" + " WHERE " + RecordColumns.IDENTITY_ID + " = ?" + " AND " + RecordColumns.DATASET_NAME + " = ?" ); stmt.BindText(1, oldDatasetName + "." + oldIdentityId + "-" + timestamp); stmt.BindText(2, oldIdentityId); stmt.BindText(3, oldDatasetName); stmt.Step(); stmt.FinalizeStm(); } stmt = db.Prepare( DatasetColumns.BuildUpdate( new string[] { DatasetColumns.IDENTITY_ID }, DatasetColumns.IDENTITY_ID + " = ?" ) ); stmt.BindText(1, newIdentityId); stmt.BindText(2, oldIdentityId); stmt.Step(); stmt.FinalizeStm(); stmt = db.Prepare( RecordColumns.BuildUpdate( new string[] { RecordColumns.IDENTITY_ID }, RecordColumns.IDENTITY_ID + " = ?" ) ); stmt.BindText(1, newIdentityId); stmt.BindText(2, oldIdentityId); stmt.Step(); } else { // 1. copy oldIdentityId/dataset to newIdentityId/dataset // datasets table stmt = db.Prepare("INSERT INTO " + TABLE_DATASETS + "(" + DatasetColumns.IDENTITY_ID + "," + DatasetColumns.DATASET_NAME + "," + DatasetColumns.CREATION_TIMESTAMP + "," + DatasetColumns.STORAGE_SIZE_BYTES + "," + DatasetColumns.RECORD_COUNT // last sync count is reset to default 0 + ")" + " SELECT " + "'" + newIdentityId + "'," // assign new owner + DatasetColumns.DATASET_NAME + "," + DatasetColumns.CREATION_TIMESTAMP + "," + DatasetColumns.STORAGE_SIZE_BYTES + "," + DatasetColumns.RECORD_COUNT + " FROM " + TABLE_DATASETS + " WHERE " + DatasetColumns.IDENTITY_ID + " = ?" ); stmt.BindText(1, oldIdentityId); stmt.Step(); stmt.FinalizeStm(); // records table stmt = db.Prepare("INSERT INTO " + TABLE_RECORDS + "(" + RecordColumns.IDENTITY_ID + "," + RecordColumns.DATASET_NAME + "," + RecordColumns.KEY + "," + RecordColumns.VALUE + "," // sync count is resset to default 0 + RecordColumns.LAST_MODIFIED_TIMESTAMP + "," + RecordColumns.LAST_MODIFIED_BY + "," + RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP // modified is reset to default 1 (dirty) + ")" + " SELECT " + "'" + newIdentityId + "'," // assign new owner + RecordColumns.DATASET_NAME + "," + RecordColumns.KEY + "," + RecordColumns.VALUE + "," + RecordColumns.LAST_MODIFIED_TIMESTAMP + "," + RecordColumns.LAST_MODIFIED_BY + "," + RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP + " FROM " + TABLE_RECORDS + " WHERE " + RecordColumns.IDENTITY_ID + " = ?" ); stmt.BindText(1, oldIdentityId); stmt.Step(); stmt.FinalizeStm(); // 2. rename oldIdentityId/dataset to // newIdentityId/dataset.oldIdentityId // datasets table stmt = db.Prepare("UPDATE " + TABLE_DATASETS + " SET " + DatasetColumns.IDENTITY_ID + " = '" + newIdentityId + "', " + DatasetColumns.DATASET_NAME + " = " + DatasetColumns.DATASET_NAME + " || '." + oldIdentityId + "'" + " WHERE " + DatasetColumns.IDENTITY_ID + " = ?" ); stmt.BindText(1, oldIdentityId); stmt.Step(); stmt.FinalizeStm(); // records table stmt = db.Prepare("UPDATE " + TABLE_RECORDS + " SET " + RecordColumns.IDENTITY_ID + " = '" + newIdentityId + "', " + RecordColumns.DATASET_NAME + " = " + RecordColumns.DATASET_NAME + " || '." + oldIdentityId + "'" + " WHERE " + RecordColumns.IDENTITY_ID + " = ?" ); stmt.BindText(1, oldIdentityId); stmt.Step(); } } finally { stmt.FinalizeStm(); } } }
/// <summary> /// Add an event to the store. /// </summary> /// <returns><c>true</c>, if event was put, <c>false</c> otherwise.</returns> public bool PutEvent(string eventString, string appId) { bool success = false; bool proceedToInsert = false; long currentDatabaseSize = GetDatabaseSize(); if (string.IsNullOrEmpty(appId)) { throw new ArgumentNullException("AppId"); } if (currentDatabaseSize >= _maxDbSize) { proceedToInsert = false; InvalidOperationException e = new InvalidOperationException(); _logger.Error(e, "The database size has exceeded the threshold limit. Unable to insert any new events"); } else if (currentDatabaseSize / _maxDbSize >= _dbWarningThreshold) { proceedToInsert = true; _logger.InfoFormat("The database size is almost full"); } else { proceedToInsert = true; } //keep the lock as short as possible if (proceedToInsert) { lock (_lock) { SQLiteStatement stmt = null; try { #if SQL_DEBUG DateTime _dbExecutionStartTime = DateTime.Now; #endif string query = "INSERT INTO " + TABLE_NAME + " (" + EVENT_COLUMN_NAME + "," + EVENT_ID_COLUMN_NAME + "," + MA_APP_ID_COLUMN_NAME + ") values(?,?,?)"; stmt = db.Prepare(query); stmt.BindText(1, eventString); stmt.BindText(2, Guid.NewGuid().ToString()); stmt.BindText(3, appId); stmt.Step(); success = true; #if SQL_DEBUG DateTime _dbExecutionEndTime = DateTime.Now; double totalSeconds = _dbExecutionEndTime.Subtract(_dbExecutionStartTime).TotalSeconds; AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "SQLiteEventStore", "Put Operation completed on local store in " + totalSeconds + " seconds"); #endif } finally { if (stmt != null) { stmt.FinalizeStm(); } } } } return(success); }
private void UpdateOrInsertRecord(string identityId, string datasetName, Record record) { lock (sqlite_lock) { SQLiteStatement stmt = null; try { stmt = db.Prepare( RecordColumns.BuildQuery( RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " + RecordColumns.DATASET_NAME + " = @whereDatasetName AND " + RecordColumns.KEY + " = @whereKey " )); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.BindText(3, record.Key); bool recordsFound = false; while (stmt.Read()) { recordsFound = true; } stmt.FinalizeStm(); if (recordsFound) { stmt = db.Prepare( RecordColumns.BuildUpdate( new string[] { RecordColumns.VALUE, RecordColumns.SYNC_COUNT, RecordColumns.MODIFIED, RecordColumns.LAST_MODIFIED_TIMESTAMP, RecordColumns.LAST_MODIFIED_BY, RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP }, RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " + RecordColumns.DATASET_NAME + " = @whereDatasetName AND " + RecordColumns.KEY + " = @whereKey " )); stmt.BindText(1, record.Value); stmt.BindInt(2, record.SyncCount); stmt.BindInt(3, record.IsModified ? 1 : 0); stmt.BindDateTime(4, record.LastModifiedDate); stmt.BindText(5, record.LastModifiedBy); stmt.BindDateTime(6, record.DeviceLastModifiedDate); stmt.BindText(7, identityId); stmt.BindText(8, datasetName); stmt.BindText(9, record.Key); stmt.Step(); } else { stmt = db.Prepare(RecordColumns.BuildInsert()); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.BindText(3, record.Key); stmt.BindText(4, record.Value); stmt.BindInt(5, record.SyncCount); stmt.BindDateTime(6, record.LastModifiedDate); stmt.BindText(7, record.LastModifiedBy); stmt.BindDateTime(8, record.DeviceLastModifiedDate); stmt.BindInt(9, record.IsModified ? 1 : 0); stmt.Step(); } } finally { stmt.FinalizeStm(); } } }
private bool PutValueInternal(string identityId, string datasetName, string key, string value) { lock (sqlite_lock) { Record record = this.GetRecord(identityId, datasetName, key); if (record != null && string.Equals(record.Value, value)) { return(true); } SQLiteStatement stmt = null; try { if (record == null) { stmt = db.Prepare(RecordColumns.BuildInsert()); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.BindText(3, key); stmt.BindText(4, value); stmt.BindInt(5, 0); stmt.BindDateTime(6, DateTime.Now); stmt.BindText(7, ""); stmt.BindInt(8, 0); stmt.BindInt(9, 1); stmt.Step(); return(true); } else { stmt = db.Prepare( RecordColumns.BuildUpdate( new string[] { RecordColumns.IDENTITY_ID, RecordColumns.DATASET_NAME, RecordColumns.KEY, RecordColumns.VALUE, RecordColumns.MODIFIED, RecordColumns.SYNC_COUNT, RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP }, RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " + RecordColumns.DATASET_NAME + " = @whereDatasetName AND " + RecordColumns.KEY + " = @whereKey " )); stmt.BindText(1, identityId); stmt.BindText(2, datasetName); stmt.BindText(3, key); stmt.BindText(4, value); stmt.BindInt(5, 1); stmt.BindInt(6, record.SyncCount); stmt.BindDateTime(7, DateTime.Now); stmt.BindText(8, identityId); stmt.BindText(9, datasetName); stmt.BindText(10, key); stmt.Step(); return(true); } } finally { stmt.FinalizeStm(); } } }
/// <summary> /// Re-index all soup elements for passed indexPaths /// </summary> /// <param name="soupName"></param> /// <param name="indexPaths"></param> /// <param name="handleTx"></param> public void ReIndexSoup(string soupName, string[] indexPaths, bool handleTx) { lock (smartlock) { DBHelper db = DBHelper.GetInstance(DatabasePath); string soupTableName = db.GetSoupTableName(soupName); if (String.IsNullOrWhiteSpace(soupTableName)) { throw new SmartStoreException("Soup: " + soupName + " does not exist"); } Dictionary <string, IndexSpec> mapAllSpecs = IndexSpec.MapForIndexSpecs(GetSoupIndexSpecs(soupName)); IndexSpec[] indexSpecs = (from indexPath in indexPaths where mapAllSpecs.ContainsKey(indexPath) select mapAllSpecs[indexPath]) .ToArray(); if (indexSpecs.Length == 0) { return; // nothing to do } if (handleTx) { db.BeginTransaction(); } using ( SQLiteStatement stmt = db.Query(soupTableName, new[] { IdCol, SoupCol }, String.Empty, String.Empty, String.Empty)) { if (stmt.DataCount > 0) { try { do { string soupEntryId = stmt.GetText(0); string soupRaw = stmt.GetText(1); try { JObject soupElt = JObject.Parse(soupRaw); var contentValues = new Dictionary <string, object>(); foreach (IndexSpec indexSpec in indexSpecs) { ProjectIndexedPaths(soupElt, contentValues, indexSpec); } db.Update(soupTableName, contentValues, IdPredicate, soupEntryId + String.Empty); } catch (JsonException e) { PlatformAdapter.SendToCustomLogger(e, LoggingLevel.Error); Debug.WriteLine("SmartStore.ReIndexSoup: Could not parse soup element " + soupEntryId); } } while (stmt.Step() == SQLiteResult.ROW); } finally { if (handleTx) { db.CommitTransaction(); } } } } } }