34 #ifndef AIMS_GRAPH_QSQLGRAPHDATABASE_H
35 #define AIMS_GRAPH_QSQLGRAPHDATABASE_H
38 #include <qsqldatabase.h>
39 #include <qsqlquery.h>
40 #include <qsqlerror.h>
76 typedef std::map<std::string, std::map<std::string,
118 bool open(
const std::string & user,
const std::string & password );
122 QSqlQuery
exec(
const std::string & query )
const;
147 std::map<std::string, std::string> & atts,
148 bool addinherited =
true,
149 const std::string & assyntax = std::string() )
const;
153 std::string & values,
bool first =
true,
154 bool addinherited =
true )
const;
193 std::list<carto::rc_ptr<Graph> >
195 std::list<CurrentGraphData> & graphsinfo,
196 bool allownewgraphs =
true );
231 std::list<carto::rc_ptr<Graph> >
233 std::list<CurrentGraphData> & graphsinfo,
234 bool allownewgraphs =
true );
252 const std::list<std::string> & attributes,
253 QSqlQuery & query,
int eid );
259 const std::list<std::string> & attributes,
260 const std::vector<QVariant> & query,
267 const std::map<std::string, std::vector<std::string> > & vatts,
292 std::string _hostname;
295 mutable QSqlDatabase *_database;
296 std::string _connectionname;
328 return database().exec( query.c_str() );
338 inline bool QSqlGraphDatabase::CurrentGraphData::operator ==
341 return gid == other.gid && graph == other.graph;
Graph manipulation in SQL databases utilities.
void close()
Close the connection. After this call, queries cannot be done.
void updateVertexIndexMap(CurrentGraphData &data)
Fills the CurrentGraphData vertexindex2eid map.
std::map< std::string, std::list< std::string > > syntaxInheritance
Database schema syntax: elements types inheritance.
bool open()
Actually open the database connection.
void readGraphAttributes(Graph &g, int eid)
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...
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.
void updateEdgeIndexMap(CurrentGraphData &data)
Fills the CurrentGraphData edgeindex2eid map.
carto::Object header()
The header stores information about how to open the database, and possibly an initial selection query...
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.
void updateVertexMap(CurrentGraphData &data)
Fills the CurrentGraphData vertexeid map.
QSqlQuery exec(const std::string &query) const
Shortcut to the Qt QSqlDatabase exec() query for SQL code.
QSqlError lastError() const
Shortcut to the Qt QSqlDatabase lastError() call for SQL code.
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 ...
carto::Object parsedUrl()
Decomposed URL.
carto::rc_ptr< Syntax > attributesSyntax
Database schema syntax: supported attributes (database columns) for each element type.
std::map< std::string, std::map< std::string, std::vector< std::string > > > Syntax
bool open(const std::string &user, const std::string &password)
void insertOrUpdateVertex(Vertex *vert, CurrentGraphData &data)
Store a graph vertex into the database, or updates it if it already exists.
void setHeader(carto::Object hdr)
void readGraphAttributes(std::list< CurrentGraphData > &graphsinfo)
void fillGraphData(CurrentGraphData &data, Graph &g, int geid=-1)
Fills the CurrentGraphData structure using database information (performs appropriate queries)
void readElementAttributes(GraphObject &, const std::list< std::string > &attributes, QSqlQuery &query, int eid)
Set the element attributes contained in the query result.
std::string hostname() const
Address of the database (may be a local file for SQLite)
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 Q...
QSqlDatabase & database() const
Qt database.
void insertOrUpdateEdge(Edge *v, CurrentGraphData &data)
Store a graph edge into the database, or updates it if it already exists.
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,...
void updateElement(const GraphObject &el, int eid)
Store in the database the attributes of an existing element (graph, vertex or edge)
bool readSchema()
Read the database schema (or syntax) from the SQL database.
void updateEdgeMap(CurrentGraphData &data)
Fills the CurrentGraphData edgeeid map.
void setUrl(const std::string &url, carto::Object header=carto::none())
Set the database address, and parse it.
This structure stores information needed to help and speed-up graph queries in SQL databases.
std::map< int, int > edgeindex2eid
CurrentGraphData(int eid, Graph *g)
std::map< Vertex *, int > vertexeid
bool operator==(const CurrentGraphData &) const
std::map< Edge *, int > edgeeid
std::map< int, int > vertexindex2eid