Class: ladybug::Result
- Inherits:
-
Object
- Object
- ladybug::Result
- Defined in:
- ext/ladybug_ext/result.c
Class Method Summary collapse
-
.Ladybug::Result.from_next_set(result) ⇒ Object
Return a Ladybug::Result for the next result set after the specified
result.
Instance Method Summary collapse
-
#finish ⇒ Object
Discard a result and free up its memory.
-
#finished? ⇒ Boolean
Returns
trueif the receiver has been finished. -
#get_column_names ⇒ Object
Returns the names of the columns of the results as an Array of Strings.
-
#get_next_values ⇒ Object
Returns the next tuple of the query result values if there is one, otherwise returns
nil. -
#has_next? ⇒ Boolean
Returns true if we have not consumed all tuples in the query result, false otherwise.
-
#has_next_set? ⇒ Boolean
Returns true if there was more than one result set in the results, and the current set is not the last one.
-
#num_columns ⇒ Integer
Returns the number of columns in the query result.
-
#num_tuples ⇒ Integer
Returns the number of tuples in the query result.
-
#reset_iterator ⇒ Object
Resets the iterator of the query result to the beginning.
-
#success? ⇒ Boolean
Returns true if the query is executed successful, false otherwise.
-
#to_s ⇒ String
Returns the result as a String.
Class Method Details
.Ladybug::Result.from_next_set(result) ⇒ Object
Return a Ladybug::Result for the next result set after the specified result.
Returns nil if there is no next result set..
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'ext/ladybug_ext/result.c', line 169
static VALUE
rlbug_result_s_from_next_set( VALUE klass, VALUE result )
{
rlbug_query_result *start_result = rlbug_get_result( result );
rlbug_query_result *next_result;
VALUE result_obj;
if ( RTEST(start_result->next_result) ) {
return start_result->next_result;
}
if ( !lbug_query_result_has_next_query_result(&start_result->result) ) {
return Qnil;
}
next_result = rlbug_result_alloc();
if ( lbug_query_result_get_next_query_result(&start_result->result, &next_result->result) != LbugSuccess ) {
char *err_detail = lbug_query_result_get_error_message( &next_result->result );
char errmsg[ 4096 ] = "\0";
snprintf( errmsg, 4096, "Could not fetch next query result set: %s.", err_detail );
xfree( next_result );
next_result = NULL;
lbug_destroy_string( err_detail );
rb_raise( rlbug_eQueryError, "%s", errmsg );
}
DEBUG_GC( ">>> allocated result %p\n", next_result );
result_obj = rb_class_new_instance( 0, 0, klass );
RTYPEDDATA_DATA( result_obj ) = next_result;
next_result->connection = start_result->connection;
next_result->previous_result = result;
start_result->next_result = result_obj;
return result_obj;
}
|
Instance Method Details
#finish ⇒ Object
Discard a result and free up its memory. An exception is raised if the result is used after this call.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'ext/ladybug_ext/result.c', line 428
static VALUE
rlbug_result_finish( VALUE self )
{
rlbug_query_result *result = CHECK_RESULT( self );
lbug_query_result *i_result = &result->result;
VALUE related_res;
if ( !result->finished ) {
DEBUG_GC( ">>> Finishing %p\n", result );
result->finished = true;
if ( i_result->_query_result != NULL ) {
lbug_query_result_destroy( i_result );
}
if ( RTEST(result->previous_result) ) {
related_res = result->previous_result;
result->previous_result = Qnil;
rb_funcall( related_res, rb_intern("finish"), 0 );
}
if ( RTEST(result->next_result) ) {
related_res = result->next_result;
result->next_result = Qnil;
rb_funcall( related_res, rb_intern("finish"), 0 );
}
}
return Qtrue;
}
|
#finished? ⇒ Boolean
Returns true if the receiver has been finished.
465 466 467 468 469 470 471 472 473 474 |
# File 'ext/ladybug_ext/result.c', line 465
static VALUE
rlbug_result_finished_p( VALUE self )
{
rlbug_query_result *result = CHECK_RESULT( self );
if ( result->finished ) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#get_column_names ⇒ Object
Returns the names of the columns of the results as an Array of Strings.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'ext/ladybug_ext/result.c', line 401
static VALUE
rlbug_result_get_column_names( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
uint64_t col_count = lbug_query_result_get_num_columns( &result->result );
char *name;
VALUE rval = rb_ary_new();
for ( uint64_t i = 0 ; i < col_count ; i++ ) {
if ( lbug_query_result_get_column_name(&result->result, i, &name) != LbugSuccess ) {
rb_raise( rlbug_eError, "couldn't fetch name of column %llu", i );
}
rb_ary_push( rval, rb_str_new2(name) );
}
return rval;
}
|
#get_next_values ⇒ Object
Returns the next tuple of the query result values if there is one, otherwise
returns nil.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'ext/ladybug_ext/result.c', line 354
static VALUE
rlbug_result_get_next_values( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
lbug_flat_tuple tuple;
lbug_logical_type column_type;
lbug_value column_value;
uint64_t column_count = lbug_query_result_get_num_columns( &result->result );
VALUE current_value = Qnil,
rval = rb_ary_new();
if ( !lbug_query_result_has_next(&result->result) ) {
return Qnil;
}
if ( lbug_query_result_get_next(&result->result, &tuple) != LbugSuccess ) {
char *err_detail = lbug_query_result_get_error_message( &result->result );
char errmsg[ 4096 ] = "\0";
snprintf( errmsg, 4096, "Could not fetch next tuple: %s.", err_detail );
lbug_destroy_string( err_detail );
rb_raise( rlbug_eQueryError, "%s", errmsg );
}
for ( uint64_t i = 0 ; i < column_count ; i++ ) {
lbug_query_result_get_column_data_type( &result->result, i, &column_type );
lbug_flat_tuple_get_value( &tuple, i, &column_value );
current_value = rlbug_convert_logical_lbug_value_to_ruby( &column_type, &column_value );
rb_ary_push( rval, current_value );
}
lbug_flat_tuple_destroy( &tuple );
return rval;
}
|
#has_next? ⇒ Boolean
Returns true if we have not consumed all tuples in the query result, false otherwise.
295 296 297 298 299 300 301 302 303 304 305 |
# File 'ext/ladybug_ext/result.c', line 295
static VALUE
rlbug_result_has_next_p( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
if ( lbug_query_result_has_next(&result->result) ) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#has_next_set? ⇒ Boolean
Returns true if there was more than one result set in the results, and the current set is not the last one. You can call #next_set to move on to the next result set.
317 318 319 320 321 322 323 324 325 326 327 |
# File 'ext/ladybug_ext/result.c', line 317
static VALUE
rlbug_result_has_next_set_p( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
if ( lbug_query_result_has_next_query_result(&result->result) ) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#num_columns ⇒ Integer
Returns the number of columns in the query result.
240 241 242 243 244 245 246 247 |
# File 'ext/ladybug_ext/result.c', line 240
static VALUE
rlbug_result_num_columns( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
const uint64_t count = lbug_query_result_get_num_columns( &result->result );
return ULONG2NUM( count );
}
|
#num_tuples ⇒ Integer
Returns the number of tuples in the query result.
257 258 259 260 261 262 263 264 |
# File 'ext/ladybug_ext/result.c', line 257
static VALUE
rlbug_result_num_tuples( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
const uint64_t count = lbug_query_result_get_num_tuples( &result->result );
return ULONG2NUM( count );
}
|
#reset_iterator ⇒ Object
Resets the iterator of the query result to the beginning.
337 338 339 340 341 342 343 |
# File 'ext/ladybug_ext/result.c', line 337
static VALUE
rlbug_result_reset_iterator( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
lbug_query_result_reset_iterator( &result->result );
return Qtrue;
}
|
#success? ⇒ Boolean
Returns true if the query is executed successful, false otherwise.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/ladybug_ext/result.c', line 220
static VALUE
rlbug_result_success_p( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
if ( lbug_query_result_is_success(&result->result) ) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#to_s ⇒ String
Returns the result as a String.
274 275 276 277 278 279 280 281 282 283 284 |
# File 'ext/ladybug_ext/result.c', line 274
static VALUE
rlbug_result_to_s( VALUE self )
{
rlbug_query_result *result = rlbug_get_result( self );
char *string = lbug_query_result_to_string( &result->result );
VALUE rval = rb_str_new2( string );
lbug_destroy_string( string );
return rval;
}
|