protected override void AppendInsertQuery(IDbCommand command, ParameterGenerator seed, VirtualRegistryKey item) { var paramHandle = seed.Next(); var paramName = seed.Next(); // Append query for insertion of the key. command.CommandText += string.Format("INSERT INTO [{0}] ({1}, {2}) VALUES ({3}, {4});", _DatabaseKeyTable, _DatabaseKeyHandle, _DatabaseKeyName, paramHandle, paramName); command.Parameters.Add(CreateParameter(paramHandle, item.Handle)); command.Parameters.Add(CreateParameter(paramName, item.Path)); // Append queries for insertion of the values. AppendInsertQueryForValues(command, seed, item.Handle, item.Values.Values); }
protected override void AppendDeleteQuery(IDbCommand command, ParameterGenerator seed, VirtualRegistryKey item) { var param = seed.Next(); command.CommandText += string.Format("DELETE FROM {0} WHERE {1} = {2}; DELETE FROM {3} WHERE {4} = {2};", _DatabaseKeyTable, _DatabaseKeyHandle, param, _DatabaseValueTable, _DatabaseValueKey); command.Parameters.Add(CreateParameter(param, item.Handle)); }
private void AppendInsertQueryForValues(IDbCommand command, ParameterGenerator seed, object keyHandle, IEnumerable <VirtualRegistryValue> values) { foreach (var value in values) { var paramHandle = seed.Next(); var paramName = seed.Next(); var paramValue = seed.Next(); var paramType = seed.Next(); command.CommandText += string.Format("INSERT INTO [{0}] ({1}, {2}, {3}, {4}) VALUES ({5}, {6}, {7}, {8});", _DatabaseValueTable, _DatabaseValueKey, _DatabaseValueName, _DatabaseValueValue, _DatabaseValueType, paramHandle, paramName, paramValue, paramType); command.Parameters.Add(CreateParameter(paramHandle, keyHandle)); command.Parameters.Add(CreateParameter(paramName, value.Name)); command.Parameters.Add(CreateParameter(paramValue, value.Data)); command.Parameters.Add(CreateParameter(paramType, Enum.GetName(typeof(ValueType), value.Type))); } }
protected override void AppendUpdateQuery(IDbCommand command, ParameterGenerator seed, VirtualRegistryKey item) { var paramHandle = seed.Next(); var paramName = seed.Next(); // Append query for update of the key. command.CommandText += string.Format("UPDATE {0} SET {1} = {2} WHERE {3} = {4};", _DatabaseKeyTable, _DatabaseKeyName, paramName, _DatabaseKeyHandle, paramHandle); command.Parameters.Add(CreateParameter(paramHandle, item.Handle)); command.Parameters.Add(CreateParameter(paramName, item.Path)); // Delete all values. It's too complicated to use an update query. paramHandle = seed.Next(); command.CommandText += string.Format("DELETE FROM {0} WHERE {1} = {2};", _DatabaseValueTable, _DatabaseValueKey, paramHandle); command.Parameters.Add(CreateParameter(paramHandle, item.Handle)); // Now re-add all values. AppendInsertQueryForValues(command, seed, item.Handle, item.Values.Values); }