@@ -506,33 +506,40 @@ stmt_stat_internal(VALUE hash_or_sym, sqlite3_stmt *stmt)
506506 return 0 ;
507507}
508508
509+ /* call-seq: stmt.stats_as_hash(hash)
510+ *
511+ * Returns a Hash containing information about the statement.
512+ */
513+ static VALUE
514+ stats_as_hash (VALUE self )
515+ {
516+ sqlite3StmtRubyPtr ctx ;
517+ TypedData_Get_Struct (self , sqlite3StmtRuby , & statement_type , ctx );
518+ REQUIRE_OPEN_STMT (ctx );
519+ VALUE arg = rb_hash_new ();
520+
521+ stmt_stat_internal (arg , ctx -> st );
522+ return arg ;
523+ }
524+
509525/* call-seq: stmt.stmt_stat(hash_or_key)
510526 *
511527 * Returns a Hash containing information about the statement.
512528 */
513529static VALUE
514- stmt_stat (VALUE self , VALUE arg ) // arg is (nil || hash || symbol )
530+ stat_for (VALUE self , VALUE key )
515531{
516532 sqlite3StmtRubyPtr ctx ;
517533 TypedData_Get_Struct (self , sqlite3StmtRuby , & statement_type , ctx );
518534 REQUIRE_OPEN_STMT (ctx );
519535
520- if (NIL_P (arg )) {
521- arg = rb_hash_new ();
522- }
523- else if (SYMBOL_P (arg )) {
524- size_t value = stmt_stat_internal (arg , ctx -> st );
536+ if (SYMBOL_P (key )) {
537+ size_t value = stmt_stat_internal (key , ctx -> st );
525538 return SIZET2NUM (value );
526539 }
527- else if (RB_TYPE_P (arg , T_HASH )) {
528- // ok
529- }
530540 else {
531- rb_raise (rb_eTypeError , "non-hash or symbol given" );
541+ rb_raise (rb_eTypeError , "non-symbol given" );
532542 }
533-
534- stmt_stat_internal (arg , ctx -> st );
535- return arg ;
536543}
537544
538545#ifdef SQLITE_STMTSTATUS_MEMUSED
@@ -587,10 +594,11 @@ init_sqlite3_statement(void)
587594 rb_define_method (cSqlite3Statement , "column_name" , column_name , 1 );
588595 rb_define_method (cSqlite3Statement , "column_decltype" , column_decltype , 1 );
589596 rb_define_method (cSqlite3Statement , "bind_parameter_count" , bind_parameter_count , 0 );
590- rb_define_method (cSqlite3Statement , "stmt_stat" , stmt_stat , 1 );
591597#ifdef SQLITE_STMTSTATUS_MEMUSED
592598 rb_define_method (cSqlite3Statement , "memused" , memused , 0 );
593599#endif
594600
595601 rb_define_private_method (cSqlite3Statement , "prepare" , prepare , 2 );
602+ rb_define_private_method (cSqlite3Statement , "stats_as_hash" , stats_as_hash , 0 );
603+ rb_define_private_method (cSqlite3Statement , "stat_for" , stat_for , 1 );
596604}
0 commit comments