Пример #1
1
        public int Update(AdoAdapter adapter, string tableName, IList<IDictionary<string, object>> data, IDbTransaction transaction, IList<string> keyFields)
        {
            int count = 0;
            if (data == null) throw new ArgumentNullException("data");
            if (data.Count < 2) throw new ArgumentException("UpdateMany requires more than one record.");

            if (keyFields.Count == 0) throw new NotSupportedException("Adapter does not support key-based update for this object.");
            if (!AllRowsHaveSameKeys(data)) throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary<string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                    ExpressionHelper.CriteriaDictionaryToExpression(
                                                                        tableName, GetCriteria(keyFields, exampleRow)));

            using (var connectionScope = ConnectionScope.Create(transaction, adapter.CreateConnection))
            using (var command = commandBuilder.GetRepeatableCommand(connectionScope.Connection))
            {
                var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                foreach (var row in data)
                {
                    foreach (var kvp in row)
                    {
                        propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                    }
                    count += command.ExecuteNonQuery();
                }
            }

            return count;
        }
        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null,
                                  bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var dataDictionary = BuildDataDictionary(adapter, data, table);

            string columnList = dataDictionary.Keys.Select(c => c.QuotedName).Aggregate((agg, next) => agg + "," + next);
            string valueList = dataDictionary.Keys.Select(s => "?").Aggregate((agg, next) => agg + "," + next);

            var insertSql = new StringBuilder();
            insertSql.AppendFormat("INSERT INTO {0} ({1}) VALUES ({2});", table.QualifiedName, columnList, valueList);
            if (resultRequired)
            {
                var identityColumn = table.Columns.FirstOrDefault(c => c.IsIdentity);
                if (identityColumn != null)
                {
                    insertSql.AppendFormat(" SELECT * FROM {0} WHERE {1} = LAST_INSERT_ID();", table.QualifiedName,
                                           identityColumn.QuotedName);
                    return ExecuteSingletonQuery(adapter, insertSql.ToString(), dataDictionary.Keys,
                                                 dataDictionary.Values, transaction);
                }
            }
            Execute(adapter, insertSql.ToString(), dataDictionary.Keys, dataDictionary.Values, transaction);
            return null;
        }
Пример #3
0
 public BulkInserterHelper(AdoAdapter adapter, IEnumerable <IDictionary <string, object> > data, Table table, List <Column> columns)
 {
     Adapter  = adapter;
     Data     = data;
     _table   = table;
     _columns = columns;
 }
Пример #4
0
        public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction, Func<IDictionary<string,object>, Exception, bool> onError, bool resultRequired)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var columns = table.Columns.Where(c => !c.IsIdentity).ToList();

            string columnList = string.Join(",", columns.Select(c => c.QuotedName));
            string valueList = string.Join(",", columns.Select(c => "?"));

            string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";

            var helper = transaction == null
                             ? new BulkInserterHelper(adapter, data, table, columns)
                             : new BulkInserterTransactionHelper(adapter, data, table, columns, transaction);

            if (resultRequired)
            {
                var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);
                if (identityColumn != null)
                {
                    var identityFunction = adapter.GetIdentityFunction();
                    if (!string.IsNullOrWhiteSpace(identityFunction))
                    {
                        return InsertRowsAndReturn(adapter, identityFunction, helper, insertSql, table, onError);
                    }
                }
            }

            helper.InsertRowsWithoutFetchBack(insertSql, onError);

            return null;
        }
    public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction)
    {
      var table = DatabaseSchema.Get(adapter.ConnectionProvider, adapter.ProviderHelper).FindTable(tableName);
      if (table == null) throw new SimpleDataException(String.Format("Table '{0}' not found", tableName));

      var insertData = data.Select(row => row.Where(p => table.HasColumn(p.Key) && !table.FindColumn(p.Key).IsIdentity).ToDictionary());

      var insertColumns = insertData.First().Keys.Select(table.FindColumn).ToArray();

      var columnsSql = insertColumns.Select(s => s.QuotedName).Aggregate((agg, next) => String.Concat(agg, ",", next));
      var valuesSql = insertColumns.Select((val, idx) => ":p" + idx.ToString()).Aggregate((agg, next) => String.Concat(agg, ",", next));

      var insertSql = string.Format("INSERT INTO {0} ({1}) VALUES({2}) RETURNING *;", table.QualifiedName, columnsSql, valuesSql);
      if (transaction != null)
      {
        using(var cmd = transaction.Connection.CreateCommand())
        {
          cmd.Transaction = transaction;
          cmd.CommandText = insertSql;
          return insertData.Select(row => ExecuteInsert(cmd, insertColumns, row.Values.ToArray())).ToList();
        }
      }

      using (var conn = adapter.ConnectionProvider.CreateConnection())
      {
        conn.Open();
        using(var cmd = conn.CreateCommand())
        {
          cmd.CommandText = insertSql;
          return insertData.Select(row => ExecuteInsert(cmd, insertColumns, row.Values.ToArray())).ToList();
        }
      }
    }
