???????
??????????????????????????????????д???????????????????????????????????????????G?????????????  ?????????????C#?????????????MySQL??
????????????????? select ?????????????C#?ж???????д???? ???????????????С?  ?????? select -> process -> insert???????衣 ??????????С??????£??????? or ??????)????
??????1??С?????????????????????????????????????? ??????????????????????
??????????????????????????
????????? ????????????
???????????????????к???????о??°??
????1. ????????-??????????????ORM????????EF??NHibernat ?????????
????2. ????????-AK47?? ???Dapper??PetaPoco?????cs?????????Ч????ü????????????????????PetaPoco :)??
????3. ???????????????????????Connection??Command?? ???д?????SQL?????
??????????
??????????????????????????????PASS?? ???????????????????С?
??????????????Dapper??PetaPoco ??????????????????????????IL????漼?????????????????Ч???PASS
?????e????????????????SQL???? ????DataReader ???и?Ч????????????????????????????????????????
??????????????£?
using (var conn = new MySqlConnection("Connection String..."))
{
conn.Open();
//????????????????????????????????????
var c = new MySqlCommand("set net_write_timeout=9999999; set net_read_timeout=9999999"?? conn);
c.ExecuteNonQuery();
MySqlCommand rcmd = new MySqlCommand();
rcmd.Connection = conn;
rcmd.CommandText = @"SELECT `f1`??`f2` FROM `table1`";
//???????????г??
rcmd.CommandTimeout = 99999999;
var myData = rcmd.ExecuteReader();
while (myData.Read())
{
var f1= myData.GetInt32(0);
var f2= myData.GetString(1);
//?????????????....
}
}
????????????????????????????????????????????????????????  ????????????????????
????????? ???????
???????????????????????????????????????? ??????????Щ?????????????????????????????????????C#??????????????? ?????θ?Ч??д?????????????
???????????????д?? ???????CLR via C# ????????????? ??O(∩_∩)O??????~ ????????????
?????????? ???????
?????????????????Ч???  ????????? ?????????BeginTransaction?? ???EndTransaction?? ????????????????????Ч??? ??????и????Ч?????????????insert???
????????????????
????insert into table (f1??f2) values(1??'sss')??values(2??'bbbb')??values(3??'cccc');
???????values??????????????????????????????????? ??
????????????????????100MB??SQL??У?MySQL???????????????????????????????? ??? MySQL?????????max_allowed_packet  ?????????? ?????1MB
??????????????α?????
//???StringBuilder??Ч????????
var sqlBuilder = new StringBuilder();
//???insert ?????
string sqlHeader = "insert into table1 (`f1`??`f2`) values";
sqlBuilder.Append(sqlHeader);
using (var conn = new MySqlConnection("Connection String..."))
{
conn.Open();
//????????????????????????????????????
var c = new MySqlCommand("set net_write_timeout=9999999; set net_read_timeout=9999999"?? conn);
c.ExecuteNonQuery();
MySqlCommand rcmd = new MySqlCommand();
rcmd.Connection = conn;
rcmd.CommandText = @"SELECT `f1`??`f2` FROM `table1`";
//???????????г??
rcmd.CommandTimeout = 99999999;
var myData = rcmd.ExecuteReader();
while (myData.Read())
{
var f1 = myData.GetInt32(0);
var f2 = myData.GetString(1);
//?????????????....
sqlBuilder.AppendFormat("({0}??'{1}')??"?? f1??AddSlash(f2));
if (sqlBuilder.Length >= 1024 * 1024 * 1024)//????????1MB length??????????????? 1MB??Packet???????????????
{
insertCmd.Execute(sqlBuilder.Remove(sqlBuilder.Length-1??1).ToString())//??????????????
sqlBuilder.Clear();//???
sqlBuilder.Append(sqlHeader);//?????insert ?
}
}
}
??????????????? ???????????Ч???????????????
????????
????????????????2???????????DataReader??SQL??????????Щ??????????
???????????????????????? ??Ч ?? ????? ?????????????????????????????
??????????????????  ??ν????????? ????????????????????????????????????????Щ??????????????????????д??