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
44namespace prepare {
45
48 };
49
50 /* class to add () parameters to a prepare statement */
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
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
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 );
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 */
Definition connection.hpp:46
Definition prepared_statement.hpp:51
declaration(connection &c, const string &stmt)
Definition prepared_statement.hpp:63
invocation & setparam(const string &value, bool nonnull)
invocation & setparam(const int &value, bool nonnull)
invocation & setparam(const double &value, bool nonnull)
invocation & setparam(const long &value, bool nonnull)
invocation(connection &c, transaction &t, const string &stmt)
invocation & setparam(const uintmax_t &value, bool nonnull)
invocation & setparam(const char *value, bool nonnull)
invocation & setparam(const unsigned int &value, bool nonnull)
Definition prepared_statement.hpp:90
void setparam(const int pos, const long value)
void setparam(const int pos, const int value)
void setparam(const int pos, const uintmax_t value)
void setparam(const int pos, const char *value)
void addparam(const string &sqltype, prepare::param_treatment &treatment)
prepared_stmt(sqlite3 *db, string __sql)
void setparam(const int pos, const double value)
sqlite3_stmt * getStmt() const
void setparam(const int pos, const unsigned int value)
Definition result.hpp:42
Definition transaction.hpp:36
#define SQLITEXX_LIBEXPORT
Definition dllexport.h:35
param_treatment
Definition prepared_statement.hpp:46
@ treat_direct
Definition prepared_statement.hpp:47
Definition connection.hpp:41