Class: ladybug::PreparedStatement

Inherits:
Object
  • Object
show all
Defined in:
ext/ladybug_ext/prepared_statement.c

Instance Method Summary collapse

Instance Method Details

#bind_variable(name, value) ⇒ Object

Binds the given value to the given parameter name in the prepared statement



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'ext/ladybug_ext/prepared_statement.c', line 251

static VALUE
rlbug_prepared_statement_bind_variable( VALUE self, VALUE name, VALUE value )
{
	rlbug_prepared_statement *stmt = CHECK_PREPARED_STATEMENT( self );
	VALUE name_string = rb_funcall( name, rb_intern("to_s"), 0 );
	const char *name_s = StringValueCStr( name_string );
	lbug_value *null_value;

	switch (TYPE(value)) {
		case T_TRUE:
		case T_FALSE:
			lbug_prepared_statement_bind_bool( &stmt->statement, name_s, RTEST(value) );
			break;

		// fallthrough
		case T_FLOAT:
			lbug_prepared_statement_bind_float( &stmt->statement, name_s, NUM2DBL(value) );
			break;

		case T_BIGNUM:
			lbug_prepared_statement_bind_int64( &stmt->statement, name_s, NUM2LL(value) );
			break;

		case T_FIXNUM:
			lbug_prepared_statement_bind_int32( &stmt->statement, name_s, NUM2INT(value) );
			break;

		case T_SYMBOL:
			rb_notimplement();
			break; // not reached

		case T_NIL:
			null_value = lbug_value_create_null();
			lbug_prepared_statement_bind_value( &stmt->statement, name_s, null_value );
			lbug_value_destroy( null_value );
			break;

		case T_OBJECT:
		case T_CLASS:
		case T_MODULE:
		case T_REGEXP:
		case T_ARRAY:
		case T_HASH:
		case T_STRUCT:
		case T_COMPLEX:
		case T_RATIONAL:
		case T_FILE:
		case T_DATA:
		case T_STRING:
		default:
			rlbug_bind_string( stmt, name_s, value );
			break;

			// lbug_prepared_statement_bind_int8
			// lbug_prepared_statement_bind_int16
			// lbug_prepared_statement_bind_uint64
			// lbug_prepared_statement_bind_uint32
			// lbug_prepared_statement_bind_uint16
			// lbug_prepared_statement_bind_uint8

			// lbug_prepared_statement_bind_double
			// lbug_prepared_statement_bind_date
			// lbug_prepared_statement_bind_timestamp_ns
			// lbug_prepared_statement_bind_timestamp_sec
			// lbug_prepared_statement_bind_timestamp_tz
			// lbug_prepared_statement_bind_timestamp_ms
			// lbug_prepared_statement_bind_timestamp
			// lbug_prepared_statement_bind_interval
			// lbug_prepared_statement_bind_value
	}

	return Qtrue;
}

#connectionObject

Return the Ladybug::Connection used to run this statement.



341
342
343
344
345
346
# File 'ext/ladybug_ext/prepared_statement.c', line 341

static VALUE
rlbug_prepared_statement_connection( VALUE self )
{
	rlbug_prepared_statement *statement_s = rlbug_get_prepared_statement( self );
	return statement_s->connection;
}

#queryString

Return the query string used to build this statement.

Returns:

  • (String)


356
357
358
359
360
361
# File 'ext/ladybug_ext/prepared_statement.c', line 356

static VALUE
rlbug_prepared_statement_query( VALUE self )
{
	rlbug_prepared_statement *statement_s = rlbug_get_prepared_statement( self );
	return statement_s->query;
}

#success?Boolean

Returns true if the query was prepared successfully.

Returns:

  • (Boolean)


231
232
233
234
235
236
237
238
239
240
241
# File 'ext/ladybug_ext/prepared_statement.c', line 231

static VALUE
rlbug_prepared_statement_success_p( VALUE self )
{
	rlbug_prepared_statement *stmt = CHECK_PREPARED_STATEMENT( self );

	if ( lbug_prepared_statement_is_success(&stmt->statement) ) {
		return Qtrue;
	} else {
		return Qfalse;
	}
}