Skip to content

Commit

Permalink
added automatic support for and an eh? method for sqlcipher
Browse files Browse the repository at this point in the history
  • Loading branch information
WA9ACE committed Jun 6, 2018
1 parent 3fd6dda commit 16e4ee8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

# --with-sqlite3-{dir,include,lib}
if with_config('sqlcipher')
$CFLAGS << ' -DUSING_SQLCIPHER'
dir_config("sqlcipher", cppflags, ldflags)
$CFLAGS << ' -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2'
else
dir_config("sqlite3", cppflags, ldflags)
end
Expand All @@ -67,7 +67,7 @@ def asplode missing
find_library 'pthread', 'pthread_create' # 1.8 support. *shrug*

if with_config('sqlcipher')
asplode('sqlcipher') unless find_library 'sqlcipher', 'codec_get_cipher_version'
asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
else
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
end
Expand Down
14 changes: 7 additions & 7 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ static VALUE libversion(VALUE UNUSED(klass))
return INT2NUM(sqlite3_libversion_number());
}

#ifdef CIPHER_VERSION
static VALUE cipherversion(VALUE UNUSED(klass))
static VALUE using_sqlcipher(VALUE UNUSED(klass))
{
return rb_str_new2(codec_get_cipher_version());
}
#ifdef USING_SQLCIPHER
return Qtrue;
#else
return Qfalse;
#endif
}

/* Returns the compile time setting of the SQLITE_THREADSAFE flag.
* See: https://www.sqlite.org/c3ref/threadsafe.html
Expand Down Expand Up @@ -151,9 +153,7 @@ void Init_sqlite3_native()
#ifdef HAVE_SQLITE3_BACKUP_INIT
init_sqlite3_backup();
#endif
#ifdef CIPHER_VERSION
rb_define_singleton_method(mSqlite3, "cipherversion", cipherversion, 0);
#endif
rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
Expand Down
9 changes: 0 additions & 9 deletions test/test_sqlcipher.rb

This file was deleted.

0 comments on commit 16e4ee8

Please sign in to comment.