Пример #6
0
 public BulkInserterHelper(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data, Table table, List<Column> columns)
 {
     Adapter = adapter;
     Data = data;
     _table = table;
     _columns = columns;
 }
Пример #7
0
        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null, bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var dataDictionary = BuildDataDictionary(adapter, data, table);

            string columnList = dataDictionary.Keys.Select(c => c.QuotedName).Aggregate((agg, next) => agg + "," + next);
            string valueList = dataDictionary.Keys.Select(s => "?").Aggregate((agg, next) => agg + "," + next);

            var insertSql = new StringBuilder();
            bool identityInsert = adapter.AdoOptions != null && adapter.AdoOptions.IdentityInsert;
            if (identityInsert)
            {
                insertSql.AppendFormat("SET IDENTITY_INSERT {0} ON; ", table.QualifiedName);
            }
            insertSql.AppendFormat("INSERT INTO {0} ({1})", table.QualifiedName, columnList);
            if (resultRequired)
            {
                insertSql.Append(" OUTPUT INSERTED.*");
            }
            insertSql.AppendFormat(" VALUES ({0})", valueList);
            
            if (identityInsert)
            {
                insertSql.AppendFormat("; SET IDENTITY_INSERT {0} OFF; ", table.QualifiedName);
            }

            if (resultRequired)
            {
                return ExecuteSingletonQuery(adapter, insertSql.ToString(), dataDictionary.Keys,
                                             dataDictionary.Values, transaction);
            }
            Execute(adapter, insertSql.ToString(), dataDictionary.Keys, dataDictionary.Values, transaction);
            return null;
        }
Пример #8
0
        private static IEnumerable<IDictionary<string, object>> InsertRowsWithSeparateStatements(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data,
                                                                    IDbTransaction transaction, Table table, List<Column> columns,
                                                                    string insertSql, string selectSql)
        {
            if (transaction != null)
            {
                var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(transaction.Connection, insertSql);
                var selectCommand = transaction.Connection.CreateCommand();
                selectCommand.CommandText = selectSql;
                insertCommand.Transaction = transaction;
                selectCommand.Transaction = transaction;
                return data.Select(row => InsertRow(row, columns, table, insertCommand, selectCommand)).ToList();
            }

            using (var connection = adapter.CreateConnection())
            {
                using (var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(connection, insertSql))
                using (var selectCommand = connection.CreateCommand())
                {
                    selectCommand.CommandText = selectSql;
                    connection.Open();
                    return data.Select(row => InsertRow(row, columns, table, insertCommand, selectCommand)).ToList();
                }
            }
        }
Пример #9
0
        public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var columns = table.Columns.Where(c => !c.IsIdentity).ToList();

            string columnList = string.Join(",", columns.Select(c => c.QuotedName));
            string valueList = string.Join(",", columns.Select(c => "?"));

            string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";

            var identityFunction = adapter.GetIdentityFunction();
            if (!string.IsNullOrWhiteSpace(identityFunction))
            {
                var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);

                if (identityColumn != null)
                {
                    var selectSql = "select * from " + table.QualifiedName + " where " + identityColumn.QuotedName +
                                     " = " + identityFunction;
                    if (adapter.ProviderSupportsCompoundStatements)
                    {
                        return InsertRowsWithCompoundStatement(adapter, data, transaction, table, columns, selectSql, insertSql);
                    }

                    return InsertRowsWithSeparateStatements(adapter, data, transaction, table, columns, insertSql, selectSql);
                }
            }

            InsertRowsWithoutFetchBack(adapter, data, table, columns, insertSql);

            return null;
        }
