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.ScriptEnvironment() grph = cgiEnv.GetGraph() dsn_nam = cgiEnv.m_entity_id_dict["Dsn"] logging.debug("dsn=(%s)", dsn_nam) node_dsn = survol_odbc_dsn.MakeUri(dsn_nam) odbc_connect_string = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam) try: cnxn = pyodbc.connect(odbc_connect_string) logging.debug("Connected: %s", dsn_nam) 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. map_index_to_prop = { 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 ?? tab_nam = row.table_name nod_tab = survol_odbc_table.MakeUri(dsn_nam, tab_nam) grph.add((node_dsn, pc.property_odbc_table, nod_tab)) # This prints only some columns. for idx_col in map_index_to_prop: predicate_node = map_index_to_prop[idx_col] grph.add((nod_tab, predicate_node, lib_util.NodeLiteral(row[idx_col]))) except Exception as exc: lib_common.ErrorMessageHtml("node_dsn=%s Unexpected error:%s" % (dsn_nam, str(exc))) 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) 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])
def AddInfo(grph, node, entity_ids_arr): dsnNam = entity_ids_arr[0] tabNam = entity_ids_arr[0] nodeTable = odbc_table.MakeUri(dsnNam, tabNam) grph.add((nodeTable, lib_common.MakeProp("ODBC table"), node))