public void Write(TupleWrapper tuple, string tablename) { object[] rawdata = tuple.getData(); object[] rawcolumns = tuple.getColumns(); string columns = rawcolumns[0].ToString(); string data = "'" + rawdata[0].ToString() + "'"; for (int i = 1; i < rawcolumns.Length; i++) { columns += " , " + rawcolumns[i].ToString(); } for (int i = 1; i < rawdata.Length; i++) { if (rawdata[i].GetType() == typeof(DBNull)) { data += " , " + "" + "null" + ""; } else if (rawdata[i].GetType() == typeof(DateTime)) { data += " , " + "'" + convertDate(rawdata[i].ToString()) + "'"; } else { data += " , " + "'" + rawdata[i].ToString().Replace("\'", "") + "'"; } } string query = "INSERT INTO " + tablename + " (" + columns + ")" + " " + " VALUES(" + data + ")"; ExecuteNonQuery(query); }
public void batchInsert(TupleWrapper tuple, string tablename, int batchSize = 10000) { object[] rawdata = tuple.getData(); object[] rawcolumns = tuple.getColumns(); string columns = rawcolumns[0].ToString(); string data = "'" + rawdata[0].ToString() + "'"; for (int i = 1; i < rawcolumns.Length; i++) { columns += " , " + rawcolumns[i].ToString(); } for (int i = 1; i < rawdata.Length; i++) { if (rawdata[i] == null) { data += " , " + "'" + "null" + "'"; } else if (rawdata[i].GetType() == typeof(DateTime)) { data += " , " + "'" + convertDate(rawdata[i].ToString()) + "'"; } else { data += " , " + "'" + rawdata[i].ToString().Replace("\'", "") + "'"; } } batch += "INSERT INTO " + tablename + " (" + columns + ")" + " " + " VALUES(" + data + ") \n"; counter++; if (counter == batchSize) { counter = 0; ExecuteNonQuery(batch); } }