Пример #10
0
        public IEnumerable <IDictionary <string, object> > Insert(AdoAdapter adapter, string tableName, IEnumerable <IDictionary <string, object> > data, IDbTransaction transaction)
        {
            var table   = adapter.GetSchema().FindTable(tableName);
            var columns = table.Columns.Where(c => !c.IsIdentity).ToList();

            string columnList = string.Join(",", columns.Select(c => c.QuotedName));
            string valueList  = string.Join(",", columns.Select(c => "?"));

            string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";

            var helper = transaction == null
                             ? new BulkInserterHelper(adapter, data, table, columns)
                             : new BulkInserterTransactionHelper(adapter, data, table, columns, transaction);

            var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);

            if (identityColumn != null)
            {
                var identityFunction = adapter.GetIdentityFunction();
                if (!string.IsNullOrWhiteSpace(identityFunction))
                {
                    return(InsertRowsAndReturn(adapter, identityFunction, helper, insertSql, table));
                }
            }

            helper.InsertRowsWithoutFetchBack(insertSql);

            return(null);
        }
        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction, bool returnRequired)
        {
            var s = DatabaseSchema.Get(adapter.ConnectionProvider, new ProviderHelper());
            var table = s.FindTable(tableName);
            
            var tuples = InitializeInsertion(table);
            foreach (var d in data)
                tuples[d.Key.Homogenize()].InsertedValue = d.Value;

            Func<IDbCommand> command =
                () =>
                    {
                        var c = transaction != null
                                    ? transaction.Connection.CreateCommand()
                                    : adapter.CreateConnection().CreateCommand();
                        return c;
                    };

            IDbCommand cmd;
            using (cmd = ConstructCommand(tuples, table.QualifiedName, command))
            {
                cmd.WriteTrace();
                cmd.Connection.TryOpen();
                cmd.ExecuteNonQuery();
                var returnData = new DbDictionary();
                foreach (var it in tuples.Values)
                    returnData.Add(it.SimpleDataColumn, NormalizeReturningValue((IDbDataParameter)cmd.Parameters[it.ReturningParameterName]));
                data = returnData;
            }

            return data;
        }
Пример #12
0
        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null,
            bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);

            var insertData = data.Where(p => table.HasColumn(p.Key)).Select((kv, idx) => new InsertColumn
            {
                Name = kv.Key,
                ParameterName = "@p" + idx,
                Value = kv.Value,
                Column = (FbColumn) table.FindColumn(kv.Key)
            }).ToArray();

            if (transaction == null)
            {
                using (var connection = adapter.ConnectionProvider.CreateConnection())
                {
                    connection.Open();
                    return CreateAndExecuteInsertCommand(connection, table, insertData, resultRequired);
                }
            }
            else
            {
                return CreateAndExecuteInsertCommand(transaction.Connection, table, insertData, resultRequired, transaction);
            }
            
        }
Пример #13
0
 protected QueryBuilderBase(AdoAdapter adapter, int bulkIndex, IFunctionNameConverter functionNameConverter)
 {
     _adoAdapter = adapter;
     _bulkIndex = bulkIndex;
     _schema = _adoAdapter.GetSchema();
     _commandBuilder = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder, functionNameConverter);
 }
Пример #14
0
 public QueryBuilder(AdoAdapter adoAdapter, int bulkIndex)
 {
     _adoAdapter               = adoAdapter;
     _bulkIndex                = bulkIndex;
     _schema                   = _adoAdapter.GetSchema();
     _commandBuilder           = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder);
 }
 protected QueryBuilderBase(AdoAdapter adapter, int bulkIndex, IFunctionNameConverter functionNameConverter)
 {
     _adoAdapter               = adapter;
     _bulkIndex                = bulkIndex;
     _schema                   = _adoAdapter.GetSchema();
     _commandBuilder           = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder, functionNameConverter);
 }
Пример #16
0
 public QueryBuilder(AdoAdapter adoAdapter, int bulkIndex)
 {
     _adoAdapter = adoAdapter;
     _bulkIndex = bulkIndex;
     _schema = _adoAdapter.GetSchema();
     _commandBuilder = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder);
 }
Пример #17
0
 public AdoAdapterUpserter(AdoAdapter adapter, IDbTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
     if (transaction != null)
     {
         _connection = transaction.Connection;
     }
 }
