コード例 #1
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_with_commit(self):
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         c = a.cursor()
         b.execute(
             "create table cbob33(c1 INTEGER, c2 NVARCHAR(10)) in pybank")
         a.commit()
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         b.execute("select * from cbob33")
コード例 #2
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_with_no_commit(self):
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         c = a.cursor()
         b.execute(
             "create table cbob(c1 INTEGER, c2 NVARCHAR(10)) in pybank")
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         with self.assertRaises(ProgrammingError):
             b.execute("select * from cbob")
コード例 #3
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_with_no_commit_insert(self):
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         c = a.cursor()
         b.execute(
             "create table cbobc(c1 INTEGER, c2 NVARCHAR(10)) in pybank")
         a.commit()
         a.execute("insert into cbobc values (?, ?)", (11, 'aaa'))
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         b.execute("select * from cbobc")
         self.assertEqual(b.fetchall(), [])
コード例 #4
0
def setup():
    syscon = mimerpy.connect(**SYSUSR)
    with syscon.cursor() as c:
        c.execute("CREATE IDENT MIMERPY AS USER USING 'PySecret'")
        c.execute("GRANT DATABANK,IDENT TO MIMERPY")
    syscon.commit()
    tstcon = mimerpy.connect(**TSTUSR)
    with tstcon.cursor() as c:
        c.execute("CREATE DATABANK PYBANK")
        c.execute("CREATE IDENT %s AS USER" % OSUSER)
        c.execute("ALTER IDENT %s ADD OS_USER '%s'" % (OSUSER, OSUSER))
    tstcon.commit()
    return (syscon, tstcon)
コード例 #5
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_cursor_close(self):
     con = mimerpy.connect(**db_config.TSTUSR)
     b = con.cursor()
     b.close()
     with self.assertRaises(ProgrammingError):
         b.execute("Hello")
     con.close()
コード例 #6
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
    def test_autocommit_2(self):
        b = self.tstcon.execute("create table bobr66(c1 INTEGER) in pybank")
        self.tstcon.commit()

        a = mimerpy.connect(**db_config.TSTUSR)
        a.autocommit(False)
        b = a.execute("insert into bobr66 values (:a)", (1133))
        a.close()

        a = mimerpy.connect(**db_config.TSTUSR)
        a.autocommit(True)
        b = a.execute("insert into bobr66 values (:a)", (23885))
        a.close()

        b = self.tstcon.execute("select * from bobr66")
        self.assertEqual(b.fetchone(), (23885, ))
        b.close()
コード例 #7
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_operate_after_closed(self):
     a = mimerpy.connect(**db_config.TSTUSR)
     a.close()
     a.close()
     with self.assertRaises(ProgrammingError):
         a.execute("Kalle")
     with self.assertRaises(ProgrammingError):
         a.executemany("Kalle", ("Kula"))
コード例 #8
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_weakref(self):
     from weakref import ref
     import gc
     con = mimerpy.connect(**db_config.TSTUSR)
     w = ref(con)
     con.close()
     del con
     gc.collect()
     self.assertTrue(w() is None)
コード例 #9
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def thread_test(self):
     try:
         a = mimerpy.connect(**db_config.TSTUSR)
         cur = a.cursor()
         cur.execute("select * from threadbob")
         cur.fetchone()
         a.close()
     except Exception as e:
         ###print("Error: in thread: ", e)
         """ """
コード例 #10
0
    def connect(self):
        self.initConnection()

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

        self.initCursor()
        self.printConnected()
コード例 #11
0
        def condis(self):
            mylist = []
            for ac in range(5):
                con = mimerpy.connect(**db_config.TSTUSR)
                mylist.append([con, True])

            for a in range(100):
                rand = random.randint(0, 4)
                if (not mylist[rand][1]):
                    mylist.pop(rand)
                    conn = mimerpy.connect(**db_config.TSTUSR)
                    mylist.append([conn, True])
                else:
                    mylist[rand][0].close()
                    mylist[rand][1] = False

            for ab in mylist:
                if (ab[1]):
                    ab[0].close()
コード例 #12
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_multiple_cursors(self):
     a = mimerpy.connect(**db_config.TSTUSR)
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     b = a.cursor()
     a.close()
コード例 #13
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
    def test_autocommit_3(self):
        b = self.tstcon.execute("create table bob63(c1 INTEGER) in pybank")
        self.tstcon.commit()

        a = mimerpy.connect(**db_config.TSTUSR)
        b = a.execute("insert into bob63 values (:a)", (1133))
        a.close()

        b = self.tstcon.execute("select * from bob63")
        self.assertEqual(b.fetchone(), [])
        b.close()
コード例 #14
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
    def test_condis(self):
        mylist = []
        number_of_connections = 20
        for a in range(number_of_connections):
            con = mimerpy.connect(**db_config.TSTUSR)
            mylist.append([con, True])

        for a in range(300):
            rand = random.randint(0, number_of_connections - 1)
            if (not mylist[rand][1]):
                mylist.pop(rand)
                con = mimerpy.connect(**db_config.TSTUSR)
                mylist.append([con, True])
            else:
                mylist[rand][0].close()
                mylist[rand][1] = False

        for a in mylist:
            if (a[1]):
                a[0].close()
