コード例 #1
0
ファイル: MySql.cs プロジェクト: wumingbear/SmartSql
        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();
            }
        }
コード例 #2
0
ファイル: PostgreSql.cs プロジェクト: wumingbear/SmartSql
        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();
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
ファイル: MyUtils.cs プロジェクト: denghe/69net
 // 填充 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);
             }
         }
     }
 }
コード例 #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();
            }
        }