Пример #18
0
        public int Update(AdoAdapter adapter, string tableName, IList <IDictionary <string, object> > data, IEnumerable <string> criteriaFieldNames, IDbTransaction transaction)
        {
            int count = 0;

            if (data == null || !data.Any())
            {
                return(count);
            }

            var criteriaFieldNameList = criteriaFieldNames.ToList();

            if (criteriaFieldNameList.Count == 0)
            {
                throw new NotSupportedException("Adapter does not support key-based update for this object.");
            }

            if (!AllRowsHaveSameKeys(data))
            {
                throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            }
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary <string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                                        ExpressionHelper.CriteriaDictionaryToExpression(
                                                                                            tableName, GetCriteria(criteriaFieldNameList, exampleRow)));

            var connection = adapter.CreateConnection();

            using (connection.MaybeDisposable())
                using (var command = commandBuilder.GetRepeatableCommand(connection, adapter.Options as AdoOptions))
                {
                    if (transaction != null)
                    {
                        command.Transaction = transaction;
                    }
                    connection.OpenIfClosed();
                    var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                    foreach (var row in data)
                    {
                        foreach (var kvp in row)
                        {
                            if (propertyToParameterMap.ContainsKey(kvp.Key))
                            {
                                propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                            }
                        }
                        count += command.TryExecuteNonQuery();
                    }
                }

            return(count);
        }
Пример #19
0
        public AdoAdapterAggregator(AdoAdapter adapter, DbTransaction transaction)
        {
			if (adapter == null) throw new ArgumentNullException("adapter");
			_adapter = adapter;

			if (transaction != null)
			{
				_transaction = transaction;
				_connection = transaction.Connection;
			}
		}
Пример #20
0
        public IDbCommand GetDbCommand(AdoAdapter adapter, IDbConnection connection, IEnumerable<object> parameterValues)
        {
            var command = connection.CreateCommand(adapter.AdoOptions);
            command.CommandText = _commandText;

            foreach (var parameter in CreateParameters(adapter.GetSchema(), command, parameterValues))
            {
                command.Parameters.Add(parameter);
            }
            return command;
        }
Пример #21
0
        public IDbCommand GetDbCommand(AdoAdapter adapter, IDbConnection connection, IEnumerable <object> parameterValues)
        {
            var command = connection.CreateCommand(adapter.AdoOptions);

            command.CommandText = _commandText;

            foreach (var parameter in CreateParameters(adapter.GetSchema(), command, parameterValues))
            {
                command.Parameters.Add(parameter);
            }
            return(command);
        }
        private static Dictionary<Column, object> BuildDataDictionary(AdoAdapter adapter,
                                                                      IDictionary<string, object> data, Table table)
        {
            Func<string, bool> columnFilter = key =>
                                              table.HasColumn(key) &&
                                              (table.FindColumn(key).IsWriteable ||
                                               ((adapter.AdoOptions != null && adapter.AdoOptions.IdentityInsert) && table.FindColumn(key).IsIdentity));
            
            return data.Where(kvp => columnFilter(kvp.Key))
                       .ToDictionary(kvp => table.FindColumn(kvp.Key), kvp => kvp.Value);

        } 
Пример #23
0
        public AdoAdapterFinder(AdoAdapter adapter, IDbTransaction transaction)
        {
            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }
            _adapter = adapter;

            if (transaction != null)
            {
                _transaction = transaction;
                _connection  = transaction.Connection;
            }
        }
Пример #24
0
 private static void InsertRowsWithoutFetchBack(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data, Table table, List<Column> columns,
                                                string insertSql)
 {
     using (var connection = adapter.CreateConnection())
     {
         using (var insertCommand = new CommandHelper(adapter.SchemaProvider).Create(connection, insertSql))
         {
             connection.Open();
             foreach (var row in data)
             {
                 InsertRow(row, columns, table, insertCommand);
             }
         }
     }
 }
Пример #25
0
        private static IEnumerable<IDictionary<string, object>> InsertRowsAndReturn(AdoAdapter adapter, string identityFunction, BulkInserterHelper helper, string insertSql, Table table, Func<IDictionary<string, object>, Exception, bool> onError)
        {
            var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);

            if (identityColumn != null)
            {
                var selectSql = "select * from " + table.QualifiedName + " where " + identityColumn.QuotedName +
                                " = " + identityFunction;
                if (adapter.ProviderSupportsCompoundStatements)
                {
                    return helper.InsertRowsWithCompoundStatement(insertSql, selectSql, onError);
                }
                return helper.InsertRowsWithSeparateStatements(insertSql, selectSql, onError);
            }

            return null;
        }
