def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() #pidNum = cgiEnv.m_entity_id_dict["Pid"] #filNam = cgiEnv.m_entity_id_dict["File"] #sqlQuery_encode = cgiEnv.m_entity_id_dict["Query"] # sqlQuery_encode = cgiEnv.GetId() # TODO: This should be packaged in sql/__init__.py. #sqlQuery = lib_util.Base64Decode(sqlQuery_encode) sqlQuery = sql_query.GetEnvArgs(cgiEnv) dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) nodeSqlQuery = sqlserver_query.MakeUri(sqlQuery, dsnNam) propSheetToQuery = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sqlQuery) # Based on the pid and the filnam, find which database connection it is. # What is the schema ?? list_of_nodes = sqlserver_query.QueryToNodesList( sqlQuery, {"Dsn": dsnNam}, list_of_table_names, dsnNam + ":SqlServerSchema") for nodTab in list_of_nodes: grph.add((nodeSqlQuery, propSheetToQuery, nodTab)) cgiEnv.OutCgiRdf()
def Main(): # cgiEnv = lib_common.CgiEnv() cgiEnv = lib_oracle.OracleEnv() grph = cgiEnv.GetGraph() sqlQuery = sql_query.GetEnvArgs(cgiEnv) dbNam = cgiEnv.m_entity_id_dict["Db"] # This is simply the user. oraSchema = cgiEnv.OracleSchema() nodeSqlQuery = oracle_query.MakeUri(sqlQuery, dbNam) propSheetToQuery = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sqlQuery) list_of_nodes = oracle_query.QueryToNodesList(sqlQuery, {"Db": dbNam}, list_of_table_names, oraSchema) for nodTab in list_of_nodes: grph.add((nodeSqlQuery, propSheetToQuery, nodTab)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() #pidNum = cgiEnv.m_entity_id_dict["Pid"] #filNam = cgiEnv.m_entity_id_dict["File"] #sqlQuery_encode = cgiEnv.m_entity_id_dict["Query"] # sqlQuery_encode = cgiEnv.GetId() # TODO: This should be packaged in sql/__init__.py. #sqlQuery = lib_util.Base64Decode(sqlQuery_encode) sqlQuery = sql_query.GetEnvArgs(cgiEnv) nodeSqlQuery = sql_query.MakeUri(sqlQuery) propSheetToQuery = lib_common.MakeProp("Table dependency") list_of_tables = lib_sql.TableDependencies(sqlQuery) # Based on the pid and the filnam, find which database connection it is. for tabNam in list_of_tables: nodTab = sheet.MakeUri(tabNam) grph.add( ( nodeSqlQuery, propSheetToQuery, nodTab ) ) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() sqlQuery = sql_query.GetEnvArgs(cgiEnv) filNam = cgiEnv.m_entity_id_dict["File"] nodeSqlQuery = sqlite_query.MakeUri(sqlQuery, filNam) propSheetToQuery = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sqlQuery) list_of_nodes = sqlite_query.QueryToNodesList(sqlQuery, {"File": filNam}, list_of_table_names) for nodTab in list_of_nodes: grph.add((nodeSqlQuery, propSheetToQuery, nodTab)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() sqlQuery = sql_query.GetEnvArgs(cgiEnv) # TODO: It would be nicer to use a new function CIM_Process.GetEnvArgs. Not urgent. processId = cgiEnv.m_entity_id_dict["Handle"] nodeProcessQuery = embedded_sql_query.MakeUri(sqlQuery,processId) list_of_tables = lib_sql.TableDependencies(sqlQuery) propTypeDb = lib_common.MakeProp("Database type") arrProps = [] #listModulesUsingSqlQueries = [ # ("sources_types.oracle","__init__.py"), # ... # ("sources_types.CIM_Process.memory_regex_search","search_connection_strings.py") ... for ( namDbType, scriptNam ) in lib_sql.listModulesUsingSqlQueries : sys.stderr.write("\nnamDbType=%s scriptNam=%s\n"%(namDbType,scriptNam)) # TODO: We should check if the syntax of the query is conformant to the database. # TODO: We should check if the process is linked with this database. moduleDbType = lib_util.GetScriptModule(namDbType, scriptNam) # This removes the ".py" file extension. nodeTypeDb = lib_util.FromModuleToDoc(moduleDbType,scriptNam[:-3]) # This creates a non-clickable node. TODO: DOES NOT WORK ?? propTypeThisDb = lib_common.MakeProp(namDbType) arrProps.append(propTypeThisDb) grph.add((nodeProcessQuery,propTypeDb,nodeTypeDb)) try: # Now transforms the list of tables or views into nodes for this database. if not moduleDbType: sys.stderr.write("No module for namDbType=%s\n"%namDbType) continue try: # This returns the possible database credentials for this database type. # This returns also a module name. Maybe a schema, in the future. # "oracle.DatabaseEnvParams()" defined in "oracle/__init__.py" dbTp_envParams = moduleDbType.DatabaseEnvParams(processId) except AttributeError: exc = sys.exc_info()[1] # Maybe the function is not defined in this module or other error. sys.stderr.write("Caught: %s\n"%str()) continue if not dbTp_envParams: continue queryEntity = dbTp_envParams[0] moduleQueryEntity = lib_util.GetEntityModule(queryEntity) if not moduleQueryEntity: # Should not happen, otherwise how can we get the parameters for this ? sys.stderr.write("queryEntity=%s. No module\n"%queryEntity) continue listArgs = dbTp_envParams[1] # For example ( "oracle/query", ( { "Db":"XE" } ) ) for connectionKW in listArgs: # sys.stderr.write("queryEntity=%s connectionKW=%s\n"%(queryEntity,connectionKW)) try: # HELAS ON FAIT LE TRAVAIL DEUX FOIS, DE TESTER SI LES SHEETS SONT DES TABLES OU DES VIEWS. # Il faudrait un mode degrade ou on ne fait que tester. # "oracle.query.QueryToNodesList()" defined in "oracle/query/__init__.py" # sys.stderr.write("queryEntity=%s moduleQueryEntity=%s\n"%(queryEntity,str(moduleQueryEntity))) listTableNodes = moduleQueryEntity.QueryToNodesList(sqlQuery,connectionKW,list_of_tables) except Exception: exc = sys.exc_info()[0] sys.stderr.write("queryEntity=%s Caught %s\n"%(queryEntity,str(exc))) continue if not listTableNodes: sys.stderr.write("No nodes\n") continue # We know this is a valid query for this connection, so we add a link to it. # Dans le lien on devra retester si vraiment valide. # C est la ou on voit qu il vaudrait mieux avoir des dict. nodeDbQuery = sql_query.MakeUri(sqlQuery,queryEntity,**connectionKW) grph.add((nodeTypeDb,propTypeThisDb,nodeDbQuery)) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml( "Unexpected exception:%s" % ( str(sys.exc_info()))) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT",arrProps)