Module: Libsql::SQLite3

Defined in:
ext/libsql/c/libsql_ext.c,
ext/libsql/c/libsql_blob.c,
ext/libsql/c/libsql_database.c,
ext/libsql/c/libsql_constants.c,
ext/libsql/c/libsql_statement.c

Defined Under Namespace

Modules: Constants Classes: Blob, Error, Statement

Class Method Summary collapse

Class Method Details

.Libsql::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.

Returns:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'ext/libsql/c/libsql_ext.c', line 136

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

.Libsql::SQLite.escape(string) ⇒ Object

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



107
108
109
110
# File 'ext/libsql/c/libsql_ext.c', line 107

VALUE libsql_ext_sqlite3_escape( VALUE self, VALUE string )
{ 
    return ( Qnil == string ) ? Qnil : libsql_ext_format_string( "%q", string );
}

.Libsql::SQLite.quote(string) ⇒ Object

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



119
120
121
122
# File 'ext/libsql/c/libsql_ext.c', line 119

VALUE libsql_ext_sqlite3_quote( VALUE self, VALUE string )
{
    return ( Qnil == string ) ? Qnil : libsql_ext_format_string( "%Q", string );
}

.Libsql::SQLite3.randomness(N) ⇒ String of length N

Generate N bytes of random data.

Returns:

  • (String of length N)


201
202
203
204
205
206
207
208
# File 'ext/libsql/c/libsql_ext.c', line 201

VALUE libsql_ext_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 );
}

.Libsql::SQLite.temp_directoryString?

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.

Returns:

  • (String, nil)


48
49
50
51
52
53
54
55
# File 'ext/libsql/c/libsql_ext.c', line 48

VALUE libsql_ext_sqlite3_get_temp_directory( VALUE self )
{
    if (NULL == sqlite3_temp_directory) {
        return Qnil;
    } else {
        return rb_str_new2( sqlite3_temp_directory );
    }
}

.Libsql::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.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/libsql/c/libsql_ext.c', line 65

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

.Libsql::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.

Returns:



31
32
33
34
35
36
37
38
# File 'ext/libsql/c/libsql_ext.c', line 31

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