Пример #26
0
        public int Update(AdoAdapter adapter, string tableName, IList<IDictionary<string, object>> data, IEnumerable<string> criteriaFieldNames, IDbTransaction transaction)
        {
            int count = 0;
            if (data == null || !data.Any()) 
                return count;

            var criteriaFieldNameList = criteriaFieldNames.ToList();
            if (criteriaFieldNameList.Count == 0) throw new NotSupportedException("Adapter does not support key-based update for this object.");

            if (!AllRowsHaveSameKeys(data)) throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary<string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                    ExpressionHelper.CriteriaDictionaryToExpression(
                                                                        tableName, GetCriteria(criteriaFieldNameList, exampleRow)));

            var connection = adapter.CreateConnection();
            using (connection.MaybeDisposable())
            using (var command = commandBuilder.GetRepeatableCommand(connection))
            {
                if (transaction != null)
                {
                    command.Transaction = transaction;
                }
                connection.OpenIfClosed();
                var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                foreach (var row in data)
                {
                    foreach (var kvp in row)
                    {
                        if (propertyToParameterMap.ContainsKey(kvp.Key))
                        {
                            propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                        }
                    }
                    count += command.ExecuteNonQuery();
                }
            }

            return count;
        }
Пример #27
0
        internal IDictionary<string, object> ExecuteSingletonQuery(AdoAdapter adapter, string sql, IEnumerable<Column> columns, IEnumerable<Object> values, IDbTransaction transaction)
        {
            if (transaction != null)
            {
                var command = new CommandHelper(adapter).CreateInsert(transaction.Connection, sql, columns, values.ToArray());
                command.Transaction = transaction;
                return TryExecuteSingletonQuery(command);
            }

            var connection = adapter.CreateConnection();
            using (connection.MaybeDisposable())
            {
                using (var command = new CommandHelper(adapter).CreateInsert(connection, sql, columns, values.ToArray()))
                {
                    connection.OpenIfClosed();
                    return TryExecuteSingletonQuery(command);
                }
            }
        }
Пример #28
0
 public void InitDataBase(string connectionString)
 {
     var ado = new AdoAdapter();
     var sql = new SqlQueryPager();
     var db = Database.OpenConnection(connectionString);
     var prowinceDictionary = new Dictionary<int, int>();
     using (var connection = new SqlConnection(connectionString))
     {
         connection.Open();
         using (var command = new SqlCommand(Const.DBCreateScript, connection))
         {
             command.ExecuteNonQuery();
         }
     }
     foreach (var province in TestData.ProvinceData.GetProvinces())
     {
         db.Province.Insert(new { Name = province.Name, Code = province.Code });
     }
     var provinces = db.Province.All().ToList();
     foreach (var province in provinces)
     {
         prowinceDictionary.Add(province.Code, province.Id);
     }
     Bulk.BulkUploadToSql bulk =
            Bulk.BulkUploadToSql.Load(
                TestData.HomeData.GetHomes()
                    .Select(
                        i =>
                            new Bulk.Home
                            {
                                AddTime = DateTime.Now,
                                BuildYear = i.BuildYear,
                                City = i.City,
                                Description = i.Description,
                                Price = i.Price,
                                Surface = i.Surface,
                                ProvinceId = prowinceDictionary[i.HomeProvince.Code],
                            }), "Home", 10000, connectionString);
     bulk.Flush();
 }
Пример #29
0
 private static Dictionary<Column, object> BuildDataDictionary(AdoAdapter adapter, IDictionary<string, object> data, Table table)
 {
     Func<string, bool> columnFilter;
     if (adapter.AdoOptions != null && adapter.AdoOptions.IdentityInsert)
     {
         columnFilter =
             key =>
                 {
                     Column column;
                     if (table.TryFindColumn(key, out column))
                     {
                         return column.IsWriteable || column.IsIdentity;
                     }
                     return false;
                 };
     }
     else
     {
         columnFilter = key => table.HasColumn(key) && table.FindColumn(key).IsWriteable;
     }
     var dataDictionary = data.Where(kvp => columnFilter(kvp.Key))
         .ToDictionary(kvp => table.FindColumn(kvp.Key), kvp => kvp.Value);
     return dataDictionary;
 }
Пример #30
0
 public AdoAdapterAggregator(AdoAdapter adapter) : this(adapter, null)
 {
 }
 public IProcedureExecutor GetProcedureExecutor(AdoAdapter adapter, ObjectName procedureName)
 {
     return new ProcedureExecutor(adapter, procedureName);
 }
Пример #32
0
 public AdoAdapterGetter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #33
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #34
0
 public int Update(AdoAdapter adapter, string tableName, IList <IDictionary <string, object> > data, IDbTransaction transaction)
 {
     return(Update(adapter, tableName, data, adapter.GetKeyFieldNames(tableName).ToList(), transaction));
 }
