def MakeUri(strQuery,thePid): #strQueryEncoded = lib_util.Base64Encode(strQuery) # TODO: We have hard-coded the process definition with "Handle". # TODO: The entity parameter should be passed differently, more elegant. Not sure. #return lib_common.gUriGen.UriMakeFromDict("sql/query",{ "Query" : strQueryEncoded, "Handle" : thePid }) # return sql_query.MakeUri( strQuery, "CIM_Process/embedded_sql_query", { "Handle" : thePid } ) return sql_query.MakeUri( strQuery, "CIM_Process/embedded_sql_query", Handle = thePid )
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) # 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 MakeUri(str_query, the_pid): # TODO: We have hard-coded the process definition with "Handle". # TODO: The entity parameter should be passed differently, more elegant. Not sure. return sql_query_module.MakeUri(str_query, "CIM_Process/embedded_sql_query", Handle=the_pid)
def MakeUri(strQuery, theDsn): # TODO: The right thing todo ? return sql_query.MakeUri(strQuery, "sqlserver/query", Dsn=theDsn)
def MakeUri(strQuery, fileName): return sql_query.MakeUri(strQuery, "sqlite/query", Path=fileName)
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)
def MakeUri(str_query, file_name): return sql_query_module.MakeUri(str_query, "sqlite/query", File=file_name)
def MakeUri(str_query, the_dsn): # TODO: The right thing todo ? return sql_query_module.MakeUri(str_query, "sqlserver/query", Dsn=the_dsn)
def MakeUri(str_query, instance_name): return sql_query_module.MakeUri(str_query, "mysql/query", Instance=instance_name)
def MakeUri(str_query, the_db): # TODO: We have hard-coded the process definition with "Db". # TODO: The entity parameter should be passed differently, more elegant. Not sure. return sql_query_module.MakeUri(str_query, "oracle/query", Db=the_db)
def MakeUri(strQuery,instanceName): return sql_query.MakeUri( strQuery, "mysql/query", Instance = instanceName )