Пример #1
0
 def __init__(self, options):
     self.connection = cx_OracleUtils.Connect(options.schema,
                                              options.setRole)
     self.cursor = self.connection.cursor()
     if options.arraySize:
         self.cursor.arraysize = options.arraySize
     self.commitPoint = options.commitPoint
     self.reportPoint = options.reportPoint
     self.dateFormat = options.dateFormat
     self.cursor.execute("select * from %s" % options.tableName)
     self.columnIndexes = {}
     self.dateColumns = {}
     bindVars = []
     bindVarNames = []
     columnNames = []
     for item in self.cursor.description:
         name, dataType, size, internalSize, prec, scale, nullsOk = item
         if dataType == self.connection.DATETIME:
             self.dateColumns[name.upper()] = None
         elif dataType != self.connection.CLOB:
             dataType = self.connection.STRING
         self.columnIndexes[name.upper()] = len(bindVars)
         bindVars.append(self.cursor.var(dataType, size))
         columnNames.append(name)
         bindVarNames.append(":%s" % len(bindVars))
     sql = "insert into %s (%s) values (%s)" % \
             (options.tableName, ",".join(columnNames),
              ",".join(bindVarNames))
     self.cursor.prepare(sql)
     self.cursor.setinputsizes(*bindVars)
     self.allowCustomTags = False
     self.columnValue = None
Пример #2
0
def main():
    """
    Method that performs the work of the script.
    """
    options = get_options()
    connection = cx_OracleUtils.Connect(options.schema)
    cx_Logging.Trace("Connected to %s@%s", connection.username, connection.dsn)
    cx_Logging.Trace("Listening on pipe %s...", options.pipeName)

    # display the messages
    for message in cx_OracleDebugger.MessageGenerator(connection,
            options.pipeName):
        cx_Logging.Trace("%s", message)
Пример #3
0
    help="enable this <role> [identified by <password>] in the target "
    "database immediately after connecting by calling "
    "dbms_session.set_role")
cx_LoggingOptions.AddOptions(parser)
parser.AddArgument("source",
                   required=True,
                   help="a select statement or the name of the table to query")
parser.AddArgument(
    "destination",
    help="the name of a table or view to perform the insert and update "
    "statements against")
options = parser.Parse()
cx_LoggingOptions.ProcessOptions(options)

# set up the source connection
sourceConnection = cx_OracleUtils.Connect(options.sourceSchema,
                                          options.sourceRole)
sourceCursor = sourceConnection.cursor()
if options.arraySize:
    sourceCursor.arraysize = options.arraySize
if options.maxLongSize:
    sourceCursor.setoutputsize(options.maxLongSize)

# set up the destination connection
destConnection = cx_OracleUtils.Connect(options.destSchema, options.destRole)
cursor = destConnection.cursor()

# determine query to execute
sourceSQL = options.source.strip()
destinationTable = options.destination
if not sourceSQL.lower().startswith("select ") and os.path.isfile(sourceSQL):
    sourceSQL = file(sourceSQL).read().strip()
Пример #4
0
                 metavar="STR",
                 help="append an order by clause with this value to the query")
cx_LoggingOptions.AddOptions(parser)
parser.AddArgument("fileName",
                   required=True,
                   help="the name of the file to which to write the data or "
                   "'-' to write the data to stdout")
parser.AddArgument("source", required = True,
        help = "the name of the table from which to export all of the data " \
               "or the select statement which should be executed to " \
               "determine the data to export")
options = parser.Parse()
cx_LoggingOptions.ProcessOptions(options)

# connect to the database and execute the query
connection = cx_OracleUtils.Connect(options.schema, options.setRole)
cursor = connection.cursor()
if options.arraySize is not None:
    cursor.arraysize = options.arraySize
if options.source.lower().startswith("select "):
    query = options.source
else:
    query = "select * from %s" % options.source
if options.sortBy:
    query += " order by %s" % options.sortBy
cursor.execute(query)
names = [item[0] for item in cursor.description]

# write the data to the XML file
if options.fileName == "-":
    outputFile = sys.stdout
parser.AddArgument(
    "fileName",
    required=True,
    help="the name of the file from which to read the data that "
    "is to be imported")
parser.AddArgument(
    "values",
    keywords=True,
    help="any number of values of the form name=value which will be "
    "turned into bind variables which will be bound to the "
    "statement that is to be executed")
options = parser.Parse()
cx_LoggingOptions.ProcessOptions(options)

# connect to the database
connection = cx_OracleUtils.Connect(options.schema)
cursor = connection.cursor()

# verify options
if options.binary:
    mode = "rb"
    bindType = cx_Oracle.LONG_BINARY
else:
    mode = "r"
    bindType = cx_Oracle.LONG_STRING
data = open(options.fileName, mode).read()
if options.statementInFile:
    options.statement = open(options.statement).read().strip()
options.isColumn = " " not in options.statement
if not options.isColumn:
    statement = options.statement