Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Capturing error from sql
#1
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.
Reply
#2
Please use Python tags to retain the indentation of your code. See the BBCode link in my signature below for details.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capturing BS4 values into DF and writing to CSV cubangt 18 1,948 Sep-05-2023, 01:57 PM
Last Post: cubangt
  capturing multiline output for number of parameters jss 3 809 Sep-01-2023, 05:42 PM
Last Post: jss
  Json filter is not capturing desired key/element mrapple2020 1 1,124 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  Capturing inputs values from internal python script limors11 11 5,190 Jun-16-2019, 05:05 PM
Last Post: DeaD_EyE
  Capturing a snapshot from the video sreeramp96 1 2,180 May-24-2019, 07:02 AM
Last Post: heiner55
  HTTP response capturing issue miunika 1 2,025 Mar-16-2019, 01:46 PM
Last Post: Larz60+
  HTTP response capturing issue anna 2 2,500 Mar-15-2019, 03:08 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020