calling ".sql" files in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: calling ".sql" files in python (/thread-7632.html) |
calling ".sql" files in python - raopatwari - Jan-18-2018 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() RE: calling ".sql" files in python - Larz60+ - Jan-18-2018 On line 13, You have indented cur.close so that the cursor is closed after the 1st iteration of loop remove indentation RE: calling ".sql" files in python - raopatwari - Jan-18-2018 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 RE: calling ".sql" files in python - nilamo - Jan-18-2018 (Jan-18-2018, 04:59 PM)raopatwari Wrote: I get all sorts of errorsWhat sorts of errors? Please share the full traceback, so we're not guessing what your issues are. |