def Main():
    paramkey_extensive_scan = "Extensive scan"

    # Beware that unchecked checkboxes are not posted, i.e. boolean variables set to False.
    # http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked
    cgiEnv = lib_common.ScriptEnvironment(
        parameters={paramkey_extensive_scan: False})
    pidint = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    paramExtensiveScan = cgiEnv.get_parameters(paramkey_extensive_scan)

    # By default, uses a small map of possible connection strings keyword.
    # Otherwise it is very slow to scan the whole process memory.
    if paramExtensiveScan:
        rgx_dsn = survol_odbc.regex_odbc_heavy
    else:
        rgx_dsn = survol_odbc.regex_odbc_light

    aggreg_dsns = _get_aggreg_dsns(pidint, rgx_dsn)

    node_process = lib_uris.gUriGen.PidUri(pidint)

    # TODO: Add a parameter to choose between light and heavy connection string definition.

    # TODO: Eliminate aggregated strings containing one or two tokens,
    # because they cannot be genuine DSNs.
    # 29812569: SERVER=\MYMACHINE
    # 34515016: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes
    # 34801013: SERVER=\MYMACHINE
    # 35634904: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes

    for aggreg_offset in aggreg_dsns:
        # Do not take the character before the keyword.
        aggreg_dsn_raw = aggreg_dsns[aggreg_offset]

        # Replaces all non-printable characters by spaces.
        # This should be done now by the regular expressions, but better be sure.
        aggreg_dsn = re.sub(b'[\x00-\x1f\x7f-\xff]+', b' ', aggreg_dsn_raw)

        # This should contain Ascii, convertible to UTF-8, but if the regular expression catch something else,
        # this decode throw: 'utf-8' codec can't decode bytes in position 3768-3769: invalid continuation byte.
        aggreg_dsn = aggreg_dsn.decode("utf-8", "ignore")
        dsn_full = str(aggreg_offset) + ": " + aggreg_dsn
        logging.debug("aggreg_offset=%s dsn_full=%s", aggreg_offset, dsn_full)
        grph.add((node_process, pc.property_information,
                  lib_util.NodeLiteral(dsn_full)))

        ### NO! Confusion between DSN and connection string.
        # All the existing code does: ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
        # which basically creates "DSN=dsvNam;PWD=..." but here we already have the connection string.
        # TODO: Should we assimilate both ???
        node_dsn = survol_odbc_dsn.MakeUri(aggreg_dsn)
        grph.add((node_process, pc.property_odbc_dsn, node_dsn))
        # Fix this message.
        grph.add((node_dsn, pc.property_odbc_driver,
                  lib_util.NodeLiteral("ODBC driver")))

    cgiEnv.OutCgiRdf()
示例#2
0
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()
示例#3
0
def AddInfo(grph, node, entity_ids_arr):
    dsnNam = entity_ids_arr[0]
    # tabNam = entity_ids_arr[1]

    nodeDsn = survol_odbc_dsn.MakeUri(dsnNam)

    grph.add((node, pc.property_odbc_table, nodeDsn))
