Module: Amalgalite::SQLite3
- Defined in:
- ext/amalgalite/c/amalgalite.c,
ext/amalgalite/c/amalgalite_blob.c,
ext/amalgalite/c/amalgalite_database.c,
ext/amalgalite/c/amalgalite_constants.c,
ext/amalgalite/c/amalgalite_statement.c
Defined Under Namespace
Modules: Constants Classes: Blob, Error, Statement
Class Method Summary collapse
-
.Amalgalite::SQLite3.complete?(..., opts = { :utf16) ⇒ Boolean
Is the text passed in as a parameter a complete SQL statement? Or is additional input required before sending the SQL to the extension.
-
.Amalgalite::SQLite.escape(string) ⇒ Object
Takes the input string and escapes each ‘ (single quote) character by doubling it.
-
.Amalgalite::SQLite.quote(string) ⇒ Object
Takes the input string and surrounds it with single quotes, it also escapes each embedded single quote with double quotes.
-
.Amalgalite::SQLite3.randomness(N) ⇒ String of length N
Generate N bytes of random data.
-
.Amalgalite::SQLite.temp_directory ⇒ String?
Return the directory name that all that all the temporary files created by SQLite creates will be placed.
-
.Amalgalite::SQLite.temp_directory( = "/tmp/location") ⇒ Object
Set the temporary directory used by sqlite to store temporary directories.
-
.Amalgalite::SQLite3.threadsafe? ⇒ Boolean
Has the SQLite3 extension been compiled “threadsafe”.
Class Method Details
.Amalgalite::SQLite3.complete?(..., opts = { :utf16) ⇒ Boolean
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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/amalgalite/c/amalgalite.c', line 135
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) ⇒ Object
Takes the input string and escapes each ‘ (single quote) character by doubling it.
106 107 108 109 |
# File 'ext/amalgalite/c/amalgalite.c', line 106
VALUE am_sqlite3_escape( VALUE self, VALUE string )
{
return ( Qnil == string ) ? Qnil : amalgalite_format_string( "%q", string );
}
|
.Amalgalite::SQLite.quote(string) ⇒ Object
Takes the input string and surrounds it with single quotes, it also escapes each embedded single quote with double quotes.
118 119 120 121 |
# File 'ext/amalgalite/c/amalgalite.c', line 118
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
Generate N bytes of random data.
200 201 202 203 204 205 206 207 |
# File 'ext/amalgalite/c/amalgalite.c', line 200
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 );
}
|
.Amalgalite::SQLite.temp_directory ⇒ String?
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.
47 48 49 50 51 52 53 54 |
# File 'ext/amalgalite/c/amalgalite.c', line 47
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") ⇒ Object
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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/amalgalite/c/amalgalite.c', line 64
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? ⇒ Boolean
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.
30 31 32 33 34 35 36 37 |
# File 'ext/amalgalite/c/amalgalite.c', line 30
VALUE am_sqlite3_threadsafe(VALUE self)
{
if (sqlite3_threadsafe()) {
return Qtrue;
} else {
return Qfalse;
}
}
|