Пример #35
0
 public AdoAdapterInserter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #36
0
 public QueryBuilder(AdoAdapter adoAdapter)
     : base(adoAdapter)
 {
 }
Пример #37
0
 public QueryBuilder(AdoAdapter adoAdapter)
 {
     _adoAdapter = adoAdapter;
     _schema     = _adoAdapter.GetSchema();
 }
Пример #38
0
 public AdoAdapterQueryRunner(AdoAdapter adapter, AdoAdapterTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
 }
 protected QueryBuilderBase(AdoAdapter adapter, int bulkIndex) : this(adapter, bulkIndex, null)
 {
 }
Пример #40
0
 public AdoAdapterInserter(AdoAdapter adapter, IDbTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
 }
Пример #41
0
 public AdoAdapterQueryRunner(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #42
0
 public AdoAdapterGetter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #43
0
 public ProcedureExecutor(AdoAdapter adapter, ObjectName procedureName)
 {
     _adapter       = adapter;
     _procedureName = procedureName;
     _executeImpl   = ExecuteReader;
 }
Пример #44
0
 public AdoAdapterQueryRunner(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #45
0
 public CommandHelper(AdoAdapter adapter)
 {
     _adapter = adapter;
     _schemaProvider = adapter.SchemaProvider;
 }
Пример #46
0
 public AdoAdapterQueryRunner(AdoAdapter adapter, AdoAdapterTransaction transaction)
 {
     _adapter = adapter;
     _transaction = transaction;
 }
Пример #47
0
        public static IObservable <IDictionary <string, object> > ToObservable(this IDbCommand command, IDbConnection connection, AdoAdapter adapter, IDictionary <string, int> index)
        {
            var runner = adapter.ProviderHelper.GetCustomProvider <IObservableQueryRunner>(adapter.ConnectionProvider) ?? new ObservableQueryRunner();

            return(runner.Run(command, connection, index));
        }
Пример #48
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, (IDbTransaction)null)
 {
 }
Пример #49
0
 public static IObservable <IDictionary <string, object> > ToObservable(this IDbCommand command, IDbConnection connection, AdoAdapter adapter)
 {
     return(ToObservable(command, connection, adapter, null));
 }
Пример #50
0
 public AdoAdapterFinder(AdoAdapter adapter, IDbConnection connection)
 {
     _adapter = adapter;
     _connection = connection;
 }
Пример #51
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #52
0
 public CommandHelper(AdoAdapter adapter)
 {
     _adapter        = adapter;
     _schemaProvider = adapter.SchemaProvider;
 }
Пример #53
0
 public QueryBuilder(AdoAdapter adoAdapter) : this(adoAdapter, -1)
 {
 }
Пример #54
0
 public AdoAdapterUpserter(AdoAdapter adapter) : this(adapter, (IDbTransaction)null)
 {
 }
Пример #55
0
        private static IEnumerable <IDictionary <string, object> > InsertRowsAndReturn(AdoAdapter adapter, string identityFunction, BulkInserterHelper helper,
                                                                                       string insertSql, Table table)
        {
            var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);

            if (identityColumn != null)
            {
                var selectSql = "select * from " + table.QualifiedName + " where " + identityColumn.QuotedName +
                                " = " + identityFunction;
                if (adapter.ProviderSupportsCompoundStatements)
                {
                    return(helper.InsertRowsWithCompoundStatement(insertSql, selectSql));
                }
                return(helper.InsertRowsWithSeparateStatements(insertSql, selectSql));
            }

            return(null);
        }
Пример #56
0
 public AdoAdapterUpserter(AdoAdapter adapter, IDbConnection connection)
 {
     _adapter    = adapter;
     _connection = connection;
 }
Пример #57
0
 public AdoAdapterAggregator(AdoAdapter adapter) : this(adapter, null)
 {
 }
Пример #58
0
 public AdoAdapterRelatedFinder(AdoAdapter adapter)
 {
     _adapter = adapter;
 }
 public BulkInserterTransactionHelper(AdoAdapter adapter, IEnumerable <IDictionary <string, object> > data, Table table, List <Column> columns, IDbTransaction transaction)
     : base(adapter, data, table, columns)
 {
     _transaction = transaction;
 }
Пример #60
0
 public QueryBuilder(AdoAdapter adoAdapter, int bulkIndex) : base(adoAdapter, bulkIndex)
 {
 }