Ejemplo n.º 1
0
 def test_lob(self):
     xmlt = minidom.parse('configuration/python_config.xml')
     ips = xmlt.childNodes[0].getElementsByTagName('ip')
     ip = ips[0].childNodes[0].toxml()
     ports = xmlt.childNodes[0].getElementsByTagName('port')
     port = ports[0].childNodes[0].toxml()
     dbnames = xmlt.childNodes[0].getElementsByTagName('dbname')
     dbname = dbnames[0].childNodes[0].toxml()
     conStr = "CUBRID:" + ip + ":" + port + ":" + dbname + ":::"
     con = _cubrid.connect(conStr, "dba", "")
     cur = con.cursor()
     lob = con.lob()
     try:
         cur.prepare("drop table if exists lob_tb")
         cur.execute()
         cur.prepare(
             "create table lob_tb(image_id int PRIMARY KEY AUTO_INCREMENT, image BLOB)"
         )
         cur.execute()
         cur.prepare("insert into lob_tb values(NULL,?)")
         #lob=con.lob()
         lob.imports('cubrid_logo.png')
         cur.bind_lob(1, lob)
         cur.execute()
     except Exception, e:
         errorValue = str(e)
         print("errorValue: ", errorValue)
Ejemplo n.º 2
0
 def test_lob(self):
     xmlt = minidom.parse("configuration/python_config.xml")
     ips = xmlt.childNodes[0].getElementsByTagName("ip")
     ip = ips[0].childNodes[0].toxml()
     ports = xmlt.childNodes[0].getElementsByTagName("port")
     port = ports[0].childNodes[0].toxml()
     dbnames = xmlt.childNodes[0].getElementsByTagName("dbname")
     dbname = dbnames[0].childNodes[0].toxml()
     conStr = "CUBRID:" + ip + ":" + port + ":" + dbname + ":::"
     con = _cubrid.connect(conStr, "dba", "")
     cur = con.cursor()
     lob = con.lob()
     try:
         cur.prepare("drop table if exists lob_tb")
         cur.execute()
         cur.prepare("create table lob_tb(image_id int PRIMARY KEY AUTO_INCREMENT, image BLOB)")
         cur.execute()
         cur.prepare("insert into lob_tb values(NULL,?)")
         # lob=con.lob()
         lob.imports("cubrid_logo.png")
         cur.bind_lob(1, lob)
         cur.execute()
     except Exception, e:
         errorValue = str(e)
         print("errorValue: ", errorValue)
Ejemplo n.º 3
0
 def test_lob_null(self):
     xmlt = minidom.parse('configuration/python_config.xml')
     ips = xmlt.childNodes[0].getElementsByTagName('ip')
     ip = ips[0].childNodes[0].toxml()
     ports = xmlt.childNodes[0].getElementsByTagName('port')
     port = ports[0].childNodes[0].toxml()
     dbnames = xmlt.childNodes[0].getElementsByTagName('dbname')
     dbname = dbnames[0].childNodes[0].toxml()
     conStr = "CUBRID:"+ip+":"+port+":"+dbname+":::"
     con =_cubrid.connect(conStr, "dba","")
     cur=con.cursor()
     try:
        cur.prepare("drop table if exists collection_tb")
        cur.execute()
        cur.prepare("create table collection_tb( a set of int, b multiset of int , c list of int )")
        cur.execute()
        cur.prepare("insert into collection_tb values({},{},{}),(null,null,null),( {1,1},{1,1},{1,1})")
        cur.execute()
        cur.prepare("select * from collection_tb where a seteq {'1'} order by 1,2")
        cur.execute()
        row=cur.fetch_row()
        print ("row value: ", row)
        row=cur.fetch_row()
        print ("row value: ", row)
        row=cur.fetch_row()
        print ("row value: ", row)
     except Exception,e:
           errorValue=str(e)
           print("errorValue: ",errorValue)
