<s> '''<STR_LIT>''' <EOL> import sys , os , io , time , re , datetime <EOL> from math import isnan , isinf <EOL> from decimal import Decimal <EOL> from arelle . ModelValue import dateTime <EOL> import socket <EOL> TRACESQLFILE = None <EOL> def noop ( * args , ** kwargs ) : return <EOL> class NoopException ( Exception ) : <EOL> pass <EOL> try : <EOL> import pg8000 <EOL> hasPostgres = True <EOL> pgConnect = pg8000 . connect <EOL> pgOperationalError = pg8000 . OperationalError <EOL> pgProgrammingError = pg8000 . ProgrammingError <EOL> pgInterfaceError = pg8000 . InterfaceError <EOL> except ImportError : <EOL> hasPostgres = False <EOL> pgConnect = noop <EOL> pgOperationalError = pgProgrammingError = pgInterfaceError = NoopException <EOL> try : <EOL> import pymysql <EOL> hasMySql = True <EOL> mysqlConnect = pymysql . connect <EOL> mysqlProgrammingError = pymysql . ProgrammingError <EOL> mysqlInterfaceError = pymysql . InterfaceError <EOL> mysqlInternalError = pymysql . InternalError <EOL> except ImportError : <EOL> try : <EOL> import MySQLdb <EOL> hasMySql = True <EOL> mysqlConnect = MySQLdb . connect <EOL> mysqlProgrammingError = MySQLdb . ProgrammingError <EOL> mysqlInterfaceError = MySQLdb . InterfaceError <EOL> mysqlInternalError = MySQLdb . InternalError <EOL> except ImportError : <EOL> hasMySql = False <EOL> mysqlConnect = noop <EOL> mysqlProgrammingError = mysqlInterfaceError = mysqlInternalError = NoopException <EOL> try : <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> import cx_Oracle <EOL> hasOracle = True <EOL> oracleConnect = cx_Oracle . connect <EOL> oracleDatabaseError = cx_Oracle . DatabaseError <EOL> oracleInterfaceError = cx_Oracle . InterfaceError <EOL> oracleNCLOB = cx_Oracle . NCLOB <EOL> except ImportError : <EOL> hasOracle = False <EOL> oracleConnect = noop <EOL> oracleDatabaseError = oracleInterfaceError = NoopException <EOL> oracleCLOB = None <EOL> try : <EOL> import pyodbc <EOL> hasMSSql = True <EOL> mssqlConnect = pyodbc . connect <EOL> mssqlOperationalError = pyodbc . OperationalError <EOL> mssqlProgrammingError = pyodbc . ProgrammingError <EOL> mssqlInterfaceError = pyodbc . InterfaceError <EOL> mssqlInternalError = pyodbc . InternalError <EOL> mssqlDataError = pyodbc . DataError <EOL> mssqlIntegrityError = pyodbc . IntegrityError <EOL> except ImportError : <EOL> hasMSSql = False <EOL> mssqlConnect = noop <EOL> mssqlOperationalError = mssqlProgrammingError = mssqlInterfaceError = mssqlInternalError = mssqlDataError = mssqlIntegrityError = NoopException <EOL> try : <EOL> import sqlite3 <EOL> hasSQLite = True <EOL> sqliteConnect = sqlite3 . connect <EOL> sqliteParseDecltypes = sqlite3 . PARSE_DECLTYPES <EOL> sqliteOperationalError = sqlite3 . OperationalError <EOL> sqliteProgrammingError = sqlite3 . ProgrammingError <EOL> sqliteInterfaceError = sqlite3 . InterfaceError <EOL> sqliteInternalError = sqlite3 . InternalError <EOL> sqliteDataError = sqlite3 . DataError <EOL> sqliteIntegrityError = sqlite3 . IntegrityError <EOL> except ImportError : <EOL> hasSQLite = False <EOL> sqliteConnect = noop <EOL> sqliteParseDecltypes = None <EOL> sqliteOperationalError = sqliteProgrammingError = sqliteInterfaceError = sqliteInternalError = sqliteDataError = sqliteIntegrityError = NoopException <EOL> def isSqlConnection ( host , port , timeout = <NUM_LIT:10> , product = None ) : <EOL> t = <NUM_LIT:2> <EOL> while t < timeout : <EOL> try : <EOL> if product == "<STR_LIT>" and hasPostgres : <EOL> pgConnect ( user = '<STR_LIT>' , host = host , port = int ( port or <NUM_LIT> ) , socket_timeout = t ) <EOL> elif product == "<STR_LIT>" and hasMySql : <EOL> mysqlConnect ( user = '<STR_LIT>' , host = host , port = int ( port or <NUM_LIT> ) , socket_timeout = t ) <EOL> elif product == "<STR_LIT>" and hasOracle : <EOL> orclConnect = oracleConnect ( '<STR_LIT>' <EOL> . format ( "<STR_LIT>" , "<STR_LIT>" , host , <EOL> "<STR_LIT>" . format ( port ) if port else "<STR_LIT>" ) ) <EOL> elif product == "<STR_LIT>" and hasMSSql : <EOL> mssqlConnect ( user = '<STR_LIT>' , host = host , socket_timeout = t ) <EOL> elif product == "<STR_LIT>" and hasSQLite : <EOL> sqliteConnect ( "<STR_LIT>" , t ) <EOL> except ( pgProgrammingError , mysqlProgrammingError , oracleDatabaseError , sqliteProgrammingError ) : <EOL> return True <EOL> except ( pgInterfaceError , mysqlInterfaceError , oracleInterfaceError , <EOL> mssqlOperationalError , mssqlInterfaceError , sqliteOperationalError , sqliteInterfaceError ) : <EOL> return False <EOL> except socket . timeout : <EOL> t = t + <NUM_LIT:2> <EOL> return False <EOL> class XPDBException ( Exception ) : <EOL> def __init__ ( self , code , message , ** kwargs ) : <EOL> self . code = code <EOL> self . message = message <EOL> self . kwargs = kwargs <EOL> self . args = ( self . __repr__ ( ) , ) <EOL> def __repr__ ( self ) : <EOL> return _ ( '<STR_LIT>' ) . format ( self . code , self . message % self . kwargs ) <EOL> class SqlDbConnection ( ) : <EOL> def __init__ ( self , modelXbrl , user , password , host , port , database , timeout , product ) : <EOL> self . modelXbrl = modelXbrl <EOL> self . disclosureSystem = modelXbrl . modelManager . disclosureSystem <EOL> if product == "<STR_LIT>" : <EOL> if not hasPostgres : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) <EOL> self . conn = pgConnect ( user = user , password = password , host = host , <EOL> port = int ( port or <NUM_LIT> ) , <EOL> database = database , <EOL> socket_timeout = timeout or <NUM_LIT> ) <EOL> self . product = product <EOL> elif product == "<STR_LIT>" : <EOL> if not hasMySql : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) <EOL> self . conn = mysqlConnect ( user = user , passwd = password , host = host , <EOL> port = int ( port or <NUM_LIT> ) , <EOL> db = database , <EOL> connect_timeout = timeout or <NUM_LIT> , <EOL> charset = '<STR_LIT:utf8>' ) <EOL> self . product = product <EOL> elif product == "<STR_LIT>" : <EOL> if not hasOracle : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) <EOL> self . conn = oracleConnect ( '<STR_LIT>' <EOL> . format ( user , password , host , <EOL> "<STR_LIT>" . format ( port ) if port else "<STR_LIT>" ) ) <EOL> self . product = product <EOL> elif product == "<STR_LIT>" : <EOL> if not hasMSSql : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) <EOL> self . conn = mssqlConnect ( '<STR_LIT>' <EOL> . format ( user , <EOL> password , <EOL> host , <EOL> database ) ) <EOL> self . product = product <EOL> elif product == "<STR_LIT>" : <EOL> if not hasSQLite : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) ) <EOL> self . conn = sqliteConnect ( database , ( timeout or <NUM_LIT> ) , detect_types = sqliteParseDecltypes ) <EOL> self . product = product <EOL> self . syncSequences = False <EOL> else : <EOL> self . product = None <EOL> self . tableColTypes = { } <EOL> self . tableColDeclaration = { } <EOL> self . accessionId = "<STR_LIT>" <EOL> self . tempInputTableName = "<STR_LIT>" . format ( os . getpid ( ) ) <EOL> def close ( self , rollback = False ) : <EOL> if not self . isClosed : <EOL> try : <EOL> self . closeCursor ( ) <EOL> if rollback : <EOL> self . rollback ( ) <EOL> self . conn . close ( ) <EOL> self . __dict__ . clear ( ) <EOL> except Exception as ex : <EOL> self . __dict__ . clear ( ) <EOL> if sys . version [ <NUM_LIT:0> ] >= '<STR_LIT:3>' : <EOL> raise ex . with_traceback ( ex . __traceback__ ) <EOL> else : <EOL> raise ex <EOL> @ property <EOL> def isClosed ( self ) : <EOL> return not bool ( self . __dict__ ) <EOL> def showStatus ( self , msg , clearAfter = None ) : <EOL> self . modelXbrl . modelManager . showStatus ( msg , clearAfter ) <EOL> def pyBoolFromDbBool ( self , str ) : <EOL> return str in ( "<STR_LIT>" , "<STR_LIT:t>" , True ) <EOL> def pyNoneFromDbNULL ( self , str ) : <EOL> return None <EOL> def dbNum ( self , num ) : <EOL> if isinstance ( num , ( int , float ) ) : <EOL> if isinf ( num ) or isnan ( num ) : <EOL> return None <EOL> return num <EOL> return None <EOL> def dbStr ( self , s ) : <EOL> if self . product == "<STR_LIT>" : <EOL> return "<STR_LIT:'>" + str ( s ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT:'>" <EOL> elif self . product == "<STR_LIT>" : <EOL> return "<STR_LIT:N>" + self . conn . escape ( str ( s ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> return "<STR_LIT:'>" + str ( s ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT:'>" <EOL> else : <EOL> return "<STR_LIT:'>" + str ( s ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) + "<STR_LIT:'>" <EOL> def dbTableName ( self , tableName ) : <EOL> if self . product == "<STR_LIT>" : <EOL> return '<STR_LIT:">' + tableName + '<STR_LIT:">' <EOL> else : <EOL> return tableName <EOL> @ property <EOL> def cursor ( self ) : <EOL> try : <EOL> return self . _cursor <EOL> except AttributeError : <EOL> self . _cursor = self . conn . cursor ( ) <EOL> return self . _cursor <EOL> def closeCursor ( self ) : <EOL> try : <EOL> self . _cursor . close ( ) <EOL> del self . _cursor <EOL> except ( AttributeError , <EOL> pgOperationalError , <EOL> mysqlProgrammingError , <EOL> oracleDatabaseError ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . _cursor <EOL> def commit ( self ) : <EOL> self . conn . commit ( ) <EOL> def rollback ( self ) : <EOL> try : <EOL> self . conn . rollback ( ) <EOL> except ( pg8000 . ConnectionClosedError ) : <EOL> pass <EOL> def dropTemporaryTable ( self ) : <EOL> if self . product == "<STR_LIT>" : <EOL> self . execute ( """<STR_LIT>""" . format ( self . tempInputTableName ) , <EOL> close = True , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> elif self . product == "<STR_LIT>" : <EOL> self . execute ( """<STR_LIT>""" . format ( self . tempInputTableName ) , <EOL> close = True , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> def lockTables ( self , tableNames , isSessionTransaction = False ) : <EOL> '''<STR_LIT>''' <EOL> if self . product in ( "<STR_LIT>" , "<STR_LIT>" ) and isSessionTransaction : <EOL> result = self . execute ( '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( tableNames ) ) , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> elif self . product in ( "<STR_LIT>" , ) : <EOL> result = self . execute ( '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' . format ( t ) for t in tableNames ] ) ) , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> elif self . product in ( "<STR_LIT>" , ) and isSessionTransaction : <EOL> result = self . execute ( '<STR_LIT>' , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> def unlockAllTables ( self ) : <EOL> if self . product in ( "<STR_LIT>" , ) : <EOL> result = self . execute ( '<STR_LIT>' , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> elif self . product in ( "<STR_LIT>" , ) : <EOL> result = self . execute ( '<STR_LIT>' , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> def execute ( self , sql , commit = False , close = True , fetch = True , params = None , action = "<STR_LIT>" ) : <EOL> cursor = self . cursor <EOL> try : <EOL> if isinstance ( params , dict ) : <EOL> cursor . execute ( sql , ** params ) <EOL> elif isinstance ( params , ( tuple , list ) ) : <EOL> cursor . execute ( sql , params ) <EOL> else : <EOL> cursor . execute ( sql ) <EOL> except ( pgProgrammingError , <EOL> mysqlProgrammingError , mysqlInternalError , <EOL> oracleDatabaseError , <EOL> mssqlOperationalError , mssqlInterfaceError , mssqlDataError , <EOL> mssqlProgrammingError , mssqlIntegrityError , <EOL> sqliteOperationalError , sqliteInterfaceError , sqliteDataError , <EOL> socket . timeout , <EOL> ValueError ) as ex : <EOL> if TRACESQLFILE : <EOL> with io . open ( TRACESQLFILE , "<STR_LIT:a>" , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> fh . write ( "<STR_LIT>" <EOL> . format ( action , str ( ex ) , sql ) ) <EOL> raise <EOL> if fetch : <EOL> result = cursor . fetchall ( ) <EOL> else : <EOL> result = None <EOL> if commit : <EOL> self . conn . commit ( ) <EOL> if close : <EOL> self . closeCursor ( ) <EOL> return result <EOL> def create ( self , ddlFile ) : <EOL> startedAt = time . time ( ) <EOL> self . showStatus ( "<STR_LIT>" ) <EOL> for table in self . tablesInDB ( ) : <EOL> result = self . execute ( '<STR_LIT>' % self . dbTableName ( table ) , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> self . showStatus ( "<STR_LIT>" ) <EOL> for sequence in self . sequencesInDB ( ) : <EOL> result = self . execute ( '<STR_LIT>' % sequence , <EOL> close = False , commit = False , fetch = False , action = "<STR_LIT>" ) <EOL> self . modelXbrl . profileStat ( _ ( "<STR_LIT>" ) , time . time ( ) - startedAt ) <EOL> startedAt = time . time ( ) <EOL> with io . open ( os . path . dirname ( __file__ ) + os . sep + ddlFile , <EOL> '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> sql = fh . read ( ) . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) <EOL> sqlstatements = [ ] <EOL> def findstatements ( start , end , laststatement ) : <EOL> for line in sql [ start : end ] . split ( '<STR_LIT:\n>' ) : <EOL> stmt , comment1 , comment2 = line . partition ( "<STR_LIT>" ) <EOL> laststatement += stmt + '<STR_LIT:\n>' <EOL> if '<STR_LIT:;>' in stmt : <EOL> sqlstatements . append ( laststatement ) <EOL> laststatement = '<STR_LIT>' <EOL> return laststatement <EOL> stmt = '<STR_LIT>' <EOL> i = <NUM_LIT:0> <EOL> patternDollarEsc = re . compile ( r"<STR_LIT>" , re . DOTALL + re . MULTILINE ) <EOL> while i < len ( sql ) : <EOL> match = patternDollarEsc . search ( sql , i ) <EOL> if not match : <EOL> stmt = findstatements ( i , len ( sql ) , stmt ) <EOL> sqlstatements . append ( stmt ) <EOL> break <EOL> dollarescape = match . group ( ) <EOL> j = match . end ( ) <EOL> stmt = findstatements ( i , j , stmt ) <EOL> i = sql . find ( dollarescape , j ) <EOL> if i > j : <EOL> if self . product == "<STR_LIT>" : <EOL> stmt = sql [ j : i ] <EOL> i += len ( dollarescape ) <EOL> else : <EOL> i += len ( dollarescape ) <EOL> stmt += sql [ j : i ] <EOL> sqlstatements . append ( stmt ) <EOL> stmt = '<STR_LIT>' <EOL> action = "<STR_LIT>" . format ( os . path . basename ( ddlFile ) ) <EOL> for i , sql in enumerate ( sqlstatements ) : <EOL> if any ( cmd in sql <EOL> for cmd in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) : <EOL> statusMsg , sep , rest = sql . strip ( ) . partition ( '<STR_LIT:\n>' ) <EOL> self . showStatus ( statusMsg [ <NUM_LIT:0> : <NUM_LIT:50> ] ) <EOL> result = self . execute ( sql , close = False , commit = False , fetch = False , action = action ) <EOL> if TRACESQLFILE : <EOL> with io . open ( TRACESQLFILE , "<STR_LIT:a>" , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> fh . write ( "<STR_LIT>" <EOL> . format ( i , sql , result ) ) <EOL> fh . write ( sql ) <EOL> self . showStatus ( "<STR_LIT>" ) <EOL> self . conn . commit ( ) <EOL> self . modelXbrl . profileStat ( _ ( "<STR_LIT>" ) , time . time ( ) - startedAt ) <EOL> self . closeCursor ( ) <EOL> def databasesInDB ( self ) : <EOL> return self . execute ( { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } [ self . product ] , <EOL> action = "<STR_LIT>" ) <EOL> def dropAllTablesInDB ( self ) : <EOL> if self . product == "<STR_LIT>" : <EOL> self . execute ( "<STR_LIT>" ) <EOL> self . execute ( "<STR_LIT>" , commit = True , action = "<STR_LIT>" ) <EOL> elif self . product in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for tableName in self . tablesInDB ( ) : <EOL> self . execute ( "<STR_LIT>" . format ( self . dbTableName ( tableName ) ) , <EOL> action = "<STR_LIT>" ) <EOL> def tablesInDB ( self ) : <EOL> return set ( tableRow [ <NUM_LIT:0> ] <EOL> for tableRow in <EOL> self . execute ( { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } [ self . product ] ) ) <EOL> def sequencesInDB ( self ) : <EOL> try : <EOL> return set ( sequenceRow [ <NUM_LIT:0> ] <EOL> for sequenceRow in <EOL> self . execute ( { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } [ self . product ] ) ) <EOL> except KeyError : <EOL> return set ( ) <EOL> def columnTypeFunctions ( self , table ) : <EOL> if table not in self . tableColTypes : <EOL> if self . product == "<STR_LIT>" : <EOL> colTypesResult = self . execute ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( table ) ) <EOL> colTypes = [ ] <EOL> for name , fulltype , dataPrecision , charColDeclLength in colTypesResult : <EOL> name = name . lower ( ) <EOL> fulltype = fulltype . lower ( ) <EOL> if fulltype in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> colDecl = "<STR_LIT>" . format ( fulltype , charColDeclLength ) <EOL> elif fulltype == "<STR_LIT>" and dataPrecision : <EOL> colDecl = "<STR_LIT>" . format ( fulltype , dataPrecision ) <EOL> else : <EOL> colDecl = fulltype <EOL> colTypes . append ( ( name , fulltype , colDecl ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> colTypesResult = self . execute ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( table ) ) <EOL> colTypes = [ ] <EOL> for name , fulltype , characterMaxLength in colTypesResult : <EOL> name = name . lower ( ) <EOL> if fulltype in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if characterMaxLength == - <NUM_LIT:1> : <EOL> characterMaxLength = "<STR_LIT>" <EOL> colDecl = "<STR_LIT>" . format ( fulltype , characterMaxLength ) <EOL> else : <EOL> colDecl = fulltype <EOL> colTypes . append ( ( name , fulltype , colDecl ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> colTypesResult = self . execute ( "<STR_LIT>" <EOL> . format ( table ) ) <EOL> colTypes = [ ] <EOL> for cid , name , type , notnull , dflt_value , pk in colTypesResult : <EOL> name = name . lower ( ) <EOL> type = type . lower ( ) <EOL> colTypes . append ( ( name , type , type ) ) <EOL> else : <EOL> colTypes = self . execute ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( '<STR_LIT>' if self . product == '<STR_LIT>' else '<STR_LIT>' , <EOL> self . dbTableName ( table ) ) ) <EOL> self . tableColTypes [ table ] = dict ( ( name , <EOL> ( '<STR_LIT>' + typename if typename in <EOL> { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:int>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:date>" , "<STR_LIT>" } <EOL> else "<STR_LIT>" if fulltype . startswith ( "<STR_LIT>" ) <EOL> else '<STR_LIT>' , <EOL> int if typename in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:int>" , "<STR_LIT>" , "<STR_LIT>" ) else <EOL> float if typename in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) else <EOL> self . pyBoolFromDbBool if typename in ( "<STR_LIT>" , "<STR_LIT>" ) else <EOL> dateTime if typename in ( "<STR_LIT:date>" , "<STR_LIT>" ) else <EOL> str ) ) <EOL> for name , fulltype , colDecl in colTypes <EOL> for typename in ( fulltype . partition ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] , ) ) <EOL> if self . product in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . tableColDeclaration [ table ] = dict ( ( name , colDecl ) <EOL> for name , fulltype , colDecl in colTypes ) <EOL> return self . tableColTypes [ table ] <EOL> def getTable ( self , table , idCol , newCols = None , matchCols = None , data = None , commit = False , <EOL> comparisonOperator = '<STR_LIT:=>' , checkIfExisting = False , insertIfNotMatched = True , <EOL> returnMatches = True , returnExistenceStatus = False ) : <EOL> if not data or not newCols or not matchCols : <EOL> return ( ) <EOL> isOracle = self . product == "<STR_LIT>" <EOL> isMSSql = self . product == "<STR_LIT>" <EOL> isPostgres = self . product == "<STR_LIT>" <EOL> isSQLite = self . product == "<STR_LIT>" <EOL> newCols = [ newCol . lower ( ) for newCol in newCols ] <EOL> matchCols = [ matchCol . lower ( ) for matchCol in matchCols ] <EOL> returningCols = [ ] <EOL> if idCol : <EOL> returningCols . append ( idCol . lower ( ) ) <EOL> for matchCol in matchCols : <EOL> if matchCol not in returningCols : <EOL> returningCols . append ( matchCol ) <EOL> colTypeFunctions = self . columnTypeFunctions ( table ) <EOL> colDeclarations = self . tableColDeclaration . get ( table ) <EOL> try : <EOL> colTypeCast = tuple ( colTypeFunctions [ colName ] [ <NUM_LIT:0> ] for colName in newCols ) <EOL> colTypeFunction = [ colTypeFunctions [ colName ] [ <NUM_LIT:1> ] for colName in returningCols ] <EOL> if returnExistenceStatus : <EOL> colTypeFunction . append ( self . pyBoolFromDbBool ) <EOL> except KeyError as err : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> table = table , missingColumnName = str ( err ) ) <EOL> rowValues = [ ] <EOL> rowLongValues = [ ] <EOL> if isOracle : <EOL> longColValues = { } <EOL> else : <EOL> longColValues = [ ] <EOL> for row in data : <EOL> colValues = [ ] <EOL> for col in row : <EOL> if isinstance ( col , bool ) : <EOL> if isOracle or isMSSql or isSQLite : <EOL> colValues . append ( '<STR_LIT:1>' if col else '<STR_LIT:0>' ) <EOL> else : <EOL> colValues . append ( '<STR_LIT>' if col else '<STR_LIT>' ) <EOL> elif isinstance ( col , int ) : <EOL> colValues . append ( str ( col ) ) <EOL> elif isinstance ( col , float ) : <EOL> if _ISFINITE ( col ) : <EOL> colValues . append ( str ( col ) ) <EOL> else : <EOL> colValues . append ( '<STR_LIT>' ) <EOL> elif isinstance ( col , Decimal ) : <EOL> if col . is_finite ( ) : <EOL> colValues . append ( str ( col ) ) <EOL> else : <EOL> colValues . append ( '<STR_LIT>' ) <EOL> elif isinstance ( col , ( datetime . date , datetime . datetime ) ) and self . product == "<STR_LIT>" : <EOL> colValues . append ( "<STR_LIT>" . format ( col . year , col . month , col . day ) ) <EOL> elif isinstance ( col , datetime . datetime ) and ( isMSSql or isSQLite ) : <EOL> colValues . append ( "<STR_LIT>" . format ( col . year , col . month , col . day , col . hour , col . minute , col . second ) ) <EOL> elif isinstance ( col , datetime . date ) and ( isMSSql or isSQLite ) : <EOL> colValues . append ( "<STR_LIT>" . format ( col . year , col . month , col . day ) ) <EOL> elif col is None : <EOL> colValues . append ( '<STR_LIT>' ) <EOL> elif isinstance ( col , _STR_BASE ) and len ( col ) >= <NUM_LIT> and ( isOracle or isMSSql ) : <EOL> if isOracle : <EOL> colName = "<STR_LIT>" . format ( len ( colValues ) ) <EOL> longColValues [ colName ] = col <EOL> colValues . append ( "<STR_LIT::>" + colName ) <EOL> else : <EOL> longColValues . append ( col ) <EOL> colValues . append ( "<STR_LIT:?>" ) <EOL> else : <EOL> colValues . append ( self . dbStr ( col ) ) <EOL> if not rowValues and isPostgres : <EOL> for i , cast in enumerate ( colTypeCast ) : <EOL> if cast : <EOL> colValues [ i ] = colValues [ i ] + cast <EOL> rowColValues = "<STR_LIT:U+002CU+0020>" . join ( colValues ) <EOL> rowValues . append ( "<STR_LIT:(>" + rowColValues + "<STR_LIT:)>" if not isOracle else rowColValues ) <EOL> if longColValues : <EOL> rowLongValues . append ( longColValues ) <EOL> if isOracle : <EOL> longColValues = { } <EOL> else : <EOL> longColValues = [ ] <EOL> else : <EOL> rowLongValues . append ( None ) <EOL> values = "<STR_LIT>" . join ( rowValues ) <EOL> _table = self . dbTableName ( table ) <EOL> _inputTableName = self . tempInputTableName <EOL> if self . product == "<STR_LIT>" : <EOL> sql = [ ( ( '''<STR_LIT>''' + ( '''<STR_LIT>''' + ( '''<STR_LIT>''' if checkIfExisting else '<STR_LIT>' ) + '''<STR_LIT>''' if insertIfNotMatched else '<STR_LIT>' ) + '''<STR_LIT>''' + ( ( '''<STR_LIT>''' if checkIfExisting else '<STR_LIT>' ) + ( '''<STR_LIT>''' if ( checkIfExisting and insertIfNotMatched ) else '<STR_LIT>' ) + ( '''<STR_LIT>''' if insertIfNotMatched else '<STR_LIT>' ) ) + '''<STR_LIT>''' ) % { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( returningCols ) , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( c ) for c in returningCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( col , comparisonOperator ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : values , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" <EOL> } , None , True ) ] <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( newCol , colDeclarations [ newCol ] ) <EOL> for newCol in newCols ) } , None , False ) , <EOL> ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : values } , None , False ) ] <EOL> if insertIfNotMatched : <EOL> if checkIfExisting : <EOL> _where = ( '<STR_LIT>' % <EOL> { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( col , comparisonOperator ) <EOL> for col in matchCols ) } ) <EOL> _whereLock = ( "<STR_LIT>" % { "<STR_LIT>" : _table } ) <EOL> else : <EOL> _where = "<STR_LIT>" ; <EOL> _whereLock = "<STR_LIT>" <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : _whereLock } , None , False ) ) <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : _where } , None , False ) ) <EOL> elif returnMatches or returnExistenceStatus : <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _table } , None , False ) ) <EOL> if returnMatches or returnExistenceStatus : <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , col ) <EOL> for col in returningCols ) } , None , True ) ) <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName } , None , False ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( newCol , colDeclarations [ newCol ] ) <EOL> for newCol in newCols ) } , None , False ) ] <EOL> def insertMSSqlRows ( i , j , params ) : <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : "<STR_LIT:U+002CU+0020>" . join ( rowValues [ i : j ] ) } , params , False ) ) <EOL> iMax = len ( rowValues ) <EOL> i = <NUM_LIT:0> <EOL> while ( i < iMax ) : <EOL> for j in range ( i , min ( i + <NUM_LIT:1000> , iMax ) ) : <EOL> if rowLongValues [ j ] is not None : <EOL> if j > i : <EOL> insertMSSqlRows ( i , j , None ) <EOL> insertMSSqlRows ( j , j + <NUM_LIT:1> , rowLongValues [ j ] ) <EOL> i = j + <NUM_LIT:1> <EOL> break <EOL> if i < j + <NUM_LIT:1> and i < iMax : <EOL> insertMSSqlRows ( i , j + <NUM_LIT:1> , None ) <EOL> i = j + <NUM_LIT:1> <EOL> if insertIfNotMatched : <EOL> sql . append ( ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( "<STR_LIT>" . format ( _inputTableName , newCol ) <EOL> for newCol in newCols ) } , None , False ) ) <EOL> if returnMatches or returnExistenceStatus : <EOL> sql . append ( <EOL> ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , col ) <EOL> for col in returningCols ) } , None , True ) ) <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName } , None , False ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( newCol , colDeclarations [ newCol ] ) <EOL> for newCol in newCols ) } , None , False ) ] <EOL> def insertOrclRows ( i , j , params ) : <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" . join ( "<STR_LIT>" . format ( r ) <EOL> for r in rowValues [ i : j ] ) } , params , False ) ) <EOL> iMax = len ( rowValues ) <EOL> i = <NUM_LIT:0> <EOL> while ( i < iMax ) : <EOL> for j in range ( i , min ( i + <NUM_LIT:1000> , iMax ) ) : <EOL> if rowLongValues [ j ] is not None : <EOL> if j > i : <EOL> insertOrclRows ( i , j , None ) <EOL> insertOrclRows ( j , j + <NUM_LIT:1> , rowLongValues [ j ] ) <EOL> i = j + <NUM_LIT:1> <EOL> break <EOL> if i < j + <NUM_LIT:1> and i < iMax : <EOL> insertOrclRows ( i , j + <NUM_LIT:1> , None ) <EOL> i = j + <NUM_LIT:1> <EOL> if insertIfNotMatched : <EOL> sql . append ( ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( "<STR_LIT>" . format ( _inputTableName , newCol ) <EOL> for newCol in newCols ) } , None , False ) ) <EOL> if returnMatches or returnExistenceStatus : <EOL> sql . append ( <EOL> ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , col ) <EOL> for col in returningCols ) } , None , True ) ) <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName } , None , False ) ) <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( newCol , colDeclarations [ newCol ] ) <EOL> for newCol in newCols ) } , None , False ) ] <EOL> def insertSQLiteRows ( i , j , params ) : <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : "<STR_LIT:U+002CU+0020>" . join ( rowValues [ i : j ] ) } , params , False ) ) <EOL> iMax = len ( rowValues ) <EOL> i = <NUM_LIT:0> <EOL> while ( i < iMax ) : <EOL> for j in range ( i , min ( i + <NUM_LIT> , iMax ) ) : <EOL> if rowLongValues [ j ] is not None : <EOL> if j > i : <EOL> insertSQLiteRows ( i , j , None ) <EOL> insertSQLiteRows ( j , j + <NUM_LIT:1> , rowLongValues [ j ] ) <EOL> i = j + <NUM_LIT:1> <EOL> break <EOL> if i < j + <NUM_LIT:1> and i < iMax : <EOL> insertSQLiteRows ( i , j + <NUM_LIT:1> , None ) <EOL> i = j + <NUM_LIT:1> <EOL> if insertIfNotMatched : <EOL> if checkIfExisting : <EOL> _where = ( '<STR_LIT>' % <EOL> { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( col , comparisonOperator ) <EOL> for col in matchCols ) } ) <EOL> else : <EOL> _where = "<STR_LIT>" ; <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : _where } , None , False ) ) <EOL> if returnMatches or returnExistenceStatus : <EOL> sql . append ( <EOL> ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( newCols ) , <EOL> "<STR_LIT>" : '<STR_LIT>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , col ) <EOL> for col in matchCols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" if returnExistenceStatus else "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , col ) <EOL> for col in returningCols ) } , None , True ) ) <EOL> sql . append ( ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName } , None , False ) ) <EOL> if insertIfNotMatched and self . syncSequences : <EOL> sql . append ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _table } , None , False ) ) <EOL> if TRACESQLFILE : <EOL> with io . open ( TRACESQLFILE , "<STR_LIT:a>" , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> fh . write ( "<STR_LIT>" <EOL> . format ( self . accessionId , table , len ( sql ) , len ( data ) ) ) <EOL> for sqlStmt , params , fetch in sql : <EOL> fh . write ( "<STR_LIT>" + sqlStmt + "<STR_LIT>" . format ( params if params else "<STR_LIT>" ) ) <EOL> tableRows = [ ] <EOL> for sqlStmt , params , fetch in sql : <EOL> if params and isOracle : <EOL> self . cursor . setinputsizes ( ** dict ( ( name , oracleNCLOB ) for name in params ) ) <EOL> result = self . execute ( sqlStmt , commit = commit , close = False , fetch = fetch , params = params ) <EOL> if fetch and result : <EOL> tableRows . extend ( result ) <EOL> if TRACESQLFILE : <EOL> with io . open ( TRACESQLFILE , "<STR_LIT:a>" , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> fh . write ( "<STR_LIT>" <EOL> . format ( self . accessionId , table , len ( tableRows ) , '<STR_LIT:\n>' . join ( str ( r ) for r in tableRows ) ) ) <EOL> return tuple ( tuple ( None if colValue == "<STR_LIT>" or colValue is None else <EOL> colTypeFunction [ i ] ( colValue ) <EOL> for i , colValue in enumerate ( row ) ) <EOL> for row in tableRows ) <EOL> def updateTable ( self , table , cols = None , data = None , commit = False ) : <EOL> if not cols or not data : <EOL> return ( ) <EOL> isOracle = self . product == "<STR_LIT>" <EOL> isSQLite = self . product == "<STR_LIT>" <EOL> idCol = cols [ <NUM_LIT:0> ] <EOL> colTypeFunctions = self . columnTypeFunctions ( table ) <EOL> colDeclarations = self . tableColDeclaration . get ( table ) <EOL> try : <EOL> colTypeCast = tuple ( colTypeFunctions [ colName ] [ <NUM_LIT:0> ] for colName in cols ) <EOL> except KeyError as err : <EOL> raise XPDBException ( "<STR_LIT>" , <EOL> _ ( "<STR_LIT>" ) , <EOL> table = table , missingColumnName = str ( err ) ) <EOL> rowValues = [ ] <EOL> for row in data : <EOL> colValues = [ ] <EOL> for col in row : <EOL> if isinstance ( col , bool ) : <EOL> colValues . append ( '<STR_LIT>' if col else '<STR_LIT>' ) <EOL> elif isinstance ( col , ( int , float ) ) : <EOL> colValues . append ( str ( col ) ) <EOL> elif col is None : <EOL> colValues . append ( '<STR_LIT>' ) <EOL> else : <EOL> colValues . append ( self . dbStr ( col ) ) <EOL> if not rowValues and self . product == "<STR_LIT>" : <EOL> for i , cast in enumerate ( colTypeCast ) : <EOL> if cast : <EOL> colValues [ i ] = colValues [ i ] + cast <EOL> rowColValues = "<STR_LIT:U+002CU+0020>" . join ( colValues ) <EOL> if isOracle : <EOL> rowValues . append ( rowColValues ) <EOL> elif isSQLite : <EOL> rowValues . append ( colValues ) <EOL> else : <EOL> rowValues . append ( "<STR_LIT:(>" + rowColValues + "<STR_LIT:)>" ) <EOL> if not isOracle and not isSQLite : <EOL> values = "<STR_LIT>" . join ( rowValues ) <EOL> _table = self . dbTableName ( table ) <EOL> _inputTableName = self . tempInputTableName <EOL> if self . product == "<STR_LIT>" : <EOL> sql = [ ( '''<STR_LIT>''' ) % { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( col for col in cols ) , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( cols [ i ] ) <EOL> for i , col in enumerate ( cols ) <EOL> if i > <NUM_LIT:0> ) , <EOL> "<STR_LIT>" : values } ] <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( col , colDeclarations [ col ] ) <EOL> for col in cols ) } , <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( cols ) , <EOL> "<STR_LIT>" : values } , <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table } , <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( cols [ i ] ) <EOL> for i , col in enumerate ( cols ) <EOL> if i > <NUM_LIT:0> ) } , <EOL> "<STR_LIT>" % { "<STR_LIT>" : _inputTableName } ] <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( col , colDeclarations [ col ] ) <EOL> for col in cols ) } ] <EOL> for i in range ( <NUM_LIT:0> , len ( rowValues ) , <NUM_LIT> ) : <EOL> values = "<STR_LIT>" . join ( rowValues [ i : i + <NUM_LIT> ] ) <EOL> sql . append ( "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( cols ) , <EOL> "<STR_LIT>" : values } ) <EOL> sql . append ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , cols [ i ] ) <EOL> for i , col in enumerate ( cols ) <EOL> if i > <NUM_LIT:0> ) } ) <EOL> sql . append ( "<STR_LIT>" % { "<STR_LIT>" : _inputTableName } ) <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( col , colDeclarations [ col ] ) <EOL> for col in cols ) } ] <EOL> for i in range ( <NUM_LIT:0> , len ( rowValues ) , <NUM_LIT> ) : <EOL> sql . append ( <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( cols ) , <EOL> "<STR_LIT>" : "<STR_LIT>" . join ( "<STR_LIT>" . format ( r ) <EOL> for r in rowValues [ i : i + <NUM_LIT> ] ) } ) <EOL> sql . append ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT>" : _inputTableName , <EOL> "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( _table , _inputTableName , cols [ i ] ) <EOL> for i , col in enumerate ( cols ) <EOL> if i > <NUM_LIT:0> ) } ) <EOL> sql . append ( "<STR_LIT>" % { "<STR_LIT>" : _inputTableName } ) <EOL> elif self . product == "<STR_LIT>" : <EOL> sql = [ "<STR_LIT>" % <EOL> { "<STR_LIT>" : _table , <EOL> "<STR_LIT>" : idCol , <EOL> "<STR_LIT>" : rowValue [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" : '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( col , rowValue [ i ] ) <EOL> for i , col in enumerate ( cols ) <EOL> if i > <NUM_LIT:0> ) } <EOL> for rowValue in rowValues ] <EOL> if TRACESQLFILE : <EOL> with io . open ( TRACESQLFILE , "<STR_LIT:a>" , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> fh . write ( "<STR_LIT>" <EOL> . format ( self . accessionId , table , len ( sql ) , len ( data ) ) ) <EOL> for sqlStmt in sql : <EOL> fh . write ( sqlStmt ) <EOL> for sqlStmt in sql : <EOL> self . execute ( sqlStmt , commit = commit , fetch = False , close = False ) </s>
