0

I found isql(using subprocess) is taking less time compare to Sybase module in python. Could someone please suggest me, should I use subprocess or Sybase. Below is the small test script which I have used for my understanding.

Query = 'select count(*) from my_table'

start_time1 = datetime.now()
db = Sybase.connect(mdbserver,muserid,mpassword,mdatabase)
c = db.cursor()
c.execute(Query)
list1 = c.fetchall()
end_time1 = datetime.now()
print (end_time1-start_time1)

start_time2 = datetime.now()
command = "./isql -S "+mdbserver+" -U "+muserid+" -P "+mpassword+" -D "+mdatabase+" -s '"+Delimiter+"' --retserverror -w 99999 <<EOF\nSET NOCOUNT ON\n   "+Query+"\ngo\nEOF"
proc = subprocess.Popen(
    command,
    stdout=subprocess.PIPE,stderr=subprocess.PIPE,
    shell=True,
    cwd=sybase_bin
)
output, error = proc.communicate()
end_time2 = datetime.now()
print (end_time2 - start_time2)
Reetesh Nigam
  • 133
  • 2
  • 2
  • 15

1 Answers1

0

isql is intended for interactive access to the database, and it returns data formatted for screen output. There is additional padding and formatting that can't be directly controlled. It also does not work well when you are looking at binary/image or other non varchar data.

The Python Module will pull the data as expected, without additional formatting.

So as long as you are only pulling columns that aren't too wide, or have binary data, then you can probably get away with using subprocess. The better solution would be to use the python module.

Mike Gardner
  • 6,611
  • 5
  • 24
  • 34
  • Will isql impact execution of application as invoking new process over head the entire application . – Reetesh Nigam Feb 11 '16 at 04:39
  • @ReeteshNigam Not sure what the overhead is, compared to the python module, but there is a cost, both in compute cycles and database memory consumed. – Mike Gardner Feb 11 '16 at 04:43