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

Ecapuslate a SQLite3 Database stat

Methods

current   highwater   new   reset!   update!  

Attributes

code  [R] 
name  [R] 

Public Class methods

[Source]

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

Public Instance methods

[Source]

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

[Source]

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

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

[Source]

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

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

[Source]

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

    am_sqlite3    *am_db;

    VALUE reset    = Qfalse;
    VALUE db       = rb_iv_get( self, "@api_db" );

    Data_Get_Struct(db, am_sqlite3, am_db);

    if ( argc > 0 ) {
        reset = argv[0];
        reset_flag = ( Qtrue == reset ) ? 1 : 0 ;
    }

    rc = sqlite3_db_status( am_db->db, 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 database 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]