| |
- builtins.object
-
- SqlRunner
class SqlRunner(builtins.object) |
|
SqlRunner(user, pswd, dbUrl)
Runs SQL scripts and statements after connecting to the oracle
database.
Requires oracledb from oracle (https://python-oracledb.readthedocs.io/en/latest/index.html) |
|
Methods defined here:
- __init__(self, user, pswd, dbUrl)
- Constructor
:param user: the user name to login to the RDBMS
:param pswd: the password
:param dbUrl: the URL to connect to the RDBMS
- close(self)
- Close the connection and the cursor.
Normally invoked by atexit but can be invoked anytime.
The SqlRunner object can't be used after closing, unless an alternate
cursor is passed to the methods.
:return:
- executeSqlFromFile(self, fileName, alternateCursor=None, ignoreErrors=False)
- Execute the script read from the passed file
:param fileName: the name of the file with the SQL script
:param alternateCursor: the cursor to use instead of the one passed in the constructor
:param ignoreErrors: if True ignore the errors returned by runnng a SQL comamnd
otherwise terminates immediately if an error occurs
:return: the total number of rows that have currently been fetched from the cursor (
for select statements) or that have been affected by the operation
(for insert, update and delete statements
- executeSqlScript(self, script, alternateCursor=None)
- Execute the passed SQL script.
Note: it asumes that
a) SQL staments are separated by ';'
b) the script does not contain ';' other than those for separating SQL statements
:param script: the script to sun
:param alternateCursor: the cursor to use instead of the one passed in the constructor
:return: the total number of rows that have currently been fetched from the cursor (
for select statements) or that have been affected by the operation
(for insert, update and delete statements)
- executeSqlStatement(self, cmd, alternateCursor=None)
- Execute the SQL statement in the parameter
:param cmd: the SQL statement to run
:param alternateCursor: the cursor to use instead of the one passed in the constructor
:return: the number of rows that have currently been fetched from the cursor (
for select statements) or that have been affected by the operation
(for insert, update and delete statements).
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |