예제 #1
0
 def test_escape_string(self):
     '''test escape string'''
     try:
         print CUBRIDdb.escape_string('', 1, 1)
     except Exception, e:
         errorValue = str(e)
         print("errorValue: ", errorValue)
예제 #2
0
파일: set.py 프로젝트: CUBRID/cubrid-python
 def test_escape_string(self):
     '''test escape string'''
     try:
         print CUBRIDdb.escape_string('',1,1)
     except Exception,e:
         errorValue=str(e)
         print("errorValue: ",errorValue)
예제 #3
0
def query(param, ip):
    print(param)

    if "server" not in param:
        return "select server"

    server = param["server"]

    id = ""
    pw = ""
    query = ""
    dbname = ""
    port = ""

    if "id" in param:
        if isinstance(param["id"], list):
            id = param["id"][0]
        else:
            id = param["id"]

    if "pw" in param:
        if isinstance(param["pw"], list):
            pw = param["pw"][0]
        else:
            pw = param["pw"]

    if "query" in param:
        query = param["query"]

    if "db" in param:
        dbname = param["db"]

    if "port" in param:
        port = param["port"]

    if param["query_type"] == "query":
        conn = CUBRIDdb.connect("CUBRID:%s:%s:%s:%s:%s:" % (server, port, dbname, id, pw))
        cursor = conn.cursor()

        syslog("[hubblemon-cubrid-query:%s-%s-%s(%s)] %s" % (server, dbname, id, ip, query))
        ret = cursor.execute(query)
        # print(ret)

        return common.core.return_as_table(cursor)

    else:  # exec
        conn = CUBRIDdb.connect("CUBRID:%s:%s:%s:%s:%s:" % (server, port, dbname, id, pw))
        cursor = conn.cursor()

        p = {"conn": conn, "cursor": cursor, "result": "None"}

        syslog("[hubblemon-cubrid-eval:%s-%s-%s(%s)] %s" % (server, dbname, id, ip, query))
        exec(query)

        return p["result"]
예제 #4
0
def query(param, ip):
	print(param)

	if 'server' not in param:
		return 'select server'	

	server = param['server']

	id = ''
	pw = ''
	query = ''
	dbname = ''
	port = ''

	if 'id' in param:
		if isinstance(param['id'], list):
			id = param['id'][0]
		else:
			id = param['id']

	if 'pw' in param:
		if isinstance(param['pw'], list):
			pw = param['pw'][0]
		else:
			pw = param['pw']

	if 'query' in param:
		query = param['query']

	if 'db' in param:
		dbname = param['db']

	if 'port' in param:
		port = param['port']

	if param['query_type'] == 'query':
		conn = CUBRIDdb.connect('CUBRID:%s:%s:%s:%s:%s:' % (server, port, dbname, id, pw))
		cursor = conn.cursor()

		syslog('[hubblemon-cubrid-query:%s-%s-%s(%s)] %s' % (server, dbname, id, ip, query))
		ret = cursor.execute(query)
		#print(ret)

		return common.core.return_as_table(cursor)
	
	else: # exec
		conn = CUBRIDdb.connect('CUBRID:%s:%s:%s:%s:%s:' % (server, port, dbname, id, pw))
		cursor = conn.cursor()

		p = {'conn':conn, 'cursor':cursor, 'result':'None' }

		syslog('[hubblemon-cubrid-eval:%s-%s-%s(%s)] %s' % (server, dbname, id, ip, query))
		exec(query)

		return p['result']
예제 #5
0
 def setUp(self):
         conStr = self.getConStr()                
         self.con = CUBRIDdb.connect(conStr, "dba","")
         self.cur = self.con.cursor()
         self.cur.execute("DROP TABLE IF EXISTS issue")
         self.cur.execute("CREATE TABLE issue(nameid int primary key ,age int,name VARCHAR(40))")
         self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('Mike',1,30),('John',2,28),('Bill',3,45)")
예제 #6
0
    def get_new_connection(self, conn_params):
        settings_dict = self.settings_dict

        # Connection to CUBRID database is made through connect() method.
        # Syntax:
        # connect (url[, user[password]])
        #    url - CUBRID:host:port:db_name:db_user:db_password:::
        #    user - Authorized username.
        #    password - Password associated with the username.
        url = "CUBRID"
        user = "******"
        passwd = ""

        if settings_dict['HOST'].startswith('/'):
            url += ':' + settings_dict['HOST']
        elif settings_dict['HOST']:
            url += ':' + settings_dict['HOST']
        else:
            url += ':localhost'
        if settings_dict['PORT']:
            url += ':' + settings_dict['PORT']
        if settings_dict['NAME']:
            url += ':' + settings_dict['NAME']
        if settings_dict['USER']:
            user = settings_dict['USER']
        if settings_dict['PASSWORD']:
            passwd = settings_dict['PASSWORD']

        url += ':::'

        con = Database.connect(url, user, passwd, charset='utf8')
        con.set_fetch_value_converter(django_fetch_value_converter)

        return con
예제 #7
0
        def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                #view_tb and view v 
                nsql2='drop table if exists view_tb'
                self.cursor.execute(nsql2)
                nsql3='create table view_tb(qty INT, price INT)'
                self.cursor.execute(nsql3)
                viewSql="INSERT INTO view_tb VALUES (3,50)"
                valueInsert=self.cursor.execute(viewSql)
                self.assertEquals(valueInsert,1)

                print "create view !"
                viewSql2='CREATE VIEW v AS SELECT qty, price, qty*price AS "value" FROM view_tb'
                self.cursor.execute(viewSql2)

                #table a_tbl and view b_view
                nsql2='drop table if exists py_a_tbl'
                self.cursor.execute(nsql2)
                nsql3='CREATE TABLE py_a_tbl(id INT NOT NULL,phone VARCHAR(10))'
                self.cursor.execute(nsql3)
                insertSql="INSERT INTO py_a_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333'), (4, NULL), (5, NULL)"
                valueInsert=self.cursor.execute(insertSql)
                self.assertEquals(valueInsert,5)
                viewSql2='CREATE VIEW b_view AS SELECT * FROM py_a_tbl WHERE phone IS NOT NULL WITH CHECK OPTION'
                self.cursor.execute(viewSql2)
예제 #8
0
	def setUp(self):
                conStr = self.getConStr()                
                self.con = CUBRIDdb.connect(conStr, "dba","")
		self.cur = self.con.cursor()

		sqlDrop = "drop table if exists numeric_db"
		self.cur.execute(sqlDrop)
		sqlDrop = "drop table if exists datetime_db"
		self.cur.execute(sqlDrop)
		sqlDrop = "drop table if exists bit_db"
		self.cur.execute(sqlDrop)
		sqlDrop = "drop table if exists character_db"
		self.cur.execute(sqlDrop)
		sqlDrop = "drop table if exists collection_db"
		self.cur.execute(sqlDrop)

		sqlCreate = "create table numeric_db(c_int int, c_short short,c_numeric numeric(10,4),c_float float,c_double double,c_monetary monetary)"
		self.cur.execute(sqlCreate)
                sqlCreate = "create table datetime_db(c_date date, c_time time, c_datetime datetime, c_timestamp timestamp)"
                self.cur.execute(sqlCreate)
                sqlCreate = "create table bit_db(c_bit bit(8),c_varbit bit varying(8))"
                self.cur.execute(sqlCreate)
                sqlCreate = "create table character_db(c_char char(4),c_varchar varchar(4),c_string string,c_nchar nchar(4),c_varnchar nchar varying(4))"
                self.cur.execute(sqlCreate)
		sqlCreate = "create table collection_db(c_set set,c_multiset multiset, c_sequence sequence)"
                self.cur.execute(sqlCreate)
예제 #9
0
    def setUp(self):
        conStr = self.getConStr()
        self.conn = CUBRIDdb.connect(conStr, "dba", "")
        self.cursor = self.conn.cursor()
        #view_tb and view v
        nsql2 = 'drop table if exists view_tb'
        self.cursor.execute(nsql2)
        nsql3 = 'create table view_tb(qty INT, price INT)'
        self.cursor.execute(nsql3)
        viewSql = "INSERT INTO view_tb VALUES (3,50)"
        valueInsert = self.cursor.execute(viewSql)
        self.assertEquals(valueInsert, 1)

        print "create view !"
        viewSql2 = 'CREATE VIEW v AS SELECT qty, price, qty*price AS "value" FROM view_tb'
        self.cursor.execute(viewSql2)

        #table a_tbl and view b_view
        nsql2 = 'drop table if exists py_a_tbl'
        self.cursor.execute(nsql2)
        nsql3 = 'CREATE TABLE py_a_tbl(id INT NOT NULL,phone VARCHAR(10))'
        self.cursor.execute(nsql3)
        insertSql = "INSERT INTO py_a_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333'), (4, NULL), (5, NULL)"
        valueInsert = self.cursor.execute(insertSql)
        self.assertEquals(valueInsert, 5)
        viewSql2 = 'CREATE VIEW b_view AS SELECT * FROM py_a_tbl WHERE phone IS NOT NULL WITH CHECK OPTION'
        self.cursor.execute(viewSql2)
예제 #10
0
    def setUp(self):
        conStr = self.getConStr()
        self.con = CUBRIDdb.connect(conStr, "dba", "")
        self.cur = self.con.cursor()

        sqlDrop = "drop table if exists numeric_db"
        self.cur.execute(sqlDrop)
        sqlDrop = "drop table if exists datetime_db"
        self.cur.execute(sqlDrop)
        sqlDrop = "drop table if exists bit_db"
        self.cur.execute(sqlDrop)
        sqlDrop = "drop table if exists character_db"
        self.cur.execute(sqlDrop)
        sqlDrop = "drop table if exists collection_db"
        self.cur.execute(sqlDrop)

        sqlCreate = "create table numeric_db(c_int int, c_short short,c_numeric numeric(10,4),c_float float,c_double double,c_monetary monetary)"
        self.cur.execute(sqlCreate)
        sqlCreate = "create table datetime_db(c_date date, c_time time, c_datetime datetime, c_timestamp timestamp)"
        self.cur.execute(sqlCreate)
        sqlCreate = "create table bit_db(c_bit bit(8),c_varbit bit varying(8))"
        self.cur.execute(sqlCreate)
        sqlCreate = "create table character_db(c_char char(4),c_varchar varchar(4),c_string string,c_nchar nchar(4),c_varnchar nchar varying(4))"
        self.cur.execute(sqlCreate)
        sqlCreate = "create table collection_db(c_set set,c_multiset multiset, c_sequence sequence)"
        self.cur.execute(sqlCreate)
예제 #11
0
 def test_ValidConn(self):
     try:
         self.con1 = CUBRIDdb.connect("CUBRID:localhost:33111:demodb",
                                      "dba", "")
         self.con1.close
     except Exception, e:
         pass
예제 #12
0
    def _cursor(self):
        if not self._valid_connection():
            settings_dict = self.settings_dict

            # Connection to CUBRID database is made through connect() method.
            # Syntax:
            # connect (url[,user[password]])
            #    url - CUBRID:host:port:db_name:db_user:db_password
            #    user - Authorized username.
            #    password - Password associated with the username.
            url = "CUBRID"
            if settings_dict['HOST'].startswith('/'):
                url += ':' + settings_dict['HOST']
            elif settings_dict['HOST']:
                url += ':' + settings_dict['HOST']
            else:
                url += ':localhost'
            if settings_dict['PORT']:
                url += ':' + settings_dict['PORT']
            if settings_dict['NAME']:
                url += ':' + settings_dict['NAME']
            if settings_dict['USER']:
                url += ':' + settings_dict['USER']
            if settings_dict['PASSWORD']:
                url += ':' + settings_dict['PASSWORD']

            self.connection = Database.connect(url)
            connection_created.send(sender=self.__class__, connection=self)
        cursor = CursorWrapper(self.connection.cursor())
        return cursor
예제 #13
0
    def get_new_connection(self, conn_params):
        settings_dict = self.settings_dict

        # Connection to CUBRID database is made through connect() method.
        # Syntax:
        # connect (url[, user[password]])
        #    url - CUBRID:host:port:db_name:db_user:db_password:::
        #    user - Authorized username.
        #    password - Password associated with the username.
        url = "CUBRID"
        user = "******"
        passwd = ""

        if settings_dict['HOST'].startswith('/'):
            url += ':' + settings_dict['HOST']
        elif settings_dict['HOST']:
            url += ':' + settings_dict['HOST']
        else:
            url += ':localhost'
        if settings_dict['PORT']:
            url += ':' + settings_dict['PORT']
        if settings_dict['NAME']:
            url += ':' + settings_dict['NAME']
        if settings_dict['USER']:
            user = settings_dict['USER']
        if settings_dict['PASSWORD']:
            passwd = settings_dict['PASSWORD']

        url += ':::'

        con = Database.connect(url, user, passwd, charset='utf8')
        con.set_fetch_value_converter(django_fetch_value_converter)

        return con
예제 #14
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                nsql='drop table if exists partition_tb'
                self.cursor.execute(nsql)
                nsql2="create table partition_tb(id int not null primary key ,test_char char(50),test_varchar varchar(2000), test_bit bit(16),test_varbit bit varying(20),test_nchar nchar(50),test_nvarchar nchar varying(2000),test_string string,test_datetime timestamp)"
                self.cursor.execute(nsql2)
예제 #15
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                nsql='drop table if exists executemany_tb'
                self.cursor.execute(nsql)
                nsql2='create table executemany_tb(name VARCHAR(40),category VARCHAR(40))'
                self.cursor.execute(nsql2)
예제 #16
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, 'dba','')
		self.cursor= self.conn.cursor()
                nsql='drop table if exists enum03'
                self.cursor.execute(nsql)
                nsql2="create class enum03(i INT, working_days ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'), answers ENUM('Yes', 'No', 'Cancel'))"
                self.cursor.execute(nsql2)
예제 #17
0
 def setUp(self):
     conStr = self.getConStr()
     self.conn = CUBRIDdb.connect(conStr, 'dba', '')
     self.cursor = self.conn.cursor()
     nsql = 'drop table if exists enum03'
     self.cursor.execute(nsql)
     nsql2 = "create class enum03(i INT, working_days ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'), answers ENUM('Yes', 'No', 'Cancel'))"
     self.cursor.execute(nsql2)
예제 #18
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                nsql='drop table if exists tdb'
                self.cursor.execute(nsql)
                nsql2='create table tdb(a int primary key, b varchar(20), c timestamp)'
                self.cursor.execute(nsql2)