示例#4
0
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])
示例#5
0
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
        # 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.
        map_index_to_prop = {
            #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 ??
            proc_nam = row[2]

            nod_proc = survol_odbc_procedure.MakeUri(dsn_nam, proc_nam)
            grph.add((node_dsn, pc.property_odbc_procedure, nod_proc))

            # This prints only some columns.
            for idxcol in map_index_to_prop:
                predicate_node = map_index_to_prop[idxcol]
                grph.add((nod_proc, predicate_node,
                          lib_util.NodeLiteral(row[idxcol])))

    except Exception as exc:
        lib_common.ErrorMessageHtml("node_dsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure])
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)

        for prmstr in dir(pyodbc):
            if not prmstr.startswith("SQL_"):
                continue

            # 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:
                grph.add((node_dsn, prop, lib_util.NodeLiteral("Unavailable")))
                continue

            try:
                prm_value = cnxn.getinfo(prm)
            except:
                continue

            try:
                grph.add((node_dsn, prop, lib_util.NodeLiteral(prm_value)))
            except Exception as exc:
                txt = str(exc)
                grph.add((node_dsn, prop, lib_util.NodeLiteral(txt)))
                continue

    except Exception as exc:
        lib_common.ErrorMessageHtml("node_dsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf()
def Main():
    paramkeyExtensiveScan = "Extensive scan"

    # Beware that unchecked checkboxes are not posted, i.e. boolean variables set to False.
    # http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked
    cgiEnv = lib_common.CgiEnv(parameters={paramkeyExtensiveScan: False})
    pidint = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    paramExtensiveScan = cgiEnv.GetParameters(paramkeyExtensiveScan)

    # By default, uses a small map of possible connection strings keyword.
    # Otherwise it is very slow to scan the whole process memory.
    if paramExtensiveScan:
        mapRgx = survol_odbc.mapRgxODBC
    else:
        mapRgx = survol_odbc.mapRgxODBC_Light

    aggregDsns = GetAggregDsns(pidint, mapRgx)

    node_process = lib_common.gUriGen.PidUri(pidint)

    # TODO: Add a parameter to choose between light and heavy connection string definition.

    # TODO: Eliminate aggregated strings containing one or two tokens,
    # because they cannot be genuine DSNs.
    # 29812569: SERVER=\RCHATEAU-HP
    # 34515016: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes
    # 34801013: SERVER=\RCHATEAU-HP
    # 35634904: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes

    for aggregOffset in aggregDsns:
        # Do not take the character before the keyword.
        aggregDSN = aggregDsns[aggregOffset]
        dsnFull = str(aggregOffset) + ": " + aggregDSN
        sys.stderr.write("aggregOffset=%s dsnFull=%s\n" %
                         (aggregOffset, dsnFull))
        grph.add((node_process, pc.property_information,
                  lib_common.NodeLiteral(dsnFull)))

        ### NO! Confusion between DSN and connection string.
        # All the existing code does: ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
        # which basically creates "DSN=dsvNam;PWD=..." but here we already have the connection string.
        # TODO: Should we assimilate both ???
        nodeDsn = survol_odbc_dsn.MakeUri(aggregDSN)
        grph.add((node_process, pc.property_odbc_dsn, nodeDsn))
        # Fix this message.
        grph.add((nodeDsn, pc.property_odbc_driver,
                  lib_common.NodeLiteral("ODBC driver")))

    cgiEnv.OutCgiRdf()
示例#8
0
def display_data_sources(grph):
    sources = pyodbc.dataSources()

    for dsn in sources:
        driver = sources[dsn]

        DEBUG("dsn=%s driver=%s", dsn, driver)

        # This creates a connection string.
        nodeDsn = survol_odbc_dsn.MakeUri("DSN=" + dsn)
        grph.add((lib_common.nodeMachine, pc.property_odbc_dsn, nodeDsn))
        grph.add(
            (nodeDsn, pc.property_odbc_driver, lib_common.NodeLiteral(driver)))
示例#9
0
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 display_data_sources(grph):
    # https://stackoverflow.com/questions/41591287/driver-not-found-even-though-its-listed-in-pyodbc-datasources
    # The list produced by pyodbc.dataSources() is misleading because it shows the results
    # from both the 32-bit and 64-bit "Platform".
    # A more reliable way to get the list of available drivers is to use pyodbc.drivers()
    logging.debug("Before pyodbc.dataSources")
    sources = pyodbc.dataSources()

    for dsn in sources:
        driver = sources[dsn]

        logging.debug("dsn=%s driver=%s", dsn, driver)

        # This creates a connection string.
        node_dsn = survol_odbc_dsn.MakeUri("DSN=" + dsn)
        grph.add((lib_common.nodeMachine, pc.property_odbc_dsn, node_dsn))
        grph.add(
            (node_dsn, pc.property_odbc_driver, lib_util.NodeLiteral(driver)))
示例#11
0
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] )
示例#12
0
def AddOdbcNode(grph, mach_nam, srv_name, tcp_port):
    # cn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=192.168.0.14;PORT=1433;UID=essaisql;PWD=xyz')
    if lib_util.isPlatformLinux:
        driver_name = "ODBC Driver 13 for SQL Server"
    else:
        driver_name = "ODBC Driver 13 for SQL Server"

    # For example "MYMACHINE\\SQLEXPRESS"
    cred_key = "%s\\%s" % (mach_nam, srv_name)
    logging.debug("cred_key=%s", cred_key)
    a_cred = lib_credentials.GetCredentials("SqlExpress", cred_key)

    if a_cred:
        str_dsn = 'DRIVER={%s};SERVER=%s;PORT=%s;UID=%s;PWD=%s' % (
            driver_name, mach_nam, tcp_port, a_cred[0], a_cred[1])
        logging.debug("str_dsn=%s", str_dsn)

        node_dsn = survol_odbc_dsn.MakeUri(str_dsn)
        grph.add((lib_common.nodeMachine, pc.property_odbc_dsn, node_dsn))
