aimsgui
5.1.2
|
Graph manipulation in SQL databases utilities. More...
#include <aims/graph/qsqlgraphdatabase.h>
Classes | |
struct | CurrentGraphData |
This structure stores information needed to help and speed-up graph queries in SQL databases. More... | |
Public Types | |
typedef std::map< std::string, std::map< std::string, std::vector< std::string > > > | Syntax |
Public Member Functions | |
QSqlGraphDatabase () | |
~QSqlGraphDatabase () | |
void | setUrl (const std::string &url, carto::Object header=carto::none()) |
Set the database address, and parse it. More... | |
bool | open () |
Actually open the database connection. More... | |
bool | open (const std::string &user, const std::string &password) |
void | close () |
Close the connection. After this call, queries cannot be done. More... | |
QSqlQuery | exec (const std::string &query) const |
Shortcut to the Qt QSqlDatabase exec() query for SQL code. More... | |
QSqlError | lastError () const |
Shortcut to the Qt QSqlDatabase lastError() call for SQL code. More... | |
std::string | hostname () const |
Address of the database (may be a local file for SQLite) More... | |
QSqlDatabase & | database () const |
Qt database. More... | |
carto::Object | header () |
The header stores information about how to open the database, and possibly an initial selection query, to restrict to a given single graph, especially for Reader<Graph> operations. More... | |
carto::Object | parsedUrl () |
Decomposed URL. More... | |
void | setHeader (carto::Object hdr) |
bool | readSchema () |
Read the database schema (or syntax) from the SQL database. More... | |
void | sqlAttributes (const GraphObject &el, std::map< std::string, std::string > &atts, bool addinherited=true, const std::string &assyntax=std::string()) const |
Build an attributes/value list from a graph element according to the database schema, in a SQL-compatible way. More... | |
void | sqlAttributesAsStrings (const GraphObject &el, std::string &names, std::string &values, bool first=true, bool addinherited=true) const |
Same as sqlAttributes but fills two strings for attributes names and values, as needed for SQL insert queries. More... | |
void | insertOrUpdateVertex (Vertex *vert, CurrentGraphData &data) |
Store a graph vertex into the database, or updates it if it already exists. More... | |
void | insertOrUpdateEdge (Edge *v, CurrentGraphData &data) |
Store a graph edge into the database, or updates it if it already exists. More... | |
std::list< carto::rc_ptr< Graph > > | partialReadFromVertexQuery (const std::string &sqlquery, std::list< CurrentGraphData > &graphsinfo, bool allownewgraphs=true) |
Reads information from a given SQL selection query, and fills graph/vertices information from it. More... | |
std::list< carto::rc_ptr< Graph > > | partialReadFromEdgeQuery (const std::string &sqlquery, std::list< CurrentGraphData > &graphsinfo, bool allownewgraphs=true) |
Reads information from a given SQL selection query, and fills edge information from it. More... | |
void | updateElement (const GraphObject &el, int eid) |
Store in the database the attributes of an existing element (graph, vertex or edge) More... | |
void | fillGraphData (CurrentGraphData &data, Graph &g, int geid=-1) |
Fills the CurrentGraphData structure using database information (performs appropriate queries) More... | |
void | updateVertexIndexMap (CurrentGraphData &data) |
Fills the CurrentGraphData vertexindex2eid map. More... | |
void | updateEdgeIndexMap (CurrentGraphData &data) |
Fills the CurrentGraphData edgeindex2eid map. More... | |
void | updateVertexMap (CurrentGraphData &data) |
Fills the CurrentGraphData vertexeid map. More... | |
void | updateEdgeMap (CurrentGraphData &data) |
Fills the CurrentGraphData edgeeid map. More... | |
void | readElementAttributes (GraphObject &, const std::list< std::string > &attributes, QSqlQuery &query, int eid) |
Set the element attributes contained in the query result. More... | |
void | readElementAttributes (GraphObject &item, const std::list< std::string > &attributes, const std::vector< QVariant > &query, int i) |
Set the element attributes contained in the query result, but read from an already filled vector of QVariant instrad of directly the SQL query result. More... | |
void | readElementAttributes (GraphObject &item, QSqlQuery &query, const std::map< std::string, std::vector< std::string > > &vatts, int i) |
read/set all the attributes of the given element, which must have all been queried in the attributes map order. More... | |
void | readGraphAttributes (Graph &g, int eid) |
void | readGraphAttributes (std::list< CurrentGraphData > &graphsinfo) |
Public Attributes | |
carto::rc_ptr< Syntax > | attributesSyntax |
Database schema syntax: supported attributes (database columns) for each element type. More... | |
std::map< std::string, std::list< std::string > > | syntaxInheritance |
Database schema syntax: elements types inheritance. More... | |
Graph manipulation in SQL databases utilities.
A QSqlGraphDatabase instance stores the database connection, and caches several needed information on the database, amongst which the database schema (elements inheritance and attributes).
It is useful to facilitate IO for graphs in SQL databases. It is used by Reader<Graph> and Writer<Graph> for database formats. It can also be used to perform partial reading on multiple graphs:
(the example is in python language, it is just a bit clearer)
Definition at line 73 of file qsqlgraphdatabase.h.
typedef std::map<std::string, std::map<std::string, std::vector<std::string> > > aims::QSqlGraphDatabase::Syntax |
Definition at line 77 of file qsqlgraphdatabase.h.
aims::QSqlGraphDatabase::QSqlGraphDatabase | ( | ) |
aims::QSqlGraphDatabase::~QSqlGraphDatabase | ( | ) |
void aims::QSqlGraphDatabase::close | ( | ) |
Close the connection. After this call, queries cannot be done.
|
inline |
Qt database.
Definition at line 302 of file qsqlgraphdatabase.h.
Referenced by exec(), and lastError().
|
inline |
Shortcut to the Qt QSqlDatabase exec() query for SQL code.
Definition at line 326 of file qsqlgraphdatabase.h.
References database().
void aims::QSqlGraphDatabase::fillGraphData | ( | CurrentGraphData & | data, |
Graph & | g, | ||
int | geid = -1 |
||
) |
Fills the CurrentGraphData structure using database information (performs appropriate queries)
|
inline |
The header stores information about how to open the database, and possibly an initial selection query, to restrict to a given single graph, especially for Reader<Graph> operations.
Definition at line 308 of file qsqlgraphdatabase.h.
|
inline |
Address of the database (may be a local file for SQLite)
Definition at line 320 of file qsqlgraphdatabase.h.
void aims::QSqlGraphDatabase::insertOrUpdateEdge | ( | Edge * | v, |
CurrentGraphData & | data | ||
) |
Store a graph edge into the database, or updates it if it already exists.
void aims::QSqlGraphDatabase::insertOrUpdateVertex | ( | Vertex * | vert, |
CurrentGraphData & | data | ||
) |
Store a graph vertex into the database, or updates it if it already exists.
|
inline |
Shortcut to the Qt QSqlDatabase lastError() call for SQL code.
Definition at line 332 of file qsqlgraphdatabase.h.
References database().
bool aims::QSqlGraphDatabase::open | ( | ) |
Actually open the database connection.
bool aims::QSqlGraphDatabase::open | ( | const std::string & | user, |
const std::string & | password | ||
) |
|
inline |
Decomposed URL.
Definition at line 314 of file qsqlgraphdatabase.h.
std::list<carto::rc_ptr<Graph> > aims::QSqlGraphDatabase::partialReadFromEdgeQuery | ( | const std::string & | sqlquery, |
std::list< CurrentGraphData > & | graphsinfo, | ||
bool | allownewgraphs = true |
||
) |
Reads information from a given SQL selection query, and fills edge information from it.
The SQL query is executed as is, and must include eid, vertex1 and vertex2 from edges.
It is also strongly advised to also get the class_name column from the class table (via a JOIN in the SQL query) because it avoids individual queries for it in each edge, and if possible the graph eid (via a JOIN on the vertices in ths SQL query).
Referenced graphs /vertices are queried and added to the CurrentGraphData list if allownewgraphs is true, otherwise edges belonging to an "unknown" graph are dropped.
for instance:
std::list<carto::rc_ptr<Graph> > aims::QSqlGraphDatabase::partialReadFromVertexQuery | ( | const std::string & | sqlquery, |
std::list< CurrentGraphData > & | graphsinfo, | ||
bool | allownewgraphs = true |
||
) |
Reads information from a given SQL selection query, and fills graph/vertices information from it.
The SQL query is executed as is, and must include eid and graph columns from vertices.
It is also strongly advised to also get the class_name column from the class table (via a JOIN in the SQL query) because it avoids individual queries for it in each vertex.
Referenced graphs are queried and added to the CurrentGraphData list if allownewgraphs is true, otherwise vertices belonging to an "unknown" graph are dropped.
for instance:
void aims::QSqlGraphDatabase::readElementAttributes | ( | GraphObject & | , |
const std::list< std::string > & | attributes, | ||
QSqlQuery & | query, | ||
int | eid | ||
) |
Set the element attributes contained in the query result.
void aims::QSqlGraphDatabase::readElementAttributes | ( | GraphObject & | item, |
const std::list< std::string > & | attributes, | ||
const std::vector< QVariant > & | query, | ||
int | i | ||
) |
Set the element attributes contained in the query result, but read from an already filled vector of QVariant instrad of directly the SQL query result.
void aims::QSqlGraphDatabase::readElementAttributes | ( | GraphObject & | item, |
QSqlQuery & | query, | ||
const std::map< std::string, std::vector< std::string > > & | vatts, | ||
int | i | ||
) |
read/set all the attributes of the given element, which must have all been queried in the attributes map order.
i | is the index in the query of the first attribute |
void aims::QSqlGraphDatabase::readGraphAttributes | ( | Graph & | g, |
int | eid | ||
) |
void aims::QSqlGraphDatabase::readGraphAttributes | ( | std::list< CurrentGraphData > & | graphsinfo | ) |
bool aims::QSqlGraphDatabase::readSchema | ( | ) |
Read the database schema (or syntax) from the SQL database.
This fills the attributesSyntax and syntaxInheritance fields.
void aims::QSqlGraphDatabase::setHeader | ( | carto::Object | hdr | ) |
void aims::QSqlGraphDatabase::setUrl | ( | const std::string & | url, |
carto::Object | header = carto::none() |
||
) |
Set the database address, and parse it.
Or it can be already parsed in an Object. Only after using this method, hostname(), header(), parsedUrl() and open() methods may be used.
The url may contain an initial selection query, to restrict to a given single graph, especially for Reader<Graph> operations.
void aims::QSqlGraphDatabase::sqlAttributes | ( | const GraphObject & | el, |
std::map< std::string, std::string > & | atts, | ||
bool | addinherited = true , |
||
const std::string & | assyntax = std::string() |
||
) | const |
Build an attributes/value list from a graph element according to the database schema, in a SQL-compatible way.
void aims::QSqlGraphDatabase::sqlAttributesAsStrings | ( | const GraphObject & | el, |
std::string & | names, | ||
std::string & | values, | ||
bool | first = true , |
||
bool | addinherited = true |
||
) | const |
Same as sqlAttributes but fills two strings for attributes names and values, as needed for SQL insert queries.
void aims::QSqlGraphDatabase::updateEdgeIndexMap | ( | CurrentGraphData & | data | ) |
Fills the CurrentGraphData edgeindex2eid map.
void aims::QSqlGraphDatabase::updateEdgeMap | ( | CurrentGraphData & | data | ) |
Fills the CurrentGraphData edgeeid map.
void aims::QSqlGraphDatabase::updateElement | ( | const GraphObject & | el, |
int | eid | ||
) |
Store in the database the attributes of an existing element (graph, vertex or edge)
void aims::QSqlGraphDatabase::updateVertexIndexMap | ( | CurrentGraphData & | data | ) |
Fills the CurrentGraphData vertexindex2eid map.
void aims::QSqlGraphDatabase::updateVertexMap | ( | CurrentGraphData & | data | ) |
Fills the CurrentGraphData vertexeid map.
carto::rc_ptr<Syntax> aims::QSqlGraphDatabase::attributesSyntax |
Database schema syntax: supported attributes (database columns) for each element type.
Definition at line 285 of file qsqlgraphdatabase.h.
std::map<std::string, std::list<std::string> > aims::QSqlGraphDatabase::syntaxInheritance |
Database schema syntax: elements types inheritance.
Definition at line 287 of file qsqlgraphdatabase.h.