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
  Calling python from another program eedjsa 9 948 Dec-27-2025, 04:06 PM
Last Post: eedjsa
  C++ program embedding Python crashes when calling PyUnicode_AsUTF8 Alexandros 4 2,451 Sep-19-2025, 11:11 AM
Last Post: Alexandros
  python script is hanging while calling a procedure in database prasanthi417 4 3,221 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 2,866 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Calling python from c++ in visual studio pdk5 0 3,122 May-24-2021, 10:18 AM
Last Post: pdk5
  Calling Oracle REST SQL from Python johnjacob 2 3,429 Nov-05-2020, 04:19 AM
Last Post: johnjacob
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 8,039 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Calling Variables from Other Files in Different Folders illmattic 14 12,911 Aug-01-2020, 07:02 PM
Last Post: deanhystad
  Calling Extended Embedding Python as shared library jibarra 0 3,115 Jul-19-2019, 05:22 PM
Last Post: jibarra
  Calling from many different files davy_yg 1 3,263 Feb-14-2019, 04:39 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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