コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }