def test_connection_properties(self):
        #Get NuoDB release 
        con = self._connect()
        cursor = con.cursor()
        try:
            cursor.execute("select getReleaseversion() from dual")
        except ProgrammingError as pe:
            return #2.0 or earlier, skip test
            
        version = cursor.fetchone()[0]
        majorVersion = version[0]
        minorVersion = version[2]
        if(majorVersion is '2'):
            if(minorVersion is not '3'):
                return

        clientInfo = "NuoDB Python driver"
        tmp_args = self.connect_kw_args.copy()
        tmp_args['options'] = {'schema': 'test', 'clientInfo': clientInfo}
        con = pynuodb.connect(**tmp_args)#self._connect({'clientInfo':'Hello World'})
        cursor = con.cursor()
        cursor.execute("select * from SYSTEM.CONNECTIONS")
        result = cursor.fetchone()

        #Make sure our clientHost, clientProcessId and clientInfo remain the same in the SYSTEM.CONNECTIONS table
        self.assertEqual(platform.node(), result[17]) #ClientHost
        self.assertEqual(str(os.getpid()), result[18]) #clientProcessId
        self.assertEqual(clientInfo, result[19]) #clientInfo
Пример #2
0
    def test_connection_properties(self):
        #Get NuoDB release
        con = self._connect()
        cursor = con.cursor()
        try:
            cursor.execute("select getReleaseversion() from dual")
        except ProgrammingError as pe:
            return #2.0 or earlier, skip test

        #Determine NuoDB version in the form Major.Minor
        version = cursor.fetchone()[0]
        majorVersion = int(version[0])
        minorVersion = int(version[2])
        if(majorVersion == 2):
            if(minorVersion < 3):
                return

        clientInfo = "NuoDB Python driver"
        tmp_args = self.connect_kw_args.copy()
        tmp_args['options'] = {'schema': 'test', 'clientInfo': clientInfo}
        con = pynuodb.connect(**tmp_args)
        cursor = con.cursor()
        cursor.execute("select clientprocessid, clientinfo from SYSTEM.CONNECTIONS")
        result = cursor.fetchone()

        #Make sure our clientProcessId and clientInfo remain the same in the SYSTEM.CONNECTIONS table
        self.assertEqual(str(os.getpid()), result[0]) #clientProcessId
        self.assertEqual(clientInfo, result[1]) #clientInfo
Пример #3
0
 def test_nosuchport(self):
     try:
         con = pynuodb.connect("pynuodb_test", "localhost:23456", "dba",
                               "dba_password")
         self.fail()
     except:
         pass
Пример #4
0
 def test_nosuchhost(self):
     try:
         con = pynuodb.connect("pynuodb_test", "nosuchhost", "dba",
                               "dba_password")
         self.fail()
     except:
         pass
 def test_nosuchpassword(self):
     try:
         con = pynuodb.connect("pynuodb_test", "localhost", "dba", "nosuchpassword")
         self.fail();
     except ProgrammingError:
         pass;
     except:
         self.fail();
Пример #6
0
 def test_nosuchuser(self):
     try:
         con = pynuodb.connect("pynuodb_test", self.host, "nosuchuser", "dba_password")
         self.fail()
     except ProgrammingError:
         pass
     except:
         self.fail()
Пример #7
0
 def test_nosuchdatabase(self):
     try:
         con = pynuodb.connect("nosuchdatabase", self.host, "dba", "dba_password")
         self.fail()
     except SessionException:
         pass
     except:
         self.fail()
Пример #8
0
 def test_nosuchpassword(self):
     try:
         con = pynuodb.connect(DATABASE_NAME, self.host, DBA_USER, "nosuchpassword")
         self.fail()
     except ProgrammingError:
         pass
     except:
         self.fail()
Пример #9
0
 def test_nosuchuser(self):
     try:
         con = pynuodb.connect(DATABASE_NAME, self.host, "nosuchuser", DBA_PASSWORD)
         self.fail()
     except ProgrammingError:
         pass
     except:
         self.fail()
Пример #10
0
 def test_nosuchdatabase(self):
     try:
         con = pynuodb.connect("nosuchdatabase", self.host, "dba", "dba_password")
         self.fail()
     except SessionException:
         pass
     except:
         self.fail()
 def test_nosuchdatabase(self):
     try:
         con = pynuodb.connect("nosuchdatabase", "localhost", "dba", "dba_password");
         self.fail();
     except SessionException:
         pass;
     except:
         self.fail();
Пример #12
0
 def __init__(self, 
              dbname,
              host,
              username,
              password,
              options
              ):
   self.connection = pynuodb.connect(dbname, host, username, password, options)
Пример #13
0
 def test_nosuchuser(self):
     try:
         con = pynuodb.connect("pynuodb_test", self.host, "nosuchuser",
                               "dba_password")
         self.fail()
     except ProgrammingError:
         pass
     except:
         self.fail()
Пример #14
0
    def _cursor(self):
        settings_dict = self.settings_dict
        if self.connection is None:
            if not settings_dict['NAME']:
                from django.core.exceptions import ImproperlyConfigured
                raise ImproperlyConfigured(
                    "settings.DATABASES is improperly configured. "
                    "Please supply the NAME value.")
            conn_params = {
                'database': settings_dict['NAME'],
            }
            conn_params.update(settings_dict['OPTIONS'])
            if 'autocommit' in conn_params:
                del conn_params['autocommit']

            if settings_dict.has_key('SCHEMA'):
                options = {
                    "schema": settings_dict.get('SCHEMA', 'user') or 'user'
                }
            else:
                options = {"schema": "user"}

            if settings_dict['DBA_USER']:
                conn_params['user'] = settings_dict['DBA_USER']
            if settings_dict['DBA_PASSWORD']:
                conn_params['password'] = force_str(
                    settings_dict['DBA_PASSWORD'])
            if settings_dict['HOST']:
                conn_params['host'] = settings_dict['HOST']
            if settings_dict['PORT']:
                options['port'] = settings_dict['PORT']
            tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')
            #             options['timezone'] = tz
            conn_params['options'] = options
            self.connection = Database.connect(**conn_params)
            if tz:
                try:
                    get_parameter_status = self.connection.get_parameter_status
                except AttributeError:
                    conn_tz = None
                else:
                    conn_tz = get_parameter_status('TimeZone')
            self._get_nuodb_version()
            connection_created.send(sender=self.__class__, connection=self)
        cursor = self.connection.cursor()
        cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None
        return CursorWrapper(cursor)
Пример #15
0
    def _cursor(self):
        settings_dict = self.settings_dict
        if self.connection is None:
            if not settings_dict['NAME']:
                from django.core.exceptions import ImproperlyConfigured
                raise ImproperlyConfigured(
                    "settings.DATABASES is improperly configured. "
                    "Please supply the NAME value.")
            conn_params = {
                'database': settings_dict['NAME'],
            }
            conn_params.update(settings_dict['OPTIONS'])
            if 'autocommit' in conn_params:
                del conn_params['autocommit']
            
            if settings_dict.has_key('SCHEMA'):
                options = {"schema": settings_dict.get('SCHEMA', 'user') or 'user'}
            else:
                options = {"schema": "user"}
            
            if settings_dict['DBA_USER']:
                conn_params['user'] = settings_dict['DBA_USER']
            if settings_dict['DBA_PASSWORD']:
                conn_params['password'] = force_str(settings_dict['DBA_PASSWORD'])
            if settings_dict['HOST']:
                conn_params['host'] = settings_dict['HOST']
            if settings_dict['PORT']:
                options['port'] = settings_dict['PORT']
            tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')
#             options['timezone'] = tz
            conn_params['options'] = options
            self.connection = Database.connect(**conn_params)
            if tz:
                try:
                    get_parameter_status = self.connection.get_parameter_status
                except AttributeError:
                    conn_tz = None
                else:
                    conn_tz = get_parameter_status('TimeZone')
            self._get_nuodb_version()
            connection_created.send(sender=self.__class__, connection=self)
        cursor = self.connection.cursor()
        cursor.tzinfo_factory = utc_tzinfo_factory if settings.USE_TZ else None
        return CursorWrapper(cursor)
Пример #16
0
    def test_connection_properties(self):
        #Get NuoDB release
        con = self._connect()
        cursor = con.cursor()
        try:
            cursor.execute("select getReleaseversion() from dual")

            #Determine NuoDB version in the form Major.Minor
            version = cursor.fetchone()[0]
            majorVersion = int(version[0])
            minorVersion = int(version[2])
            if (majorVersion == 2):
                if (minorVersion < 3):
                    return

        except ProgrammingError as pe:
            return  #2.0 or earlier, skip test
        finally:
            con.close()

        clientInfo = "NuoDB Python driver"
        tmp_args = self.connect_kw_args.copy()
        tmp_args['options'] = {'schema': 'test', 'clientInfo': clientInfo}
        con = pynuodb.connect(**tmp_args)
        try:
            cursor = con.cursor()
            cursor.execute(
                "select clientprocessid, clientinfo from SYSTEM.CONNECTIONS")

            result = cursor.fetchone()

            #Make sure our clientProcessId and clientInfo remain the same in
            #the SYSTEM.CONNECTIONS table
            self.assertEqual(str(os.getpid()), result[0])  #clientProcessId
            self.assertEqual(clientInfo, result[1])  #clientInfo
        finally:
            con.close()
Пример #17
0
import pynuodb

connection = pynuodb.connect("softsysActorweb", "localhost", "kgallagher", "softsys", options={'schema':'user'})
cursor = connection.cursor()

# cursor.execute("SELECT * FROM ACTOR")
# print cursor.fetchall()

while 1:
	search_movie = raw_input('Would you like to search by movie (m) or actor (a)?: ')
	if (search_movie == "q"): break

	if (search_movie == "m" or search_movie == "M"):
		data_input = raw_input('What movie would you like to search the actor/actress database by?: ')
		if (search_movie == "q"): break
		cursor.execute("SELECT NAME FROM ACTOR WHERE MOVIE LIKE \'%"+data_input+"%\'")
		for i in cursor.fetchall():
			print i[0]

	elif (search_movie == "a" or search_movie == "A"):
		data_input = raw_input('Which actor would you like to search the movie database by?: ')
		if (search_movie == "q"): break

		cursor.execute("SELECT MOVIE FROM ACTOR WHERE NAME LIKE \'%"+data_input+"%\'")
		for i in cursor.fetchall():
			print i[0]
	else:
		print("Unrecognizable character, type 'q' to exit if that's what you want to do")
Пример #18
0
 def test_nosuchport(self):
     try:
         con = pynuodb.connect(DATABASE_NAME, "localhost:23456", DBA_USER, DBA_PASSWORD)
         self.fail()
     except:
         pass
Пример #19
0
 def test_nosuchhost(self):
     try:
         con = pynuodb.connect(DATABASE_NAME, "nosuchhost", DBA_USER, DBA_PASSWORD)
         self.fail()
     except:
         pass
Пример #20
0
""" This assumes that you have the quickstart database running (test@localhost).
If you don't, you can start it by running /opt/nuodb/run-quickstart
"""
import pynuodb

connection = pynuodb.connect("test", "localhost", "dba", "goalie",  options = {"schema":"hockey"})
cursor = connection.cursor()
cursor.arraysize = 3
cursor.execute("select * from hockey")
print cursor.fetchone()
Пример #21
0
import pynuodb

con = pynuodb.connect("Thousand", "localhost", "dba", "goalie", options = {"schema":"user"})
con.auto_commit = True

cursor = con.cursor()
# Insert 10 million rows
for i in xrange(0, 5000):
    test_batch = []
    for j in xrange(0, 2000):
        id = (i * 2000) + j
        test_batch.append([id, str(id) + "?", "now"])
    cursor.executemany("insert into user.polls_poll values (?, ?, ?)", test_batch)

