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,
114 void setUrl(
const std::string & url,
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;
QSqlError lastError() const
Shortcut to the Qt QSqlDatabase lastError() call for SQL code.
void readGraphAttributes(Graph &g, int eid)
bool operator==(const CurrentGraphData &) const
CurrentGraphData(int eid, Graph *g)
void updateElement(const GraphObject &el, int eid)
Store in the database the attributes of an existing element (graph, vertex or edge) ...
carto::Object header()
The header stores information about how to open the database, and possibly an initial selection query...
carto::Object parsedUrl()
Decomposed URL.
std::map< int, int > edgeindex2eid
carto::rc_ptr< Syntax > attributesSyntax
Database schema syntax: supported attributes (database columns) for each element type.
void readElementAttributes(GraphObject &, const std::list< std::string > &attributes, QSqlQuery &query, int eid)
Set the element attributes contained in the query result.
void setUrl(const std::string &url, carto::Object header=carto::none())
Set the database address, and parse it.
void setHeader(carto::Object hdr)
std::map< Vertex *, int > vertexeid
bool readSchema()
Read the database schema (or syntax) from the SQL database.
std::map< std::string, std::list< std::string > > syntaxInheritance
Database schema syntax: elements types inheritance.
bool open()
Actually open the database connection.
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...
void updateVertexMap(CurrentGraphData &data)
Fills the CurrentGraphData vertexeid map.
std::string hostname() const
Address of the database (may be a local file for SQLite)
void updateVertexIndexMap(CurrentGraphData &data)
Fills the CurrentGraphData vertexindex2eid map.
void updateEdgeIndexMap(CurrentGraphData &data)
Fills the CurrentGraphData edgeindex2eid map.
Graph manipulation in SQL databases utilities.
QSqlDatabase & database() const
Qt database.
std::map< int, int > vertexindex2eid
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...
std::map< std::string, std::map< std::string, std::vector< std::string > > > Syntax
void insertOrUpdateEdge(Edge *v, CurrentGraphData &data)
Store a graph edge into the database, or updates it if it already exists.
std::map< Edge *, int > edgeeid
void close()
Close the connection. After this call, queries cannot be done.
void updateEdgeMap(CurrentGraphData &data)
Fills the CurrentGraphData edgeeid map.
This structure stores information needed to help and speed-up graph queries in SQL databases...
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.
void insertOrUpdateVertex(Vertex *vert, CurrentGraphData &data)
Store a graph vertex into the database, or updates it if it already exists.
void fillGraphData(CurrentGraphData &data, Graph &g, int geid=-1)
Fills the CurrentGraphData structure using database information (performs appropriate queries) ...
QSqlQuery exec(const std::string &query) const
Shortcut to the Qt QSqlDatabase exec() query for SQL code.
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...