blob: 818ab354669b573ec68b39dd3b4b3b281c35fe0f (
plain)
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
|
#include "compiledsql.h"
#include <boost/algorithm/string/predicate.hpp>
CompiledSQL::CompiledSQL(SQLite::Database& db):
m_stmt{},
m_db{db},
m_isSelect{}
{
}
void CompiledSQL::init(const std::string& stmt)
{
if (m_stmt) {
m_stmt->reset();
} else {
if (
#if __cplusplus >= 202002
stmt.starts_with("SELECT ")
#else
boost::algorithm::starts_with(stmt, "SELECT ")
#endif
) {
m_isSelect = true;
} else {
m_isSelect = false;
}
m_stmt = std::make_shared<SQLite::Statement>(m_db, stmt);
}
}
bool CompiledSQL::execute()
{
if (m_isSelect) {
return m_stmt->executeStep();
} else {
return m_stmt->exec();
}
}
|