Amazon.CognitoSync.SyncManager.Internal.SQLiteLocalStorage.UpdateOrInsertRecord C# (CSharp) Method

UpdateOrInsertRecord() private method

private UpdateOrInsertRecord ( string identityId, string datasetName, Record record ) : void
identityId string
datasetName string
record Amazon.CognitoSync.SyncManager.Record
return void
        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);
                }
            }
        }