1

I'm using isql command in python for sybase databases, isql command by default returns zero as return code if the database query has failed, I want it to return some non zero value if the query has failed so that i could i know that my query is invalid.

I looked it over on the internet, i have found that using --retserverror option with isql would solve the purpose but i'm getting some errors while using it

I'm using following python code:-

ps = subprocess.Popen("""./isql -S %s -U %s -P %s -D %s --retserverror -s "|" -w 10000 <<EOF
%s
go
EOF""" % (server,userid,password,database,Query),stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
error = ps.stderr.read()
out, err = ps.communicate()
if ps.returncode == 0:
   final = out
else:
         print "Error"
    final = error
print final

Output:-

Syntax Error in '--retserverror'.
usage: ./isql [-b] [-e] [-F] [-p] [-n] [-v] [-X] [-Y] [-Q]
    [-a display_charset] [-A packet_size] [-c cmdend] [-D database]
    [-E editor [-h header [-H hostname [-i inputfile]
    [-I interfaces_file] [-J client_charset] [-K keytab_file]
    [-l login_timeout] [-m errorlevel] [-M labelname labelvalue]
    [-o outputfile] [-P password] [-R remote_server_principal]
    [-s col_separator] [-S server_name] [-t timeout] [-U username]
    [-V [security_options]] [-w column_width] [-z localename]
    [-Z security_mechanism]

Can anyone guide me here?

Mike Gardner
  • 6,611
  • 5
  • 24
  • 34
Bad_Coder
  • 1,019
  • 1
  • 20
  • 38
  • Which database are you using? – Tanuj Mathur Sep 03 '14 at 06:41
  • --retservererror is only available in Sybase 15 ESD#10 and above. What version of Sybase are you running? Can you include the out of the 'isql -v' command? – Tanuj Mathur Sep 03 '14 at 06:55
  • Sybase CTISQL Utility/12.5.1/P-EBF12368 ESD #7/DRV.12.5.1.3/Linux Intel/Linux 2.4.18-18.7.xsmp i686/BUILD1251-040/OPT/Mon Jan 24 20:01:17 2005 – Bad_Coder Sep 03 '14 at 07:10
  • return status you are checking is of isql command and not of the query that failed. I do it by redirecting the output (-o) to an output file and than checking for error text in the file. – Meet Sep 10 '14 at 08:05

1 Answers1

0

You will want to use raiseerror function to set an error number. Custom error messages can be added using sp_addmessage

Check out my answer here for more details, the answer links to Sybase ASE 15.5 Documentation.

Here are the links for ASE 12.5.1:

raiserror sp_addmessage

Community
  • 1
  • 1
Mike Gardner
  • 6,611
  • 5
  • 24
  • 34