Python Forum

Full Version: Capturing error from sql
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi - very new to python. I have a function that connects to teradata using jdwh. The function works well but the function returns nothing when there is an sql error. Function is as shown below - I’m advised that jdwh will return “exit code 1” if there was an error:

def db_execute(sql,ret='stdout'):

ret_type = {'stdout': 0 , 'out': 0, 'err':1, 'error':1, 'stderror':1}

args = ['jdwh']

db_cmd = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

out = db_cmd.communicate(input = sql)

if ret_type[ret] not in list(ret_type.values()):
return None
return out[ret_type[ret]]

Any help appreciated.
Please use Python tags to retain the indentation of your code. See the BBCode link in my signature below for details.