Exemplo n.º 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;
        }
Exemplo n.º 3
0
 public BulkInserterHelper(AdoAdapter adapter, IEnumerable <IDictionary <string, object> > data, Table table, List <Column> columns)
 {
     Adapter  = adapter;
     Data     = data;
     _table   = table;
     _columns = columns;
 }
Exemplo n.º 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();
        }
      }
    }
Exemplo n.º 6
0
 public BulkInserterHelper(AdoAdapter adapter, IEnumerable<IDictionary<string, object>> data, Table table, List<Column> columns)
 {
     Adapter = adapter;
     Data = data;
     _table = table;
     _columns = columns;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 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);
            }
            
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 17
0
 public AdoAdapterUpserter(AdoAdapter adapter, IDbTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
     if (transaction != null)
     {
         _connection = transaction.Connection;
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
			}
		}
Exemplo n.º 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;
        }
Exemplo n.º 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);

        } 
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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();
 }
Exemplo n.º 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;
 }
Exemplo n.º 30
0
 public AdoAdapterAggregator(AdoAdapter adapter) : this(adapter, null)
 {
 }
 public IProcedureExecutor GetProcedureExecutor(AdoAdapter adapter, ObjectName procedureName)
 {
     return new ProcedureExecutor(adapter, procedureName);
 }
Exemplo n.º 32
0
 public AdoAdapterGetter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 33
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 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));
 }
Exemplo n.º 35
0
 public AdoAdapterInserter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 36
0
 public QueryBuilder(AdoAdapter adoAdapter)
     : base(adoAdapter)
 {
 }
Exemplo n.º 37
0
 public QueryBuilder(AdoAdapter adoAdapter)
 {
     _adoAdapter = adoAdapter;
     _schema     = _adoAdapter.GetSchema();
 }
Exemplo n.º 38
0
 public AdoAdapterQueryRunner(AdoAdapter adapter, AdoAdapterTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
 }
 protected QueryBuilderBase(AdoAdapter adapter, int bulkIndex) : this(adapter, bulkIndex, null)
 {
 }
Exemplo n.º 40
0
 public AdoAdapterInserter(AdoAdapter adapter, IDbTransaction transaction)
 {
     _adapter     = adapter;
     _transaction = transaction;
 }
Exemplo n.º 41
0
 public AdoAdapterQueryRunner(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 42
0
 public AdoAdapterGetter(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 43
0
 public ProcedureExecutor(AdoAdapter adapter, ObjectName procedureName)
 {
     _adapter       = adapter;
     _procedureName = procedureName;
     _executeImpl   = ExecuteReader;
 }
Exemplo n.º 44
0
 public AdoAdapterQueryRunner(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 45
0
 public CommandHelper(AdoAdapter adapter)
 {
     _adapter = adapter;
     _schemaProvider = adapter.SchemaProvider;
 }
Exemplo n.º 46
0
 public AdoAdapterQueryRunner(AdoAdapter adapter, AdoAdapterTransaction transaction)
 {
     _adapter = adapter;
     _transaction = transaction;
 }
Exemplo n.º 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));
        }
Exemplo n.º 48
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, (IDbTransaction)null)
 {
 }
Exemplo n.º 49
0
 public static IObservable <IDictionary <string, object> > ToObservable(this IDbCommand command, IDbConnection connection, AdoAdapter adapter)
 {
     return(ToObservable(command, connection, adapter, null));
 }
Exemplo n.º 50
0
 public AdoAdapterFinder(AdoAdapter adapter, IDbConnection connection)
 {
     _adapter = adapter;
     _connection = connection;
 }
Exemplo n.º 51
0
 public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 52
0
 public CommandHelper(AdoAdapter adapter)
 {
     _adapter        = adapter;
     _schemaProvider = adapter.SchemaProvider;
 }
Exemplo n.º 53
0
 public QueryBuilder(AdoAdapter adoAdapter) : this(adoAdapter, -1)
 {
 }
Exemplo n.º 54
0
 public AdoAdapterUpserter(AdoAdapter adapter) : this(adapter, (IDbTransaction)null)
 {
 }
Exemplo n.º 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);
        }
Exemplo n.º 56
0
 public AdoAdapterUpserter(AdoAdapter adapter, IDbConnection connection)
 {
     _adapter    = adapter;
     _connection = connection;
 }
Exemplo n.º 57
0
 public AdoAdapterAggregator(AdoAdapter adapter) : this(adapter, null)
 {
 }
Exemplo n.º 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;
 }
Exemplo n.º 60
0
 public QueryBuilder(AdoAdapter adoAdapter, int bulkIndex) : base(adoAdapter, bulkIndex)
 {
 }