Python Forum

Full Version: calling ".sql" files in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Python gurus,
I have sql file, in that
I have some commands like set echo on, set feedback on
and drop table, create table and inserts
and pkg scripts followed by "/".
how do I call this script in pyhton, so far my trials, its not working

def get_rules():
   con = pyutils.conn_st()
   cur = con.cursor()
   f = open("run_all_su.sql")
   full_sql = f.read()
   sql_commands = full_sql.split(';')
   #sql_commands = full_sql.replace('\n', '').split(';')[:-1] # this bring just [] which is  empty
   print(sql_commands)
   for sql_command in sql_commands:
       print(sql_command)
       cur.execute(sql_command)

       cur.close()
   con.close()
On line 13, You have indented cur.close so that the cursor is closed after the 1st iteration of loop
remove indentation
I did what said. still issues
That sql script runs fine when I logon to database and run it with @s.sql
but when I call from python
I get all sorts of errors
(Jan-18-2018, 04:59 PM)raopatwari Wrote: [ -> ]I get all sorts of errors
What sorts of errors? Please share the full traceback, so we're not guessing what your issues are.