/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/basic_statement.cc

  • Committer: Tim Marston
  • Date: 2015-02-26 08:56:26 UTC
  • Revision ID: tim@ed.am-20150226085626-vba9c55uz3ta094h
improved support for blobs: added bind_blob(), added blob_t for binding stream
operators and blob() creation function; detect blob column type in row::column()

Show diffs side-by-side

added added

removed removed

24
24
#include <sqlite3cc/exception.h>
25
25
#include <sqlite3cc/connection.h>
26
26
#include <sqlite3cc/manipulator.h>
27
 
#include <string.h>
28
27
 
29
28
 
30
29
sqlite::detail::basic_statement::basic_statement(
83
82
        const char *value,
84
83
        unsigned int value_length )
85
84
{
 
85
                // bind as text (applying the type affinity of the underlying column)
86
86
        return sqlite3_bind_text( _handle, index, value, value_length,
87
87
                SQLITE_STATIC );
88
88
}
143
143
}
144
144
 
145
145
 
 
146
int sqlite::detail::basic_statement::bind_blob(
 
147
        unsigned int index,
 
148
        const char *value,
 
149
        unsigned int value_length )
 
150
{
 
151
        return sqlite3_bind_blob( _handle, index, value, value_length,
 
152
                SQLITE_TRANSIENT );
 
153
}
 
154
 
 
155
 
 
156
int sqlite::detail::basic_statement::bind_blob(
 
157
        unsigned int index,
 
158
        const std::string &value )
 
159
{
 
160
        return bind_blob( index, value.c_str(), value.length() );
 
161
}
 
162
 
 
163
 
 
164
int sqlite::detail::basic_statement::bind_blob(
 
165
        const std::string &name,
 
166
        const char *value,
 
167
        unsigned int value_length )
 
168
{
 
169
        return bind_blob( bind_parameter_index( name ), value, value_length );
 
170
}
 
171
 
 
172
 
 
173
int sqlite::detail::basic_statement::bind_blob(
 
174
        const std::string &name,
 
175
        const std::string &value )
 
176
{
 
177
        return bind_blob( bind_parameter_index( name ), value );
 
178
}
 
179
 
 
180
 
146
181
int sqlite::detail::basic_statement::finalize()
147
182
{
148
183
        int code = SQLITE_OK;
171
206
}
172
207
 
173
208
 
174
 
 
175
209
template< >
176
210
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
177
211
        < sqlite::detail::null_t >(
192
226
        _bind_index = t._index;
193
227
        return *this;
194
228
}
 
229
 
 
230
 
 
231
template< >
 
232
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
 
233
        < sqlite::detail::blob_t >(
 
234
        const sqlite::detail::blob_t &t )
 
235
{
 
236
        int code = bind_blob( _bind_index, t.value, t.value_length );
 
237
        if( code != SQLITE_OK ) throw sqlite_error( _connection, code );
 
238
        _bind_index++;
 
239
        return *this;
 
240
}
 
241
 
 
242
 
 
243
template< >
 
244
int sqlite::detail::basic_statement::bind< int >(
 
245
        unsigned int index,
 
246
        const int &value )
 
247
{
 
248
        return sqlite3_bind_int( _handle, index, value );
 
249
}
 
250
 
 
251
 
 
252
template< >
 
253
int sqlite::detail::basic_statement::bind< double >(
 
254
        unsigned int index,
 
255
        const double &value )
 
256
{
 
257
        return sqlite3_bind_double( _handle, index, value );
 
258
}