Ejemplo n.º 1
0
    def run_test_spinout_timestamp(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        # Get the server type
        serverinfo = ifx_db.server_info(conn)

        if conn:

            drop = "DROP PROCEDURE PROC_TIMESTAMP"
            try:
                result = ifx_db.exec_immediate(conn, drop)
            except:
                pass

            # Create the SP with timestamp parameters

            create = "CREATE PROCEDURE PROC_TIMESTAMP ( INOUT PAR1 DATETIME YEAR TO FRACTION(5), OUT PAR2 DATETIME YEAR TO FRACTION(5)) LET PAR2 = PAR1; END PROCEDURE"
            result = ifx_db.exec_immediate(conn, create)

            # call the SP. Expect PAR2 to contain value passed to PAR1
            par1 = "2017-05-13 22:47:29.82688"
            par2 = ""

            print "Values of bound parameters _before_ CALL:"
            print "  1: %s 2: %s\n" % (par1, par2)

            stmt, par1, par2 = ifx_db.callproc(conn, 'proc_timestamp',
                                               (par1, par2))
            if stmt is not None:
                print "Values of bound parameters _after_ CALL:"
                print "  1: %s 2: %s\n" % (par1, par2)

            ifx_db.close(conn)
        else:
            print("Connection failed.")
    def run_test_146(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)
        server = ifx_db.server_info(conn)

        if conn:
            name = "Peaches"
            second_name = "Rickety Ride"
            weight = 0

            print "Values of bound parameters _before_ CALL:"
            print "  1: %s 2: %s 3: %d\n" % (name, second_name, weight)

            stmt, name, second_name, weight = ifx_db.callproc(
                conn, 'match_animal', (name, second_name, weight))

            if stmt is not None:
                print "Values of bound parameters _after_ CALL:"
                print "  1: %s 2: %s 3: %d\n" % (name, second_name, weight)

                if (server.DBMS_NAME[0:3] != 'IDS'):
                    print "Results:"
                    row = ifx_db.fetch_tuple(stmt)
                    while (row):
                        print "  %s, %s, %s" % (row[0].strip(), row[1].strip(),
                                                row[2])
                        row = ifx_db.fetch_tuple(stmt)
    def run_test_148(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)

        if conn:
            ##### Set up #####
            serverinfo = ifx_db.server_info(conn)
            server = serverinfo.DBMS_NAME[0:3]
            try:
                sql = "DROP TABLE sptb"
                ifx_db.exec_immediate(conn, sql)
            except:
                pass

            try:
                sql = "DROP PROCEDURE sp"
                ifx_db.exec_immediate(conn, sql)
            except:
                pass

            sql = "CREATE TABLE sptb (c1 INTEGER, c2 FLOAT, c3 VARCHAR(10), c4 INT8, c5 VARCHAR(20))"

            ifx_db.exec_immediate(conn, sql)

            sql = "INSERT INTO sptb (c1, c2, c3, c4, c5) VALUES (1, 5.01, 'varchar', 3271982, 'varchar data')"
            ifx_db.exec_immediate(conn, sql)

            sql = """CREATE PROCEDURE sp(OUT out1 INTEGER, OUT out2 FLOAT, OUT out3 VARCHAR(10), OUT out4 INT8, OUT out5 VARCHAR(20));
                 SELECT c1, c2, c3, c4, c5 INTO out1, out2, out3, out4, out5 FROM sptb; END PROCEDURE;"""
            ifx_db.exec_immediate(conn, sql)
            #############################

            ##### Run the test #####

            out1 = 0
            out2 = 0.00
            out3 = ""
            out4 = 0
            out5 = ""

            stmt, out1, out2, out3, out4, out5 = ifx_db.callproc(
                conn, 'sp', (out1, out2, out3, out4, out5))

            print "out 1:"
            print out1
            print "out 2:"
            print out2
            print "out 3:"
            print out3
            print "out 4:"
            print out4
            print "out 5:"
            print out5
            #############################
        else:
            print "Connection failed."
    def run_test_146(self):
        conn = ifx_db.connect(config.ConnStr, config.user, config.password)
        server = ifx_db.server_info(conn)

        if conn:
            name = "Peaches"
            second_name = "Rickety Ride"
            weight = 0

            print "Values of bound parameters _before_ CALL:"
            print "  1: %s 2: %s 3: %d\n" % (name, second_name, weight)

            stmt, name, second_name, weight = ifx_db.callproc(
                conn, 'match_animal', (name, second_name, weight))

            if stmt is not None:
                print "Values of bound parameters _after_ CALL:"
                print "  1: %s 2: %s 3: %d\n" % (name, second_name, weight)