|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78488 - in sandbox/icl/libs/xplore/br1/sqlbrowser: . Dag data/concept data/qsql
From: afojgo_at_[hidden]
Date: 2012-05-16 08:07:01
Author: jofaber
Date: 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
New Revision: 78488
URL: http://svn.boost.org/trac/boost/changeset/78488
Log:
Layer continued for data access.
Text files modified:
sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h | 6 ++++
sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 1
sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/GetCreator.h | 6 ----
sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/Selector.h | 25 ++++++++++++-----
sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/SelectorTraits.h | 5 ++-
sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h | 54 +++++++++++----------------------------
sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlSelector.h | 32 ++++++++++++++++++-----
sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro | 8 +++--
8 files changed, 73 insertions(+), 64 deletions(-)
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbType.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -112,6 +112,12 @@
class EdgeType
{
public:
+ EdgeType(tKey uKey, const tString& aName)
+ : m_uKey(uKey), m_aName(aName) {}
+
+ QString toString()const
+ { return QString("Edge: Key=%1, Name=%2").arg(m_uKey).arg(m_aName); }
+
private:
tKey m_uKey;
tString m_aName;
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -190,6 +190,7 @@
data::QSqlSelector selector;
dag::db::TypeGraph tygra;
+ selector.setDatabase(connectionWidget->currentDatabase());
success = makeTypeGraph(selector, tygra);
if(success)
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/GetCreator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/GetCreator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/GetCreator.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -13,12 +13,6 @@
template<class Object, class Accessor>
struct GetCreator;
-template<class Object>
-struct GetCreator<QSqlSelector>
-{
- typedef QSqlCreator<Object, QSqlSelector> type;
-};
-
} // namespace data
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/Selector.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/Selector.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/Selector.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -23,19 +23,28 @@
typename boost::enable_if< IsQuerySelector<Accessor>, bool>::type
makeTypeGraph(Accessor& accessor, dag::db::TypeGraph& typeGraph)
{
- typedef QSqlCreator<dag::db::EdgeType,Accessor> tCreator;
+ typedef typename GetCreator<dag::db::EdgeType,Accessor>::type tCreator;
typedef typename Accessor::const_iterator const_iterator;
- //DataSelectorConcept<Accessor>::
- // select(accessor, CreatorConcept<Object,Accessor>::createQuery());
+ typedef typename CreatorTraits<dag::db::EdgeType,tCreator> tCreatorInstance;
- //JODO transform(accessor, typeGraph, CreatorConcept<TypeEdge,AccessorT>);
- //for(iterator it = accessor.begin(); it != accessor.end(); ++it)
+ SelectorTraits<Accessor>::
+ select(accessor,
+ CreatorTraits<dag::db::EdgeType,tCreator>::createQuery());
+
+ QString check;
+ for(const_iterator it = accessor.begin(); it != accessor.end(); ++it)
+ {
+ //check += it->field(4).value().toString();
+ dag::db::EdgeType aEdge
+ = CreatorTraits<dag::db::EdgeType,tCreator>::create(it);
+ check += aEdge.toString();
+ check += "\n";
+ }
- QString ObjSql = CreatorTraits<dag::db::EdgeType,tCreator>::createQuery();
QMessageBox msgBox;
- QString msg = "Insertion. ";
- msg += ObjSql;
+ QString msg = "Edges:\n";
+ msg += check;
msgBox.setText(msg);
msgBox.exec();
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/SelectorTraits.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/SelectorTraits.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/concept/SelectorTraits.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -16,15 +16,16 @@
//==============================================================================
//= Concept: DataSelector Traits
//==============================================================================
-template<class Accessor, class Query>
+template<class Accessor>
struct SelectorTraits
{
typedef typename Accessor::size_type size_type;
+ typedef typename Accessor::tQuery tQuery;
typedef typename Accessor::iterator const_iterator;
static const_iterator begin(const Accessor& accessor);
static const_iterator end(const Accessor& accessor);
- static size_type select(const Query&);
+ static size_type select(const tQuery&);
};
} // namespace data
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlCreator.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -5,8 +5,12 @@
#pragma once
+#include <QSqlRecord.h>
+#include <QSqlField.h>
+
#include "Dag/DbType.h"
#include "data/concept/CreatorTraits.h"
+#include "data/concept/GetCreator.h"
#include "data/qsql/QSqlSelector.h"
namespace data
@@ -17,32 +21,13 @@
template<class Object, class Accessor>
class QSqlCreator;
-/*
-{
-public:
- typedef QSqlCreator type;
- typedef Object tObject;
- typedef Accessor tAccessor;
-
- typedef typename tAccessor::tResultSet tResultSet;
- typedef typename tAccessor::const_iterator const_iterator;
-
- static tString createQuery()
- {
- return "...";
- }
-
- static tObject create(const_iterator it)
- {
- return tObject();
- }
-};
-*/
template<>
class QSqlCreator<dag::db::EdgeType, QSqlSelector>
{
public:
+ enum { eKey=0, eRefSourceType, eRefRelationType, eRefTargetType, eName };
+
typedef QSqlCreator type;
typedef dag::db::EdgeType tObject;
typedef QSqlSelector tAccessor;
@@ -52,18 +37,25 @@
static tString createQuery()
{
- return "SELECT ...";
+ return "SELECT key, refSourceType, refRelationType, refTargetType, name FROM EdgeType ";
}
static tObject create(const_iterator it)
{
- return dag::db::EdgeType();
+ return dag::db::EdgeType(it->field(eKey).value().toInt(),
+ it->field(eName).value().toString());
}
};
+template<class Object>
+struct GetCreator<Object, QSqlSelector>
+{
+ typedef QSqlCreator<Object, QSqlSelector> type;
+};
+
+
-template<class Object, class Accessor>class QSqlCreator;
//==============================================================================
//= Concept: data::Creator Spec: QSqlCreator
@@ -80,18 +72,4 @@
};
-/*
-template<>
-struct CreatorTraits<dag::db::EdgeType, QSqlCreator<dag::db::EdgeType, data::QSqlSelector> >
-{
- typedef dag::db::EdgeType tObject;
- typedef data::QSqlSelector tAccessor;
- typedef QSqlCreator<dag::db::EdgeType, data::QSqlSelector> tCreator;
- typedef tAccessor::const_iterator const_iterator;
-
- static tString createQuery(){ tCreator::createQuery(); }
- static tObject create(const_iterator it){ return tCreator::create(it); }
-};
-*/
-
} // namespace data
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlSelector.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlSelector.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/data/qsql/QSqlSelector.h 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -9,11 +9,14 @@
#include <cstddef>
//boost
//qt
+#include <QSqlDatabase.h>
#include <QSqlQuery.h>
+#include <QSqlRecord.h>
//concepts
#include "data/concept/SelectorTraits.h"
+#include "connectionwidget.h"
// Data access sql, xml, file etc. lives in namespace data
namespace data
@@ -23,17 +26,30 @@
{
public:
typedef QSqlSelector type;
+ typedef tString tQuery;
typedef std::size_t size_type;
- typedef QVector<QVariant> tResultSet;
+ typedef QSqlRecord tRecord;
+ typedef QVector<tRecord> tResultSet;
typedef tResultSet::const_iterator const_iterator;
- typedef QSqlQuery tQuery;
const_iterator begin()const{ return m_aResultSet.begin(); }
const_iterator end() const{ return m_aResultSet.end(); }
- size_type select(const tQuery&);
+
+ size_type select(const tQuery& querySql)
+ {
+ QSqlQuery query = QSqlQuery(querySql, m_aDatabase);
+ query.exec();
+ while(query.next())
+ m_aResultSet.push_back(query.record());
+
+ return m_aResultSet.size();
+ }
+
+ void setDatabase(const QSqlDatabase& db){ m_aDatabase = db; }
private:
- tResultSet m_aResultSet;
+ tResultSet m_aResultSet;
+ QSqlDatabase m_aDatabase;
};
@@ -41,14 +57,16 @@
//= Concept: data::Selector Specialisation: QSqlSelector
//==============================================================================
template<>
-struct SelectorTraits<QSqlSelector, QSqlQuery>
+struct SelectorTraits<QSqlSelector>
{
typedef std::size_t size_type;
typedef QSqlSelector::const_iterator const_iterator;
+ typedef QSqlSelector::tQuery tQuery;
static const_iterator begin(const QSqlSelector& accessor){ return accessor.begin(); }
- static const_iterator end (const QSqlSelector& accessor){ return accessor.end(); };
- static size_type select(const QSqlQuery&);
+ static const_iterator end (const QSqlSelector& accessor){ return accessor.end(); }
+ static size_type select(QSqlSelector& accessor, const tString& query)
+ { return accessor.select(query); }
};
} // namespace data
Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro 2012-05-16 08:06:59 EDT (Wed, 16 May 2012)
@@ -3,8 +3,8 @@
QT += sql
-#INCLUDEPATH += /cygwin/home/jofa/dev/boost/branches/release
-INCLUDEPATH += C:\NIBuild\3rdparty\boost-1.48.0
+INCLUDEPATH += /cygwin/home/jofa/dev/boost/branches/release
+#INCLUDEPATH += C:\NIBuild\3rdparty\boost-1.48.0
HEADERS = browser.h connectionwidget.h qsqlconnectiondialog.h \
exttableview.h \
@@ -24,7 +24,8 @@
data/concept/IsQuerySelector.h \
data/concept/CreatorTraits.h \
data/qsql/QSqlSelector.h \
- data/qsql/QSqlCreator.h
+ data/qsql/QSqlCreator.h \
+ data/concept/GetCreator.h
SOURCES = main.cpp browser.cpp connectionwidget.cpp qsqlconnectiondialog.cpp \
exttableview.cpp \
dagitem.cpp \
@@ -60,3 +61,4 @@
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk