Esempio n. 1
0
        public async Task InsertAsync()
        {
            var batchInsertNum = 1000000;
            var batchTable     = new DbTable("t_test");

            batchTable.AddColumn(new DbColumn
            {
                AutoIncrement = true,
                DataType      = typeof(long),
                Name          = "id"
            });
            batchTable.AddColumn("name");
            batchTable.AddColumn("no");
            for (var i = 0; i < batchInsertNum; i++)
            {
                var row = batchTable.AddRow();
                row["name"] = "SmartSql-" + Guid.NewGuid().ToString("N");
                row["no"]   = i;
            }
            using (BatchInsert batchInsert = new BatchInsert(_sqlMapper))
            {
                batchInsert.Table = batchTable;
                await batchInsert.InsertAsync();
            }
        }
Esempio n. 2
0
        public async Task InsertAsync()
        {
            var batchInsertNum = 1000000;
            var batchTable     = new DbTable("t_test");

            batchTable.AddColumn("Name");
            batchTable.AddColumn("No");
            for (var i = 0; i < batchInsertNum; i++)
            {
                var row = batchTable.AddRow();
                row["Name"] = "SmartSql-" + Guid.NewGuid().ToString("N");
                row["No"]   = i;
            }
            using (BatchInsert batchInsert = new BatchInsert(_sqlMapper))
            {
                batchInsert.Table = batchTable;
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "Name",
                    Mapping = "name"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "No",
                    Mapping = "no"
                });
                await batchInsert.InsertAsync();
            }
        }
Esempio n. 3
0
        //helper method
        private DbRow AddKeyColumnRow(DbTable table, string constrName, string tableName, string columnName, int ordinalPosition)
        {
            var row = table.AddRow();

            row["CONSTRAINT_NAME"]  = constrName;
            row["TABLE_NAME"]       = tableName;
            row["COLUMN_NAME"]      = columnName;
            row["ORDINAL_POSITION"] = ordinalPosition;
            return(row);
        }
Esempio n. 4
0
        public static DbTable ToDbTable(IDataReader dataReader)
        {
            DbTable dbTable = new DbTable();

            InitDbTableColumns(dataReader, dbTable);
            while (dataReader.Read())
            {
                var dbRow = dbTable.AddRow();
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    var colName = dataReader.GetName(i);
                    dbRow[colName] = dataReader[colName];
                }
            }
            return(dbTable);
        }
Esempio n. 5
0
        public async static Task <DbTable> ToDbTableAsync(IDataReaderWrapper dataReader)
        {
            DbTable dbTable = new DbTable();

            InitDbTableColumns(dataReader, dbTable);
            while (await dataReader.ReadAsync())
            {
                var dbRow = dbTable.AddRow();
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    var colName = dataReader.GetName(i);
                    dbRow[colName] = dataReader[colName];
                }
            }
            return(dbTable);
        }
Esempio n. 6
0
        private DbTable ToDbTable(System.Data.DataTable table)
        {
            var tbl = new DbTable();

            foreach (DataColumn col in table.Columns)
            {
                tbl.AddColumn(col.ColumnName, col.DataType);
            }
            foreach (DataRow drow in table.Rows)
            {
                var row = tbl.AddRow();
                foreach (var c in tbl.Columns)
                {
                    row[c.Index] = drow[c.Index];
                }
            }
            return(tbl);
        }
Esempio n. 7
0
 // 填充 rows
 public static void FillDbTable(DbTable dt, MySqlDataReader r)
 {
     while (r.Read())
     {
         var dr = dt.AddRow();
         for (int i = 0; i < r.FieldCount; ++i)
         {
             if (dt.columns[i].nullable && r.IsDBNull(i))
             {
                 dr[i].SetNull();
             }
             else
             {
                 FillValue(dr, r, i);
             }
         }
     }
 }
Esempio n. 8
0
        public void Insert()
        {
            var batchInsertNum = 1000000;
            var batchTable     = new DbTable("t_test");

            batchTable.AddColumn(new DbColumn
            {
                AutoIncrement = true,
                DataType      = typeof(long),
                Name          = "id"
            });
            batchTable.AddColumn("name", typeof(string));
            batchTable.AddColumn("no", typeof(int));
            for (var i = 0; i < batchInsertNum; i++)
            {
                var row = batchTable.AddRow();
                row["name"] = "SmartSql-" + Guid.NewGuid().ToString("N");
                row["no"]   = i;
            }
            using (BatchInsert batchInsert = new BatchInsert(_sqlMapper))
            {
                batchInsert.Table = batchTable;
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "id",
                    Mapping = "Id"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "name",
                    Mapping = "Name"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "no",
                    Mapping = "No"
                });
                batchInsert.Insert();
            }
        }