summaryrefslogtreecommitdiff
path: root/project2/sql
diff options
context:
space:
mode:
Diffstat (limited to 'project2/sql')
-rw-r--r--project2/sql/Jamfile.jam8
-rw-r--r--project2/sql/mockDatabase.cpp2
-rw-r--r--project2/sql/mockDatasource.cpp2
-rw-r--r--project2/sql/sql-modMySQL.cpp2
-rw-r--r--project2/sql/sql-modODBC.cpp2
-rw-r--r--project2/sql/sql-modPQ.cpp2
-rw-r--r--project2/sql/sql-modSQLite.cpp2
-rw-r--r--project2/sql/sqlBulkLoad.cpp4
-rw-r--r--project2/sql/sqlCache.cpp20
-rw-r--r--project2/sql/sqlMergeTask.cpp12
-rw-r--r--project2/sql/sqlWriter.cpp10
-rw-r--r--project2/sql/sqlWriter.h10
-rw-r--r--project2/sql/tablepatch.cpp15
-rw-r--r--project2/sql/tablepatch.h2
-rw-r--r--project2/sql/unittests/Jamfile.jam2
15 files changed, 45 insertions, 50 deletions
diff --git a/project2/sql/Jamfile.jam b/project2/sql/Jamfile.jam
index 17c0223..4bf1088 100644
--- a/project2/sql/Jamfile.jam
+++ b/project2/sql/Jamfile.jam
@@ -14,7 +14,6 @@ lib p2sqlmodMySQL :
sql-modMySQL.cpp :
<library>../../libmysqlpp//mysqlpp
<library>glibmm
- <include>../../libmisc
<library>../common//p2common
<library>p2sql
: :
@@ -26,7 +25,6 @@ lib p2sqlmodSQLite :
sql-modSQLite.cpp :
<library>../../libsqlitepp//sqlitepp
<library>glibmm
- <include>../../libmisc
<library>../common//p2common
<library>p2sql
<library>boost_filesystem
@@ -39,7 +37,6 @@ lib p2sqlmodODBC :
sql-modODBC.cpp :
<library>../../libodbcpp//odbcpp
<library>glibmm
- <include>../../libmisc
<library>../common//p2common
<library>p2sql
: :
@@ -51,7 +48,6 @@ lib p2sqlmodPQ :
sql-modPQ.cpp :
<library>../../libpqpp//pqpp
<library>glibmm
- <include>../../libmisc
<library>../common//p2common
<library>p2sql
: :
@@ -59,7 +55,6 @@ lib p2sqlmodPQ :
;
cpp-pch pch : pch.hpp :
- <include>../../libmisc
<include>../../libdbpp
<library>glibmm
<library>../common//p2common
@@ -76,8 +71,7 @@ lib p2sql :
<library>boost_filesystem
<library>../common//p2common
<library>../basics//p2basics
- <library>../lib//p2lib
- <include>../../libmisc
+ <library>..//adhocutil
<library>fl
: :
<include>.
diff --git a/project2/sql/mockDatabase.cpp b/project2/sql/mockDatabase.cpp
index b73001a..3ad409d 100644
--- a/project2/sql/mockDatabase.cpp
+++ b/project2/sql/mockDatabase.cpp
@@ -1,6 +1,6 @@
#include "mockDatabase.h"
#include "mockDatasource.h"
-#include <misc.h>
+#include <buffer.h>
#include <logger.h>
#include <fstream>
#include <modifycommand.h>
diff --git a/project2/sql/mockDatasource.cpp b/project2/sql/mockDatasource.cpp
index df5d325..6c281e1 100644
--- a/project2/sql/mockDatasource.cpp
+++ b/project2/sql/mockDatasource.cpp
@@ -10,6 +10,6 @@ unsigned int MockConnectionLoader::mocked = 0;
DB::Connection *
MockConnectionLoader::create(const std::string & n) const
{
- return safeMapFind<std::runtime_error>(mocks, n)->second->openConnection();
+ return AdHoc::safeMapFind<std::runtime_error>(mocks, n)->second->openConnection();
}
diff --git a/project2/sql/sql-modMySQL.cpp b/project2/sql/sql-modMySQL.cpp
index 0466cbc..728c9e1 100644
--- a/project2/sql/sql-modMySQL.cpp
+++ b/project2/sql/sql-modMySQL.cpp
@@ -1,7 +1,7 @@
#include "connectionLoader.h"
#include "../libmysqlpp/connection.h"
#include "sql-modMySQL.h"
-#include <misc.h>
+#include <buffer.h>
#include <scripts.h>
#include <logger.h>
#include <fstream>
diff --git a/project2/sql/sql-modODBC.cpp b/project2/sql/sql-modODBC.cpp
index 29d2441..5b9c858 100644
--- a/project2/sql/sql-modODBC.cpp
+++ b/project2/sql/sql-modODBC.cpp
@@ -1,7 +1,7 @@
#include "connectionLoader.h"
#include "../libodbcpp/connection.h"
#include "sql-modODBC.h"
-#include <misc.h>
+#include <buffer.h>
#include <scripts.h>
#include <logger.h>
diff --git a/project2/sql/sql-modPQ.cpp b/project2/sql/sql-modPQ.cpp
index ec2fcf3..84a9411 100644
--- a/project2/sql/sql-modPQ.cpp
+++ b/project2/sql/sql-modPQ.cpp
@@ -1,7 +1,7 @@
#include "connectionLoader.h"
#include "../libpqpp/connection.h"
#include "sql-modPQ.h"
-#include <misc.h>
+#include <buffer.h>
#include <scripts.h>
#include <logger.h>
diff --git a/project2/sql/sql-modSQLite.cpp b/project2/sql/sql-modSQLite.cpp
index ef8e133..2f19302 100644
--- a/project2/sql/sql-modSQLite.cpp
+++ b/project2/sql/sql-modSQLite.cpp
@@ -1,7 +1,7 @@
#include "connectionLoader.h"
#include "../libsqlitepp/connection.h"
#include "sql-modSQLite.h"
-#include <misc.h>
+#include <buffer.h>
#include <scripts.h>
#include <logger.h>
#include <boost/filesystem/operations.hpp>
diff --git a/project2/sql/sqlBulkLoad.cpp b/project2/sql/sqlBulkLoad.cpp
index 813323c..d976997 100644
--- a/project2/sql/sqlBulkLoad.cpp
+++ b/project2/sql/sqlBulkLoad.cpp
@@ -2,7 +2,7 @@
#include "task.h"
#include <commonObjects.h>
#include "rdbmsDataSource.h"
-#include "scopeObject.h"
+#include <scopeExit.h>
#include "stream.h"
class SqlBulkLoad : public Task {
@@ -27,7 +27,7 @@ class SqlBulkLoad : public Task {
{
auto wdb = db->getWritable();
wdb->beginBulkUpload(targetTable(ec), extras(ec));
- ScopeObject tidy([]{},
+ AdHoc::ScopeExit tidy([]{},
[&]{ wdb->endBulkUpload(NULL); },
[&]{ wdb->endBulkUpload("Stack unwind in progress"); });
stream->runStream(boost::bind(&DB::Connection::bulkUploadData, wdb.get(), _1, _2), ec);
diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp
index 142bf6f..cf33f8e 100644
--- a/project2/sql/sqlCache.cpp
+++ b/project2/sql/sqlCache.cpp
@@ -32,7 +32,7 @@ class SqlCache : public RowSetCache {
db = co->dataSource<RdbmsDataSource>(DataSource);
}
- static void appendKeyCols(Buffer * sql, unsigned int * off, const Glib::ustring & col)
+ static void appendKeyCols(AdHoc::Buffer * sql, unsigned int * off, const Glib::ustring & col)
{
if ((*off)++) {
sql->append(", ");
@@ -40,7 +40,7 @@ class SqlCache : public RowSetCache {
sql->append(col.c_str());
}
- static void appendKeyBinds(Buffer * sql, unsigned int * off)
+ static void appendKeyBinds(AdHoc::Buffer * sql, unsigned int * off)
{
if ((*off)++) {
sql->append(", ");
@@ -48,7 +48,7 @@ class SqlCache : public RowSetCache {
sql->append("?");
}
- static void appendKeyAnds(Buffer * sql, const Glib::ustring & col)
+ static void appendKeyAnds(AdHoc::Buffer * sql, const Glib::ustring & col)
{
sql->appendf(" AND h.%s = ?", col.c_str());
}
@@ -127,7 +127,7 @@ class SqlCache : public RowSetCache {
RowSetCPtr getCachedRowSet(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const
{
- Buffer sql;
+ AdHoc::Buffer sql;
sql.appendf("SELECT r.* \
FROM %s p, %s_%s_%s h LEFT OUTER JOIN %s_%s_%s_rows r \
ON h.p2_cacheid = r.p2_cacheid \
@@ -166,7 +166,7 @@ class SqlCache : public RowSetCache {
cols[name] = value;
}
void finishRow() const {
- Buffer sql;
+ AdHoc::Buffer sql;
sql.appendf("INSERT INTO %s_%s_%s_rows(p2_row", HeaderTable.c_str(), n.c_str(), f.c_str());
for (const Values::value_type & a : attrs) {
sql.appendf(", p2attr_%s", a.first.c_str());
@@ -206,19 +206,19 @@ class SqlCache : public RowSetCache {
RowSetPresenterPtr openFor(ExecContext * ec, const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps)
{
- Buffer sp;
+ AdHoc::Buffer sp;
sp.appendf("SAVEPOINT sp%p", this);
auto con = db->getWritable();
ModifyPtr s = ModifyPtr(con->newModifyCommand(sp));
s->execute();
// Header
- Buffer del;
+ AdHoc::Buffer del;
del.appendf("INSERT INTO %s(p2_time) VALUES(?)", HeaderTable.c_str());
ModifyPtr h = ModifyPtr(con->newModifyCommand(del));
h->bindParamT(0, boost::posix_time::microsec_clock::universal_time());
h->execute();
// Record set header
- Buffer sql;
+ AdHoc::Buffer sql;
sql.appendf("INSERT INTO %s_%s_%s(", HeaderTable.c_str(), n.c_str(), f.c_str());
unsigned int offset = 0;
applyKeys(ec, boost::bind(appendKeyCols, &sql, &offset, _1), ps);
@@ -235,7 +235,7 @@ class SqlCache : public RowSetCache {
void save(ExecContext *, const Glib::ustring & , const Glib::ustring & , const IHaveParameters * )
{
- Buffer sp;
+ AdHoc::Buffer sp;
sp.appendf("RELEASE SAVEPOINT sp%p", this);
auto con = db->getWritable();
ModifyPtr s = ModifyPtr(con->newModifyCommand(sp));
@@ -244,7 +244,7 @@ class SqlCache : public RowSetCache {
void discard(ExecContext *, const Glib::ustring & , const Glib::ustring & , const IHaveParameters * )
{
- Buffer sp;
+ AdHoc::Buffer sp;
sp.appendf("ROLLBACK TO SAVEPOINT sp%p", this);
auto con = db->getWritable();
ModifyPtr s = ModifyPtr(con->newModifyCommand(sp));
diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp
index 91bf3e0..b6c504f 100644
--- a/project2/sql/sqlMergeTask.cpp
+++ b/project2/sql/sqlMergeTask.cpp
@@ -6,9 +6,9 @@
#include "exceptions.h"
#include "sqlVariableBinder.h"
#include "scriptLoader.h"
-#include "scopeObject.h"
+#include <scopeExit.h>
#include "execContext.h"
-#include <misc.h>
+#include <buffer.h>
#include <stdio.h>
#include <stdexcept>
#include <boost/algorithm/string/join.hpp>
@@ -145,7 +145,7 @@ SqlMergeTask::execute(ExecContext * ec) const
{
auto savepoint(stringf("sqlmerge_savepoint_%p", this));
destdb->savepoint(savepoint);
- ScopeObject SPHandler(NULL,
+ AdHoc::ScopeExit SPHandler(NULL,
boost::bind(&DB::Connection::releaseSavepoint, destdb.get(), savepoint),
boost::bind(&DB::Connection::rollbackToSavepoint, destdb.get(), savepoint));
createTempTable();
@@ -223,7 +223,7 @@ SqlMergeTask::createTempKey() const
{
if (useView(NULL)) return;
/* Primary key */
- Buffer idx;
+ AdHoc::Buffer idx;
idx.appendf("ALTER TABLE %s ADD CONSTRAINT pk_%s PRIMARY KEY(%s)",
dtablet.c_str(), dtablet.c_str(),
boost::algorithm::join(keys, ", ").c_str());
@@ -244,7 +244,7 @@ SqlMergeTask::createTempKey() const
DB::ModifyCommand *
SqlMergeTask::insertCommand() const
{
- Buffer ins;
+ AdHoc::Buffer ins;
ins.appendf("INSERT INTO %s(", dtablet.c_str());
foreach(Columns::const_iterator, cols, c) {
if (c != cols.begin()) {
@@ -323,7 +323,7 @@ SqlMergeTask::copyToTempTable(ExecContext * ec) const
i->execute(ec);
}
if (sqlCommand) {
- Buffer ins;
+ AdHoc::Buffer ins;
ins.appendf("INSERT INTO %s(", dtablet.c_str());
foreach(Columns::const_iterator, cols, c) {
if (c != cols.begin()) {
diff --git a/project2/sql/sqlWriter.cpp b/project2/sql/sqlWriter.cpp
index f654636..e3f632e 100644
--- a/project2/sql/sqlWriter.cpp
+++ b/project2/sql/sqlWriter.cpp
@@ -49,13 +49,13 @@ DynamicSql::SqlCommand::getSqlFor(const Glib::ustring & f) const
for (const SqlCommand::Filters::value_type & filter : filters) {
filter.second->active = (filter.second->name == f);
}
- Buffer sql;
+ AdHoc::Buffer sql;
writeSql(sql);
return Glib::ustring(sql.str());
}
void
-DynamicSql::SqlCommand::writeSql(Buffer & sql) const
+DynamicSql::SqlCommand::writeSql(AdHoc::Buffer & sql) const
{
for (const SqlWriterPtr & w : writers) {
w->writeSql(sql);
@@ -80,7 +80,7 @@ DynamicSql::SqlFilter::SqlFilter(ScriptNodePtr p) :
}
void
-DynamicSql::SqlFilter::writeSql(Buffer & sql) const
+DynamicSql::SqlFilter::writeSql(AdHoc::Buffer & sql) const
{
if (active) {
for (const SqlWriterPtr & w : writers) {
@@ -105,7 +105,7 @@ DynamicSql::SqlParameter::SqlParameter(ScriptNodePtr n) :
}
void
-DynamicSql::SqlParameter::writeSql(Buffer & sql) const
+DynamicSql::SqlParameter::writeSql(AdHoc::Buffer & sql) const
{
sql.append("?");
}
@@ -122,7 +122,7 @@ DynamicSql::SqlText::SqlText(const Glib::ustring & n) :
}
void
-DynamicSql::SqlText::writeSql(Buffer & sql) const
+DynamicSql::SqlText::writeSql(AdHoc::Buffer & sql) const
{
sql.append(text);
}
diff --git a/project2/sql/sqlWriter.h b/project2/sql/sqlWriter.h
index 33a57fb..7fb9fa0 100644
--- a/project2/sql/sqlWriter.h
+++ b/project2/sql/sqlWriter.h
@@ -18,14 +18,14 @@ namespace DynamicSql {
public:
SqlWriter();
virtual ~SqlWriter();
- virtual void writeSql(Buffer & sql) const = 0;
+ virtual void writeSql(AdHoc::Buffer & sql) const = 0;
virtual void bindParams(ExecContext *, DB::Command *, unsigned int & offset) const = 0;
};
class SqlText : public SqlWriter {
public:
SqlText(const Glib::ustring &);
- virtual void writeSql(Buffer & sql) const;
+ virtual void writeSql(AdHoc::Buffer & sql) const;
virtual void bindParams(ExecContext *, DB::Command *, unsigned int & offset) const;
const Glib::ustring text;
@@ -34,14 +34,14 @@ namespace DynamicSql {
class SqlParameter : public SqlWriter, Variable {
public:
SqlParameter(ScriptNodePtr);
- virtual void writeSql(Buffer & sql) const;
+ virtual void writeSql(AdHoc::Buffer & sql) const;
virtual void bindParams(ExecContext *, DB::Command *, unsigned int & offset) const;
};
class SqlFilter : public SqlWriter {
public:
SqlFilter(ScriptNodePtr);
- virtual void writeSql(Buffer & sql) const;
+ virtual void writeSql(AdHoc::Buffer & sql) const;
virtual void bindParams(ExecContext *, DB::Command *, unsigned int & offset) const;
const Glib::ustring name;
@@ -55,7 +55,7 @@ namespace DynamicSql {
class SqlCommand : public SqlWriter {
public:
SqlCommand(ScriptNodePtr);
- virtual void writeSql(Buffer & sql) const;
+ virtual void writeSql(AdHoc::Buffer & sql) const;
virtual void bindParams(ExecContext *, DB::Command *, unsigned int & offset) const;
typedef std::multimap<Glib::ustring, SqlFilterPtr> Filters;
Glib::ustring getSqlFor(const Glib::ustring & f) const;
diff --git a/project2/sql/tablepatch.cpp b/project2/sql/tablepatch.cpp
index f49c4ee..2c634d6 100644
--- a/project2/sql/tablepatch.cpp
+++ b/project2/sql/tablepatch.cpp
@@ -1,10 +1,9 @@
#include <pch.hpp>
#include "tablepatch.h"
#include <stdio.h>
-#include <misc.h>
+#include <buffer.h>
#include <selectcommand.h>
#include <column.h>
-#include <buffer.h>
#include <boost/algorithm/string/join.hpp>
using namespace DB;
@@ -56,7 +55,7 @@ TablePatch::patch(ExecContext * ec, DynamicSql::SqlWriterPtr insteadOfDelete, Dy
void
TablePatch::doDeletes(ExecContext * ec, DynamicSql::SqlWriterPtr insteadOfDelete, DynamicSql::SqlWriterPtr where, DynamicSql::SqlWriterPtr order)
{
- Buffer toDelSql;
+ AdHoc::Buffer toDelSql;
switch (db.bulkDeleteStyle()) {
case BulkDeleteUsingSubSelect:
{
@@ -195,7 +194,7 @@ TablePatch::doUpdates(ExecContext * ec, DynamicSql::SqlWriterPtr where, DynamicS
// -----------------------------------------------------------------
// Build SQL for list of updates to perform ------------------------
// -----------------------------------------------------------------
- Buffer toUpdSel;
+ AdHoc::Buffer toUpdSel;
toUpdSel.append("SELECT ");
foreach (Columns::const_iterator, cols, col) {
if (pk.find(*col) == pk.end()) {
@@ -247,7 +246,7 @@ TablePatch::doUpdates(ExecContext * ec, DynamicSql::SqlWriterPtr where, DynamicS
// -----------------------------------------------------------------
// Build SQL to perform updates ------------------------------------
// -----------------------------------------------------------------
- Buffer updSql;
+ AdHoc::Buffer updSql;
updSql.appendf("UPDATE %s SET ",
dest.c_str());
first = true;
@@ -300,7 +299,7 @@ TablePatch::doUpdates(ExecContext * ec, DynamicSql::SqlWriterPtr where, DynamicS
// -----------------------------------------------------------------
// Build SQL for list of updates to perform ------------------------
// -----------------------------------------------------------------
- Buffer updSql;
+ AdHoc::Buffer updSql;
updSql.appendf("UPDATE %s a SET ",
dest.c_str());
bool first = true;
@@ -370,7 +369,7 @@ TablePatch::doUpdates(ExecContext * ec, DynamicSql::SqlWriterPtr where, DynamicS
// -----------------------------------------------------------------
// Build SQL for list of updates to perform ------------------------
// -----------------------------------------------------------------
- Buffer updSql;
+ AdHoc::Buffer updSql;
updSql.appendf("UPDATE %s a, %s b SET ",
dest.c_str(), src.c_str());
bool first = true;
@@ -442,7 +441,7 @@ TablePatch::doInserts(ExecContext * ec, DynamicSql::SqlWriterPtr order)
// -----------------------------------------------------------------
// Build SQL for copying new records -------------------------------
// -----------------------------------------------------------------
- Buffer toInsSql;
+ AdHoc::Buffer toInsSql;
toInsSql.appendf("INSERT INTO %s",
dest.c_str());
foreach (Columns::const_iterator, cols, col) {
diff --git a/project2/sql/tablepatch.h b/project2/sql/tablepatch.h
index df574bf..f08e543 100644
--- a/project2/sql/tablepatch.h
+++ b/project2/sql/tablepatch.h
@@ -10,6 +10,8 @@
#include <buffer.h>
#include "sqlWriter.h"
+#define foreach(_type, _con, _it) for (_type _it = ((_con).begin()); _it != ((_con).end()); _it++)
+
class TablePatch {
public:
typedef std::string Table;
diff --git a/project2/sql/unittests/Jamfile.jam b/project2/sql/unittests/Jamfile.jam
index 8fb6918..d59a62e 100644
--- a/project2/sql/unittests/Jamfile.jam
+++ b/project2/sql/unittests/Jamfile.jam
@@ -18,7 +18,7 @@ lib sqlTestCore :
<library>../../common//p2common
<library>../../basics//p2basics
<library>../../ut//p2ut
- <library>../../lib//p2lib
+ <library>../..//adhocutil
<library>../../xml//p2xml
<library>..//p2sql
<library>boost_system