|
def | __init__ (self, connection) |
|
def | getTables (self, exceptTables) |
|
def | executeQuery (self, query, data={}) |
|
def | tableSize (self, tableName) |
|
def | columnNames (self, tableName) |
|
def | getIndexes (self) |
|
def | getPrimaryKeys (self) |
|
def | getForeignKeys (self) |
|
def | sqliteType (self, oraType) |
|
def | tableCreationCommand (self, tableName, primaryKeys, foreignKeys, indexes) |
|
def | extractSchema (self, creationFileName) |
|
def | copyTable (self, tableName, sqliteInserter, size) |
|
Definition at line 102 of file AtlTriggerDBCopy.py.
◆ __init__()
def AtlTriggerDBCopy.OracleExporter.__init__ |
( |
|
self, |
|
|
|
connection |
|
) |
| |
Definition at line 104 of file AtlTriggerDBCopy.py.
105 self.connection = connection
106 self.primaryKeys =
None
107 self.foreignKeys =
None
109 self.allTables =
None
110 self.ignoreTablesCreate = [
'TT_WRITELOCK',
'HLT_SMT_TO_HRE',
'HLT_PARAMETER',
'HLT_RELEASE',
'TRIGGER_LOG',
111 'DBCOPY_SOURCE_DATABASE',
'HLT_RULE_SET',
'TEMP',
'HLT_RULE_PARAMETER',
'HLT_RULE_COMPONENT',
112 'HLT_SETUP',
'TT_USERS',
'HLT_RULE',
"HLT_HRC_TO_HRP",
"HLT_HRE_TO_HRS",
113 "HLT_HRS_TO_HRU",
"HLT_HRU_TO_HRC",
"HLT_PRESCALE_SET_ALIAS",
"HLT_PRESCALE_SET_COLL",
114 "PRESCALE_SET_ALIAS",
"TRIGGER_ALIAS",
"L1_PRESCALE_SET_ALIAS",
"L1_CALO_SIN_COS",
115 "L1_CI_TO_CSC",
"L1_JET_INPUT",
"L1_MUON_THRESHOLD_SET"]
116 self.ignoreTablesFill = self.ignoreTablesCreate + [ ]
117 print(
"Tables to ignore creation: %r" % len(self.ignoreTablesCreate))
118 print(
"Tables to ignore filling: %r" % len(self.ignoreTablesFill))
◆ columnNames()
def AtlTriggerDBCopy.OracleExporter.columnNames |
( |
|
self, |
|
|
|
tableName |
|
) |
| |
Definition at line 148 of file AtlTriggerDBCopy.py.
148 def columnNames(self,tableName):
149 query_ColumnNames =
"SELECT column_name, data_type FROM sys.all_tab_columns WHERE owner = :SCHEMA AND table_name = :TABLE_NAME ORDER BY column_id"
150 data = {
"SCHEMA" : self.connection.schema,
"TABLE_NAME" : tableName }
151 result = self.executeQuery( query = query_ColumnNames, data = data )
152 colNames, colTypes = zip(*result)
153 return colNames, colTypes
◆ copyTable()
def AtlTriggerDBCopy.OracleExporter.copyTable |
( |
|
self, |
|
|
|
tableName, |
|
|
|
sqliteInserter, |
|
|
|
size |
|
) |
| |
Definition at line 248 of file AtlTriggerDBCopy.py.
248 def copyTable(self, tableName, sqliteInserter, size):
250 schema = self.connection.schema
251 colNames,_ = self.columnNames(tableName)
252 colNameList =
",".
join(colNames)
253 bindVarList =
",".
join(len(colNames)*[
"?"])
254 insertStatement = f
"INSERT INTO {tableName} ({colNameList}) VALUES ({bindVarList})"
256 selectQuery = f
"SELECT {colNameList} FROM {schema}.{tableName}"
258 result = self.executeQuery( selectQuery )
261 sqliteInserter.insertBulk(insertStatement, result)
266 print(
"%i / %i" % (c, size))
268 sqliteInserter.insert(insertStatement, data)
271 sqliteInserter.commit()
◆ executeQuery()
def AtlTriggerDBCopy.OracleExporter.executeQuery |
( |
|
self, |
|
|
|
query, |
|
|
|
data = {} |
|
) |
| |
Definition at line 135 of file AtlTriggerDBCopy.py.
136 cursor = self.connection.
cursor()
137 cursor.arraysize = 1000
138 cursor.execute( query, **data )
◆ extractSchema()
def AtlTriggerDBCopy.OracleExporter.extractSchema |
( |
|
self, |
|
|
|
creationFileName |
|
) |
| |
Definition at line 239 of file AtlTriggerDBCopy.py.
239 def extractSchema(self, creationFileName):
240 fk = self.getForeignKeys()
241 pk = self.getPrimaryKeys()
242 indexes = self.getIndexes()
243 with open(creationFileName,
"w")
as fh:
244 print(
"Creating schema file for sqlite: %s" % creationFileName)
245 for tableName
in self.getTables(exceptTables = self.ignoreTablesCreate):
246 print(self.tableCreationCommand( tableName, pk[tableName], fk.get(tableName,
list()), indexes.get(tableName,
list())), file = fh)
◆ getForeignKeys()
def AtlTriggerDBCopy.OracleExporter.getForeignKeys |
( |
|
self | ) |
|
Definition at line 190 of file AtlTriggerDBCopy.py.
190 def getForeignKeys(self):
191 if self.foreignKeys
is not None:
192 return self.foreignKeys
193 print(
"retrieving foreign key constraints from Oracle")
194 query_ForeignKeys =
"""
195 SELECT c.table_name, c.constraint_name, a.column_name, c.r_constraint_name, r.table_name, r.column_name
196 FROM sys.all_constraints c
198 sys.all_cons_columns a
199 on (c.constraint_type='R' and c.constraint_name = a.constraint_name and c.owner = :SCHEMA and a.owner = :SCHEMA)
201 sys.all_cons_columns r
202 on (c.r_constraint_name = r.constraint_name and r.owner = :SCHEMA)
204 data = {
"SCHEMA" : self.connection.schema }
206 result = self.executeQuery( query = query_ForeignKeys, data = data )
207 for table, _, fkcol, _, rtable, rcol
in result:
210 fk[table] += [ {
"col" : fkcol,
"rtab" : rtable,
"rcol" : rcol } ]
211 self.foreignKeys = fk
212 return self.foreignKeys
◆ getIndexes()
def AtlTriggerDBCopy.OracleExporter.getIndexes |
( |
|
self | ) |
|
Definition at line 155 of file AtlTriggerDBCopy.py.
155 def getIndexes(self):
156 if self.indexes
is not None:
159 print(
"retrieving indexes from Oracle")
161 SELECT table_name, index_name, column_name FROM sys.all_ind_columns WHERE table_owner = :SCHEMA
163 data = {
"SCHEMA" : self.connection.schema }
164 result = self.executeQuery( query = query_Indexes, data = data )
165 for table_name, index_name, column_name
in result:
166 if table_name
not in self.indexes:
167 self.indexes[table_name] = {}
168 self.indexes[table_name][index_name] = column_name
◆ getPrimaryKeys()
def AtlTriggerDBCopy.OracleExporter.getPrimaryKeys |
( |
|
self | ) |
|
Definition at line 171 of file AtlTriggerDBCopy.py.
171 def getPrimaryKeys(self):
172 if self.primaryKeys
is not None:
173 return self.primaryKeys
174 print(
"retrieving primary key constraints from Oracle")
175 query_PrimaryKeys =
"""
176 SELECT table_name, column_name, position FROM sys.all_cons_columns WHERE owner = :SCHEMA AND constraint_name in
177 (SELECT constraint_name FROM sys.all_constraints WHERE owner = :SCHEMA AND constraint_type='P')
178 ORDER BY table_name, position
180 data = {
"SCHEMA" : self.connection.schema }
182 result = self.executeQuery( query = query_PrimaryKeys, data = data )
183 for table_name, column_name, _
in result:
184 if table_name
not in pk:
186 pk[table_name] += [ column_name ]
187 self.primaryKeys = pk
188 return self.primaryKeys
◆ getTables()
def AtlTriggerDBCopy.OracleExporter.getTables |
( |
|
self, |
|
|
|
exceptTables |
|
) |
| |
Definition at line 121 of file AtlTriggerDBCopy.py.
121 def getTables(self, exceptTables):
122 if self.allTables
is None:
123 query_ListAllTables =
"SELECT table_name FROM all_tables WHERE owner=:SCHEMA"
124 data = {
"SCHEMA" : self.connection.schema }
125 result = self.executeQuery(query_ListAllTables, data)
126 self.allTables = [x[0]
for x
in result]
127 print(
"All tables: %i" % len(self.allTables))
128 tables = deepcopy(self.allTables)
129 if exceptTables
is not None:
130 for x
in exceptTables:
◆ sqliteType()
def AtlTriggerDBCopy.OracleExporter.sqliteType |
( |
|
self, |
|
|
|
oraType |
|
) |
| |
Definition at line 214 of file AtlTriggerDBCopy.py.
214 def sqliteType(self, oraType):
215 if oraType.startswith(
"TIMESTAMP"):
217 d = {
"VARCHAR2" :
"TEXT",
219 "NUMBER" :
"INTEGER",
◆ tableCreationCommand()
def AtlTriggerDBCopy.OracleExporter.tableCreationCommand |
( |
|
self, |
|
|
|
tableName, |
|
|
|
primaryKeys, |
|
|
|
foreignKeys, |
|
|
|
indexes |
|
) |
| |
Definition at line 224 of file AtlTriggerDBCopy.py.
224 def tableCreationCommand(self, tableName, primaryKeys, foreignKeys, indexes):
225 colNames, colTypes = self.columnNames(tableName)
227 for colName, colType
in zip(colNames,colTypes):
228 lines.append(
"%s %s" % (colName, self.sqliteType(colType)) )
229 lines.append(
"PRIMARY KEY (%s)" %
",".
join(primaryKeys) )
230 for fk
in foreignKeys:
231 lines.append(
"FOREIGN KEY (%s) REFERENCES %s (%s)" % (fk[
"col"], fk[
"rtab"], fk[
"rcol"]) )
232 creationCommand = f
"CREATE TABLE IF NOT EXISTS {tableName} (\n "
233 creationCommand +=
",\n ".
join(lines)
234 creationCommand +=
"\n);\n"
235 for index_name
in indexes:
236 creationCommand +=
"CREATE INDEX %s on %s(%s);\n" % (index_name, tableName, indexes[index_name])
237 return creationCommand
◆ tableSize()
def AtlTriggerDBCopy.OracleExporter.tableSize |
( |
|
self, |
|
|
|
tableName |
|
) |
| |
Definition at line 141 of file AtlTriggerDBCopy.py.
141 def tableSize(self,tableName):
142 query_TableSize =
"SELECT COUNT(*) FROM {schema}.{tableName}"
143 qdict = {
"schema" : self.connection.schema,
"tableName" : tableName }
144 result = self.executeQuery( query_TableSize.format(**qdict) )
145 row = result.fetchone()
◆ allTables
AtlTriggerDBCopy.OracleExporter.allTables |
◆ connection
AtlTriggerDBCopy.OracleExporter.connection |
◆ foreignKeys
AtlTriggerDBCopy.OracleExporter.foreignKeys |
◆ ignoreTablesCreate
AtlTriggerDBCopy.OracleExporter.ignoreTablesCreate |
◆ ignoreTablesFill
AtlTriggerDBCopy.OracleExporter.ignoreTablesFill |
◆ indexes
AtlTriggerDBCopy.OracleExporter.indexes |
◆ primaryKeys
AtlTriggerDBCopy.OracleExporter.primaryKeys |
The documentation for this class was generated from the following file: