Class: Amalgalite::SQLite3::Database::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/amalgalite/sqlite3/database/status.rb,
ext/amalgalite/c/amalgalite_database.c

Overview

A Stat represents a single Database Status code and its current highwater mark.

Some stats may not have a current or a highwater value, in those cases the associated has_current? or has_highwater? method returns false and the current or highwater method also returns nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_db, name) ⇒ Stat

Returns a new instance of Stat.



15
16
17
18
19
20
21
# File 'lib/amalgalite/sqlite3/database/status.rb', line 15

def initialize( api_db, name )
  @name      = name
  @code      = ::Amalgalite::SQLite3::Constants::DBStatus.value_from_name( name )
  @current   = nil
  @highwater = nil
  @api_db    = api_db 
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



13
14
15
# File 'lib/amalgalite/sqlite3/database/status.rb', line 13

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/amalgalite/sqlite3/database/status.rb', line 12

def name
  @name
end

Instance Method Details

#currentObject



23
24
25
26
# File 'lib/amalgalite/sqlite3/database/status.rb', line 23

def current
  update!
  return @current
end

#highwaterObject



28
29
30
31
# File 'lib/amalgalite/sqlite3/database/status.rb', line 28

def highwater
  update!
  return @highwater
end

#reset!Object

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



37
38
39
# File 'lib/amalgalite/sqlite3/database/status.rb', line 37

def reset!
  update!( true )
end

#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

Returns:

  • (nil)


231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'ext/amalgalite/c/amalgalite_database.c', line 231

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;
}