Python Forum
calling ".sql" files in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling ".sql" files in python
#1
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()
Reply
#2
On line 13, You have indented cur.close so that the cursor is closed after the 1st iteration of loop
remove indentation
Reply
#3
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
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python script is hanging while calling a procedure in database prasanthi417 4 500 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,036 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Calling python from c++ in visual studio pdk5 0 2,153 May-24-2021, 10:18 AM
Last Post: pdk5
  Calling Oracle REST SQL from Python johnjacob 2 2,031 Nov-05-2020, 04:19 AM
Last Post: johnjacob
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,743 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Calling Variables from Other Files in Different Folders illmattic 14 5,511 Aug-01-2020, 07:02 PM
Last Post: deanhystad
  Calling Extended Embedding Python as shared library jibarra 0 2,214 Jul-19-2019, 05:22 PM
Last Post: jibarra
  Calling from many different files davy_yg 1 2,179 Feb-14-2019, 04:39 AM
Last Post: ichabod801
  Python calling function unexpectedly lucaswinnerton 1 1,995 Jan-24-2019, 10:40 PM
Last Post: stullis
  Running a python tool transforming xml files into epub files silfer 7 5,391 May-10-2018, 03:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020