def _getSchema(self): """ Get the schema if any: * if there is an explicit "*.schema.sql" then copy it in the build directory and set self.schema. * if there is a default state then try to infer the schema. * otherwise return none. """ explicit_schema_file = os.path.join(self.directory, '%s.schema.sql' % self.name) if os.path.isfile(explicit_schema_file): return Schema( self.name, self, fileContent(explicit_schema_file), schemaFilename=explicit_schema_file, isGenerated=False) elif self.hasStates: sql_rst = self.defaultState.getInferredSchema() return Schema( self.name, self, sql_rst, schemaFilename=None, isGenerated=True ) else: return None
def __init__(self, queriesFilename, case): #: filename of the queries file. self.filename = queriesFilename _ = os.path.basename(self.filename).replace('.queries.sql', '') #: name of the query set, without numbering information at the beginning self.name = re.sub('^[0-9]+_', '', _) #: SQL Text correspoding to the query files self.sql = fileContent(self.filename) #: Case containing this QuerySet self.case = case #: Schema text cut in logical blocks. #: list[sqlrst.structure.Block] self.blocks = sqlrst.parser.sqlRstToBlockSequence(self.sql) #: list[Query]. #: List of queries extracted from the query set. self.queryList = self.__extractQueries() #: str|None. #: filename of the generated rst file self.buildRstFile = None # will be filled by build()
def executeScript(self, sqlFile): # sqlite3 cannot execute multiple statement at the same time # close the existing engine if it exist if self.sqlAlchemyEngine is not None: self.sqlAlchemyEngine.dispose() self.sqlAlchemyEngine = None # use sqlite3 interface sqlite3_connection = sqlite3.connect(self.dbFile) # with tempfile.NamedTemporaryFile(mode='w',suffix='.sql') as f: # f.write(self.dbFile) try: sqlite3_connection.executescript(fileContent(sqlFile)) except: print ( 'Exception raised when executing Script "%s":\n%s' % (sqlFile, fileContent(sqlFile)) ) raise sqlite3_connection.close()
def __init__(self, queriesFilename, case): #: filename of the queries file. self.filename = queriesFilename #: name of the query set, without numbering information at the beginning _ = os.path.basename(self.filename).replace('.queries.sql','') self.name = re.sub('^[0-9]+_','',_) #: SQL Text correspoding to the query files self.sql = fileContent(self.filename) #: Case containing this QuerySet self.case = case #: Schema text cut in logical blocks. #: list[sqlrst.structure.Block] self.blocks = sqlrst.parser.sqlRstToBlockSequence(self.sql) #: list[Query]. #: List of queries extracted from the query set. self.queryList = self.__extractQueries() #: str|None. #: filename of the generated rst file self.buildRstFile = None # will be filled by build()
* blocks * buildRstFile * v queryList """ def __init__(self, queriesFilename, case, verbose=False): #: filename of the queries file. self.filename = queriesFilename _ = os.path.basename(self.filename).replace('.queries.sql', '') #: name of the query set, without numbering information at the beginning # self.name = re.sub('^[0-9]+_','',_) self.name = _ #: SQL Text correspoding to the query files self.sql = fileContent(self.filename) #: Case containing this QuerySet self.case = case #: Schema text cut in logical blocks. #: list[sqlrst.structure.Block] self.blocks = sqlrst.parser.sqlRstToBlockSequence(self.sql) #: list[Query]. #: List of queries extracted from the query set. self.queryList = self.__extractQueries() #: str|None. #: filename of the generated rst file self.buildRstFile = None # will be filled by build()
def defineSQLSchema(self, sqlFile): assert(self.schemaFile is None) self.executeScript(sqlFile) self.schemaFile = sqlFile self.schemaText = fileContent(self.schemaFile)
def executeScript(self, sqlFile): self.execute(fileContent(sqlFile))