コード例 #15
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
    def test_rollback_not_working(self):
        b = self.tstcon.execute("create table bob7(c1 INTEGER) in pybank")
        b.execute("insert into bob7 values (:a)", (1133))
        self.tstcon.rollback()
        b.execute("select * from bob7")
        self.assertEqual(b.fetchone(), ())
        b.close()

        a = mimerpy.connect(**db_config.TSTUSR)
        b = a.execute("select * from bob6")
        a.close()
コード例 #16
0
ファイル: db_config.py プロジェクト: mimersql/MimerPy
def setup():
    if MIMERPY_TRACE:
        mimerpy._trace()
    syscon = mimerpy.connect(**SYSUSR)
    with syscon.cursor() as c:
        try:
            c.execute("DROP IDENT MIMERPY CASCADE")
        except mimerpy.DatabaseError as de:
            if de.message[0] != -12517:
                pass
            else:
                pass

        c.execute("CREATE IDENT MIMERPY AS USER USING 'PySecret'")
        c.execute("GRANT DATABANK,IDENT TO MIMERPY")
    syscon.commit()
    tstcon = mimerpy.connect(**TSTUSR)
    with tstcon.cursor() as c:
        c.execute("CREATE DATABANK PYBANK")
        c.execute(F"CREATE IDENT \"{OSUSER}\" AS USER")
        c.execute(F"ALTER IDENT \"{OSUSER}\" ADD OS_USER '{OSUSER}' ")
    tstcon.commit()
    return (syscon, tstcon)
コード例 #17
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
        def thread_test(self):
            try:
                a = mimerpy.connect(**db_config.TSTUSR)
                a.close()
            except Exception as e:
                print("Error: in thread: ", e)
                """ """
            try:
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))
                _thread.start_new_thread(thread_test, (self, ))

            except Exception as e:
                print("Error: unable to start thread: ", e)
                """ """
コード例 #18
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_invalid_login_3(self):
     with self.assertRaises(IntegrityError):
         a = mimerpy.connect()
コード例 #19
0
import mimerpy

import db_config

if __name__ == '__main__':
    with mimerpy.connect(**db_config.SYSUSR) as syscon:
        with syscon.cursor() as c:
            c.execute("drop ident mimerpy cascade")
        syscon.commit()
コード例 #20
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_2(self):
     a = mimerpy.connect(**db_config.TSTUSR)
     b = mimerpy.connect(**db_config.TSTUSR)
     a.close()
     b.close()
コード例 #21
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_os_user3(self):
     con = mimerpy.connect(db_config.DBNAME,
                           user=db_config.OSUSER,
                           password='******')
     con.execute("select 1+1 from system.onerow")
     con.close()
コード例 #22
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_os_user1(self):
     con = mimerpy.connect(db_config.DBNAME)
     con.execute("select 1+1 from system.onerow")
     con.close()
コード例 #23
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_many_no_close(self):
     for a in range(100):
         con = mimerpy.connect(**db_config.TSTUSR)
コード例 #24
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect(self):
     con = mimerpy.connect(**db_config.TSTUSR)
     con.close()
コード例 #25
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_cursor(self):
     con = mimerpy.connect(**db_config.TSTUSR)
     b = con.cursor()
     b.close()
     con.close()
コード例 #26
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_invalid_option(self):
     with self.assertRaises(TypeError):
         wrong = db_config.TSTUSR.copy()
         wrong['warpspeed'] = 'extra'
         a = mimerpy.connect(**wrong)
コード例 #27
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_cursor_close_connection_only(self):
     con = mimerpy.connect(**db_config.TSTUSR)
     b = con.cursor()
     con.close()
コード例 #28
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_with(self):
     with mimerpy.connect(**db_config.TSTUSR) as a:
         b = a.cursor()
         c = a.cursor()
コード例 #29
0
    args = parser.parse_args()

    something = False

    if args.tag:
        something = True
        print(mimerpy.version)

    if args.version:
        something = True
        print("Mimerpy  version %s" % mimerpy.__version__)
        print("MimerAPI version %s" % mimerapi.__version__)

    if args.sql:
        something = True
        try:
            with mimerpy.connect(dsn=args.database,
                                 user=args.user,
                                 password=args.password,
                                 autocommit=True) as con:
                with con.cursor() as cur:
                    cur.execute(args.sql)
                    if cur.description is not None:
                        r = cur.fetchall()
                        print(r)
        except Exception as e:
            print(e)

    if not something:
        print("Use option -h to get help")
コード例 #30
0
ファイル: testConnection.py プロジェクト: mimersql/MimerPy
 def test_connect_invalid_login_2(self):
     with self.assertRaises(DatabaseError):
         a = mimerpy.connect("self.d", "du", "där")