Capturing error from sql - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Capturing error from sql (/thread-11230.html) |
Capturing error from sql - Grego - Jun-29-2018 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. RE: Capturing error from sql - ichabod801 - Jun-29-2018 Please use Python tags to retain the indentation of your code. See the BBCode link in my signature below for details. |