internal void UpdateOrInsertRecord(string identityId, string datasetName, Record record)
        {
            lock (sqlite_lock)
            {
                string checkRecordExistsQuery = "SELECT COUNT(*) FROM " + SQLiteLocalStorage.TABLE_RECORDS + " WHERE " +
                                                RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " +
                                                RecordColumns.DATASET_NAME + " = @whereDatasetName AND " +
                                                RecordColumns.KEY + " = @whereKey ";

                bool recordsFound = false;

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = checkRecordExistsQuery;
                    BindData(command, identityId, datasetName, record.Key);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            recordsFound = reader.GetInt32(0) > 0;
                        }
                    }
                }

                if (recordsFound)
                {
                    string updateRecordQuery =
                        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 "
                            );

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = updateRecordQuery;
                        BindData(command, record.Value, record.SyncCount, record.IsModified ? 1 : 0, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, identityId, datasetName, record.Key);
                        command.ExecuteNonQuery();
                    }
                }
                else
                {
                    string insertRecord = RecordColumns.BuildInsert();
                    using (var command = new SQLiteCommand(insertRecord, connection))
                    {
                        BindData(command, identityId, datasetName, record.Key, record.Value, record.SyncCount, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, record.IsModified ? 1 : 0);
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
        internal void UpdateOrInsertRecord(string identityId, string datasetName, Record record)
        {
            lock (sqlite_lock)
            {
                string checkRecordExistsQuery = "SELECT count(*) FROM " + SQLiteLocalStorage.TABLE_RECORDS + " WHERE " +
                                                RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " +
                                                RecordColumns.DATASET_NAME + " = @whereDatasetName AND " +
                                                RecordColumns.KEY + " = @whereKey ";

                bool             recordsFound = false;
                Sqlite3Statement stmt         = null;
                try
                {
                    stmt = ExecuteQuery(checkRecordExistsQuery, identityId, datasetName, record.Key);
                    while (Sqlite3.sqlite3_step(stmt) == Sqlite3.SQLITE_ROW)
                    {
                        recordsFound = Sqlite3.sqlite3_column_int(stmt, 0) > 0;
                    }
                }
                finally
                {
                    if (stmt != null)
                    {
                        Sqlite3.sqlite3_finalize(stmt);
                    }
                }

                if (recordsFound)
                {
                    string updateRecordQuery =
                        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 "
                            );

                    Execute(updateRecordQuery, record.Value, record.SyncCount, record.IsModified ? 1 : 0, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, identityId, datasetName, record.Key);
                }
                else
                {
                    string insertRecord = RecordColumns.BuildInsert();
                    Execute(insertRecord, identityId, datasetName, record.Key, record.Value, record.SyncCount, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, record.IsModified ? 1 : 0);
                }
            }
        }
        internal void UpdateOrInsertRecord(string identityId, string datasetName, Record record)
        {
            lock (sqlite_lock)
            {
                string checkRecordExistsQuery = "SELECT count(*) FROM " + SQLiteLocalStorage.TABLE_RECORDS + " WHERE " +
                                                RecordColumns.IDENTITY_ID + " = @whereIdentityId AND " +
                                                RecordColumns.DATASET_NAME + " = @whereDatasetName AND " +
                                                RecordColumns.KEY + " = @whereKey ";

                bool recordsFound = false;
                using (var sqliteStatement = connection.Prepare(checkRecordExistsQuery))
                {
                    BindData(sqliteStatement, identityId, datasetName, record.Key);
                    var result = sqliteStatement.Step();

                    recordsFound = sqliteStatement.GetInteger(0) > 0;
                }

                if (recordsFound)
                {
                    string updateRecordQuery =
                        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 "
                            );

                    using (var sqliteStatement = connection.Prepare(updateRecordQuery))
                    {
                        BindData(sqliteStatement, record.Value, record.SyncCount, record.IsModified ? 1 : 0, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, identityId, datasetName, record.Key);
                        var result = sqliteStatement.Step();
                    }
                }
                else
                {
                    string insertRecord = RecordColumns.BuildInsert();
                    using (var sqliteStatement = connection.Prepare(insertRecord))
                    {
                        BindData(sqliteStatement, identityId, datasetName, record.Key, record.Value, record.SyncCount, record.LastModifiedDate, record.LastModifiedBy, record.DeviceLastModifiedDate, record.IsModified ? 1 : 0);
                        sqliteStatement.Step();
                    }
                }
            }
        }
Пример #4
0
        private bool PutValueHelper(string identityId, string datasetName, string key, string value)
        {
            lock (sqlite_lock)
            {
                Record record = GetRecord(identityId, datasetName, key);

                if (record != null && string.Equals(record.Value, value))
                {
                    return(true);
                }

                if (record == null)
                {
                    string insertRecord = RecordColumns.BuildInsert();
                    ExecuteMultipleHelper(new List <Statement> {
                        new Statement {
                            Query      = insertRecord,
                            Parameters = new object[] { identityId, datasetName, key, value, 0, AWSSDKUtils.CorrectedUtcNow.ToLocalTime(), string.Empty, AWSSDKUtils.CorrectedUtcNow.ToLocalTime(), 1 }
                        }
                    });
                    return(true);
                }
                else
                {
                    string insertRecord =
                        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 "
                            );
                    ExecuteMultipleHelper(new List <Statement> {
                        new Statement {
                            Query      = insertRecord,
                            Parameters = new object[] { identityId, datasetName, key, value, 1, record.SyncCount, AWSSDKUtils.CorrectedUtcNow.ToLocalTime(), identityId, datasetName, key }
                        }
                    });
                    return(true);
                }
            }
        }
Пример #5
0
 public static string BuildInsert()
 {
     return(RecordColumns.BuildInsert(ALL));
 }
Пример #6
0
        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();
                }
            }
        }
Пример #7
0
        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();
                }
            }
        }