예제 #19
0
 def setUp(self):
     conStr = self.getConStr()
     self.conn = CUBRIDdb.connect(conStr, "dba", "")
     self.cursor = self.conn.cursor()
     nsql = 'drop table if exists tdb'
     self.cursor.execute(nsql)
     nsql2 = 'create table tdb(a int primary key, b varchar(20), c timestamp)'
     self.cursor.execute(nsql2)
예제 #20
0
        def setUp(self):
                conStr = self.getConStr()                
                self.con = CUBRIDdb.connect(conStr, "dba","")
                self.cur = self.con.cursor()
                sqlDrop = "drop table if exists t_datetime"
                self.cur.execute(sqlDrop)
                sqlCreate = "create table t_datetime(c_date date, c_time time, c_datetime datetime, c_timestamp timestamp)"
		self.cur.execute(sqlCreate)
예제 #21
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                self.cursor.execute("drop class if exists hi")
                self.cursor.execute("drop class if exists tt1")
                self.cursor.execute("create class hi ( a int , b string )")
                self.cursor.execute("create class tt1( a int, b string )")
예제 #22
0
 def setUp(self):
     conStr = self.getConStr()
     self.conn = CUBRIDdb.connect(conStr, "dba", "")
     self.cursor = self.conn.cursor()
     nsql = 'drop table if exists executemany_tb'
     self.cursor.execute(nsql)
     nsql2 = 'create table executemany_tb(name VARCHAR(40),category VARCHAR(40))'
     self.cursor.execute(nsql2)
예제 #23
0
 def test_connect(self):
         print "\nconnect url is empty"
         try:
             self.con = CUBRIDdb.connect("")
         except Exception,e:
             errorValue=str(e)
             print errorValue
             self.assertEquals(errorValue,"(-20030, 'ERROR: CCI, -20030, Invalid url string')")
 def setUp(self):
     conStr = self.getConStr()
     self.conn = CUBRIDdb.connect(conStr, "dba", "")
     self.cursor = self.conn.cursor()
     dropSql = 'drop table if exists nonormal_tb'
     self.cursor.execute(dropSql)
     createSql = 'CREATE TABLE nonormal_tb(nameid int primary key ,name VARCHAR(40))'
     self.cursor.execute(createSql)
     insertSql = "INSERT INTO nonormal_tb (name,nameid) VALUES('Mike',1),('John',2),('Bill',3)"
     self.cursor.execute(insertSql)
예제 #25
0
def make_connection():
    if settings.CUBRID_CRED:
        credentials = settings.CUBRID_CRED
        connection = CUBRIDdb.connect(
            'CUBRID:' + credentials['hostname'] + ':33000:' +
            credentials['name'] + ':::', credentials['username'],
            credentials['password'])
        return connection
    else:
        return JSONResponse({'errors': 'CUBRID service not bound'})
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                dropSql='drop table if exists nonormal_tb'
                self.cursor.execute(dropSql)
                createSql='CREATE TABLE nonormal_tb(nameid int primary key ,name VARCHAR(40))'
                self.cursor.execute(createSql)
                insertSql="INSERT INTO nonormal_tb (name,nameid) VALUES('Mike',1),('John',2),('Bill',3)"
                self.cursor.execute(insertSql)
예제 #27
0
 def setUp(self):
         conStr = self.getConStr()                
         self.conn = CUBRIDdb.connect(conStr, 'dba','')
         self.cursor= self.conn.cursor()
         nsql='drop table if exists enum04'
         self.cursor.execute(nsql)
         nsql2="create class enum04(e1 enum('a', 'b'), e2 enum('Yes', 'No', 'Cancel'))"
         self.cursor.execute(nsql2)
         nsql3="insert into enum04 values (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)"
         c3=self.cursor.execute(nsql3)
예제 #28
0
 def setUp(self):
     conStr = self.getConStr()
     self.conn = CUBRIDdb.connect(conStr, 'dba', '')
     self.cursor = self.conn.cursor()
     nsql = 'drop table if exists enum04'
     self.cursor.execute(nsql)
     nsql2 = "create class enum04(e1 enum('a', 'b'), e2 enum('Yes', 'No', 'Cancel'))"
     self.cursor.execute(nsql2)
     nsql3 = "insert into enum04 values (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)"
     c3 = self.cursor.execute(nsql3)
예제 #29
0
        def setUp(self):
		conStr = self.getConStr()                
		self.con = CUBRIDdb.connect(conStr, "dba","")
#		self.con = CUBRIDdb.connect("CUBRID:localhost:33012:demodb", "dba","")
                self.cur = self.con.cursor()

                sqlDrop = "drop table if exists tdb"
                self.cur.execute(sqlDrop)
                sqlCreate = "create table tdb(id NUMERIC AUTO_INCREMENT(1, 1), age int, name varchar(50))"
                self.cur.execute(sqlCreate)
                sqlInsert = "insert into tdb values (null,20,'Lily')"
                self.cur.execute(sqlInsert)
