Esempio n. 1
0
    static CDBVariantArray TestBatch(CMysql mysql, List <KeyValuePair <CDBColumnInfoArray, CDBVariantArray> > ra)
    {
        //sql with delimiter '|'
        string sql  = @" delete from employee;delete from company|
                        INSERT INTO company(ID,NAME,ADDRESS,Income)VALUES(?,?,?,?)|
                        insert into employee(CompanyId,name,JoinDate,image,DESCRIPTION,Salary)values(?,?,?,?,?,?)|
                        SELECT * from company;select * from employee;select curtime()|
                        call sp_TestProc(?,?,?)";
        string wstr = ""; //make test data

        while (wstr.Length < 128 * 1024)
        {
            wstr += "广告做得不那么夸张的就不说了,看看这三家,都是正儿八经的公立三甲,附属医院,不是武警,也不是部队,更不是莆田,都在卫生部门直接监管下,照样明目张胆地骗人。";
        }
        string str = ""; //make test data

        while (str.Length < 256 * 1024)
        {
            str += "The epic takedown of his opponent on an all-important voting day was extraordinary even by the standards of the 2016 campaign -- and quickly drew a scathing response from Trump.";
        }
        CDBVariantArray vData = new CDBVariantArray();

        using (CScopeUQueue sbBlob = new CScopeUQueue()) {
            //first set
            vData.Add(1);
            vData.Add("Google Inc.");
            vData.Add("1600 Amphitheatre Parkway, Mountain View, CA 94043, USA");
            vData.Add(66000000000.0);
            vData.Add(1); //google company id
            vData.Add("Ted Cruz");
            vData.Add(DateTime.Now);
            sbBlob.Save(wstr);
            vData.Add(sbBlob.UQueue.GetBuffer());
            vData.Add(wstr);
            vData.Add(254000.0);
            vData.Add(1);
            vData.Add(1.4);
            vData.Add(0);

            //second set
            vData.Add(2);
            vData.Add("Microsoft Inc.");
            vData.Add("700 Bellevue Way NE- 22nd Floor, Bellevue, WA 98804, USA");
            vData.Add(93600000000.0);
            vData.Add(1); //google company id
            vData.Add("Donald Trump");
            vData.Add(DateTime.Now);
            sbBlob.UQueue.SetSize(0);
            sbBlob.Save(str);
            vData.Add(sbBlob.UQueue.GetBuffer());
            vData.Add(str);
            vData.Add(20254000.0);
            vData.Add(2);
            vData.Add(2.5);
            vData.Add(0);

            //third set
            vData.Add(3);
            vData.Add("Apple Inc.");
            vData.Add("1 Infinite Loop, Cupertino, CA 95014, USA");
            vData.Add(234000000000.0);
            vData.Add(2); //Microsoft company id
            vData.Add("Hillary Clinton");
            vData.Add(DateTime.Now);
            sbBlob.Save(wstr);
            vData.Add(sbBlob.UQueue.GetBuffer());
            vData.Add(wstr);
            vData.Add(6254000.0);
            vData.Add(0);
            vData.Add(4.5);
            vData.Add(0);
        }
        CMysql.DRows r = (handler, rowData) => {
            //rowset data come here
            int last = ra.Count - 1;
            KeyValuePair <CDBColumnInfoArray, CDBVariantArray> item = ra[last];
            item.Value.AddRange(rowData);
        };
        CMysql.DRowsetHeader rh = (handler) => {
            //rowset header comes here
            KeyValuePair <CDBColumnInfoArray, CDBVariantArray> item = new KeyValuePair <CDBColumnInfoArray, CDBVariantArray>(handler.ColumnInfo, new CDBVariantArray());
            ra.Add(item);
        };
        //first, execute delete from employee;delete from company
        //second, three sets of INSERT INTO company(ID,NAME,ADDRESS,Income)VALUES(?,?,?,?)
        //third, three sets of insert into employee(CompanyId,name,JoinDate,image,DESCRIPTION,Salary)values(?,?,?,?,?,?)
        //fourth, SELECT * from company;select * from employee;select curtime()
        //last, three sets of call sp_TestProc(?,?,?)
        bool ok = mysql.ExecuteBatch(tagTransactionIsolation.tiUnspecified, sql, vData, er, r, rh, (h) => {
            //called before rh, r and er
            //ra.Clear();
        }, null, tagRollbackPlan.rpDefault, (h, canceled) => {
            //called when canceling or socket closed if client queue is NOT used
        }, "|");

        return(vData);
    }