コード例 #1
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    table_name = cgiEnv.m_entity_id_dict["Table"]
    db_fil_nam = cgiEnv.m_entity_id_dict["File"]

    grph = cgiEnv.GetGraph()

    fil_node = lib_uris.gUriGen.FileUri(db_fil_nam)
    tab_nod = sqlite_table.MakeUri(db_fil_nam, table_name)
    grph.add((tab_nod, lib_common.MakeProp("Table"), fil_node))

    con = sqlite3.connect(db_fil_nam)
    cursor = con.cursor()

    #>>> eta = curs.execute("PRAGMA table_info('tz_data')")
    #(0, u'tzid', u'TEXT', 0, None, 0)
    #(1, u'alias', u'TEXT', 0, None, 0)

    try:
        cursor.execute("PRAGMA table_info('%s')" % table_name)

        prop_column = lib_common.MakeProp("Column")
        prop_type = lib_common.MakeProp("Type")
        for the_row in cursor.fetchall():
            column_nam = the_row[1]
            column_nod = sqlite_column.MakeUri(db_fil_nam, table_name,
                                               column_nam)
            grph.add((tab_nod, prop_column, column_nod))
            type_nam = the_row[2]
            grph.add((column_nod, prop_type, lib_util.NodeLiteral(type_nam)))
    except Exception as exc:
        lib_common.ErrorMessageHtml("Error %s:%s" % (db_fil_nam, str(exc)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [prop_column])
コード例 #2
0
def QueryToNodesList(sqlQuery,
                     connectionKW,
                     list_of_tables,
                     defaultSchemaName=None):
    nodesList = []
    for tabNam in list_of_tables:
        tmpNode = sqlite_table.MakeUri(connectionKW["File"], tabNam)
        nodesList.append(tmpNode)
    return nodesList
コード例 #3
0
def AddNodesTablesViews(grph, filNode, dbFilNam):

    # This is imported here to avoid circular references of packages including themselves.
    from sources_types.sqlite import table as sqlite_table
    from sources_types.sqlite import view as sqlite_view

    DEBUG("AddNodesTablesViews dbFilNam=%s", dbFilNam)
    try:
        con = sqlite3.connect(dbFilNam)
        cursor = con.cursor()
        # type TEXT,
        # name TEXT,
        # tbl_name TEXT,
        # rootpage INTEGER,
        # sql TEXT
        cursor.execute(
            "SELECT * FROM sqlite_master WHERE type='table' or type='view';")

        #[(u'table', u'tz_schema_version', u'tz_schema_version', 2, u'CREATE TABLE tz_schema_version (version INTEGER)'),

        for theRow in cursor.fetchall():
            theType = theRow[0]
            theName = theRow[1]
            if theType == 'table':
                nameNod = sqlite_table.MakeUri(dbFilNam, theName)
                grph.add((filNode, lib_common.MakeProp("Table"), nameNod))
            elif theType == 'view':
                nameNod = sqlite_view.MakeUri(dbFilNam, theName)
                grph.add((filNode, lib_common.MakeProp("View"), nameNod))
            else:
                continue

            theRootpage = theRow[3]
            grph.add((nameNod, lib_common.MakeProp("Root page"),
                      lib_common.NodeLiteral(theRootpage)))
            grph.add((nameNod, lib_common.MakeProp("Type"),
                      lib_common.NodeLiteral(theType)))

            # Do not print too much information in case there are too many tables.
            #theCmd = theRow[4]
            #grph.add( ( tabNod, pc.property_information, lib_common.NodeLiteral(theCmd) ) )
    except sqlite3.DatabaseError:
        lib_common.ErrorMessageHtml("Sqlite file:%s Caught:%s" %
                                    (dbFilNam, str(sys.exc_info())))
    except:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("Sqlite file:%s Unexpected error:%s" %
                                    (dbFilNam, str(exc)))
コード例 #4
0
def Main():
	cgiEnv = lib_common.CgiEnv()

	tableName = cgiEnv.m_entity_id_dict["Table"]
	dbFilNam = cgiEnv.m_entity_id_dict["File"]

	# sys.stderr.write("dbFilNam=%s\n"%dbFilNam)

	grph = cgiEnv.GetGraph()

	filNode = lib_common.gUriGen.FileUri(dbFilNam )
	tabNod = sqlite_table.MakeUri(dbFilNam,tableName)
	grph.add( ( tabNod, lib_common.MakeProp("Table"), filNode ) )

	con = sqlite3.connect(dbFilNam)
	cursor = con.cursor()

	#>>> eta = curs.execute("PRAGMA table_info('tz_data')")
	#(0, u'tzid', u'TEXT', 0, None, 0)
	#(1, u'alias', u'TEXT', 0, None, 0)

	try:
		cursor.execute("PRAGMA table_info('%s')" % tableName )

		propColumn = lib_common.MakeProp("Column")
		propType = lib_common.MakeProp("Type")
		for theRow in cursor.fetchall():
			columnNam = theRow[1]
			columnNod = sqlite_column.MakeUri(dbFilNam,tableName,columnNam)
			grph.add( ( tabNod, propColumn, columnNod ) )
			typeNam = theRow[2]
			grph.add( ( columnNod, propType, lib_common.NodeLiteral(typeNam) ) )
	except Exception:
		exc = sys.exc_info()[1]
		lib_common.ErrorMessageHtml("Error %s:%s"%(dbFilNam,str(exc)))


	cgiEnv.OutCgiRdf("LAYOUT_RECT",[propColumn])
コード例 #5
0
ファイル: __init__.py プロジェクト: rchateauneu/survol
def QueryToNodesList(connection_kw, list_of_tables, defaultSchemaName=None):
    nodes_list = []
    for tab_nam in list_of_tables:
        tmp_node = sqlite_table.MakeUri(connection_kw["File"], tab_nam)
        nodes_list.append(tmp_node)
    return nodes_list