Пример #22
0
import pynuodb

con = pynuodb.connect("Thousand",
                      "localhost",
                      "dba",
                      "goalie",
                      options={"schema": "user"})
con.auto_commit = True

cursor = con.cursor()
# Insert 10 million rows
for i in xrange(0, 5000):
    test_batch = []
    for j in xrange(0, 2000):
        id = (i * 2000) + j
        test_batch.append([id, str(id) + "?", "now"])
    cursor.executemany("insert into user.polls_poll values (?, ?, ?)",
                       test_batch)
Пример #23
0
 def test_nosuchhost(self):
     try:
         con = pynuodb.connect("pynuodb_test", "nosuchhost", "dba", "dba_password")
         self.fail();
     except:
         pass;
Пример #24
0
 def test_nosuchport(self):
     try:
         con = pynuodb.connect("pynuodb_test", "localhost:23456", "dba", "dba_password")
         self.fail();
     except:
         pass;
Пример #25
0
 def connect(self):
   self.connection = pynuodb.connect(self.dbname, self.host, self.username, self.password, self.options)
Пример #26
0
import timeit
import pynuodb

connection = pynuodb.connect("softsysActorweb",
                             "localhost",
                             "kgallagher",
                             "softsys",
                             options={'schema': 'user'})
cursor = connection.cursor()


def find():
    cursor.execute("SELECT NAME FROM ACTOR WHERE MOVIE LIKE \'%%Kendra%\'")


t = timeit.Timer('find()', setup='from __main__ import find')
print t.timeit(number=100)
print t.timeit(number=1000)
print t.timeit(number=10000)
Пример #27
0
import time
import pynuodb

smallIterations = 100
largeIterations = smallIterations * 1000

dropTable = "drop table perf_test cascade if exists"
createTable = "create table perf_test (a int,b char)"
#A database named test with user dba and password dba must be created before running
connection = pynuodb.connect("dba", "localhost", "dba", "dba")
cursor = connection.cursor()

cursor.execute("use test")
cursor.execute(dropTable)
cursor.execute(createTable)

""" Begin SMALL_INSERT_ITERATIONS test"""

smallIterationsInsertTime = time.clock()
for i in range(smallIterations):
	cursor.execute("INSERT INTO perf_test (a,b ) VALUES (%d,'A')" % i)
connection.commit()
smallIterationsInsertTime = time.clock() - smallIterationsInsertTime

print("\n Elapse time of SMALL_INSERT_ITERATIONS   =   " + str(smallIterationsInsertTime) + "s")

""" Begin SMALL_SELECT_ITERATIONS test"""

smallIterationsSelectTime = time.clock()
cursor.execute("select * from perf_test")
cursor.fetchall()
Пример #28
0
import time
import pynuodb

smallIterations = 100
largeIterations = smallIterations * 1000

dropTable = "drop table perf_test cascade if exists"
createTable = "create table perf_test (a int,b char)"
#A database named test with user dba and password dba must be created before running
connection = pynuodb.connect("dba", "localhost", "dba", "dba")
cursor = connection.cursor()

cursor.execute("use test")
cursor.execute(dropTable)
cursor.execute(createTable)
""" Begin SMALL_INSERT_ITERATIONS test"""

smallIterationsInsertTime = time.clock()
for i in range(smallIterations):
    cursor.execute("INSERT INTO perf_test (a,b ) VALUES (%d,'A')" % i)
connection.commit()
smallIterationsInsertTime = time.clock() - smallIterationsInsertTime

print("\n Elapse time of SMALL_INSERT_ITERATIONS   =   " +
      str(smallIterationsInsertTime) + "s")
""" Begin SMALL_SELECT_ITERATIONS test"""

smallIterationsSelectTime = time.clock()
cursor.execute("select * from perf_test")
cursor.fetchall()
smallIterationsSelectTime = time.clock() - smallIterationsSelectTime