protected override void InternalInsertRow(Schema.TableVar ATableVar, Row ARow) { using (SQLCommand LCommand = Connection.CreateCommand(false)) { string LTableSchema = D4.MetaData.GetTag(ATableVar.MetaData, "Storage.Schema", Device.Schema); string LTableName = Device.ToSQLIdentifier(ATableVar); if (LTableSchema != String.Empty) { LTableName = String.Format("{0}.{1}", LTableSchema, LTableName); } if (Device.CommandTimeout >= 0) { LCommand.CommandTimeout = Device.CommandTimeout; } LCommand.Statement = LTableName; LCommand.CommandType = SQLCommandType.Table; LCommand.LockType = SQLLockType.Pessimistic; SQLCursor LCursor = LCommand.Open(SQLCursorType.Dynamic, SQLIsolationLevel.Serializable); try { SQLScalarType LScalarType; Schema.TableVarColumn LColumn; string[] LNames = new string[ARow.DataType.Columns.Count]; object[] LValues = new object[ARow.DataType.Columns.Count]; for (int LIndex = 0; LIndex < ARow.DataType.Columns.Count; LIndex++) { LColumn = ATableVar.Columns[ARow.DataType.Columns[LIndex].Name]; LScalarType = (SQLScalarType)Device.DeviceScalarTypes[LColumn.DataType]; LNames[LIndex] = Device.ToSQLIdentifier(LColumn); LValues[LIndex] = ARow.HasValue(LIndex) ? LScalarType.ParameterFromScalar(ARow[LIndex]) : null; } LCursor.Insert(LNames, LValues); } finally { LCommand.Close(LCursor); } } }
// AcquireConnection(SQLConnectionHeader) // sets the SQLDeviceCursor reference for the SQLConnectionHeader record in the SQLDeviceSession public void AcquireConnection(SQLConnectionHeader connectionHeader) { _connection = connectionHeader.Connection; try { _command = _connection.CreateCommand(true); try { if (_buffer.Count > 0) { RestrictStatement(); } else { UnrestrictStatement(); } PrepareStatement(); _command.Statement = _deviceSession.Device.Emitter.Emit(_statement); _command.Parameters.AddRange(_parameters); _command.LockType = _lockType; try { _cursor = _command.Open(_cursorType, _isolationLevel); try { #if USEINCLUSIVEMULTIPLEX if (_buffer.Count > 0) { _cursor.Next(); } #endif connectionHeader.DeviceCursor = this; } catch { _command.Close(_cursor); _cursor = null; throw; } } catch (Exception exception) { _deviceSession.TransactionFailure = _connection.TransactionFailure; throw _deviceSession.WrapException(exception); } } catch { _command.Dispose(); _command = null; throw; } } catch { _connection = null; throw; } }
protected override void InternalDeleteRow(Schema.TableVar ATableVar, Row ARow) { using (SQLCommand LCommand = Connection.CreateCommand(false)) { string LTableSchema = D4.MetaData.GetTag(ATableVar.MetaData, "Storage.Schema", Device.Schema); string LTableName = Device.ToSQLIdentifier(ATableVar); if (LTableSchema != String.Empty) { LTableName = String.Format("{0}.{1}", LTableSchema, LTableName); } if (Device.CommandTimeout >= 0) { LCommand.CommandTimeout = Device.CommandTimeout; } LCommand.Statement = LTableName; LCommand.CommandType = SQLCommandType.Table; LCommand.LockType = SQLLockType.Pessimistic; SQLCursor LCursor = LCommand.Open(SQLCursorType.Dynamic, SQLIsolationLevel.Serializable); try { SQLScalarType LScalarType; Schema.TableVarColumn LColumn; Schema.Key LKey = Program.FindClusteringKey(ATableVar); #if USESEEKTOUPDATE object[] LKeyValues = new object[LKey.Columns.Count]; for (int LIndex = 0; LIndex < LKeyValues.Length; LIndex++) { LColumn = ATableVar.Columns[LKey.Columns[LIndex].Name]; LScalarType = (SQLScalarType)Device.DeviceScalarTypes[LColumn.DataType]; LKeyValues[LIndex] = ARow.HasValue(LColumn.Name) ? LScalarType.ParameterFromScalar(ARow[LColumn.Name]) : null; } if (!LCursor.FindKey(LKeyValues)) { throw new RuntimeException(RuntimeException.Codes.OptimisticConcurrencyCheckRowNotFound); } #else StringBuilder LFilter = new StringBuilder(); IADOFilterLiteralBuilder LBuilder; for (int LIndex = 0; LIndex < LKey.Columns.Count; LIndex++) { LColumn = ATableVar.Columns[LKey.Columns[LIndex].Name]; LScalarType = (SQLScalarType)Device.DeviceScalarTypes[LColumn.DataType]; LBuilder = LScalarType as IADOFilterLiteralBuilder; if (LBuilder == null) { throw new ConnectionException(ConnectionException.Codes.UnsupportedSearchableCall); } if (LIndex > 0) { LFilter.Append(" and "); } if (ARow.HasValue(LColumn.Name)) { LFilter.AppendFormat("[{0}] = {1}", Device.ToSQLIdentifier(LColumn), LBuilder.ToLiteral((IScalar)ARow[LColumn.Name])); } else { throw new RuntimeException(RuntimeException.Codes.OptimisticConcurrencyCheckRowNotFound); } } if (!LCursor.SetFilter(LFilter.ToString())) { throw new RuntimeException(RuntimeException.Codes.OptimisticConcurrencyCheckRowNotFound); } #endif LCursor.Delete(); } finally { LCommand.Close(LCursor); } } }