def InsertBLOBByPreparedStatement(): wstr = "" while len(wstr) < 128 * 1024: wstr += u'近日,一则极具震撼性的消息,在中航工业的干部职工中悄然流传:中航工业科技委副主任、总装备部先进制造技术专家组组长、原中航工业制造所所长郭恩明突然失联。老郭突然失联,在中航工业和国防科技工业投下了震撼弹,也给人们留下了难以解开的谜团,以正面形象示人的郭恩明,为什么会涉足谍海,走上不归路,是被人下药被动失足?还是没能逃过漂亮“女间谍“的致命诱惑?还是仇视社会主义,仇视航空工业,自甘堕落与国家与人民为敌?' str = "" while len(str) < 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.' sqlInsert = u'insert or replace into employee(EMPLOYEEID, CompanyId, name, JoinDate, image, DESCRIPTION, Salary) values(?, ?, ?, ?, ?, ?, ?);select * from employee where employeeid = ?' ok = sqlite.Prepare(sqlInsert, cb) vData = [] sbBlob = CUQueue() #first set of data vData.append(1) vData.append(1) #google company id vData.append("Ted Cruz") vData.append(datetime.datetime.now()) sbBlob.SaveString(wstr) vData.append(sbBlob.GetBuffer()) vData.append(wstr) vData.append(254000.0) vData.append(1) #second set of data vData.append(2) vData.append(1) #google company id vData.append("Donald Trump") vData.append(datetime.datetime.now()) sbBlob.SetSize(0) sbBlob.SaveAString(str) vData.append(sbBlob.GetBuffer()) vData.append(str) vData.append(20254000.0) vData.append(2) #third set of data vData.append(3) vData.append(2) #Microsoft company id vData.append("Hillary Clinton") vData.append(datetime.datetime.now()) sbBlob.SaveString(wstr) vData.append(sbBlob.GetBuffer()) vData.append(wstr) vData.append(6254000.0) vData.append(3) return sqlite.ExecuteParameters(vData, cbExecute, cbRows, cbRowHeader)
def OnResultReturned(self, reqId, q): if self.RouteeRequest and reqId == piConst.idComputePi: dStart = q.LoadDouble() dStep = q.LoadDouble() nNum = q.LoadUInt() dX = dStart + dStep / 2 dd = dStep * 4.0 ComputeRtn = 0.0 for n in range(0, nNum): dX += dStep ComputeRtn += dd / (1 + dX * dX) q.SetSize(0) self.SendRouteeResult(CUQueue().SaveDouble(ComputeRtn))
def TestBLOBByPreparedStatement(): sql = u'insert or replace into employee(EMPLOYEEID,CompanyId,name,JoinDate,image,' \ u'DESCRIPTION,Salary)values(?,?,?,?,?,?,?);select * from employee where employeeid=?' sqlite.Prepare(sql) vData = [] sbBlob = CUQueue() # first set of data vData.append(1) vData.append(1) # google company id vData.append("Ted Cruz") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(254000.0) vData.append(1) # second set of data vData.append(2) vData.append(1) # google company id vData.append("Donald Trump") vData.append(datetime.datetime.now()) sbBlob.SetSize(0) sbBlob.SaveAString(g_astr) vData.append(sbBlob.GetBuffer()) vData.append(g_astr) vData.append(20254000.0) vData.append(2) # third set of data vData.append(3) vData.append(2) # Microsoft company id vData.append("Hillary Clinton") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(6254000.0) vData.append(3) return sqlite.execute(vData, cbRows, cbRowHeader)
def TestEnqueue(aq): print('Going to enqueue 1024 messages ......') idMessage = 0 n = 0 while n < 1024: s = str(n) + ' Object test' m = n % 3 if m == 0: idMessage = idMessage0 elif m == 1: idMessage = idMessage1 else: idMessage = idMessage2 # enqueue two unicode strings and one int if not aq.Enqueue(TEST_QUEUE_KEY, idMessage, CUQueue().SaveString('SampleName').SaveString(s).SaveInt(n)): aq.throw(CAsyncQueue.idEnqueue) n += 1
def TestBLOBByPreparedStatement(): mysql.prepare( u'insert into employee(CompanyId,name,JoinDate,image,DESCRIPTION,Salary)values(?,?,?,?,?,?)' ) vData = [] sbBlob = CUQueue() # first set of data vData.append(1) # google company id vData.append("Ted Cruz") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(254000.0) # second set of data vData.append(1) # google company id vData.append("Donald Trump") vData.append(datetime.datetime.now()) sbBlob.SetSize(0) sbBlob.SaveAString(g_astr) vData.append(sbBlob.GetBuffer()) vData.append(g_astr) vData.append(20254000.0) # third set of data vData.append(2) # Microsoft company id vData.append("Hillary Clinton") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(6254000.0) return mysql.execute(vData)
def TestEnqueue(aq): print('Going to enqueue 1024 messages ......') idMessage = 0 n = 0 while n < 1024: s = str(n) + ' Object test' m = n % 3 if m == 0: idMessage = idMessage0 elif m == 1: idMessage = idMessage1 else: idMessage = idMessage2 # enqueue two unicode strings and one int ok = aq.Enqueue(TEST_QUEUE_KEY, idMessage, CUQueue().SaveString('SampleName').SaveString(s).SaveInt(n)) n += 1 if not ok: return False return True
def TestBatch(): # sql with delimiter '|' 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(?,?,?)' vData = [] sbBlob = CUQueue() vData.append(1) vData.append("Google Inc.") vData.append("1600 Amphitheatre Parkway, Mountain View, CA 94043, USA") vData.append(66000000000.0) vData.append(1) # google company id vData.append("Ted Cruz") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(254000.0) vData.append(1) vData.append(1.4) vData.append(0) vData.append(2) vData.append("Microsoft Inc.") vData.append( "700 Bellevue Way NE- 22nd Floor, Bellevue, WA 98804, USA") vData.append(93600000000.0) vData.append(1) # google company id vData.append("Donald Trump") vData.append(datetime.datetime.now()) sbBlob.SetSize(0) sbBlob.SaveAString(g_astr) vData.append(sbBlob.GetBuffer()) vData.append(g_astr) vData.append(20254000.0) vData.append(2) vData.append(2.5) vData.append(0) vData.append(3) vData.append("Apple Inc.") vData.append("1 Infinite Loop, Cupertino, CA 95014, USA") vData.append(234000000000.0) vData.append(2) # Microsoft company id vData.append("Hillary Clinton") vData.append(datetime.datetime.now()) sbBlob.SaveString(g_wstr) vData.append(sbBlob.GetBuffer()) vData.append(g_wstr) vData.append(6254000.0) vData.append(0) vData.append(4.5) vData.append(0) # first start a manual transaction with isolation level tiReadCommited # second, execute delete from employee;delete from company # third, prepare and execute three sets of # INSERT INTO company(ID,NAME,ADDRESS,Income)VALUES(?,?,?,?) # fourth, prepare and execute three sets of insert into employee # (CompanyId,name,JoinDate,image,DESCRIPTION,Salary)values(?,?,?,?,?,?) # fifth, SELECT * from company;select * from employee;select curtime() # sixth, prepare and execute three sets of call sp_TestProc(?,?,?) # last, commit all if no error happens or rollback if there is an error return mysql.executeBatch(tagTransactionIsolation.tiReadCommited, sql, vData, cbRows, cbRowHeader, '|', cbBatchHeader), vData
def TestBatch(): # sql with delimiter '|' 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(?,?,?)" wstr = "" while len(wstr) < 128 * 1024: wstr += u'近日,一则极具震撼性的消息,在中航工业的干部职工中悄然流传:中航工业科技委副主任、总装备部先进制造技术专家组组长、原中航工业制造所所长郭恩明突然失联。老郭突然失联,在中航工业和国防科技工业投下了震撼弹,也给人们留下了难以解开的谜团,以正面形象示人的郭恩明,为什么会涉足谍海,走上不归路,是被人下药被动失足?还是没能逃过漂亮“女间谍“的致命诱惑?还是仇视社会主义,仇视航空工业,自甘堕落与国家与人民为敌?' astr = "" while len(astr) < 256 * 1024: astr += '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.' vData = [] sbBlob = CUQueue() vData.append(1) vData.append("Google Inc.") vData.append("1600 Amphitheatre Parkway, Mountain View, CA 94043, USA") vData.append(66000000000.0) vData.append(1) # google company id vData.append("Ted Cruz") vData.append(datetime.datetime.now()) sbBlob.SaveString(wstr) vData.append(sbBlob.GetBuffer()) vData.append(wstr) vData.append(254000.0) vData.append(1) vData.append(1.4) vData.append(0) vData.append(2) vData.append("Microsoft Inc.") vData.append("700 Bellevue Way NE- 22nd Floor, Bellevue, WA 98804, USA") vData.append(93600000000.0) vData.append(1) # google company id vData.append("Donald Trump") vData.append(datetime.datetime.now()) sbBlob.SetSize(0) sbBlob.SaveAString(astr) vData.append(sbBlob.GetBuffer()) vData.append(astr) vData.append(20254000.0) vData.append(2) vData.append(2.5) vData.append(0) vData.append(3) vData.append("Apple Inc.") vData.append("1 Infinite Loop, Cupertino, CA 95014, USA") vData.append(234000000000.0) vData.append(2) # Microsoft company id vData.append("Hillary Clinton") vData.append(datetime.datetime.now()) sbBlob.SaveString(wstr) vData.append(sbBlob.GetBuffer()) vData.append(wstr) vData.append(6254000.0) vData.append(0) vData.append(4.5) vData.append(0) # 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(?,?,?) ok = mysql.ExecuteBatch(tagTransactionIsolation.tiUnspecified, sql, vData, cbExecute, cbRows, cbRowHeader, cbBatchHeader, None, tagRollbackPlan.rpDefault, cbDiscarded, '|') return vData
with CSocketPool(CHelloWorld) as sp: cc = CConnectionContext('localhost', 20901, 'PythonUser', 'TooMuchSecret') ok = sp.StartSocketPool(cc, 1, 1) hw = sp.Seek() ok = hw.AttachedClientSocket.ClientQueue.StartQueue('pqueue', 3600, False) #process requests one by one synchronously -- three round trips print(hw.sayHello(u'Jack', u'Smith')) hw.sleep(5000) ms = CMyStruct.MakeOne() res = hw.echo(ms) # asynchronously process all three requests with inline batching for best network efficiency def cbSayHello(ar): ret = ar.LoadString() print(ret) ok = hw.SendRequest(hwConst.idSayHelloHelloWorld, CUQueue().SaveString('Jack').SaveString('Smith'), cbSayHello) ok = hw.SendRequest(hwConst.idSleepHelloWorld, CUQueue().SaveUInt(5000), None) def cbEcho(ar): hw.ms = ar.Load(CMyStruct()) ok = hw.SendRequest(hwConst.idEchoHelloWorld, CUQueue().Save(ms), cbEcho) ok = hw.WaitAll() print('Press ENTER key to shutdown the demo application ......') line = sys.stdin.readline()
def sayHello(self, firstName, lastName): def arh(ar): self._res_sayHello = ar.LoadString() if self.SendRequest(hwConst.idSayHelloHelloWorld, CUQueue().SaveString(firstName).SaveString(lastName), arh): self.WaitAll() return self._res_sayHello
def echo(self, ms): def arh(ar): self._res_echo = ar.Load(CMyStruct()) if self.SendRequest(hwConst.idEchoHelloWorld, CUQueue().Save(ms), arh): self.WaitAll() return self._res_echo
def sleep(self, ms): if self.SendRequest(hwConst.idSleepHelloWorld, CUQueue().SaveUInt(ms), None): self.WaitAll()