class Amalgalite::Requires::Bootstrap
Constants
- DEFAULT_BOOTSTRAP_TABLE
- DEFAULT_COMPRESSED_COLUMN
- DEFAULT_CONTENTS_COLUMN
- DEFAULT_DB
constants for default db, table, column, rowid, contents
- DEFAULT_FILENAME_COLUMN
- DEFAULT_ROWID_COLUMN
- DEFAULT_TABLE
Public Class Methods
WARNING WARNING WARNING WARNING WARNING WARNING WARNING
This is a boostrap mechanism to eval all the code in a particular column in a specially formatted table in an sqlite database. It should only be used for a specific purpose, mainly loading the Amalgalite ruby code directly from an sqlite table.
Amalgalite::Requires adds in the ability to require code that is in an sqlite database. Since Amalgalite::Requires is itself ruby code, if Amalgalite::Requires was in an sqlite database, it could not require itself. Therefore this method is made available. It is a pure C extension method that directly calls the sqlite3 C functions directly and uses the ruby C api to eval the data in the table.
This method attaches to an sqlite3 database (filename) and then does:
SELECT filename_column_name, content_column_name FROM table_name ORDER BY rowid_column_name
For each row returned it does an eval on the code in the content_column_name and then updates _$LOADED_FEATURES_ directly with the value from filename_column_name.
The database to be opened by lift must be an sqlite3 UTF-8 database.
VALUE am_bootstrap_lift( VALUE self, VALUE args ) { sqlite3 *db = NULL; int rc; char raise_msg[BUFSIZ]; VALUE tmp = Qnil; VALUE am_db_c = rb_const_get( cARB, rb_intern("DEFAULT_DB") ); char *dbfile = NULL; if ( Qnil == args ) { args = rb_hash_new(); } else { args = rb_ary_shift( args ); } Check_Type( args, T_HASH ); /* get the arguments */ dbfile = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "dbfile" ) ) ) ) ? StringValuePtr( am_db_c ) : StringValuePtr( tmp ); /* open the database */ rc = sqlite3_open_v2( dbfile , &db, SQLITE_OPEN_READONLY, NULL); if ( SQLITE_OK != rc ) { memset( raise_msg, 0, BUFSIZ ); snprintf(raise_msg, BUFSIZ, "Failure to open database %s for bootload: [SQLITE_ERROR %d] : %s", dbfile, rc, sqlite3_errmsg( db ) ); am_bootstrap_cleanup_and_raise( raise_msg, db, NULL ); } am_bootstrap_from_db( db, args ); /* close the database */ rc = sqlite3_close( db ); if ( SQLITE_OK != rc ) { memset( raise_msg, 0, BUFSIZ ); snprintf( raise_msg, BUFSIZ, "Failure to close database : [SQLITE_ERROR %d] : %s\n", rc, sqlite3_errmsg( db )), am_bootstrap_cleanup_and_raise( raise_msg, db, NULL ); } return Qnil; }
WARNING WARNING WARNING WARNING WARNING WARNING WARNING
This is a boostrap mechanism to eval all the code in a particular column in a specially formatted table in an sqlite database. It should only be used for a specific purpose, mainly loading the Amalgalite ruby code directly from an sqlite table.
Amalgalite::Requires adds in the ability to require code that is in an sqlite database. Since Amalgalite::Requires is itself ruby code, if Amalgalite::Requires was in an sqlite database, it could not require itself. Therefore this method is made available. It is a pure C extension method that directly calls the sqlite3 C functions directly and uses the ruby C api to eval the data in the table.
This method attaches to an sqlite3 database (filename) and then does:
SELECT filename_column_name, content_column_name FROM table_name ORDER BY rowid_column_name
For each row returned it does an eval on the code in the content_column_name and then updates _$LOADED_FEATURES_ directly with the value from filename_column_name.
The database to be opened by lift must be an sqlite3 UTF-8 database.
VALUE am_bootstrap_lift( VALUE self, VALUE args ) { sqlite3 *db = NULL; int rc; char raise_msg[BUFSIZ]; VALUE tmp = Qnil; VALUE am_db_c = rb_const_get( cARB, rb_intern("DEFAULT_DB") ); char *dbfile = NULL; if ( Qnil == args ) { args = rb_hash_new(); } else { args = rb_ary_shift( args ); } Check_Type( args, T_HASH ); /* get the arguments */ dbfile = ( Qnil == (tmp = rb_hash_aref( args, rb_str_new2( "dbfile" ) ) ) ) ? StringValuePtr( am_db_c ) : StringValuePtr( tmp ); /* open the database */ rc = sqlite3_open_v2( dbfile , &db, SQLITE_OPEN_READONLY, NULL); if ( SQLITE_OK != rc ) { memset( raise_msg, 0, BUFSIZ ); snprintf(raise_msg, BUFSIZ, "Failure to open database %s for bootload: [SQLITE_ERROR %d] : %s", dbfile, rc, sqlite3_errmsg( db ) ); am_bootstrap_cleanup_and_raise( raise_msg, db, NULL ); } am_bootstrap_from_db( db, args ); /* close the database */ rc = sqlite3_close( db ); if ( SQLITE_OK != rc ) { memset( raise_msg, 0, BUFSIZ ); snprintf( raise_msg, BUFSIZ, "Failure to close database : [SQLITE_ERROR %d] : %s\n", rc, sqlite3_errmsg( db )), am_bootstrap_cleanup_and_raise( raise_msg, db, NULL ); } return Qnil; }