Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }