Class: Amalgalite::SQLite3::Statement
- Inherits:
-
Object
- Object
- Amalgalite::SQLite3::Statement
- Defined in:
- ext/amalgalite/c/amalgalite_statement.c
Instance Method Summary collapse
-
#bind_blob(position, blob) ⇒ Integer
bind a blob to the variable at position.
-
#bind_double(position, value) ⇒ nil
bind a double value to the variable at postion.
-
#bind_int(position, value) ⇒ nil
bind a int value to the variable at postion.
-
#bind_int64(position, value) ⇒ nil
bind a int64 value to the variable at postion.
-
#bind_null(position) ⇒ Integer
bind a null value to the variable at postion.
-
#bind_text(position, value) ⇒ nil
bind a string value to the variable at postion.
-
#bind_zeroblob(position, length) ⇒ Integer
bind a blob with
length
filled with zeros to the position. -
#clear_bindings! ⇒ nil
reset the SQLite3 statement back to its initial state.
-
#close ⇒ nil
Closes the statement.
-
#column_blob(index) ⇒ String
Return the data in ith column of the result as a String.
-
#column_count ⇒ Fixnum
return the number of columns in the result set.
-
#column_database_name(index) ⇒ String
Return the database name where the data in the ith column of the result set comes from.
-
#column_declared_type(index) ⇒ String
Return the declared type of the ith column in the result set.
-
#column_double(index) ⇒ Float
Return the data in ith column of the result as an Float.
-
#column_int(index) ⇒ Integer
Return the data in ith column of the result as an Integer.
-
#column_int64(index) ⇒ Integer
Return the data in ith column of the result as an Integer.
-
#column_name(index) ⇒ String
Return the column name at the ith column in the result set.
-
#column_origin_name(index) ⇒ String
Return the column name where the data in the ith column of the result set comes from.
-
#column_table_name(index) ⇒ String
Return the table name where the data in the ith column of the result set comes from.
-
#column_text(index) ⇒ String
Return the data in ith column of the result as a String.
-
#column_type(index) ⇒ SQLite3::DataType constant
Return the column type at the ith column in the result set.
-
#parameter_count ⇒ Integer
return the index of the largest parameter in the in the statement.
-
#parameter_index(name) ⇒ Integer
returns the index of the named parameter from the statement.
-
#remaining_sql ⇒ String
returns the remainging SQL leftover from the initialization sql, or nil if there is no remaining SQL.
-
#reset! ⇒ nil
reset the SQLite3 statement back to its initial state.
-
#sql ⇒ String
Return a copy of the original string used to create the prepared statement.
-
#step ⇒ Integer
Step through the next piece of the SQLite3 statement.
Instance Method Details
#bind_blob(position, blob) ⇒ Integer
bind a blob to the variable at position. This is a blob that is fully held in memory
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 68
VALUE am_sqlite3_statement_bind_blob( VALUE self, VALUE position, VALUE blob )
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
VALUE str = StringValue( blob );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_blob( am_stmt->stmt, pos, RSTRING_PTR( str ), (int)RSTRING_LEN( str ), SQLITE_TRANSIENT);
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding blob at position %d in statement: [SQLITE_ERROR %d] : %s\n",
pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_double(position, value) ⇒ nil
bind a double value to the variable at postion.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 93
VALUE am_sqlite3_statement_bind_double(VALUE self, VALUE position, VALUE value)
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
double v = NUM2DBL( value );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_double( am_stmt->stmt, pos, v );
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding [%lf] to double at position %d in statement: [SQLITE_ERROR %d] : %s\n",
v, pos,
rc, (char*)sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_int(position, value) ⇒ nil
bind a int value to the variable at postion.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 118
VALUE am_sqlite3_statement_bind_int(VALUE self, VALUE position, VALUE value)
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
int v = NUM2INT( value );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_int( am_stmt->stmt, pos, v );
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding [%d] to int at position %d in statement: [SQLITE_ERROR %d] : %s\n",
v, pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_int64(position, value) ⇒ nil
bind a int64 value to the variable at postion.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 143
VALUE am_sqlite3_statement_bind_int64(VALUE self, VALUE position, VALUE value)
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
sqlite3_int64 v = NUM2SQLINT64( value );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_int64( am_stmt->stmt, pos, v );
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding [%lld] to int64 at position %d in statement: [SQLITE_ERROR %d] : %s\n",
v, pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_null(position) ⇒ Integer
bind a null value to the variable at postion.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 18
VALUE am_sqlite3_statement_bind_null(VALUE self, VALUE position )
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_null( am_stmt->stmt, pos );
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding NULL at position %d in statement: [SQLITE_ERROR %d] : %s\n",
pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_text(position, value) ⇒ nil
bind a string value to the variable at postion.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 168
VALUE am_sqlite3_statement_bind_text(VALUE self, VALUE position, VALUE value)
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
VALUE str = StringValue( value );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_text( am_stmt->stmt, pos, RSTRING_PTR(str), (int)RSTRING_LEN(str), SQLITE_TRANSIENT);
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding [%s] to text at position %d in statement: [SQLITE_ERROR %d] : %s\n",
RSTRING_PTR(str), pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#bind_zeroblob(position, length) ⇒ Integer
bind a blob with length
filled with zeros to the position. This is a Blob that will later filled in with incremental IO routines.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 42
VALUE am_sqlite3_statement_bind_zeroblob( VALUE self, VALUE position, VALUE length)
{
am_sqlite3_stmt *am_stmt;
int pos = FIX2INT( position );
int n = (int)FIX2INT( length );
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_bind_zeroblob( am_stmt->stmt, pos, n );
if ( SQLITE_OK != rc ) {
rb_raise(eAS_Error, "Error binding zeroblob of length %d at position %d in statement: [SQLITE_ERROR %d] : %s\n",
n, pos,
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return INT2FIX(rc);
}
|
#clear_bindings! ⇒ nil
reset the SQLite3 statement back to its initial state.
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 263
VALUE am_sqlite3_statement_clear_bindings(VALUE self)
{
am_sqlite3_stmt *am_stmt;
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
rc = sqlite3_clear_bindings( am_stmt->stmt );
if ( rc != SQLITE_OK ) {
rb_raise(eAS_Error, "Error resetting statement: [SQLITE_ERROR %d] : %s\n",
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return Qnil;
}
|
#close ⇒ nil
Closes the statement. If there is a problem closing the statement then an error is raised. Closing a statement when there is an existing error is perfectly fine.
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 541
VALUE am_sqlite3_statement_close( VALUE self )
{
am_sqlite3_stmt *am_stmt;
int rc, existing_errcode;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
/* check the current error code to see if one exists, we could be
* closing a statement that has an error, and in that case we do not want to
* raise an additional error, we want to let the existing error stand
*/
existing_errcode = sqlite3_errcode( sqlite3_db_handle( am_stmt->stmt ) );
rc = sqlite3_finalize( am_stmt->stmt );
if ( (SQLITE_OK != rc) && (rc != existing_errcode) ) {
rb_raise(eAS_Error, "Failure to close statement : [SQLITE_ERROR %d] : %s\n",
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
am_stmt->stmt = NULL;
return Qnil;
}
|
#column_blob(index) ⇒ String
Return the data in ith column of the result as a String.
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 390
VALUE am_sqlite3_statement_column_blob(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
const char *data;
long length;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
data = sqlite3_column_blob( am_stmt->stmt, idx );
length = sqlite3_column_bytes( am_stmt->stmt, idx );
return rb_str_new( data, length );
}
|
#column_count ⇒ Fixnum
return the number of columns in the result set.
300 301 302 303 304 305 306 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 300
VALUE am_sqlite3_statement_column_count(VALUE self)
{
am_sqlite3_stmt *am_stmt;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return INT2FIX( sqlite3_column_count( am_stmt->stmt ) );
}
|
#column_database_name(index) ⇒ String
Return the database name where the data in the ith column of the result set comes from.
465 466 467 468 469 470 471 472 473 474 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 465
VALUE am_sqlite3_statement_column_database_name(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
const char *n ;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
n = sqlite3_column_database_name( am_stmt->stmt, idx ) ;
return ( n == NULL ? Qnil : rb_str_new2( n ) );
}
|
#column_declared_type(index) ⇒ String
Return the declared type of the ith column in the result set. This is the value that was in the original CREATE TABLE statement.
335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 335
VALUE am_sqlite3_statement_column_decltype(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
const char *decltype;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
decltype = sqlite3_column_decltype( am_stmt->stmt, idx ) ;
if ( NULL == decltype) {
return Qnil;
} else {
return rb_str_new2( decltype );
}
}
|
#column_double(index) ⇒ Float
Return the data in ith column of the result as an Float
412 413 414 415 416 417 418 419 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 412
VALUE am_sqlite3_statement_column_double(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return rb_float_new( sqlite3_column_double( am_stmt->stmt, idx )) ;
}
|
#column_int(index) ⇒ Integer
Return the data in ith column of the result as an Integer
429 430 431 432 433 434 435 436 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 429
VALUE am_sqlite3_statement_column_int(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return INT2NUM( sqlite3_column_int( am_stmt->stmt, idx )) ;
}
|
#column_int64(index) ⇒ Integer
Return the data in ith column of the result as an Integer
446 447 448 449 450 451 452 453 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 446
VALUE am_sqlite3_statement_column_int64(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return SQLINT64_2NUM( sqlite3_column_int64( am_stmt->stmt, idx )) ;
}
|
#column_name(index) ⇒ String
Return the column name at the ith column in the result set. The left-most column is number 0.
316 317 318 319 320 321 322 323 324 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 316
VALUE am_sqlite3_statement_column_name(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return rb_str_new2( sqlite3_column_name( am_stmt->stmt, idx ) );
}
|
#column_origin_name(index) ⇒ String
Return the column name where the data in the ith column of the result set comes from.
504 505 506 507 508 509 510 511 512 513 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 504
VALUE am_sqlite3_statement_column_origin_name(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
const char *n ;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
n = sqlite3_column_origin_name( am_stmt->stmt, idx );
return ( n == NULL ? Qnil : rb_str_new2( n ) );
}
|
#column_table_name(index) ⇒ String
Return the table name where the data in the ith column of the result set comes from.
484 485 486 487 488 489 490 491 492 493 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 484
VALUE am_sqlite3_statement_column_table_name(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
const char *n ;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
n = sqlite3_column_table_name( am_stmt->stmt, idx );
return ( n == NULL ? Qnil : rb_str_new2( n ) );
}
|
#column_text(index) ⇒ String
Return the data in ith column of the result as a String.
374 375 376 377 378 379 380 381 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 374
VALUE am_sqlite3_statement_column_text(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return rb_str_new2( (const char*)sqlite3_column_text( am_stmt->stmt, idx ) );
}
|
#column_type(index) ⇒ SQLite3::DataType constant
Return the column type at the ith column in the result set. The left-most column is number 0.
358 359 360 361 362 363 364 365 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 358
VALUE am_sqlite3_statement_column_type(VALUE self, VALUE v_idx)
{
am_sqlite3_stmt *am_stmt;
int idx = FIX2INT( v_idx );
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return INT2FIX( sqlite3_column_type( am_stmt->stmt, idx ) );
}
|
#parameter_count ⇒ Integer
return the index of the largest parameter in the in the statement. For all forms except ?NNN this is the number of unique parameters. Using ?NNN can create gaps in the list of parameters.
225 226 227 228 229 230 231 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 225
VALUE am_sqlite3_statement_bind_parameter_count(VALUE self)
{
am_sqlite3_stmt *am_stmt;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return INT2FIX(sqlite3_bind_parameter_count( am_stmt->stmt ) );
}
|
#parameter_index(name) ⇒ Integer
returns the index of the named parameter from the statement. Used to help with the :VVV, @VVV and $VVV pareamter replacement styles.
206 207 208 209 210 211 212 213 214 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 206
VALUE am_sqlite3_statement_bind_parameter_index(VALUE self, VALUE parameter_name)
{
am_sqlite3_stmt *am_stmt;
int idx;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
idx = sqlite3_bind_parameter_index( am_stmt->stmt, StringValuePtr( parameter_name ));
return INT2FIX( idx );
}
|
#remaining_sql ⇒ String
returns the remainging SQL leftover from the initialization sql, or nil if there is no remaining SQL
192 193 194 195 196 197 198 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 192
VALUE am_sqlite3_statement_remaining_sql(VALUE self)
{
am_sqlite3_stmt *am_stmt;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return am_stmt->remaining_sql;
}
|
#reset! ⇒ nil
reset the SQLite3 statement back to its initial state.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 239
VALUE am_sqlite3_statement_reset(VALUE self)
{
am_sqlite3_stmt *am_stmt;
int rc;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
if ( am_stmt->stmt ) {
rc = sqlite3_reset( am_stmt->stmt );
if ( rc != SQLITE_OK ) {
rb_raise(eAS_Error, "Error resetting statement: [SQLITE_ERROR %d] : %s\n",
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
return Qnil;
} else {
rb_raise(eAS_Error, "Attempting to free a non-existent statement");
}
}
|
#sql ⇒ String
Return a copy of the original string used to create the prepared statement.
522 523 524 525 526 527 528 529 530 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 522
VALUE am_sqlite3_statement_sql(VALUE self)
{
am_sqlite3_stmt *am_stmt;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return rb_str_new2( sqlite3_sql( am_stmt->stmt ) );
}
|
#step ⇒ Integer
Step through the next piece of the SQLite3 statement
285 286 287 288 289 290 291 |
# File 'ext/amalgalite/c/amalgalite_statement.c', line 285
VALUE am_sqlite3_statement_step(VALUE self)
{
am_sqlite3_stmt *am_stmt;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
return INT2FIX( sqlite3_step( am_stmt->stmt ) );
}
|