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() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) DEBUG("dsn=(%s)", dsnNam) nodeDsn = survol_odbc_dsn.MakeUri(dsnNam) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) # for prmstr in sqlgetinfo_params: for prmstr in dir(pyodbc): if not prmstr.startswith("SQL_"): continue #sys.stderr.write("prmstr: %s\n" % prmstr) # Some keywords are not interesting. This is a bit arbitrary. if prmstr in ["SQL_KEYWORDS"]: continue nicestr = prmstr[4:].replace("_", " ").capitalize() prop = lib_common.MakeProp(nicestr) try: prm = getattr(pyodbc, prmstr) # except AttributeError: except: grph.add( (nodeDsn, prop, lib_common.NodeLiteral("Unavailable"))) continue try: prm_value = cnxn.getinfo(prm) except: #txt = str( sys.exc_info()[1] ) #grph.add( (nodeDsn, prop, lib_common.NodeLiteral(txt) ) ) continue try: grph.add((nodeDsn, prop, lib_common.NodeLiteral(prm_value))) except: txt = str(sys.exc_info()[1]) grph.add((nodeDsn, prop, lib_common.NodeLiteral(txt))) continue except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info()))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) sessionId = cgiEnv.m_entity_id_dict["SessionId"] DEBUG("dsn=(%s) sessionId=%s", dsnNam, sessionId) nodeSession = survol_sqlserver_dsn.MakeUri(dsnNam) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) grph.add((nodeSession, lib_common.MakeProp("Session id"), lib_common.NodeLiteral(sessionId))) GetInfoConnections(grph, sessionId, nodeSession, cnxn) GetInfoSessions(grph, sessionId, nodeSession, cnxn) GetInfoRequests(grph, sessionId, nodeSession, cnxn, dsnNam) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info()))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) DEBUG("dsn=(%s)", dsnNam) nodeDsn = survol_sqlserver_dsn.MakeUri(dsnNam) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) cursorSessions = cnxn.cursor() qrySessions = """ SELECT host_name,host_process_id,session_id,program_name,client_interface_name,original_login_name,nt_domain,nt_user_name FROM sys.dm_exec_sessions """ propSqlServerSession = lib_common.MakeProp("SqlServer session") propSqlServerHostProcess = lib_common.MakeProp("Host process") propSqlServerProgramName = lib_common.MakeProp("Program name") propSqlServerClientInterface = lib_common.MakeProp("Client Interface") propSqlServerOriginalLoginName = lib_common.MakeProp("original_login_name") propSqlServerNTDomain = lib_common.MakeProp("nt_domain") propSqlServerNTUserName = lib_common.MakeProp("nt_user_name") for rowSess in cursorSessions.execute(qrySessions): DEBUG("rowSess.session_id=(%s)", rowSess.session_id) nodeSession = session.MakeUri(dsnNam, rowSess.session_id) grph.add((nodeDsn, propSqlServerSession, nodeSession)) if rowSess.host_process_id: node_process = lib_common.RemoteBox(rowSess.host_name).PidUri(rowSess.host_process_id) grph.add((node_process, pc.property_pid, lib_common.NodeLiteral(rowSess.host_process_id))) grph.add((nodeSession, propSqlServerHostProcess, node_process)) if rowSess.program_name: grph.add((nodeSession, propSqlServerProgramName, lib_common.NodeLiteral(rowSess.program_name))) if rowSess.client_interface_name: grph.add((nodeSession, propSqlServerClientInterface, lib_common.NodeLiteral(rowSess.client_interface_name))) # TODO: Make nodes with these: if rowSess.original_login_name: grph.add((nodeSession, propSqlServerOriginalLoginName, lib_common.NodeLiteral(rowSess.original_login_name))) if rowSess.nt_domain: grph.add((nodeSession, propSqlServerNTDomain, lib_common.NodeLiteral(rowSess.nt_domain))) if rowSess.nt_user_name: grph.add((nodeSession, propSqlServerNTUserName, lib_common.NodeLiteral(rowSess.nt_user_name))) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml( "nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info()))) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT",[propSqlServerSession,propSqlServerHostProcess])
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) sys.stderr.write("dsn=(%s)\n" % dsnNam) nodeDsn = survol_sqlserver_dsn.MakeUri(dsnNam) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) sys.stderr.write("Connected: %s\n" % dsnNam) cursorQueries = cnxn.cursor() qryQueries = """ SELECT sqltext.TEXT, req.session_id, req.status, sess.host_process_id, sess.host_name FROM sys.dm_exec_requests req CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext , sys.dm_exec_sessions sess where sess.session_id = req.session_id """ propSqlServerSqlQuery = lib_common.MakeProp("Sql query") propSqlServerHostProcess = lib_common.MakeProp("Host process") propSqlServerStatus = lib_common.MakeProp("Status") for rowQry in cursorQueries.execute(qryQueries): sys.stderr.write("rowQry.session_id=(%s)\n" % rowQry.session_id) nodeSession = session.MakeUri(dsnNam, rowQry.session_id) # A bit of cleanup. queryClean = rowQry.TEXT.replace("\n", " ").strip() # TODO: Must add connection information so we can go from the tables to sqlserver itself. nodeSqlQuery = sql_query.MakeUri(queryClean, dsnNam) grph.add((nodeSession, propSqlServerSqlQuery, nodeSqlQuery)) node_process = lib_common.RemoteBox(rowQry.host_name).PidUri( rowQry.host_process_id) grph.add((node_process, pc.property_pid, lib_common.NodeLiteral(rowQry.host_process_id))) grph.add((nodeSession, propSqlServerHostProcess, node_process)) grph.add((nodeSession, propSqlServerStatus, lib_common.NodeLiteral(rowQry.status))) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info()))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) DEBUG("dsn=(%s)", dsnNam) nodeDsn = survol_odbc_dsn.MakeUri(dsnNam) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) cursor = cnxn.cursor() # http://pyodbc.googlecode.com/git/web/docs.html # colList = ( "Catalog", "Schema", "Procedure", "Inputs", "Outputs", "Result", "Remarks", "Type") # http://pyodbc.googlecode.com/git/web/docs.html # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM', # or a data source-specific type name. mapIndexToProp = { #0: pc.property_odbc_catalog, #1: pc.property_odbc_schema, #2: pc.property_odbc_procedure, 3: pc.property_odbc_inputs, 4: pc.property_odbc_outputs, 5: pc.property_odbc_result, 6: pc.property_odbc_remarks, 7: pc.property_odbc_type } # This avoids cursor.fetchall() for row in cursor.procedures(): # TODO: What are the other properties ?? procNam = row[2] # sys.stderr.write("tabNam=%s\n" % tabNam) nodProc = survol_odbc_procedure.MakeUri(dsnNam, procNam) grph.add((nodeDsn, pc.property_odbc_procedure, nodProc)) # This prints only some columns. for idxCol in mapIndexToProp: predicateNode = mapIndexToProp[idxCol] grph.add((nodProc, predicateNode, lib_common.NodeLiteral(row[idxCol]))) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info()))) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure])
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) DEBUG("dsn=(%s)", dsnNam ) nodeDsn = survol_odbc_dsn.MakeUri( dsnNam ) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) cursor = cnxn.cursor() # http://pyodbc.googlecode.com/git/web/docs.html # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM', # or a data source-specific type name. mapIndexToProp = { 0: pc.property_odbc_catalog, 1: pc.property_odbc_schema, # 3: pc.property_odbc_table, 3: pc.property_odbc_type } # This avoids cursor.fetchall() for row in cursor.tables(): # TODO: What are the other properties ?? tabNam = row.table_name nodTab = survol_odbc_table.MakeUri( dsnNam, tabNam ) grph.add( (nodeDsn, pc.property_odbc_table, nodTab ) ) # This prints only some columns. for idxCol in mapIndexToProp: predicateNode = mapIndexToProp[idxCol] grph.add( (nodTab, predicateNode, lib_common.NodeLiteral(row[idxCol]) ) ) except Exception: WARNING("tabNam=%s", str(sys.exc_info())) exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) ) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_table] )
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) sys.stderr.write("dsn=(%s)\n" % dsnNam ) nodeDsn = survol_odbc_dsn.MakeUri( dsnNam ) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) sys.stderr.write("Connected: %s\n" % dsnNam) cursor = cnxn.cursor() # http://pyodbc.googlecode.com/git/web/docs.html # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM', # or a data source-specific type name. colList = ( "Catalog", "Schema", "Table", "Type") # This avoids cursor.fetchall() for row in cursor.tables(): # TODO: What are the other properties ?? tabNam = row.table_name # sys.stderr.write("tabNam=%s\n" % tabNam) nodTab = survol_odbc_table.MakeUri( dsnNam, tabNam ) grph.add( (nodeDsn, pc.property_odbc_table, nodTab ) ) for idxCol in ( 0, 1, 3): grph.add( (nodTab, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) ) except Exception: sys.stderr.write("tabNam=%s\n" % str(sys.exc_info())) exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) ) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_table] )
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) sys.stderr.write("dsn=(%s)\n" % dsnNam ) nodeDsn = survol_odbc_dsn.MakeUri( dsnNam ) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) sys.stderr.write("Connected: %s\n" % dsnNam) cursor = cnxn.cursor() # http://pyodbc.googlecode.com/git/web/docs.html colList = ( "Catalog", "Schema", "Procedure", "Inputs", "Outputs", "Result", "Remarks", "Type") # This avoids cursor.fetchall() for row in cursor.procedures(): # TODO: What are the other properties ?? procNam = row[2] # sys.stderr.write("tabNam=%s\n" % tabNam) nodProc = survol_odbc_procedure.MakeUri( dsnNam, procNam ) grph.add( (nodeDsn, pc.property_odbc_procedure, nodProc ) ) for idxCol in (3, 4, 5, 6, 7): grph.add( (nodProc, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) ) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) ) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure] )
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) tabNam = cgiEnv.m_entity_id_dict["Table"] DEBUG("dsn=%s tabNam=%s", dsnNam, tabNam) nodTab = survol_odbc_table.MakeUri(dsnNam, tabNam) # ('C:\\Program Files (x86)\\Microsoft Visual Studio 8\\Crystal Reports\\Samples\\en\\Databases\\xtreme', None, 'MSysAccessObjects', 'SYSTEM TABLE', None) ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) DEBUG("Connected: %s", dsnNam) cursor = cnxn.cursor() cursor.columns(table=tabNam) DEBUG("Tables OK: %s", dsnNam) rows = cursor.fetchall() # http://pyodbc.googlecode.com/git/web/docs.html # # table_cat # table_schem # table_name # column_name # data_type # type_name # column_size # buffer_length # decimal_digits # num_prec_radix # nullable # remarks # column_def # sql_data_type # sql_datetime_sub # char_octet_length # ordinal_position # is_nullable: One of SQL_NULLABLE, SQL_NO_NULLS, SQL_NULLS_UNKNOWN. # or a data source-specific type name. colList = ("Catalog", "Schema", "Table", "Column", "Data type", "Type", "Size", "Length", "Digits", "Radix", "Nullable", "Remarks", "Column def", "Sql type", "Datetime sub", "char octet length", "Ordinal", "is nullable") for row in rows: # TODO: What are the other properties ?? tabNam = row.table_name # sys.stderr.write("tabNam=%s\n" % tabNam) nodColumn = survol_odbc_column.MakeUri(dsnNam, tabNam, row[3]) grph.add((nodTab, pc.property_odbc_column, nodColumn)) for idxCol in (5, 11, 12, 13, 17): # grph.add( (nodColumn, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) ) grph.add((nodColumn, lib_common.MakeProp(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]))) except Exception: exc = sys.exc_info()[0] lib_common.ErrorMessageHtml("dsnNam=%s Unexpected error:%s" % (dsnNam, str(exc))) # cgiEnv.OutCgiRdf() cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_column])