execute a sql script file from cx_oracle?

cx-oracle, database, python

Solution

PEP-249, which cx_oracle tries to be compliant with, doesn't really have a method like that.

However, the process should be pretty straight forward. Pull the contents of the file into a string, split it on the ";" character, and then call .execute on each member of the resulting array. I'm assuming that the ";" character is only used to delimit the oracle SQL statements within the file.

f = open('tabledefinition.sql')
full_sql = f.read()
sql_commands = full_sql.split(';')

for sql_command in sql_commands:
    curs.execute(sql_command)

Problem

Is there a way to execute a sql script file using cx_oracle in python. I need to execute my create table scripts in sql files.

Original source