예제 #30
0
    def setUp(self):
        conStr = self.getConStr()
        self.con = CUBRIDdb.connect(conStr, "dba", "")
        #		self.con = CUBRIDdb.connect("CUBRID:localhost:33012:demodb", "dba","")
        self.cur = self.con.cursor()

        sqlDrop = "drop table if exists tdb"
        self.cur.execute(sqlDrop)
        sqlCreate = "create table tdb(id NUMERIC AUTO_INCREMENT(1, 1), age int, name varchar(50))"
        self.cur.execute(sqlCreate)
        sqlInsert = "insert into tdb values (null,20,'Lily')"
        self.cur.execute(sqlInsert)
예제 #31
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                nsql1='drop table if exists foreign_tb'
                self.cursor.execute(nsql1)
                nsql2='drop table if exists primary_tb'
                self.cursor.execute(nsql2)
                nsql3='create table primary_tb( id CHAR(10) PRIMARY KEY, title VARCHAR(100), artist VARCHAR(100))'
                self.cursor.execute(nsql3)
                nsql4='create table foreign_tb(album CHAR(10),dsk INTEGER,posn INTEGER,song VARCHAR(255),FOREIGN KEY (album) REFERENCES primary_tb(id) ON UPDATE RESTRICT )'
                self.cursor.execute(nsql4)
예제 #32
0
def test_ten_thread():
        conStr = getConStr()
        conn = CUBRIDdb.connect(conStr, "dba","")
        cur= conn.cursor()
        cur.execute('drop table if exists tdb')
        cur.execute('create table tdb(a int, b varchar(20), c timestamp, e int)')

	thrs=[]
	print 'starting ten thread for insert operation at:', ctime()
	for i in range(10):
		t=MyThread('insert')
		thrs.append(t)
	for n in range(10):
		thrs[n].start()
	for j in range(10):
		thrs[j].join()
	print 'end insert!'

	print 'starting ten thread for select operation at:', ctime()
	thrs1=[]
	for i in range(10):
		t1=MyThread('select')
		thrs1.append(t1)
	for n in range(10):
		thrs1[n].start()
	for j in range(10):
		thrs1[j].join()
	print 'end select!'
	
	print 'starting ten thread for update operation at:', ctime()
	thrs2=[]
	for i in range(10):
		t2=MyThread('update')
		thrs2.append(t2)
	for n in range(10):
		thrs2[n].start()
	for j in range(10):
		thrs2[j].join()
	print 'end update!'

	print 'starting ten thread for delete operation at:', ctime()
	thrs3=[]
	for i in range(10):
		t3=MyThread('delete')
		thrs3.append(t3)
	for n in range(10):
		thrs3[n].start()
	for j in range(10):
		thrs3[j].join()
	print 'end delete!'

        cur.execute('drop table if exists tdb')
예제 #33
0
def test_ten_thread():
    conStr = getConStr()
    conn = CUBRIDdb.connect(conStr, "dba", "")
    cur = conn.cursor()
    cur.execute('drop table if exists tdb')
    cur.execute('create table tdb(a int, b varchar(20), c timestamp, e int)')

    thrs = []
    print 'starting ten thread for insert operation at:', ctime()
    for i in range(10):
        t = MyThread('insert')
        thrs.append(t)
    for n in range(10):
        thrs[n].start()
    for j in range(10):
        thrs[j].join()
    print 'end insert!'

    print 'starting ten thread for select operation at:', ctime()
    thrs1 = []
    for i in range(10):
        t1 = MyThread('select')
        thrs1.append(t1)
    for n in range(10):
        thrs1[n].start()
    for j in range(10):
        thrs1[j].join()
    print 'end select!'

    print 'starting ten thread for update operation at:', ctime()
    thrs2 = []
    for i in range(10):
        t2 = MyThread('update')
        thrs2.append(t2)
    for n in range(10):
        thrs2[n].start()
    for j in range(10):
        thrs2[j].join()
    print 'end update!'

    print 'starting ten thread for delete operation at:', ctime()
    thrs3 = []
    for i in range(10):
        t3 = MyThread('delete')
        thrs3.append(t3)
    for n in range(10):
        thrs3[n].start()
    for j in range(10):
        thrs3[j].join()
    print 'end delete!'

    cur.execute('drop table if exists tdb')
예제 #34
0
        def setUp(self):
                conStr = self.getConStr()                
                self.con = CUBRIDdb.connect(conStr, "dba","")
                self.cur = self.con.cursor()

                sqlDrop = "drop table if exists tdb"
                self.cur.execute(sqlDrop)
                sqlCreate = "create table tdb(id NUMERIC AUTO_INCREMENT(1, 1), age int, name varchar(50))"
                self.cur.execute(sqlCreate)
		self.rownum = 1000
		for i in range(self.rownum):
                        sqlInsert = "insert into tdb values(1,20,'myName')"
                        self.cur.execute(sqlInsert)
