module Amalgalite::SQLite3

The SQLite ruby extension inside Amalgalite.

Constants

VERSION

Version of SQLite that ships with Amalgalite

Public Class Methods

Amalgalite::SQLite3.complete?( ... , opts = { :utf16 => false }) → True, False click to toggle source

Is the text passed in as a parameter a complete SQL statement? Or is additional input required before sending the SQL to the extension. If the extra 'opts' parameter is used, you can send in a UTF-16 encoded string as the SQL.

A complete statement must end with a semicolon.

VALUE am_sqlite3_complete(VALUE self, VALUE args)
{
    VALUE sql      = rb_ary_shift( args );
    VALUE opts     = rb_ary_shift( args );
    VALUE utf16    = Qnil;
    int   result = 0;

    if ( ( Qnil != opts ) && ( T_HASH == TYPE(opts) ) ){
        utf16 = rb_hash_aref( opts, rb_intern("utf16") );
    }

    if ( (Qfalse == utf16) || (Qnil == utf16) ) {
        result = sqlite3_complete( StringValuePtr( sql ) );
    } else {
        result = sqlite3_complete16( (void*) StringValuePtr( sql ) );
    }

    return ( result > 0 ) ? Qtrue : Qfalse;
}
Amalgalite::SQLite.escape( string ) → escaped_string click to toggle source

Takes the input string and escapes each ' (single quote) character by doubling it.

VALUE am_sqlite3_escape( VALUE self, VALUE string )
{ 
    return ( Qnil == string ) ? Qnil : amalgalite_format_string( "%q", string );
}
Amalgalite::SQLite.quote( string ) → quoted-escaped string click to toggle source

Takes the input string and surrounds it with single quotes, it also escapes each embedded single quote with double quotes.

VALUE am_sqlite3_quote( VALUE self, VALUE string )
{
    return ( Qnil == string ) ? Qnil : amalgalite_format_string( "%Q", string );
}
Amalgalite::SQLite3.randomness( N ) → String of length N click to toggle source

Generate N bytes of random data.

VALUE am_sqlite3_randomness(VALUE self, VALUE num_bytes)
{
    int n     = NUM2INT(num_bytes);
    char *buf = ALLOCA_N(char, n);

    sqlite3_randomness( n, buf );
    return rb_str_new( buf, n );
}
status() click to toggle source

return the status object for the sqlite database

# File lib/amalgalite/sqlite3/status.rb, line 57
def self.status
  @status ||= Status.new
end
Amalgalite::SQLite.temp_directory → String or nil click to toggle source

Return the directory name that all that all the temporary files created by SQLite creates will be placed. If nil is returned, then SQLite will search for an appropriate directory.

VALUE am_sqlite3_get_temp_directory( VALUE self )
{
    if (NULL == sqlite3_temp_directory) {
        return Qnil;
    } else {
        return rb_str_new2( sqlite3_temp_directory );
    }
}
Amalgalite::SQLite.temp_directory = "/tmp/location" click to toggle source

Set the temporary directory used by sqlite to store temporary directories. It is not safe to set this value after a Database has been opened.

VALUE am_sqlite3_set_temp_directory( VALUE self, VALUE new_dir )
{
    char *p   = NULL ;

    if ( NULL != sqlite3_temp_directory ) {
        free( sqlite3_temp_directory );
    }

    if ( Qnil != new_dir ) {
        VALUE str = StringValue( new_dir );

        p = calloc( RSTRING_LEN(str) + 1, sizeof(char) );
        strncpy( p, RSTRING_PTR(str), RSTRING_LEN(str) );
    }

    sqlite3_temp_directory = p;

    return Qnil;
}
Amalgalite::SQLite3.threadsafe? → true or false click to toggle source

Has the SQLite3 extension been compiled “threadsafe”. If threadsafe? is true then the internal SQLite mutexes are enabled and SQLite is threadsafe. That is threadsafe within the context of 'C' threads.

VALUE am_sqlite3_threadsafe(VALUE self)
{
    if (sqlite3_threadsafe()) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}