-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlExecutor.cpp
More file actions
74 lines (48 loc) · 2.04 KB
/
SqlExecutor.cpp
File metadata and controls
74 lines (48 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "stdafx.h"
#include "SqlExecutor.h"
#include <algorithm>
#include <functional>
#include <connection.h>
#include <statement.h>
#include "DataReader.h"
#include "statement.h"
SqlExecutor::SqlExecutor()
{
}
SqlExecutor::SqlExecutor(const SqlExecutor &other)
{
other;
}
SqlExecutor::~SqlExecutor()
{
}
SqlExecutor &SqlExecutor::operator =(const SqlExecutor &other)
{
if (this != &other)
{
}
return *this;
}
std::shared_ptr<IDataReader> SqlExecutor::ExecuteReader(const std::shared_ptr<odbc::environment> &environment, const std::string &connectionString, const orm::sql::statement &statement) const
{
std::shared_ptr<odbc::connection> connection = std::make_shared<odbc::connection>(environment, connectionString);
connection->open();
std::shared_ptr<odbc::statement> stmt = std::make_shared<odbc::statement>(connection, statement.GetSql());
const std::vector<std::shared_ptr<odbc::parameter>> ¶meters = statement.GetParameters();
std::function<void (const std::shared_ptr<odbc::parameter> &)> fn = [&stmt] (const std::shared_ptr<odbc::parameter> ¶meter) { stmt->add_parameter(parameter); };
std::for_each(parameters.cbegin(), parameters.cend(), fn);
std::shared_ptr<DataReader> reader = std::make_shared<DataReader>(stmt, statement.GetSql());
return reader;
}
std::uint32_t SqlExecutor::ExecuteSql(const std::shared_ptr<odbc::environment> &environment, const std::string &connectionString, const orm::sql::statement &statement) const
{
std::shared_ptr<odbc::connection> connection = std::make_shared<odbc::connection>(environment, connectionString);
connection->open();
odbc::statement stmt(connection, statement.GetSql());
const std::vector<std::shared_ptr<odbc::parameter>> ¶meters = statement.GetParameters();
std::function<void (const std::shared_ptr<odbc::parameter> &)> fn = [&stmt] (const std::shared_ptr<odbc::parameter> ¶meter) { stmt.add_parameter(parameter); };
std::for_each(parameters.cbegin(), parameters.cend(), fn);
stmt.execute();
std::uint32_t result = stmt.get_rows_affected();
return result;
}