Teradata / PyTd

A Python Module to make it easy to script powerful interactions with Teradata Database in a DevOps friendly way.
MIT License
108 stars 43 forks source link

Stored procedures with out parameters misplace return values #48

Closed JeremyMarshall closed 8 years ago

JeremyMarshall commented 8 years ago

Having a SP with in and out params results in the return values in the wrong place.

Passing the out params in first fixes it but it shouldn't really matter...

import teradata
import argparse
from collections import ChainMap

parser = argparse.ArgumentParser(description="TEST callproc)", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("server", help="?")
parser.add_argument("username", help="?")
parser.add_argument("password", help="Don't do this at home as the password will be visible")
parser.add_argument("-l", "--log", action='store_true', default=False, help="turn on logging stuff")

arguments = parser.parse_args()

udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0", logConsole=arguments.log)

param_boilerplate =  {'USEINTEGRATEDSECURITY':'N', 'AUTHENTICATION': 'LDAP', 'method':'odbc'}

conn_parms = ChainMap(param_boilerplate, {'system':arguments.server, 'username':arguments.username, 'password':arguments.password,'queryBands':{'Name':'TEST'}})
session = udaExec.connect(**conn_parms)

params = (
    teradata.OutParam("o_value"),
    teradata.InOutParam(0, "i_search_type"),
    teradata.InOutParam('Name', "i_name")
)
results = session.callproc("syslib.getquerybandvaluesp", params)

print("name: {}, type: {}, value:{}".format(results.i_name, results.i_search_type, results.o_value))

params = (
    teradata.InOutParam(0, "i_search_type"),
    teradata.InOutParam('Name', "i_name"),
    teradata.OutParam("o_value")
)
results = session.callproc("syslib.getquerybandvaluesp", params)
print("name: {}, type: {}, value:{}".format(results.i_name, results.i_search_type, results.o_value))

results in this The first one correct the second one not so correct but the second one is the parameters in the order for the SP

name: Name, type: 0, value:TEST
name: Name, type: TEST, value:

this is my config

escheie commented 8 years ago

The contract for the "syslib.getquerybandvaluesp" function is two IN parameters and single OUT parameter. You are passing two INOUT parameters and a single OUT parameter.

For whatever reason ODBC is allowing this, and populating the result in the first INOUT/OUT parameter it finds.

If you change your params tuple to this, it will work as expected:

params = (0, 'Name', teradata.OutParam("o_value"))