Ejemplo n.º 4
0
 def test_lob_null(self):
     xmlt = minidom.parse('configuration/python_config.xml')
     ips = xmlt.childNodes[0].getElementsByTagName('ip')
     ip = ips[0].childNodes[0].toxml()
     ports = xmlt.childNodes[0].getElementsByTagName('port')
     port = ports[0].childNodes[0].toxml()
     dbnames = xmlt.childNodes[0].getElementsByTagName('dbname')
     dbname = dbnames[0].childNodes[0].toxml()
     conStr = "CUBRID:" + ip + ":" + port + ":" + dbname + ":::"
     con = _cubrid.connect(conStr, "dba", "")
     cur = con.cursor()
     try:
         cur.prepare("drop table if exists collection_tb")
         cur.execute()
         cur.prepare(
             "create table collection_tb( a set of int, b multiset of int , c list of int )"
         )
         cur.execute()
         cur.prepare(
             "insert into collection_tb values({},{},{}),(null,null,null),( {1,1},{1,1},{1,1})"
         )
         cur.execute()
         cur.prepare(
             "select * from collection_tb where a seteq {'1'} order by 1,2")
         cur.execute()
         row = cur.fetch_row()
         print("row value: ", row)
         row = cur.fetch_row()
         print("row value: ", row)
         row = cur.fetch_row()
         print("row value: ", row)
     except Exception, e:
         errorValue = str(e)
         print("errorValue: ", errorValue)
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):

        'Create a connecton to the database.'
        self.charset = ''
        kwargs2 = kwargs.copy()
        self.charset = kwargs2.pop('charset', 'utf8')

        self.connection = _cubrid.connect(*args, **kwargs2)
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):

        'Create a connecton to the database.'
        self.charset = ''
        kwargs2 = kwargs.copy()
        self.charset = kwargs2.pop('charset', 'utf8')

        self.connection = _cubrid.connect(*args, **kwargs2)
Ejemplo n.º 7
0
    def test_row_to_dict(self):
        con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'dba')
        c = con.cursor()

        c.prepare("DROP TABLE IF EXISTS cubrid_test")
        c.execute()

        c.prepare("CREATE TABLE cubrid_test(id integer auto_increment);")
        c.execute()

        c.prepare('insert into cubrid_test (id) values (1)')
        c.execute()

        c.prepare("select * from cubrid_test")
        c.execute()

        row = c.fetch_row(1)
        print '\nrow:\n'
        print row
Ejemplo n.º 8
0
    def test_row_to_dict(self):
        con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'dba')
        c = con.cursor()

        c.prepare("DROP TABLE IF EXISTS cubrid_test")
        c.execute()

        c.prepare("CREATE TABLE cubrid_test(id integer auto_increment);")
        c.execute()

        c.prepare('insert into cubrid_test (id) values (1)')
        c.execute()

        c.prepare("select * from cubrid_test");
        c.execute()

        row = c.fetch_row(1)
        print '\nrow:\n'
        print row
Ejemplo n.º 9
0
 def test_nextresult(self):
     xmlt = minidom.parse('configuration/python_config.xml')
     ips = xmlt.childNodes[0].getElementsByTagName('ip')
     ip = ips[0].childNodes[0].toxml()
     ports = xmlt.childNodes[0].getElementsByTagName('port')
     port = ports[0].childNodes[0].toxml()
     dbnames = xmlt.childNodes[0].getElementsByTagName('dbname')
     dbname = dbnames[0].childNodes[0].toxml()
     conStr = "CUBRID:" + ip + ":" + port + ":" + dbname + ":::"
     con = _cubrid.connect(conStr, "dba", "")
     cur = con.cursor()
     lob = con.lob()
     try:
         print con
         print cur
         cur.prepare("drop table if exists nextResult_tb")
         cur.execute()
         cur.prepare("create table nextResult_tb(id int)")
         cur.execute()
         cur.prepare("insert into nextResult_tb values(1),(2),(3),(4),(5)")
         cur.execute()
         cur.prepare("drop table if exists nextResult_tb2")
         cur.execute()
         cur.prepare("create table nextResult_tb2(id int)")
         cur.execute()
         cur.prepare(
             "insert into nextResult_tb2 values(6),(7),(8),(9),(10)")
         cur.execute()
         cur.prepare(
             "select * from nextResult_tb;select * from nextResult_tb2")
         cur.execute(CUBRID_EXEC_QUERY_ALL)
         cur.next_result()
         row = cur.fetch_row()
         while row:
             print("row value: ", row)
             row = cur.fetch_row()
         print row
     except Exception, e:
         errorValue = str(e)
         print("errorValue: ", errorValue)