예제 #35
0
    def setUp(self):
        conStr = self.getConStr()
        self.con = CUBRIDdb.connect(conStr, "dba", "")
        self.cur = self.con.cursor()

        sqlDrop = "drop table if exists tdb"
        self.cur.execute(sqlDrop)
        sqlCreate = "create table tdb(id NUMERIC AUTO_INCREMENT(1, 1), age int, name varchar(50))"
        self.cur.execute(sqlCreate)
        self.rownum = 1000
        for i in range(self.rownum):
            sqlInsert = "insert into tdb values(1,20,'myName')"
            self.cur.execute(sqlInsert)
예제 #36
0
class SetTest(unittest.TestCase):
    def getConStr(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 + ":::"
        return conStr

    def setUp(self):
        conStr = self.getConStr()
        self.con = CUBRIDdb.connect(conStr, "dba", "")
        self.cur = self.con.cursor()

    def tearDown(self):
        self.cur.close
        self.con.close

    def test_escape_string(self):
        '''test escape string'''
        try:
            print CUBRIDdb.escape_string('', 1, 1)
        except Exception, e:
            errorValue = str(e)
            print("errorValue: ", errorValue)
        self.assertEqual(CUBRIDdb.escape_string("cubrid \ Laptop", 1),
                         "cubrid \ Laptop")
        self.assertEqual(CUBRIDdb.escape_string("cubrid \ Laptop", 0),
                         "cubrid \\\\ Laptop")

        try:
            print self.con.escape_string('', 1, 1)
        except Exception, e:
            errorValue = str(e)
            print("errorValue: ", errorValue)
예제 #37
0
    def connect(self):
        self.initConnection()

        try:
            self.connector = CUBRIDdb.connect(hostname=self.hostname,
                                              username=self.user,
                                              password=self.password,
                                              database=self.db,
                                              port=self.port,
                                              connect_timeout=conf.timeout)
        except CUBRIDdb.DatabaseError as ex:
            raise SqlmapConnectionException(getSafeExString(ex))

        self.initCursor()
        self.printConnected()
예제 #38
0
	def test_connect(self):
		print("01. Common connection")
                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+":::"
		self.con=CUBRIDdb.connect(conStr,'dba','')
	        self.c=self.con.cursor()
		self.c.execute("select * from db_class limit 5;")
		row=self.c.fetchone()
		print(row)
		self.c.close()
		self.con.close()
예제 #39
0
 def test_connect(self):
     print("01. Common connection")
     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 + ":::"
     self.con = CUBRIDdb.connect(conStr, 'dba', '')
     self.c = self.con.cursor()
     self.c.execute("select * from db_class limit 5;")
     row = self.c.fetchone()
     print(row)
     self.c.close()
     self.con.close()
예제 #40
0
	def test_connect_withautocommit(self):
		print("\n02. Connection with autocommit property")
                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+":::"
                self.con=CUBRIDdb.connect(conStr)
		#self.con=CUBRIDdb.connect("CUBRID:localhost:33188:pydb:::")
	        self.c=self.con.cursor()
		self.c.execute("select * from db_class limit 5;")
		row=self.c.fetchone()
		print(row)
		self.c.close()
		self.con.close()
예제 #41
0
 def test_connect_withautocommit(self):
     print("\n02. Connection with autocommit property")
     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 + ":::"
     self.con = CUBRIDdb.connect(conStr)
     #self.con=CUBRIDdb.connect("CUBRID:localhost:33188:pydb:::")
     self.c = self.con.cursor()
     self.c.execute("select * from db_class limit 5;")
     row = self.c.fetchone()
     print(row)
     self.c.close()
     self.con.close()
예제 #42
0
	def setUp(self):
                conStr = self.getConStr()                
                self.conn = CUBRIDdb.connect(conStr, "dba","")
		self.cursor= self.conn.cursor()
                nsql2='drop class if exists t'
                self.cursor.execute(nsql2)
                nsql2='drop class if exists u'
                self.cursor.execute(nsql2)

                self.cursor.execute("create table t(id int, val int, fk int)")
                self.cursor.execute("create table u(id int, val int,text string)")
                self.cursor.execute("create index _t_id on t(id)")
                self.cursor.execute("create index _t_val on t(val)")
                self.cursor.execute("create index _u_id on u(id)")
                self.cursor.execute("create index _u_val on u(val)")
                self.cursor.execute("create index _u_r_text on u(text)")
                self.cursor.execute("insert into t values (1, 100, 1),(2, 200, 1),(3, 300, 2),(4, 300, 3)")
                self.cursor.execute("insert into u values (1, 1000, '1000 text'),(2, 2000, '2000 text'),(3, 3000, '3000 text'),(3, 3001, '3001 text')")
예제 #43
0
	def run(self):
                conStr = getConStr()
                self.conn = CUBRIDdb.connect(conStr, "dba","")
                self.cur= self.conn.cursor()
		##start db operation using multiple threads
	        start_time=time.time()
   		if self.name=='insert':
			self.insert_test()
		elif self.name=='delete':
			self.delete_test()
		elif self.name=='update':
			self.update_test()
		elif self.name=='select':
			self.select_test()
		else:
			pass
		end_time=time.time()
		elapse_time=end_time-start_time
		print ("**The operation - " + self.name + " ,total elapse time:" + '%f'%elapse_time + " sec.")
예제 #44
0
 def run(self):
     conStr = getConStr()
     self.conn = CUBRIDdb.connect(conStr, "dba", "")
     self.cur = self.conn.cursor()
     ##start db operation using multiple threads
     start_time = time.time()
     if self.name == 'insert':
         self.insert_test()
     elif self.name == 'delete':
         self.delete_test()
     elif self.name == 'update':
         self.update_test()
     elif self.name == 'select':
         self.select_test()
     else:
         pass
     end_time = time.time()
     elapse_time = end_time - start_time
     print("**The operation - " + self.name + " ,total elapse time:" +
           '%f' % elapse_time + " sec.")
예제 #45
0
	def test_connection_with_ip(self):
		print("\n04. Connection with other computer")
                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()
                remoteips = xmlt.childNodes[0].getElementsByTagName('remoteIP')
                remoteip= remoteips[0].childNodes[0].toxml()
                #conStr = "CUBRID:"+remoteip+":"+port+":"+dbname+":dba::?autocommit=false"
                conStr = "CUBRID:"+remoteip+":"+port+":"+dbname+":dba::"
                print(conStr)
      		self.con=CUBRIDdb.connect(conStr,"dba","")
		self.c=self.con.cursor()
		self.c.execute("select * from db_class;")
		row=self.c.fetchone()
                print(row)
                self.c.close()
                self.con.close()
예제 #46
0
 def test_connection_with_ip(self):
     print("\n04. Connection with other computer")
     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()
     remoteips = xmlt.childNodes[0].getElementsByTagName('remoteIP')
     remoteip = remoteips[0].childNodes[0].toxml()
     #conStr = "CUBRID:"+remoteip+":"+port+":"+dbname+":dba::?autocommit=false"
     conStr = "CUBRID:" + remoteip + ":" + port + ":" + dbname + ":dba::"
     print(conStr)
     self.con = CUBRIDdb.connect(conStr, "dba", "")
     self.c = self.con.cursor()
     self.c.execute("select * from db_class;")
     row = self.c.fetchone()
     print(row)
     self.c.close()
     self.con.close()
예제 #47
0
 def test_connection_with_alhost(self):
     print("\n05. Connection with alhost")
     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()
     remoteips = xmlt.childNodes[0].getElementsByTagName('remoteIP')
     remoteip = remoteips[0].childNodes[0].toxml()
     #conStr = "CUBRID:"+ip+":"+port+":"+dbname+":dba::?althosts="+remoteip+"&autocommit=false"
     conStr = "CUBRID:" + ip + ":" + port + ":" + dbname + ":dba::?altHosts=" + remoteip + ":30188"
     print(conStr)
     self.con = CUBRIDdb.connect(conStr, "dba", "")
     #self.con=CUBRIDdb.connect("CUBRID:10.34.64.35:30012:pydb:dba::?althosts=10.34.64.59:33011&autocommit=false")
     self.c = self.con.cursor()
     self.c.execute("select * from db_class;")
     row = self.c.fetchone()
     print(row)
     self.c.close()
     self.con.close()
예제 #48
0
def test_one_thread():
	conStr = getConStr()
	conn = CUBRIDdb.connect(conStr, "dba","")
	cur= conn.cursor()
	cur.execute('drop table if exists tdb')
	cur.execute('create table tdb(a int, b varchar(20), c timestamp, e int)')	
	
	print 'starting one thread operation at:',ctime()
	t1=MyThread('insert')
	t1.start()
	t1.join()
	t1=MyThread('select')
	t1.start()
	t1.join()
	t1=MyThread('update')
	t1.start()
	t1.join()
	t1=MyThread('delete')
	t1.start()
	t1.join()
	time.sleep(1)
	cur.execute('drop table if exists tdb')
예제 #49
0
	def test_connection_with_alhost(self):
		print("\n05. Connection with alhost")
                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()
                remoteips = xmlt.childNodes[0].getElementsByTagName('remoteIP')
                remoteip= remoteips[0].childNodes[0].toxml()
                #conStr = "CUBRID:"+ip+":"+port+":"+dbname+":dba::?althosts="+remoteip+"&autocommit=false"
                conStr = "CUBRID:"+ip+":"+port+":"+dbname+":dba::?altHosts="+remoteip+":30188"
                print(conStr)
                self.con=CUBRIDdb.connect(conStr,"dba","")
		#self.con=CUBRIDdb.connect("CUBRID:10.34.64.35:30012:pydb:dba::?althosts=10.34.64.59:33011&autocommit=false")
		self.c=self.con.cursor()
		self.c.execute("select * from db_class;")
		row=self.c.fetchone()
                print(row)
                self.c.close()
                self.con.close()
예제 #50
0
class IssueTest(unittest.TestCase):
        def getConStr(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+":::"
                return conStr

        def setUp(self):
                conStr = self.getConStr()                
                self.con = CUBRIDdb.connect(conStr, "dba","")
                self.cur = self.con.cursor()
                self.cur.execute("DROP TABLE IF EXISTS issue")
                self.cur.execute("CREATE TABLE issue(nameid int primary key ,age int,name VARCHAR(40))")
                self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('Mike',1,30),('John',2,28),('Bill',3,45)")

        def tearDown(self):
                self.cur.close()
                self.con.close()

        def test_connect(self):
                print "\nconnect url is empty"
                try:
                    self.con = CUBRIDdb.connect("")
                except Exception,e:
                    errorValue=str(e)
                    print errorValue
                    self.assertEquals(errorValue,"(-20030, 'ERROR: CCI, -20030, Invalid url string')")

                try:
                    self.con = CUBRIDdb.connect()
                except Exception,e:
                    errorValue=str(e)
                    print errorValue
                    self.assertEquals(errorValue,"Required argument 'url' (pos 1) not found")
예제 #51
0
    def _cursor(self):
        if not self._valid_connection():

            settings_dict = self.settings_dict

            # Connection to CUBRID database is made through connect() method.
            # Syntax:
            # connect (url[, user[password]])
            #    url - CUBRID:host:port:db_name:db_user:db_password:::
            #    user - Authorized username.
            #    password - Password associated with the username.
            url = "CUBRID"
            user = "******"
            passwd = ""

            if settings_dict['HOST'].startswith('/'):
                url += ':' + settings_dict['HOST']
            elif settings_dict['HOST']:
                url += ':' + settings_dict['HOST']
            else:
                url += ':localhost'
            if settings_dict['PORT']:
                url += ':' + settings_dict['PORT']
            if settings_dict['NAME']:
                url += ':' + settings_dict['NAME']
            if settings_dict['USER']:
                user = settings_dict['USER']
            if settings_dict['PASSWORD']:
                passwd = settings_dict['PASSWORD']

            url += ':::'

            self.connection = Database.connect(url,
                                               user,
                                               passwd,
                                               charset='utf8')
            connection_created.send(sender=self.__class__, connection=self)
        cursor = CursorWrapper(self.connection.cursor())
        return cursor
예제 #52
0
    def setUp(self):
        conStr = self.getConStr()
        self.conn = CUBRIDdb.connect(conStr, "dba", "")
        self.cursor = self.conn.cursor()
        nsql2 = 'drop class if exists t'
        self.cursor.execute(nsql2)
        nsql2 = 'drop class if exists u'
        self.cursor.execute(nsql2)

        self.cursor.execute("create table t(id int, val int, fk int)")
        self.cursor.execute("create table u(id int, val int,text string)")
        self.cursor.execute("create index _t_id on t(id)")
        self.cursor.execute("create index _t_val on t(val)")
        self.cursor.execute("create index _u_id on u(id)")
        self.cursor.execute("create index _u_val on u(val)")
        self.cursor.execute("create index _u_r_text on u(text)")
        self.cursor.execute(
            "insert into t values (1, 100, 1),(2, 200, 1),(3, 300, 2),(4, 300, 3)"
        )
        self.cursor.execute(
            "insert into u values (1, 1000, '1000 text'),(2, 2000, '2000 text'),(3, 3000, '3000 text'),(3, 3001, '3001 text')"
        )
예제 #53
0
	def test_connection_with_wrong_parameter(self):
		print("\n03. Connection with wrong parameter")
		try:
			self.con = CUBRIDdb.connect("CUBRID:10.34.64:300a12:pydb:::")
		except Exception,e:
                        print("connect error: ", e)
예제 #54
0
# -*- encoding:utf-8 -*- 
# sample_CUBRIDdb.py

import CUBRIDdb 

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

cur = con.cursor()

cur.execute('DROP TABLE IF EXISTS test_cubrid')

cur.execute('CREATE TABLE test_cubrid (id NUMERIC AUTO_INCREMENT(2009122350, 1), name VARCHAR(50))')

cur.execute("insert into test_cubrid (name) values ('Zhang San'), ('Li Si'), ('Wang Wu'), ('Ma Liu'), ('Niu Qi')")

cur.execute("insert into test_cubrid (name) values (?), (?)", ['中文zh-cn', 'John'])

cur.execute("insert into test_cubrid (name) values (?)", ['Tom',])

cur.execute('select * from test_cubrid')

# fetch result use fetchone()
row = cur.fetchone()
print(row)

print('')

# fetch result use fetchmany()
rows = cur.fetchmany(2)
for row in rows:
    print(row)
예제 #55
0
파일: set.py 프로젝트: CUBRID/cubrid-python
 def setUp(self):
     conStr = self.getConStr()
     self.con = CUBRIDdb.connect(conStr, "dba","")
     self.cur = self.con.cursor()