forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinder.cpp
More file actions
127 lines (94 loc) · 2.61 KB
/
Binder.cpp
File metadata and controls
127 lines (94 loc) · 2.61 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Binder.cpp
//
// Library: Data/SQLite
// Package: SQLite
// Module: Binder
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/SQLite/Binder.h"
#include "Poco/Data/SQLite/Utility.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/Exception.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeFormat.h"
#include <cstdlib>
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
namespace Poco {
namespace Data {
namespace SQLite {
Binder::Binder(sqlite3_stmt* pStmt):
_pStmt(pStmt)
{
}
Binder::~Binder()
{
}
void Binder::bind(std::size_t pos, const Poco::Int32 &val, Direction dir)
{
int rc = sqlite3_bind_int(_pStmt, (int) pos, val);
checkReturn(rc);
}
void Binder::bind(std::size_t pos, const Poco::Int64 &val, Direction dir)
{
int rc = sqlite3_bind_int64(_pStmt, (int) pos, val);
checkReturn(rc);
}
#ifndef POCO_INT64_IS_LONG
void Binder::bind(std::size_t pos, const long &val, Direction dir)
{
long tmp = static_cast<long>(val);
int rc = sqlite3_bind_int(_pStmt, (int) pos, tmp);
checkReturn(rc);
}
void Binder::bind(std::size_t pos, const unsigned long &val, Direction dir)
{
long tmp = static_cast<long>(val);
int rc = sqlite3_bind_int(_pStmt, (int) pos, tmp);
checkReturn(rc);
}
#endif
void Binder::bind(std::size_t pos, const double &val, Direction dir)
{
int rc = sqlite3_bind_double(_pStmt, (int) pos, val);
checkReturn(rc);
}
void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
{
int rc = sqlite3_bind_text(_pStmt, (int) pos, val.c_str(), (int) val.size()*sizeof(char), SQLITE_TRANSIENT);
checkReturn(rc);
}
void Binder::bind(std::size_t pos, const Date& val, Direction dir)
{
DateTime dt(val.year(), val.month(), val.day());
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_DATE_FORMAT));
bind(pos, str, dir);
}
void Binder::bind(std::size_t pos, const Time& val, Direction dir)
{
DateTime dt;
dt.assign(dt.year(), dt.month(), dt.day(), val.hour(), val.minute(), val.second());
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_TIME_FORMAT));
bind(pos, str, dir);
}
void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
{
std::string dt(DateTimeFormatter::format(val, DateTimeFormat::ISO8601_FORMAT));
bind(pos, dt, dir);
}
void Binder::bind(std::size_t pos, const NullData&, Direction)
{
sqlite3_bind_null(_pStmt, static_cast<int>(pos));
}
void Binder::checkReturn(int rc)
{
if (rc != SQLITE_OK)
Utility::throwException(sqlite3_db_handle(_pStmt), rc);
}
} } } // namespace Poco::Data::SQLite