Class Amalgalite::SQLite3::Stat
In: lib/amalgalite/sqlite3/status.rb
ext/amalgalite3.c
Parent: Object

class encapsulating a single Stat

Methods

current   highwater   new   reset!   update!  

Attributes

code  [R] 
name  [R] 

Public Class methods

[Source]

    # File lib/amalgalite/sqlite3/status.rb, line 16
16:     def initialize( name )
17:       @name      = name
18:       @code      = ::Amalgalite::SQLite3::Constants::Status.value_from_name( name )
19:       @current   = nil
20:       @highwater = nil
21:     end

Public Instance methods

[Source]

    # File lib/amalgalite/sqlite3/status.rb, line 23
23:     def current
24:       update!
25:       return @current
26:     end

[Source]

    # File lib/amalgalite/sqlite3/status.rb, line 28
28:     def highwater
29:       update!
30:       return @highwater
31:     end

reset the given stat‘s highwater mark. This will also populate the _@current_ and _@highwater_ instance variables

[Source]

    # File lib/amalgalite/sqlite3/status.rb, line 37
37:     def reset!
38:       update!( true )
39:     end

Populates the _@current_ and _@higwater_ instance variables of self object with the values from the sqlite3_status call. If reset it true then the highwater mark for the stat is reset

[Source]

/*
 * call-seq:
 *    Amalgalite::SQLite3::Stat.update!( reset = false ) -> nil
 *
 * Populates the _@current_ and _@higwater_ instance variables of self
 * object with the values from the sqlite3_status call.  If reset it true then
 * the highwater mark for the stat is reset
 *
 */
VALUE am_sqlite3_stat_update_bang( int argc, VALUE *argv, VALUE self )
{
    int status_op  = -1;
    int current    = -1;
    int highwater  = -1;
    VALUE reset    = Qfalse;
    int reset_flag = 0;
    int rc;

    status_op  = FIX2INT( rb_iv_get( self, "@code" ) );
    if ( argc > 0 ) {
        reset = argv[0];
        reset_flag = ( Qtrue == reset ) ? 1 : 0 ;
    }

    rc = sqlite3_status( status_op, &current, &highwater, reset_flag );

    if ( SQLITE_OK != rc ) {
        VALUE n    = rb_iv_get( self,  "@name" ) ;
        char* name = StringValuePtr( n );
        rb_raise(eAS_Error, "Failure to retrieve status for %s : [SQLITE_ERROR %d] \n", name, rc);
    }

    rb_iv_set( self, "@current", INT2NUM( current ) );
    rb_iv_set( self, "@highwater", INT2NUM( highwater) );

    return Qnil;
}

[Validate]