Ejemplo n.º 10
0
    def test_nextresult(self):
        xmlt = minidom.parse('configuration/python_config.xml')
        ips = xmlt.childNodes[0].getElementsByTagName('ip')
        ip = ips[0].childNodes[0].toxml()
        ports = xmlt.childNodes[0].getElementsByTagName('port')
        port = ports[0].childNodes[0].toxml()
        dbnames = xmlt.childNodes[0].getElementsByTagName('dbname')
        dbname = dbnames[0].childNodes[0].toxml()
        conStr = "CUBRID:"+ip+":"+port+":"+dbname+":::"
        con = _cubrid.connect(conStr, "dba","")
        cur=con.cursor()
        lob=con.lob()
        try:
           print con
	   print cur
	   cur.prepare("drop table if exists nextResult_tb")
           cur.execute()
           cur.prepare("create table nextResult_tb(id int)")
           cur.execute()
           cur.prepare("insert into nextResult_tb values(1),(2),(3),(4),(5)")
           cur.execute()
           cur.prepare("drop table if exists nextResult_tb2")
           cur.execute()
           cur.prepare("create table nextResult_tb2(id int)")
           cur.execute()
           cur.prepare("insert into nextResult_tb2 values(6),(7),(8),(9),(10)")
           cur.execute()
           cur.prepare("select * from nextResult_tb;select * from nextResult_tb2")
           cur.execute(CUBRID_EXEC_QUERY_ALL)
           cur.next_result()
           row=cur.fetch_row()
           while row:
              print ("row value: ", row)
              row=cur.fetch_row() 
           print row
        except Exception,e:
              errorValue=str(e)
              print("errorValue: ",errorValue)
Ejemplo n.º 11
0
#sample_lob.py

import _cubrid

con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')

cur = con.cursor()

cur.prepare('create table test_lob (image BLOB)')
cur.execute()

lob_bind = con.lob()
lob_bind.imports('123.jpg')

cur.prepare("insert into test_lob values (?)")
cur.bind_lob(1, lob_bind)
cur.execute()

cur.prepare('select * from test_lob')
cur.execute()

lob_fetch = con.lob()
cur.fetch_lob(1, lob_fetch)
lob_fetch.export('123.out')

lob_bind.close()
lob_fetch.close()

cur.close()
con.close()
Ejemplo n.º 12
0
# sample_cubrid.py

import _cubrid
from _cubrid import *

print 'establish connect...'
print

con = _cubrid.connect('CUBRID:localhost:33000:demodb:::', 'public')

print 'server verison:', con.server_version()
print 'client verison:', con.client_version()
print

cur = con.cursor()

print 'create a table - test_cubrid'
print
cur.prepare('DROP TABLE IF EXISTS test_cubrid')
cur.execute()
cur.prepare('CREATE TABLE test_cubrid (id NUMERIC AUTO_INCREMENT(2009122350, 1), name VARCHAR(50))')
cur.execute()

print 'insert some data...'
print
cur.prepare("insert into test_cubrid (name) values ('Zhang San'), ('Li Si'), ('Wang Wu')")
cur.execute()

print 'rowcount:',cur.rowcount
print