示例#13
0
def _display_dsns(grph, fetch_code, dsn_type):
    odbc_iter_code = fetch_code

    prop_dsn_type = lib_common.MakeProp("Source type")
    litt_dsn_type = lib_util.NodeLiteral(dsn_type)

    while True:
        source = odbc.SQLDataSources(odbc_iter_code)
        if source == None:
            break
        # TODO: Prints the description and other data.
        dsn, driver = source
        logging.debug("dsn=%s driver=%s type=%s", dsn, driver, dsn_type)
        odbc_iter_code = odbc.SQL_FETCH_NEXT

        # This creates a connection string.
        node_dsn = survol_odbc_dsn.MakeUri("DSN=" + dsn)
        grph.add((lib_common.nodeMachine, pc.property_odbc_dsn, node_dsn))
        grph.add(
            (node_dsn, pc.property_odbc_driver, lib_util.NodeLiteral(driver)))
        grph.add((node_dsn, prop_dsn_type, litt_dsn_type))
示例#14
0
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] )
示例#15
0
def AddOdbcNode(grph, machNam, srvName, tcpPort):
    # cn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=192.168.0.14;PORT=1433;UID=essaisql;PWD=xyz')
    if lib_util.isPlatformLinux:
        driverName = "ODBC Driver 13 for SQL Server"
    else:
        driverName = "ODBC Driver 13 for SQL Server"

    # credKey = "RCHATEAU-HP\\SQLEXPRESS"
    credKey = "%s\\%s" % (machNam, srvName)
    DEBUG("credKey=%s", credKey)
    aCred = lib_credentials.GetCredentials("SqlExpress", credKey)

    if aCred:

        strDsn = 'DRIVER={%s};SERVER=%s;PORT=%s;UID=%s;PWD=%s' % (
            driverName, machNam, tcpPort, aCred[0], aCred[1])
        DEBUG("strDsn=%s", strDsn)

        ### cn = pyodbc.connect(strDsn)
        # nodeDsn = survol_odbc_dsn.MakeUri( "DSN=" + strDsn )
        nodeDsn = survol_odbc_dsn.MakeUri(strDsn)
        grph.add((lib_common.nodeMachine, pc.property_odbc_dsn, nodeDsn))
示例#16
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)
    tabNam = cgiEnv.m_entity_id_dict["Table"]

    sys.stderr.write("dsn=%s tabNam=%s\n" % (dsnNam, tabNam))

    nodeDsn = survol_odbc_dsn.MakeUri(dsnNam)
    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)
        sys.stderr.write("Connected: %s\n" % dsnNam)
        cursor = cnxn.cursor()

        cursor.columns(table=tabNam)
        sys.stderr.write("Tables OK: %s\n" % 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("nodeDsn=%s Unexpected error:%s" %
                                    (dsnNam, str(exc)))

    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_column])
示例#17
0
 def CredUrlODBC(dsn):
     from sources_types.odbc import dsn as survol_odbc_dsn
     node_dsn = survol_odbc_dsn.MakeUri("DSN=" + dsn)
     return node_dsn
示例#18
0
def AddInfo(grph, node, entity_ids_arr):
    dsn_nam = entity_ids_arr[0]
    node_dsn = survol_odbc_dsn.MakeUri(dsn_nam)

    grph.add((node, pc.property_odbc_procedure, node_dsn))