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) 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 DisplayTablesAny(theDictNam, theDict): errnum = 0 for sqlQry in theDict: print("_" * 40) expectedTables = theDict[sqlQry] sqlQry = sqlQry.replace("\n", " ").replace(" ", " ").replace(" ", " ") print("\nQUERY=" + sqlQry + "\n") lib_sql.SqlQueryWalkNodes(sqlQry, DispSqlNode) print("") resVec = lib_sql.TableDependencies(sqlQry) resVec = [s.upper() for s in resVec] vecUp = resVec vecUp.sort() if expectedTables != vecUp: errnum += 1 print("\nQUERY=" + sqlQry + "\n") print("Should be=" + str(expectedTables)) # print("Actual is="+str(resVec)) print("Result is=" + str(vecUp)) print("") print("") #exit(1) lenTot = len(theDict) print("Finished " + theDictNam + " with " + str(errnum) + " errors out of " + str(lenTot))
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.ScriptEnvironment() grph = cgiEnv.GetGraph() sql_query = cgiEnv.m_entity_id_dict["Query"] node_sql_query = sql_query_module.MakeUri(sql_query) prop_sheet_to_query = lib_common.MakeProp("Table dependency") list_of_tables = lib_sql.TableDependencies(sql_query) # Based on the pid and the filnam, find which database connection it is. for tab_nam in list_of_tables: nod_tab = sheet.MakeUri(tab_nam) grph.add((node_sql_query, prop_sheet_to_query, nod_tab)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() sql_query = cgiEnv.m_entity_id_dict["Query"] fil_nam = cgiEnv.m_entity_id_dict["File"] node_sql_query = sql_query_module.MakeUri(sql_query, fil_nam) prop_sheet_to_query = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sql_query) list_of_nodes = sql_query_module.QueryToNodesList({"File": fil_nam}, list_of_table_names) for nod_tab in list_of_nodes: grph.add((node_sql_query, prop_sheet_to_query, nod_tab)) 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_oracle.OracleEnv() grph = cgiEnv.GetGraph() sql_query = cgiEnv.m_entity_id_dict["Query"] db_nam = cgiEnv.m_entity_id_dict["Db"] # This is simply the user. ora_schema = cgiEnv.OracleSchema() node_sql_query = oracle_query.MakeUri(sql_query, db_nam) prop_sheet_to_query = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sql_query) list_of_nodes = oracle_query.QueryToNodesList({"Db": db_nam}, list_of_table_names, ora_schema) for nod_tab in list_of_nodes: grph.add((node_sql_query, prop_sheet_to_query, nod_tab)) 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)
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() sql_query = cgiEnv.m_entity_id_dict["Query"] # TODO: It would be nicer to use a new function CIM_Process.GetEnvArgs. process_id = cgiEnv.m_entity_id_dict["Handle"] node_process_query = embedded_sql_query.MakeUri(sql_query, process_id) # This returns the list of tables and views used by this query. # They will be associated to the databases possibly accessed by this process. # Then, another filtering is possible given the database content etc... # This is still experimental. list_of_tables = lib_sql.TableDependencies(sql_query) prop_type_db = lib_common.MakeProp("Database type") arr_props = [] #listModulesUsingSqlQueries = [ # ("sources_types.oracle","__init__.py"), # ... # ("sources_types.CIM_Process.memory_regex_search","search_connection_strings.py") ... for nam_db_type, script_nam in lib_sql.listModulesUsingSqlQueries: logging.debug("nam_db_type=%s script_nam=%s", nam_db_type, script_nam) # 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. module_db_type = lib_util.GetScriptModule(nam_db_type, script_nam) # This removes the ".py" file extension. node_type_db = lib_util.module_doc_string(module_db_type, script_nam[:-3]) # This creates a non-clickable node. TODO: DOES NOT WORK ?? prop_type_this_db = lib_common.MakeProp(nam_db_type) arr_props.append(prop_type_this_db) grph.add((node_process_query, prop_type_db, node_type_db)) try: # Now transforms the list of tables or views into nodes for this database. if not module_db_type: logging.debug("No module for nam_db_type=%s", nam_db_type) 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" db_tp_env_params = module_db_type.DatabaseEnvParams(process_id) except AttributeError as exc: # Maybe the function is not defined in this module or other error. logging.debug("Caught: %s", str(exc)) continue if not db_tp_env_params: continue query_entity = db_tp_env_params[0] module_query_entity = lib_util.GetEntityModule(query_entity) if not module_query_entity: # Should not happen, otherwise how can we get the parameters for this ? logging.debug("query_entity=%s. No module", query_entity) continue list_args = db_tp_env_params[1] # For example ( "oracle/query", ( { "Db":"XE" } ) ) for connection_kw in list_args: try: list_table_nodes = module_query_entity.QueryToNodesList( connection_kw, list_of_tables) except Exception as exc: logging.warning("query_entity=%s Caught %s", query_entity, str(exc)) continue if not list_table_nodes: logging.debug("No nodes") continue # We know this is a valid query for this connection, so we add a link to it. node_db_query = sql_query_module.MakeUri( sql_query, query_entity, **connection_kw) grph.add((node_type_db, prop_type_this_db, node_db_query)) except Exception as exc: lib_common.ErrorMessageHtml("Unexpected exception:%s" % str(exc)) cgiEnv.OutCgiRdf("LAYOUT_RECT", arr_props)