sqlitexx: prepared_statement.hpp Source File

sqlitexx 0.0.1

prepared_statement.hpp
Go to the documentation of this file.
1/*
2 * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
3 * Copyright (C) 2009 Andreas Baumann
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions of
7 * the GNU Lesser General Public License, as published by the Free Software
8 * Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this distribution; if not, write to:
18 * Free Software Foundation, Inc.
19 * 51 Franklin Street, Fifth Floor
20 * Boston, MA 02110-1301 USA
21 *
22 */
23
24#ifndef SQLITE3XX_PREPARED_STATEMENT_H
25#define SQLITE3XX_PREPARED_STATEMENT_H
26
27#include <vector>
28#include <string>
29
30#include <sqlite3xx/port/stdint.h> /* for uintmax_t */
31
32#include "port/dllexport.h"
33
34#include "sqlite3.h"
35
36using namespace std;
37
38namespace sqlite3xx {
39
40class connection;
41class transaction;
42class result;
43
44 namespace prepare {
45
46 enum param_treatment {
47 treat_direct
48 };
49
50 /* class to add () parameters to a prepare statement */
51 class SQLITEXX_LIBEXPORT declaration {
52 private:
53 connection& _c;
54 const string& _stmt;
55
56 public:
57 declaration( connection &c, const string& stmt );
58
59 const declaration& operator( )( const string& sql_type,
60 param_treatment treat ) const;
61 };
62
63 class SQLITEXX_LIBEXPORT invocation {
64 private:
65 connection& _c;
66 transaction& _t;
67 const string& _stmt;
68 int _pos;
69
70 public:
71 invocation( connection& c, transaction& t, const string& stmt );
72
73 invocation &setparam( const int& value, bool nonnull );
74 invocation &setparam( const unsigned int& value, bool nonnull );
75 invocation &setparam( const char* value, bool nonnull );
76 invocation &setparam( const string& value, bool nonnull );
77 invocation &setparam( const double& value, bool nonnull );
78 invocation &setparam( const long& value, bool nonnull );
79 invocation &setparam( const uintmax_t& value, bool nonnull );
80
81 result exec( ) const;
82
83 template<typename T>
84 invocation &operator( )( const T &v, bool nonnull = true ) {
85 return setparam( v, nonnull );
86 }
87 };
88}
89
90 class SQLITEXX_LIBEXPORT prepared_stmt {
91
92 private:
93 typedef pair<string,prepare::param_treatment> param;
94
95 sqlite3_stmt *_stmt;
96 string _sql;
97 vector<param> parameters;
98 sqlite3 *_db;
99
100 public:
101 prepared_stmt( sqlite3 *db, string __sql );
102 ~prepared_stmt( );
103 string sql( );
104 void addparam( const string& sqltype, prepare::param_treatment& treatment );
105
106 void reset( );
107 void setparam( const int pos, const int value );
108 void setparam( const int pos, const unsigned int value );
109 void setparam( const int pos, const char* value );
110 void setparam( const int pos, const double value );
111 void setparam( const int pos, const long value );
112 void setparam( const int pos, const uintmax_t value );
113
114 sqlite3_stmt* getStmt( ) const;
115};
116
117} /* namespace sqlite3xx */
118
119#endif /* SQLITE3XX_PREPARED_STATEMENT_H */
sqlite3xx::connection
Definition connection.hpp:46
sqlite3xx::prepare::declaration
Definition prepared_statement.hpp:51
sqlite3xx::prepare::declaration::declaration
declaration(connection &c, const string &stmt)
sqlite3xx::prepare::invocation
Definition prepared_statement.hpp:63
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const string &value, bool nonnull)
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const int &value, bool nonnull)
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const double &value, bool nonnull)
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const long &value, bool nonnull)
sqlite3xx::prepare::invocation::invocation
invocation(connection &c, transaction &t, const string &stmt)
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const uintmax_t &value, bool nonnull)
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const char *value, bool nonnull)
sqlite3xx::prepare::invocation::exec
result exec() const
sqlite3xx::prepare::invocation::setparam
invocation & setparam(const unsigned int &value, bool nonnull)
sqlite3xx::prepared_stmt
Definition prepared_statement.hpp:90
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const long value)
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const int value)
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const uintmax_t value)
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const char *value)
sqlite3xx::prepared_stmt::sql
string sql()
sqlite3xx::prepared_stmt::addparam
void addparam(const string &sqltype, prepare::param_treatment &treatment)
sqlite3xx::prepared_stmt::prepared_stmt
prepared_stmt(sqlite3 *db, string __sql)
sqlite3xx::prepared_stmt::reset
void reset()
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const double value)
sqlite3xx::prepared_stmt::getStmt
sqlite3_stmt * getStmt() const
sqlite3xx::prepared_stmt::~prepared_stmt
~prepared_stmt()
sqlite3xx::prepared_stmt::setparam
void setparam(const int pos, const unsigned int value)
sqlite3xx::result
Definition result.hpp:42
sqlite3xx::transaction
Definition transaction.hpp:36
dllexport.h
SQLITEXX_LIBEXPORT
#define SQLITEXX_LIBEXPORT
Definition dllexport.h:35
sqlite3xx::prepare::param_treatment
param_treatment
Definition prepared_statement.hpp:46
sqlite3xx::prepare::treat_direct
@ treat_direct
Definition prepared_statement.hpp:47
sqlite3xx
Definition connection.hpp:41
stdint.h