diff options
Diffstat (limited to 'project2/sql/sqlBulkLoad.cpp')
-rw-r--r-- | project2/sql/sqlBulkLoad.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/project2/sql/sqlBulkLoad.cpp b/project2/sql/sqlBulkLoad.cpp new file mode 100644 index 0000000..227f06c --- /dev/null +++ b/project2/sql/sqlBulkLoad.cpp @@ -0,0 +1,40 @@ +#include <pch.hpp> +#include "task.h" +#include "scopeObject.h" +#include "stream.h" + +class SqlBulkLoad : public Task { + public: + SqlBulkLoad(ScriptNodePtr p) : + SourceObject(p), + Task(p), + dataSource(p, "datasource"), + targetTable(p, "targettable"), + extras(p, "extras") + { + p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&stream)); + } + + void loadComplete(const CommonObjects * co) + { + db = co->dataSource<RdbmsDataSource>(dataSource()); + } + + void execute() const + { + db->getWritable().beginBulkUpload(targetTable(), extras()); + ScopeObject tidy([]{}, + [=]{ db->getWritable().endBulkUpload(NULL); }, + [=]{ db->getWritable().endBulkUpload("Stack unwind in progress"); }); + stream->runStream(boost::bind(&DB::Connection::bulkUploadData, &db->getWritable(), _1, _2)); + } + + const Variable dataSource; + const Variable targetTable; + const Variable extras; + StreamPtr stream; + protected: + const RdbmsDataSource * db; +}; + +DECLARE_LOADER("sqlbulkload", SqlBulkLoad); |