Python: How to execute a SQL file or command

Posted by Mestika on Stack Overflow See other posts from Stack Overflow or by Mestika
Published on 2010-05-16T19:16:28Z Indexed on 2010/05/16 19:20 UTC
Read the original article Hit count: 417

Filed under:
|
|
|
|

Hi,

I have this Python script:

import sys
import getopt
import timeit
import random
import os
import re
import ibm_db
import time
from string import maketrans

runs=5
queries=50
file = open("results.txt", "a")

for r in range(5):
    print "Run %s\n" % r

    os.system("python reads.py -r1 -pquery1.sql -q50 -sespec")  

file.write('END QUERY READ 01') 
file.close()
os.system("python query_read_02.py") 

Everything here is working, it is creating the results.txt file, it run the os.system("python reads.py...") file and that file is doing everything it's suppose to, but the problem comes when go and run the query_read_02.py file.

In this file, it should execute a SQL command or a SQL file on my database, so I can create an index and see what the performance of that input is, but how do i do it? I create the connection to the database in the reads.py file, but it's hard to create the queries in there because I doesn't keep track of which file it has reached, it just execute commands from what the parameters are.

I hope I've explained myself clear enough, otherwise please let me know. I just want to execute a SQL command or file which each query_read_0x.py file.

Sincerely

Mestika

© Stack Overflow or respective owner

Related posts about python

Related posts about db2