do_sqlite3-0.10.13/0000755000004100000410000000000012154173164013756 5ustar www-datawww-datado_sqlite3-0.10.13/ext/0000755000004100000410000000000012154173164014556 5ustar www-datawww-datado_sqlite3-0.10.13/ext/do_sqlite3/0000755000004100000410000000000012154173164016624 5ustar www-datawww-datado_sqlite3-0.10.13/ext/do_sqlite3/extconf.rb0000644000004100000410000000164712154173164020627 0ustar www-datawww-dataENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/ # Loads mkmf which is used to make makefiles for Ruby extensions require 'mkmf' require 'date' # Allow for custom compiler to be specified. RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] # Use some default search paths dir_config("sqlite3", ["/usr/local", "/opt/local", "/usr"]) # NOTE: use GCC flags unless Visual C compiler is used $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/ if RUBY_VERSION < '1.8.6' $CFLAGS << ' -DRUBY_LESS_THAN_186' end unless DateTime.respond_to?(:new!) $CFLAGS << ' -DHAVE_NO_DATETIME_NEWBANG' end # Do the work # create_makefile(extension_name) if have_header( "sqlite3.h" ) && have_library( "sqlite3", "sqlite3_open" ) have_func("localtime_r") have_func("gmtime_r") have_func("sqlite3_prepare_v2") have_func("sqlite3_open_v2") have_func("sqlite3_enable_load_extension") create_makefile('do_sqlite3/do_sqlite3') end do_sqlite3-0.10.13/ext/do_sqlite3/do_sqlite3.h0000644000004100000410000000052112154173164021041 0ustar www-datawww-data#ifndef DO_SQLITE3_H #define DO_SQLITE3_H #include #include #include #include #include #include #include "compat.h" #ifndef HAVE_SQLITE3_PREPARE_V2 #define sqlite3_prepare_v2 sqlite3_prepare #endif extern VALUE mDO_Sqlite3; extern void Init_do_sqlite3_extension(); #endif do_sqlite3-0.10.13/ext/do_sqlite3/compat.h0000644000004100000410000000165312154173164020265 0ustar www-datawww-data#ifndef RUBY_COMPAT_H #define RUBY_COMPAT_H /* * Rules for better ruby C extensions: * * Never use the R macros directly, always use R_ * * Never compare with RBASIC(obj)->klass, always use * rb_obj_is_instance_of() * * Never use RHASH(obj)->tbl or RHASH_TBL(). * */ // Array #ifndef RARRAY_PTR #define RARRAY_PTR(obj) RARRAY(obj)->ptr #endif #ifndef RARRAY_LEN #define RARRAY_LEN(obj) RARRAY(obj)->len #endif // String #ifndef RSTRING_PTR #define RSTRING_PTR(obj) RSTRING(obj)->ptr #endif #ifndef RSTRING_LEN #define RSTRING_LEN(obj) RSTRING(obj)->len #endif #ifndef rb_str_ptr #define rb_str_ptr(str) RSTRING_PTR(str) #endif #ifndef rb_str_ptr_readonly #define rb_str_ptr_readonly(str) RSTRING_PTR(str) #endif #ifndef rb_str_flush #define rb_str_flush(str) #endif #ifndef rb_str_update #define rb_str_update(str) #endif #ifndef rb_str_len #define rb_str_len(str) RSTRING_LEN(str) #endif #endif do_sqlite3-0.10.13/ext/do_sqlite3/do_sqlite3_extension.c0000644000004100000410000000452412154173164023137 0ustar www-datawww-data#include #include "do_common.h" #include "do_sqlite3.h" VALUE cDO_Sqlite3Extension; /*****************************************************/ /* File used for providing extensions on the default */ /* API that are driver specific. */ /*****************************************************/ VALUE do_sqlite3_cExtension_enable_load_extension(VALUE self, VALUE on) { #ifdef HAVE_SQLITE3_ENABLE_LOAD_EXTENSION VALUE id_connection = rb_intern("connection"); VALUE connection = rb_funcall(self, id_connection, 0); if (connection == Qnil) { return Qfalse; } // Retrieve the actual connection from the VALUE sqlite3_connection = rb_iv_get(connection, "@connection"); if (sqlite3_connection == Qnil) { return Qfalse; } sqlite3 *db; Data_Get_Struct(sqlite3_connection, sqlite3, db); if (!(db = DATA_PTR(connection))) { return Qfalse; } int status = sqlite3_enable_load_extension(db, on == Qtrue ? 1 : 0); if (status != SQLITE_OK) { rb_raise(eDO_ConnectionError, "Couldn't enable extension loading"); } return Qtrue; #else return Qfalse; #endif } VALUE do_sqlite3_cExtension_load_extension(VALUE self, VALUE path) { #ifdef HAVE_SQLITE3_ENABLE_LOAD_EXTENSION VALUE connection = rb_iv_get(self, "@connection"); if (connection == Qnil) { return Qfalse; } // Retrieve the actual connection from the object VALUE sqlite3_connection = rb_iv_get(connection, "@connection"); if (sqlite3_connection == Qnil) { return Qfalse; } sqlite3 *db; Data_Get_Struct(sqlite3_connection, sqlite3, db); const char *extension_path = rb_str_ptr_readonly(path); char *errmsg = sqlite3_malloc(1024); if (!errmsg) { return Qfalse; } int status = sqlite3_load_extension(db, extension_path, 0, &errmsg); if (status != SQLITE_OK) { VALUE errexp = rb_exc_new2(eDO_ConnectionError, errmsg); sqlite3_free(errmsg); rb_exc_raise(errexp); } sqlite3_free(errmsg); return Qtrue; #else return Qfalse; #endif } void Init_do_sqlite3_extension() { cDO_Sqlite3Extension = rb_define_class_under(mDO_Sqlite3, "Extension", cDO_Extension); rb_global_variable(&cDO_Sqlite3Extension); rb_define_method(cDO_Sqlite3Extension, "load_extension", do_sqlite3_cExtension_load_extension, 1); rb_define_method(cDO_Sqlite3Extension, "enable_load_extension", do_sqlite3_cExtension_enable_load_extension, 1); } do_sqlite3-0.10.13/ext/do_sqlite3/do_common.c0000644000004100000410000003400612154173164020745 0ustar www-datawww-data#include #include #include #include #include #include "do_common.h" /* * Common variables ("globals") */ // To store rb_intern values ID DO_ID_NEW; ID DO_ID_NEW_DATE; ID DO_ID_CONST_GET; ID DO_ID_RATIONAL; ID DO_ID_ESCAPE; ID DO_ID_STRFTIME; ID DO_ID_LOG; // Reference to Extlib module VALUE mExtlib; VALUE rb_cByteArray; // References to DataObjects base classes VALUE mDO; VALUE cDO_Quoting; VALUE cDO_Connection; VALUE cDO_Command; VALUE cDO_Result; VALUE cDO_Reader; VALUE cDO_Logger; VALUE cDO_Logger_Message; VALUE cDO_Extension; VALUE eDO_ConnectionError; VALUE eDO_DataError; // References to Ruby classes that we'll need VALUE rb_cDate; VALUE rb_cDateTime; VALUE rb_cBigDecimal; /* * Common Functions */ VALUE data_objects_const_get(VALUE scope, const char *constant) { return rb_funcall(scope, DO_ID_CONST_GET, 1, rb_str_new2(constant)); } void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) { struct timeval stop; VALUE message; do_int64 duration; gettimeofday(&stop, NULL); duration = (stop.tv_sec - start->tv_sec) * 1000000 + stop.tv_usec - start->tv_usec; message = rb_funcall(cDO_Logger_Message, DO_ID_NEW, 3, string, rb_time_new(start->tv_sec, start->tv_usec), INT2NUM(duration)); rb_funcall(connection, DO_ID_LOG, 1, message); } void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, const char *message, VALUE query, VALUE state) { const char *exception_type = "SQLError"; const struct errcodes *e; VALUE uri, exception; for (e = errors; e->error_name; e++) { if (e->error_no == errnum) { // return the exception type for the matching error exception_type = e->exception; break; } } uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0); exception = rb_funcall( data_objects_const_get(mDO, exception_type), DO_ID_NEW, 5, rb_str_new2(message), INT2NUM(errnum), state, query, uri ); rb_exc_raise(exception); } char *data_objects_get_uri_option(VALUE query_hash, const char *key) { VALUE query_value; char *value = NULL; if (!rb_obj_is_kind_of(query_hash, rb_cHash)) { return NULL; } query_value = rb_hash_aref(query_hash, rb_str_new2(key)); if (Qnil != query_value) { value = StringValuePtr(query_value); } return value; } void data_objects_assert_file_exists(char *file, const char *message) { if (file) { if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_str_new2(file)) == Qfalse) { rb_raise(rb_eArgError, "%s", message); } } } VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args) { int i; VALUE array = rb_ary_new(); for (i = 0; i < count; i++) { rb_ary_push(array, args[i]); } return rb_funcall(klass, DO_ID_ESCAPE, 1, array); } // Find the greatest common denominator and reduce the provided numerator and denominator. // This replaces calles to Rational.reduce! which does the same thing, but really slowly. void data_objects_reduce(do_int64 *numerator, do_int64 *denominator) { do_int64 a = *numerator, b = *denominator, c; while (a != 0) { c = a; a = b % a; b = c; } *numerator /= b; *denominator /= b; } // Generate the date integer which Date.civil_to_jd returns int data_objects_jd_from_date(int year, int month, int day) { int a, b; if (month <= 2) { year -= 1; month += 12; } a = year / 100; b = 2 - a + (a / 4); return (int)(floor(365.25 * (year + 4716)) + floor(30.6001 * (month + 1)) + day + b - 1524); } VALUE data_objects_seconds_to_offset(long seconds_offset) { do_int64 num = seconds_offset; do_int64 den = 86400; data_objects_reduce(&num, &den); return rb_funcall(rb_mKernel, DO_ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den)); } VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset) { do_int64 seconds = 0; seconds += hour_offset * 3600; seconds += minute_offset * 60; return data_objects_seconds_to_offset(seconds); } VALUE data_objects_parse_date(const char *date) { static char const *const _fmt_date = "%4d-%2d-%2d"; int year = 0, month = 0, day = 0; switch (sscanf(date, _fmt_date, &year, &month, &day)) { case 0: case EOF: return Qnil; } if(!year && !month && !day) { return Qnil; } return rb_funcall(rb_cDate, DO_ID_NEW, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day)); } VALUE data_objects_parse_time(const char *date) { static char const* const _fmt_datetime = "%4d-%2d-%2d %2d:%2d:%2d%7lf"; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0; double subsec = 0; switch (sscanf(date, _fmt_datetime, &year, &month, &day, &hour, &min, &sec, &subsec)) { case 0: case EOF: return Qnil; } usec = (int) (subsec * 1000000); /* Mysql TIMESTAMPS can default to 0 */ if ((year + month + day + hour + min + sec + usec) == 0) { return Qnil; } return rb_funcall(rb_cTime, rb_intern("local"), 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), INT2NUM(usec)); } VALUE data_objects_parse_date_time(const char *date) { static char const* const _fmt_datetime_tz_normal = "%4d-%2d-%2d%*c%2d:%2d:%2d%3d:%2d"; static char const* const _fmt_datetime_tz_subsec = "%4d-%2d-%2d%*c%2d:%2d:%2d.%*d%3d:%2d"; int tokens_read; const char *fmt_datetime; VALUE offset; int year, month, day, hour, min, sec, hour_offset, minute_offset; struct tm timeinfo; time_t target_time; time_t gmt_offset; int dst_adjustment; if (*date == '\0') { return Qnil; } /* * We handle the following cases: * - Date (default to midnight) [3 tokens, missing 5] * - DateTime [6 tokens, missing 2] * - DateTime with hour, possibly minute TZ offset [7-8 tokens] */ fmt_datetime = strchr(date, '.') ? _fmt_datetime_tz_subsec : _fmt_datetime_tz_normal; tokens_read = sscanf(date, fmt_datetime, &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset); if(!year && !month && !day && !hour && !min && !sec) { return Qnil; } switch (tokens_read) { case 8: minute_offset *= hour_offset < 0 ? -1 : 1; break; case 7: /* Only got TZ hour offset, so assume 0 for minute */ minute_offset = 0; break; case 3: /* Only got Date */ hour = 0; min = 0; sec = 0; /* Fall through */ case 6: /* Only got DateTime */ /* * Interpret the DateTime from the local system TZ. If target date would * end up in DST, assume adjustment of a 1 hour shift. * * FIXME: The DST adjustment calculation won't be accurate for timezones * that observe fractional-hour shifts. But that's a real minority for * now.. */ timeinfo.tm_year = year - 1900; timeinfo.tm_mon = month - 1; // 0 - 11 timeinfo.tm_mday = day; timeinfo.tm_hour = hour; timeinfo.tm_min = min; timeinfo.tm_sec = sec; timeinfo.tm_isdst = -1; target_time = mktime(&timeinfo); dst_adjustment = timeinfo.tm_isdst ? 3600 : 0; /* * Now figure out seconds from UTC. For that we need a UTC/GMT-adjusted * time_t, which we get from mktime(gmtime(current_time)). * * NOTE: Some modern libc's have tm_gmtoff in struct tm, but we can't count * on that. */ #ifdef HAVE_GMTIME_R gmtime_r(&target_time, &timeinfo); #else timeinfo = *gmtime(&target_time); #endif gmt_offset = target_time - mktime(&timeinfo) + dst_adjustment; hour_offset = ((int)gmt_offset / 3600); minute_offset = ((int)gmt_offset % 3600 / 60); break; default: /* Any other combo of missing tokens and we can't do anything */ rb_raise(eDO_DataError, "Couldn't parse date: %s", date); } offset = data_objects_timezone_to_offset(hour_offset, minute_offset); return rb_funcall(rb_cDateTime, DO_ID_NEW, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), offset); } VALUE data_objects_cConnection_character_set(VALUE self) { return rb_iv_get(self, "@encoding"); } VALUE data_objects_cConnection_is_using_socket(VALUE self) { return rb_iv_get(self, "@using_socket"); } VALUE data_objects_cConnection_ssl_cipher(VALUE self) { return rb_iv_get(self, "@ssl_cipher"); } VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value) { return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'")); } VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value) { // TODO: Support non-local dates. we need to call #new_offset on the date to be // quoted and pass in the current locale's date offset (self.new_offset((hours * 3600).to_r / 86400) return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'")); } VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value) { return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d'")); } /* * Accepts an array of Ruby types (Fixnum, Float, String, etc...) and turns them * into Ruby-strings so we can easily typecast later */ VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self) { VALUE entry, sub_entry; int i, j; VALUE type_strings = rb_ary_new(); VALUE array = rb_ary_new(); for (i = 0; i < argc; i++) { rb_ary_push(array, argv[i]); } for (i = 0; i < RARRAY_LEN(array); i++) { entry = rb_ary_entry(array, i); if (TYPE(entry) == T_CLASS) { rb_ary_push(type_strings, entry); } else if (TYPE(entry) == T_ARRAY) { for (j = 0; j < RARRAY_LEN(entry); j++) { sub_entry = rb_ary_entry(entry, j); if (TYPE(sub_entry) == T_CLASS) { rb_ary_push(type_strings, sub_entry); } else { rb_raise(rb_eArgError, "Invalid type given"); } } } else { rb_raise(rb_eArgError, "Invalid type given"); } } rb_iv_set(self, "@field_types", type_strings); return array; } VALUE data_objects_cReader_values(VALUE self) { VALUE state = rb_iv_get(self, "@opened"); VALUE values = rb_iv_get(self, "@values"); if (state == Qnil || state == Qfalse || values == Qnil) { rb_raise(eDO_DataError, "Reader is not initialized"); } return rb_iv_get(self, "@values"); } VALUE data_objects_cReader_fields(VALUE self) { return rb_iv_get(self, "@fields"); } VALUE data_objects_cReader_field_count(VALUE self) { return rb_iv_get(self, "@field_count"); } void data_objects_common_init(void) { rb_require("bigdecimal"); rb_require("rational"); rb_require("date"); rb_require("data_objects"); // Needed by data_objects_const_get DO_ID_CONST_GET = rb_intern("const_get"); // Get references classes needed for Date/Time parsing rb_cDate = data_objects_const_get(rb_mKernel, "Date"); rb_cDateTime = data_objects_const_get(rb_mKernel, "DateTime"); rb_cBigDecimal = data_objects_const_get(rb_mKernel, "BigDecimal"); DO_ID_NEW = rb_intern("new"); #ifdef RUBY_LESS_THAN_186 DO_ID_NEW_DATE = rb_intern("new0"); #else DO_ID_NEW_DATE = rb_intern("new!"); #endif DO_ID_CONST_GET = rb_intern("const_get"); DO_ID_RATIONAL = rb_intern("Rational"); DO_ID_ESCAPE = rb_intern("escape_sql"); DO_ID_STRFTIME = rb_intern("strftime"); DO_ID_LOG = rb_intern("log"); // Get references to the Extlib module mExtlib = data_objects_const_get(rb_mKernel, "Extlib"); rb_cByteArray = data_objects_const_get(mExtlib, "ByteArray"); // Get references to the DataObjects module and its classes mDO = data_objects_const_get(rb_mKernel, "DataObjects"); cDO_Quoting = data_objects_const_get(mDO, "Quoting"); cDO_Connection = data_objects_const_get(mDO, "Connection"); cDO_Command = data_objects_const_get(mDO, "Command"); cDO_Result = data_objects_const_get(mDO, "Result"); cDO_Reader = data_objects_const_get(mDO, "Reader"); cDO_Logger = data_objects_const_get(mDO, "Logger"); cDO_Logger_Message = data_objects_const_get(cDO_Logger, "Message"); cDO_Extension = data_objects_const_get(mDO, "Extension"); eDO_ConnectionError = data_objects_const_get(mDO, "ConnectionError"); eDO_DataError = data_objects_const_get(mDO, "DataError"); rb_global_variable(&DO_ID_NEW_DATE); rb_global_variable(&DO_ID_RATIONAL); rb_global_variable(&DO_ID_CONST_GET); rb_global_variable(&DO_ID_ESCAPE); rb_global_variable(&DO_ID_LOG); rb_global_variable(&DO_ID_NEW); rb_global_variable(&rb_cDate); rb_global_variable(&rb_cDateTime); rb_global_variable(&rb_cBigDecimal); rb_global_variable(&rb_cByteArray); rb_global_variable(&mDO); rb_global_variable(&cDO_Logger_Message); rb_global_variable(&eDO_ConnectionError); rb_global_variable(&eDO_DataError); tzset(); } /* * Common typecasting logic that can be used or overriden by Adapters. */ extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding) { #ifdef HAVE_RUBY_ENCODING_H rb_encoding *internal_encoding = rb_default_internal_encoding(); #else void *internal_encoding = NULL; #endif if (type == rb_cInteger) { return rb_cstr2inum(value, 10); } else if (type == rb_cString) { return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding); } else if (type == rb_cFloat) { return rb_float_new(rb_cstr_to_dbl(value, Qfalse)); } else if (type == rb_cBigDecimal) { return rb_funcall(rb_cBigDecimal, DO_ID_NEW, 1, rb_str_new(value, length)); } else if (type == rb_cDate) { return data_objects_parse_date(value); } else if (type == rb_cDateTime) { return data_objects_parse_date_time(value); } else if (type == rb_cTime) { return data_objects_parse_time(value); } else if (type == rb_cTrueClass) { return (!value || strcmp("0", value) == 0) ? Qfalse : Qtrue; } else if (type == rb_cByteArray) { return rb_funcall(rb_cByteArray, DO_ID_NEW, 1, rb_str_new(value, length)); } else if (type == rb_cClass) { return rb_funcall(mDO, rb_intern("full_const_get"), 1, rb_str_new(value, length)); } else if (type == rb_cNilClass) { return Qnil; } else { return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding); } } do_sqlite3-0.10.13/ext/do_sqlite3/error.h0000644000004100000410000000350712154173164020133 0ustar www-datawww-data#ifndef _DO_SQLITE3_ERROR_H_ #define _DO_SQLITE3_ERROR_H_ #include "do_common.h" static struct errcodes do_sqlite3_errors[] = { #ifdef SQLITE_ERROR ERRCODE(SQLITE_ERROR, "SyntaxError"), #endif #ifdef SQLITE_INTERNAL ERRCODE(SQLITE_INTERNAL, "SQLError"), #endif #ifdef SQLITE_PERM ERRCODE(SQLITE_PERM, "ConnectionError"), #endif #ifdef SQLITE_ABORT ERRCODE(SQLITE_ABORT, "ConnectionError"), #endif #ifdef SQLITE_BUSY ERRCODE(SQLITE_BUSY, "ConnectionError"), #endif #ifdef SQLITE_LOCKED ERRCODE(SQLITE_LOCKED, "ConnectionError"), #endif #ifdef SQLITE_NOMEM ERRCODE(SQLITE_NOMEM, "ConnectionError"), #endif #ifdef SQLITE_READONLY ERRCODE(SQLITE_READONLY, "ConnectionError"), #endif #ifdef SQLITE_INTERRUPT ERRCODE(SQLITE_INTERRUPT, "ConnectionError"), #endif #ifdef SQLITE_IOERR ERRCODE(SQLITE_IOERR, "ConnectionError"), #endif #ifdef SQLITE_CORRUPT ERRCODE(SQLITE_CORRUPT, "ConnectionError"), #endif #ifdef SQLITE_FULL ERRCODE(SQLITE_FULL, "ConnectionError"), #endif #ifdef SQLITE_CANTOPEN ERRCODE(SQLITE_CANTOPEN, "ConnectionError"), #endif #ifdef SQLITE_EMPTY ERRCODE(SQLITE_EMPTY, "ConnectionError"), #endif #ifdef SQLITE_SCHEMA ERRCODE(SQLITE_SCHEMA, "DataError"), #endif #ifdef SQLITE_TOOBIG ERRCODE(SQLITE_TOOBIG, "DataError"), #endif #ifdef SQLITE_MISMATCH ERRCODE(SQLITE_MISMATCH, "DataError"), #endif #ifdef SQLITE_CONSTRAINT ERRCODE(SQLITE_CONSTRAINT, "IntegrityError"), #endif #ifdef SQLITE_MISUSE ERRCODE(SQLITE_MISUSE, "SQLError"), #endif #ifdef SQLITE_NOLFS ERRCODE(SQLITE_NOLFS, "ConnectionError"), #endif #ifdef SQLITE_FORMAT ERRCODE(SQLITE_FORMAT, "SyntaxError"), #endif #ifdef SQLITE_RANGE ERRCODE(SQLITE_RANGE, "DataError"), #endif #ifdef SQLITE_NOTADB ERRCODE(SQLITE_NOTADB, "ConnectionError"), #endif #ifdef SQLITE_ROW ERRCODE(SQLITE_ROW, "SyntaxError"), #endif {0, NULL, NULL} }; #endif do_sqlite3-0.10.13/ext/do_sqlite3/do_sqlite3.c0000644000004100000410000003212212154173164021036 0ustar www-datawww-data#include "do_sqlite3.h" #include "error.h" #include "do_common.h" VALUE mDO_Sqlite3; VALUE cDO_Sqlite3Connection; VALUE cDO_Sqlite3Command; VALUE cDO_Sqlite3Result; VALUE cDO_Sqlite3Reader; VALUE DO_OPEN_FLAG_READONLY; VALUE DO_OPEN_FLAG_READWRITE; VALUE DO_OPEN_FLAG_CREATE; VALUE DO_OPEN_FLAG_NO_MUTEX; VALUE DO_OPEN_FLAG_FULL_MUTEX; void do_sqlite3_raise_error(VALUE self, sqlite3 *result, VALUE query) { int errnum = sqlite3_errcode(result); const char *message = sqlite3_errmsg(result); VALUE sql_state = rb_str_new2(""); data_objects_raise_error(self, do_sqlite3_errors, errnum, message, query, sql_state); } VALUE do_sqlite3_typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) { int original_type = sqlite3_column_type(stmt, i); int length = sqlite3_column_bytes(stmt, i); if (original_type == SQLITE_NULL) { return Qnil; } #ifdef HAVE_RUBY_ENCODING_H rb_encoding *internal_encoding = rb_default_internal_encoding(); #else void *internal_encoding = NULL; #endif if (type == Qnil) { switch (original_type) { case SQLITE_INTEGER: type = rb_cInteger; break; case SQLITE_FLOAT: type = rb_cFloat; break; case SQLITE_BLOB: type = rb_cByteArray; break; default: type = rb_cString; break; } } if (type == rb_cInteger) { return LL2NUM(sqlite3_column_int64(stmt, i)); } else if (type == rb_cString) { return DATA_OBJECTS_STR_NEW((char*)sqlite3_column_text(stmt, i), length, encoding, internal_encoding); } else if (type == rb_cFloat) { return rb_float_new(sqlite3_column_double(stmt, i)); } else if (type == rb_cBigDecimal) { return rb_funcall(rb_cBigDecimal, DO_ID_NEW, 1, rb_str_new((char*)sqlite3_column_text(stmt, i), length)); } else if (type == rb_cDate) { return data_objects_parse_date((char*)sqlite3_column_text(stmt, i)); } else if (type == rb_cDateTime) { return data_objects_parse_date_time((char*)sqlite3_column_text(stmt, i)); } else if (type == rb_cTime) { return data_objects_parse_time((char*)sqlite3_column_text(stmt, i)); } else if (type == rb_cTrueClass) { return strcmp((char*)sqlite3_column_text(stmt, i), "t") == 0 ? Qtrue : Qfalse; } else if (type == rb_cByteArray) { return rb_funcall(rb_cByteArray, DO_ID_NEW, 1, rb_str_new((char*)sqlite3_column_blob(stmt, i), length)); } else if (type == rb_cClass) { return rb_funcall(mDO, rb_intern("full_const_get"), 1, rb_str_new((char*)sqlite3_column_text(stmt, i), length)); } else if (type == rb_cNilClass) { return Qnil; } else { return DATA_OBJECTS_STR_NEW((char*)sqlite3_column_text(stmt, i), length, encoding, internal_encoding); } } #ifdef HAVE_SQLITE3_OPEN_V2 #define FLAG_PRESENT(query_values, flag) !NIL_P(rb_hash_aref(query_values, flag)) int do_sqlite3_flags_from_uri(VALUE uri) { VALUE query_values = rb_funcall(uri, rb_intern("query"), 0); int flags = 0; if (!NIL_P(query_values) && TYPE(query_values) == T_HASH) { /// scan for flags #ifdef SQLITE_OPEN_READONLY if (FLAG_PRESENT(query_values, DO_OPEN_FLAG_READONLY)) { flags |= SQLITE_OPEN_READONLY; } else { flags |= SQLITE_OPEN_READWRITE; } #endif #ifdef SQLITE_OPEN_NOMUTEX if (FLAG_PRESENT(query_values, DO_OPEN_FLAG_NO_MUTEX)) { flags |= SQLITE_OPEN_NOMUTEX; } #endif #ifdef SQLITE_OPEN_FULLMUTEX if (FLAG_PRESENT(query_values, DO_OPEN_FLAG_FULL_MUTEX)) { flags |= SQLITE_OPEN_FULLMUTEX; } #endif flags |= SQLITE_OPEN_CREATE; } else { flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; } return flags; } #endif int do_sqlite3_busy_timeout_from_uri(VALUE uri) { VALUE query_values = rb_funcall(uri, rb_intern("query"), 0); if(query_values != Qnil && TYPE(query_values) == T_HASH) { VALUE timeout = rb_hash_aref(query_values, rb_str_new2("busy_timeout")); if(timeout == Qnil) { return -1; } return rb_cstr2inum(RSTRING_PTR(timeout), 0); } return -1; } /****** Public API ******/ VALUE do_sqlite3_cConnection_initialize(VALUE self, VALUE uri) { VALUE path = rb_funcall(uri, rb_intern("path"), 0); sqlite3 *db = NULL; int ret; #ifdef HAVE_SQLITE3_OPEN_V2 ret = sqlite3_open_v2(StringValuePtr(path), &db, do_sqlite3_flags_from_uri(uri), 0); #else ret = sqlite3_open(StringValuePtr(path), &db); #endif if (ret != SQLITE_OK) { do_sqlite3_raise_error(self, db, Qnil); } int timeout = do_sqlite3_busy_timeout_from_uri(uri); if(timeout > 0) { sqlite3_busy_timeout(db, timeout); } rb_iv_set(self, "@uri", uri); rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db)); // Sqlite3 only supports UTF-8, so this is the standard encoding rb_iv_set(self, "@encoding", rb_str_new2("UTF-8")); #ifdef HAVE_RUBY_ENCODING_H rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index("UTF-8"))); #endif return Qtrue; } VALUE do_sqlite3_cConnection_dispose(VALUE self) { VALUE connection_container = rb_iv_get(self, "@connection"); if (connection_container == Qnil) { return Qfalse; } sqlite3 *db; Data_Get_Struct(connection_container, sqlite3, db); if (!db) { return Qfalse; } sqlite3_close(db); rb_iv_set(self, "@connection", Qnil); return Qtrue; } VALUE do_sqlite3_cConnection_quote_boolean(VALUE self, VALUE value) { return rb_str_new2(value == Qtrue ? "'t'" : "'f'"); } VALUE do_sqlite3_cConnection_quote_string(VALUE self, VALUE string) { const char *source = rb_str_ptr_readonly(string); // Wrap the escaped string in single-quotes, this is DO's convention char *escaped_with_quotes = sqlite3_mprintf("%Q", source); if(!escaped_with_quotes) { rb_memerror(); } VALUE result = rb_str_new2(escaped_with_quotes); #ifdef HAVE_RUBY_ENCODING_H rb_enc_associate_index(result, FIX2INT(rb_iv_get(self, "@encoding_id"))); #endif sqlite3_free(escaped_with_quotes); return result; } VALUE do_sqlite3_cConnection_quote_byte_array(VALUE self, VALUE string) { VALUE source = StringValue(string); VALUE array = rb_funcall(source, rb_intern("unpack"), 1, rb_str_new2("H*")); rb_ary_unshift(array, rb_str_new2("X'")); rb_ary_push(array, rb_str_new2("'")); return rb_ary_join(array, Qnil); } VALUE do_sqlite3_cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) { VALUE query = data_objects_build_query_from_args(self, argc, argv); VALUE connection = rb_iv_get(self, "@connection"); VALUE sqlite3_connection = rb_iv_get(connection, "@connection"); if (sqlite3_connection == Qnil) { rb_raise(eDO_ConnectionError, "This connection has already been closed."); } sqlite3 *db = NULL; Data_Get_Struct(sqlite3_connection, sqlite3, db); struct timeval start; char *error_message; int status; gettimeofday(&start, NULL); status = sqlite3_exec(db, rb_str_ptr_readonly(query), 0, 0, &error_message); if (status != SQLITE_OK) { do_sqlite3_raise_error(self, db, query); } data_objects_debug(connection, query, &start); int affected_rows = sqlite3_changes(db); do_int64 insert_id = sqlite3_last_insert_rowid(db); return rb_funcall(cDO_Sqlite3Result, DO_ID_NEW, 3, self, INT2NUM(affected_rows), INT2NUM(insert_id)); } VALUE do_sqlite3_cCommand_execute_reader(int argc, VALUE *argv, VALUE self) { VALUE query = data_objects_build_query_from_args(self, argc, argv); VALUE connection = rb_iv_get(self, "@connection"); VALUE sqlite3_connection = rb_iv_get(connection, "@connection"); if (sqlite3_connection == Qnil) { rb_raise(eDO_ConnectionError, "This connection has already been closed."); } sqlite3 *db = NULL; Data_Get_Struct(sqlite3_connection, sqlite3, db); sqlite3_stmt *sqlite3_reader; struct timeval start; int status; gettimeofday(&start, NULL); status = sqlite3_prepare_v2(db, rb_str_ptr_readonly(query), -1, &sqlite3_reader, 0); data_objects_debug(connection, query, &start); if (status != SQLITE_OK) { do_sqlite3_raise_error(self, db, query); } int field_count = sqlite3_column_count(sqlite3_reader); VALUE reader = rb_funcall(cDO_Sqlite3Reader, DO_ID_NEW, 0); rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, sqlite3_reader)); rb_iv_set(reader, "@field_count", INT2NUM(field_count)); rb_iv_set(reader, "@connection", connection); VALUE field_types = rb_iv_get(self, "@field_types"); if (field_types == Qnil || RARRAY_LEN(field_types) == 0) { field_types = rb_ary_new(); } else if (RARRAY_LEN(field_types) != field_count) { // Whoops... wrong number of types passed to set_types. Close the reader and raise // and error rb_funcall(reader, rb_intern("close"), 0); rb_raise(rb_eArgError, "Field-count mismatch. Expected %ld fields, but the query yielded %d", RARRAY_LEN(field_types), field_count); } VALUE field_names = rb_ary_new(); int i; for (i = 0; i < field_count; i++) { rb_ary_push(field_names, rb_str_new2((char *)sqlite3_column_name(sqlite3_reader, i))); } rb_iv_set(reader, "@fields", field_names); rb_iv_set(reader, "@field_types", field_types); return reader; } VALUE do_sqlite3_cReader_close(VALUE self) { VALUE reader_obj = rb_iv_get(self, "@reader"); if (reader_obj != Qnil) { sqlite3_stmt *reader = NULL; Data_Get_Struct(reader_obj, sqlite3_stmt, reader); sqlite3_finalize(reader); rb_iv_set(self, "@reader", Qnil); return Qtrue; } return Qfalse; } VALUE do_sqlite3_cReader_next(VALUE self) { VALUE reader = rb_iv_get(self, "@reader"); if(reader == Qnil) { rb_raise(eDO_ConnectionError, "This result set has already been closed."); } if (rb_iv_get(self, "@done") == Qtrue) { return Qfalse; } sqlite3_stmt *sqlite_reader = NULL; int result; Data_Get_Struct(reader, sqlite3_stmt, sqlite_reader); result = sqlite3_step(sqlite_reader); rb_iv_set(self, "@state", INT2NUM(result)); if (result != SQLITE_ROW) { rb_iv_set(self, "@values", Qnil); rb_iv_set(self, "@done", Qtrue); return Qfalse; } int enc = -1; #ifdef HAVE_RUBY_ENCODING_H VALUE encoding_id = rb_iv_get(rb_iv_get(self, "@connection"), "@encoding_id"); if (encoding_id != Qnil) { enc = FIX2INT(encoding_id); } #endif VALUE field_types = rb_iv_get(self, "@field_types"); int field_count = NUM2INT(rb_iv_get(self, "@field_count")); VALUE arr = rb_ary_new(); VALUE field_type; VALUE value; int i; for (i = 0; i < field_count; i++) { field_type = rb_ary_entry(field_types, i); value = do_sqlite3_typecast(sqlite_reader, i, field_type, enc); rb_ary_push(arr, value); } rb_iv_set(self, "@values", arr); return Qtrue; } VALUE do_sqlite3_cReader_values(VALUE self) { VALUE state = rb_iv_get(self, "@state"); if (state == Qnil || NUM2INT(state) != SQLITE_ROW) { rb_raise(eDO_DataError, "Reader is not initialized"); return Qnil; } return rb_iv_get(self, "@values"); } void Init_do_sqlite3() { data_objects_common_init(); mDO_Sqlite3 = rb_define_module_under(mDO, "Sqlite3"); cDO_Sqlite3Connection = rb_define_class_under(mDO_Sqlite3, "Connection", cDO_Connection); rb_define_method(cDO_Sqlite3Connection, "initialize", do_sqlite3_cConnection_initialize, 1); rb_define_method(cDO_Sqlite3Connection, "dispose", do_sqlite3_cConnection_dispose, 0); rb_define_method(cDO_Sqlite3Connection, "quote_boolean", do_sqlite3_cConnection_quote_boolean, 1); rb_define_method(cDO_Sqlite3Connection, "quote_string", do_sqlite3_cConnection_quote_string, 1); rb_define_method(cDO_Sqlite3Connection, "quote_byte_array", do_sqlite3_cConnection_quote_byte_array, 1); rb_define_method(cDO_Sqlite3Connection, "character_set", data_objects_cConnection_character_set, 0); cDO_Sqlite3Command = rb_define_class_under(mDO_Sqlite3, "Command", cDO_Command); rb_define_method(cDO_Sqlite3Command, "set_types", data_objects_cCommand_set_types, -1); rb_define_method(cDO_Sqlite3Command, "execute_non_query", do_sqlite3_cCommand_execute_non_query, -1); rb_define_method(cDO_Sqlite3Command, "execute_reader", do_sqlite3_cCommand_execute_reader, -1); cDO_Sqlite3Result = rb_define_class_under(mDO_Sqlite3, "Result", cDO_Result); cDO_Sqlite3Reader = rb_define_class_under(mDO_Sqlite3, "Reader", cDO_Reader); rb_define_method(cDO_Sqlite3Reader, "close", do_sqlite3_cReader_close, 0); rb_define_method(cDO_Sqlite3Reader, "next!", do_sqlite3_cReader_next, 0); rb_define_method(cDO_Sqlite3Reader, "values", do_sqlite3_cReader_values, 0); // TODO: DRY? rb_define_method(cDO_Sqlite3Reader, "fields", data_objects_cReader_fields, 0); rb_define_method(cDO_Sqlite3Reader, "field_count", data_objects_cReader_field_count, 0); rb_global_variable(&cDO_Sqlite3Result); rb_global_variable(&cDO_Sqlite3Reader); DO_OPEN_FLAG_READONLY = rb_str_new2("read_only"); rb_global_variable(&DO_OPEN_FLAG_READONLY); DO_OPEN_FLAG_READWRITE = rb_str_new2("read_write"); rb_global_variable(&DO_OPEN_FLAG_READWRITE); DO_OPEN_FLAG_CREATE = rb_str_new2("create"); rb_global_variable(&DO_OPEN_FLAG_CREATE); DO_OPEN_FLAG_NO_MUTEX = rb_str_new2("no_mutex"); rb_global_variable(&DO_OPEN_FLAG_NO_MUTEX); DO_OPEN_FLAG_FULL_MUTEX = rb_str_new2("full_mutex"); rb_global_variable(&DO_OPEN_FLAG_FULL_MUTEX); Init_do_sqlite3_extension(); data_objects_define_errors(mDO_Sqlite3, do_sqlite3_errors); } do_sqlite3-0.10.13/ext/do_sqlite3/do_common.h0000644000004100000410000001012012154173164020741 0ustar www-datawww-data#ifndef _DO_COMMON_H_ #define _DO_COMMON_H_ #include // Needed for defining error.h struct errcodes { int error_no; const char *error_name; const char *exception; }; #define ERRCODE(name,message) {name, #name, message} #ifdef _WIN32 typedef signed __int64 do_int64; #else typedef signed long long int do_int64; #endif #ifdef HAVE_RUBY_ENCODING_H #include #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \ ({ \ VALUE _string = rb_str_new2((const char *)str); \ if(encoding != -1) { \ rb_enc_associate_index(_string, encoding); \ } \ if(internal_encoding) { \ _string = rb_str_export_to_enc(_string, internal_encoding); \ } \ _string; \ }) #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \ ({ \ VALUE _string = rb_str_new((const char *)str, (long)len); \ if(encoding != -1) { \ rb_enc_associate_index(_string, encoding); \ } \ if(internal_encoding) { \ _string = rb_str_export_to_enc(_string, internal_encoding); \ } \ _string; \ }) #else #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \ rb_str_new2((const char *)str) #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \ rb_str_new((const char *)str, (long)len) #endif // To store rb_intern values extern ID DO_ID_NEW; extern ID DO_ID_NEW_DATE; extern ID DO_ID_CONST_GET; extern ID DO_ID_RATIONAL; extern ID DO_ID_ESCAPE; extern ID DO_ID_STRFTIME; extern ID DO_ID_LOG; // Reference to Extlib module extern VALUE mExtlib; extern VALUE rb_cByteArray; // References to DataObjects base classes extern VALUE mDO; extern VALUE cDO_Quoting; extern VALUE cDO_Connection; extern VALUE cDO_Command; extern VALUE cDO_Result; extern VALUE cDO_Reader; extern VALUE cDO_Logger; extern VALUE cDO_Logger_Message; extern VALUE cDO_Extension; extern VALUE eDO_ConnectionError; extern VALUE eDO_DataError; // References to Ruby classes that we'll need extern VALUE rb_cDate; extern VALUE rb_cDateTime; extern VALUE rb_cBigDecimal; extern void data_objects_debug(VALUE connection, VALUE string, struct timeval *start); extern char *data_objects_get_uri_option(VALUE query_hash, const char *key); extern void data_objects_assert_file_exists(char *file, const char *message); extern VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args); extern void data_objects_reduce(do_int64 *numerator, do_int64 *denominator); extern int data_objects_jd_from_date(int year, int month, int day); extern VALUE data_objects_seconds_to_offset(long seconds_offset); extern VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset); extern VALUE data_objects_parse_date(const char *date); extern VALUE data_objects_parse_time(const char *date); extern VALUE data_objects_parse_date_time(const char *date); extern VALUE data_objects_cConnection_character_set(VALUE self); extern VALUE data_objects_cConnection_is_using_socket(VALUE self); extern VALUE data_objects_cConnection_ssl_cipher(VALUE self); extern VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value); extern VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value); extern VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value); extern VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self); extern VALUE data_objects_cReader_values(VALUE self); extern VALUE data_objects_cReader_fields(VALUE self); extern VALUE data_objects_cReader_field_count(VALUE self); extern void data_objects_common_init(void); extern VALUE data_objects_const_get(VALUE scope, const char *constant); static inline void data_objects_define_errors(VALUE scope, const struct errcodes *errors) { const struct errcodes *e; for (e = errors; e->error_name; e++) { rb_const_set(scope, rb_intern(e->error_name), INT2NUM(e->error_no)); } } extern void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, const char *message, VALUE query, VALUE state); extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding); #define RSTRING_NOT_MODIFIED #endif do_sqlite3-0.10.13/tasks/0000755000004100000410000000000012154173164015103 5ustar www-datawww-datado_sqlite3-0.10.13/tasks/compile.rake0000644000004100000410000000413212154173164017377 0ustar www-datawww-databegin gem 'rake-compiler', '~>0.7' require 'rake/extensiontask' require 'rake/javaextensiontask' def gemspec @clean_gemspec ||= Gem::Specification::load(File.expand_path('../../do_sqlite3.gemspec', __FILE__)) end unless JRUBY Rake::ExtensionTask.new('do_sqlite3', gemspec) do |ext| sqlite3_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'sqlite3')) ext.lib_dir = "lib/#{gemspec.name}" ext.cross_compile = true ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] ext.cross_config_options << "--with-sqlite3-dir=#{sqlite3_lib}" ext.cross_compiling do |gemspec| gemspec.post_install_message = <<-POST_INSTALL_MESSAGE ============================================================================= You've installed the binary version of #{gemspec.name}. It was built using Sqlite3 version #{BINARY_VERSION}. It's recommended to use the exact same version to avoid potential issues. At the time of building this gem, the necessary DLL files where available in the following download: http://www.sqlite.org/sqlite-dll-win32-x86-#{BINARY_VERSION}.zip You can put the sqlite3.dll available in this package in your Ruby bin directory, for example C:\\Ruby\\bin ============================================================================= POST_INSTALL_MESSAGE end # automatically add build options to avoid need of manual input if RUBY_PLATFORM =~ /mswin|mingw/ then ext.config_options << "--with-sqlite3-dir=#{sqlite3_lib}" end end end Rake::JavaExtensionTask.new('do_sqlite3', gemspec) do |ext| ext.ext_dir = 'ext-java/src/main/java' ext.lib_dir = "lib/#{gemspec.name}" ext.debug = ENV.has_key?('DO_JAVA_DEBUG') && ENV['DO_JAVA_DEBUG'] ext.classpath = '../do_jdbc/lib/do_jdbc_internal.jar' ext.java_compiling do |gem| gem.add_dependency 'jdbc-sqlite3', '>=3.5.8' gem.add_dependency 'do_jdbc', '0.10.13' end end rescue LoadError warn "To compile, install rake-compiler (gem install rake-compiler)" end do_sqlite3-0.10.13/tasks/spec.rake0000644000004100000410000000052712154173164016705 0ustar www-datawww-datarequire 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec => [:clean, :compile]) do |spec| spec.pattern = './spec/**/*_spec.rb' end RSpec::Core::RakeTask.new(:rcov => [:clean, :compile]) do |rcov| rcov.pattern = "./spec/**/*_spec.rb" rcov.rcov = true rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/) end do_sqlite3-0.10.13/tasks/release.rake0000644000004100000410000000074012154173164017370 0ustar www-datawww-datadesc 'Builds all gems (native, binaries for JRuby and Windows)' task :build_all do `rake clean` `rake build` `rake java gem` `rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0` end desc 'Release all gems (native, binaries for JRuby and Windows)' task :release_all => :build_all do Dir["pkg/do_sqlite3-#{DataObjects::Sqlite3::VERSION}*.gem"].each do |gem_path| command = "gem push #{gem_path}" puts "Executing #{command.inspect}:" sh command end end do_sqlite3-0.10.13/tasks/retrieve.rake0000644000004100000410000000673712154173164017611 0ustar www-datawww-databegin gem 'rake-compiler', '~>0.7' require 'rake/clean' require 'rake/extensioncompiler' # download sqlite3 library and headers # only on Windows or cross platform compilation def dlltool(dllname, deffile, libfile) # define if we are using GCC or not if Rake::ExtensionCompiler.mingw_gcc_executable then dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable) tool = case RUBY_PLATFORM when /mingw/ File.join(dir, 'dlltool.exe') when /linux|darwin/ File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool") end return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}" else if RUBY_PLATFORM =~ /mswin/ then tool = 'lib.exe' else fail "Unsupported platform for cross-compilation (please, contribute some patches)." end return "#{tool} /DEF:#{deffile} /OUT:#{libfile}" end end # required folder structure for --with-sqlite3-dir (include + lib) directory "vendor/sqlite3/lib" directory "vendor/sqlite3/include" # download amalgamation BINARY_VERSION (for include files) file "vendor/sqlite-amalgamation-#{BINARY_VERSION}.zip" => ['vendor'] do |t| url = "http://www.sqlite.org/#{File.basename(t.name)}" when_writing "downloading #{t.name}" do cd File.dirname(t.name) do system "wget -c #{url} || curl -L -C - -O #{url}" end end end # download dll binaries file "vendor/sqlite-dll-win32-x86-#{BINARY_VERSION}.zip" => ['vendor'] do |t| url = "http://www.sqlite.org/#{File.basename(t.name)}" when_writing "downloading #{t.name}" do cd File.dirname(t.name) do system "wget -c #{url} || curl -L -C - -O #{url}" end end end # extract header files into include folder file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{BINARY_VERSION}.zip"] do |t| full_file = File.expand_path(t.prerequisites.last) when_writing "creating #{t.name}" do cd File.dirname(t.name) do sh "unzip -j #{full_file}" # update file timestamp to avoid Rake perform this extraction again. touch File.basename(t.name) end end end # extract dll files into lib folder file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlite-dll-win32-x86-#{BINARY_VERSION}.zip"] do |t| full_file = File.expand_path(t.prerequisites.last) when_writing "creating #{t.name}" do cd File.dirname(t.name) do sh "unzip -j #{full_file}" # update file timestamp to avoid Rake perform this extraction again. touch File.basename(t.name) end end end # generate import library from definition and dll file file "vendor/sqlite3/lib/sqlite3.lib" => ["vendor/sqlite3/lib/sqlite3.dll"] do |t| libfile = t.name dllname = libfile.ext('dll') deffile = libfile.ext('def') when_writing "creating #{t.name}" do sh dlltool(dllname, deffile, libfile) end end # clobber vendored packages CLOBBER.include('vendor') # vendor:sqlite3 task 'vendor:sqlite3' => ["vendor/sqlite3/lib/sqlite3.lib", "vendor/sqlite3/include/sqlite3.h"] # hook into cross compilation vendored sqlite3 dependency if RUBY_PLATFORM =~ /mingw|mswin/ then Rake::Task['compile'].prerequisites.unshift 'vendor:sqlite3' else if Rake::Task.tasks.map {|t| t.name }.include? 'cross' Rake::Task['cross'].prerequisites.unshift 'vendor:sqlite3' end end rescue LoadError end do_sqlite3-0.10.13/LICENSE0000644000004100000410000000206712154173164014770 0ustar www-datawww-dataCopyright (c) 2007 - 2011 Yehuda Katz, Dirkjan Bussink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. do_sqlite3-0.10.13/Rakefile0000644000004100000410000000202712154173164015424 0ustar www-datawww-datarequire 'rubygems' require 'pathname' require 'bundler' require 'rubygems/package_task' Bundler::GemHelper.install_tasks require 'rake' require 'rake/clean' ROOT = Pathname(__FILE__).dirname.expand_path require ROOT + 'lib/do_sqlite3/version' JRUBY = RUBY_PLATFORM =~ /java/ IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby' WINDOWS = Gem.win_platform? || (JRUBY && ENV_JAVA['os.name'] =~ /windows/i) SUDO = WINDOWS ? '' : ('sudo' unless ENV['SUDOLESS']) BINARY_VERSION = '3071300' CLEAN.include(%w[ {tmp,pkg}/ **/*.{o,so,bundle,jar,log,a,gem,dSYM,obj,pdb,exp,DS_Store,rbc,db} ext/do_sqlite3/Makefile ext-java/target ]) if JRUBY Rake::Task['build'].clear_actions if Rake::Task.task_defined?('build') Rake::Task['install'].clear_actions if Rake::Task.task_defined?('install') task :build => [ :java, :gem ] task :install do sh "#{Config::CONFIG['RUBY_INSTALL_NAME']} -S gem install pkg/do_sqlite3-#{DataObjects::Sqlite3::VERSION}-java.gem" end end FileList['tasks/**/*.rake'].each { |task| import task } do_sqlite3-0.10.13/spec/0000755000004100000410000000000012154173164014710 5ustar www-datawww-datado_sqlite3-0.10.13/spec/command_spec.rb0000644000004100000410000000034112154173164017663 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/command_spec' describe DataObjects::Sqlite3::Command do it_should_behave_like 'a Command' end do_sqlite3-0.10.13/spec/reader_spec.rb0000644000004100000410000000033612154173164017513 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/reader_spec' describe DataObjects::Sqlite3::Reader do it_should_behave_like 'a Reader' end do_sqlite3-0.10.13/spec/typecast/0000755000004100000410000000000012154173164016544 5ustar www-datawww-datado_sqlite3-0.10.13/spec/typecast/float_spec.rb0000644000004100000410000000054312154173164021212 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/float_spec' describe 'DataObjects::Sqlite3 with Float' do it_should_behave_like 'supporting Float' end describe 'DataObjects::Sqlite3 with Float' do it_should_behave_like 'supporting Float autocasting' end do_sqlite3-0.10.13/spec/typecast/boolean_spec.rb0000644000004100000410000000056512154173164021530 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/boolean_spec' # Sqlite3 doesn't support booleans natively, so autocasting is not available: # http://www.sqlite.org/datatype3.html describe 'DataObjects::Sqlite3 with Boolean' do it_should_behave_like 'supporting Boolean' end do_sqlite3-0.10.13/spec/typecast/integer_spec.rb0000644000004100000410000000037712154173164021547 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/integer_spec' describe 'DataObjects::Sqlite3 with Integer' do it_should_behave_like 'supporting Integer' end do_sqlite3-0.10.13/spec/typecast/datetime_spec.rb0000644000004100000410000000057112154173164021702 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/datetime_spec' # Sqlite3 doesn't support datetimes natively, so autocasting is not available: # http://www.sqlite.org/datatype3.html describe 'DataObjects::Sqlite3 with DateTime' do it_should_behave_like 'supporting DateTime' end do_sqlite3-0.10.13/spec/typecast/range_spec.rb0000644000004100000410000000037112154173164021200 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/range_spec' describe 'DataObjects::Sqlite3 with Range' do it_should_behave_like 'supporting Range' end do_sqlite3-0.10.13/spec/typecast/other_spec.rb0000644000004100000410000000042212154173164021222 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/other_spec' describe 'DataObjects::H2 with other (unknown) type' do it_should_behave_like 'supporting other (unknown) type' end do_sqlite3-0.10.13/spec/typecast/byte_array_spec.rb0000644000004100000410000000040612154173164022244 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/byte_array_spec' describe 'DataObjects::Sqlite3 with ByteArray' do it_should_behave_like 'supporting ByteArray' end do_sqlite3-0.10.13/spec/typecast/class_spec.rb0000644000004100000410000000037112154173164021211 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/class_spec' describe 'DataObjects::Sqlite3 with Class' do it_should_behave_like 'supporting Class' end do_sqlite3-0.10.13/spec/typecast/nil_spec.rb0000644000004100000410000000113612154173164020666 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/nil_spec' # splitting the descibe into two separate declaration avoids # concurrent execution of the "it_should_behave_like ....." calls # which would lock the database describe 'DataObjects::Sqlite3 with Nil' do it_should_behave_like 'supporting Nil' end describe 'DataObjects::Sqlite3 with Nil' do it_should_behave_like 'supporting writing an Nil' end describe 'DataObjects::Sqlite3 with Nil' do it_should_behave_like 'supporting Nil autocasting' end do_sqlite3-0.10.13/spec/typecast/bigdecimal_spec.rb0000644000004100000410000000057612154173164022173 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/bigdecimal_spec' # Sqlite3 doesn't support decimals natively, so autocasting is not available: # http://www.sqlite.org/datatype3.html describe 'DataObjects::Sqlite3 with BigDecimal' do it_should_behave_like 'supporting BigDecimal' end do_sqlite3-0.10.13/spec/typecast/string_spec.rb0000644000004100000410000000037412154173164021415 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/string_spec' describe 'DataObjects::Sqlite3 with String' do it_should_behave_like 'supporting String' end do_sqlite3-0.10.13/spec/typecast/time_spec.rb0000644000004100000410000000036612154173164021046 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/time_spec' describe 'DataObjects::Sqlite3 with Time' do it_should_behave_like 'supporting Time' end do_sqlite3-0.10.13/spec/typecast/array_spec.rb0000644000004100000410000000037112154173164021222 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/array_spec' describe 'DataObjects::Sqlite3 with Array' do it_should_behave_like 'supporting Array' end do_sqlite3-0.10.13/spec/typecast/date_spec.rb0000644000004100000410000000055112154173164021021 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/date_spec' # Sqlite3 doesn't support dates natively, so autocasting is not available: # http://www.sqlite.org/datatype3.html describe 'DataObjects::Sqlite3 with Date' do it_should_behave_like 'supporting Date' end do_sqlite3-0.10.13/spec/spec_helper.rb0000644000004100000410000001132112154173164017524 0ustar www-datawww-data$TESTING=true JRUBY = RUBY_PLATFORM =~ /java/ require 'rubygems' require 'rspec' require 'date' require 'ostruct' require 'fileutils' require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/ driver_lib = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(driver_lib) unless $LOAD_PATH.include?(driver_lib) # Prepend data_objects/do_jdbc in the repository to the load path. # DO NOT USE installed gems, except when running the specs from gem. repo_root = File.expand_path('../../..', __FILE__) (['data_objects'] << ('do_jdbc' if JRUBY)).compact.each do |lib| lib_path = "#{repo_root}/#{lib}/lib" $LOAD_PATH.unshift(lib_path) if File.directory?(lib_path) && !$LOAD_PATH.include?(lib_path) end require 'data_objects' require 'data_objects/spec/setup' require 'data_objects/spec/lib/pending_helpers' require 'do_sqlite3' CONFIG = OpenStruct.new CONFIG.scheme = 'sqlite3' CONFIG.database = ENV['DO_SQLITE3_DATABASE'] || ":memory:" CONFIG.uri = ENV["DO_SQLITE3_SPEC_URI"] || "#{CONFIG.scheme}:#{CONFIG.database}" CONFIG.driver = 'sqlite3' CONFIG.jdbc_driver = DataObjects::Sqlite3.const_get('JDBC_DRIVER') rescue nil CONFIG.jdbc_uri = CONFIG.uri.sub(/sqlite3/,"jdbc:sqlite") module DataObjectsSpecHelpers def setup_test_environment conn = DataObjects::Connection.new(CONFIG.uri) conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "invoices" EOF conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "users" EOF conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "widgets" EOF conn.create_command(<<-EOF).execute_non_query CREATE TABLE "users" ( "id" SERIAL, "name" VARCHAR(200) default 'Billy' NULL, "fired_at" timestamp, PRIMARY KEY ("id") ); EOF conn.create_command(<<-EOF).execute_non_query CREATE TABLE "invoices" ( "invoice_number" varchar(50) NOT NULL, PRIMARY KEY ("invoice_number") ); EOF local_offset = Rational(Time.local(2008, 2, 14).utc_offset, 86400) t = DateTime.civil(2008, 2, 14, 00, 31, 12, local_offset) conn.create_command(<<-EOF).execute_non_query CREATE TABLE "widgets" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "code" char(8) default 'A14' NULL, "name" varchar(200) default 'Super Widget' NULL, "shelf_location" text NULL, "description" text NULL, "image_data" blob NULL, "ad_description" text NULL, "ad_image" blob NULL, "whitepaper_text" text NULL, "cad_drawing" blob, "flags" boolean default 'f', "number_in_stock" smallint default 500, "number_sold" integer default 0, "super_number" bigint default 9223372036854775807, "weight" float default 1.23, "cost1" double precision default 10.23, "cost2" decimal(8,2) default 50.23, "release_date" date default '2008-02-14', "release_datetime" timestamp default '#{t.to_s}', "release_timestamp" timestamp with time zone default '2008-02-14 00:31:31' ); EOF 1.upto(16) do |n| conn.create_command(<<-EOF).execute_non_query insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', X'434144200120002044524157494e47', 1234, 13.4); EOF end conn.create_command(<<-EOF).execute_non_query update widgets set flags = 't' where id = 2 EOF conn.create_command(<<-EOF).execute_non_query update widgets set ad_description = NULL where id = 3 EOF conn.create_command(<<-EOF).execute_non_query update widgets set flags = NULL where id = 4 EOF conn.create_command(<<-EOF).execute_non_query update widgets set cost1 = NULL where id = 5 EOF conn.create_command(<<-EOF).execute_non_query update widgets set cost2 = NULL where id = 6 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_date = NULL where id = 7 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_datetime = NULL where id = 8 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_timestamp = NULL where id = 9 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_datetime = '2008-07-14 00:31:12' where id = 10 EOF conn.close end end RSpec.configure do |config| config.include(DataObjectsSpecHelpers) config.include(DataObjects::Spec::PendingHelpers) end do_sqlite3-0.10.13/spec/error/0000755000004100000410000000000012154173164016041 5ustar www-datawww-datado_sqlite3-0.10.13/spec/error/sql_error_spec.rb0000644000004100000410000000053312154173164021411 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/error/sql_error_spec' describe 'DataObjects::Sqlite3 raising SQLError' do # This fails for now, need to think of a query that also exposes the issue on sqlite :S # it_should_behave_like 'raising a SQLError' end do_sqlite3-0.10.13/spec/result_spec.rb0000644000004100000410000000116612154173164017571 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/result_spec' # splitting the descibe into two separate declaration avoids # concurrent execution of the "it_should_behave_like ....." calls # which would lock the database # TODO # the locked database created a deadlock which is worth exploring since # such situation could appear in the wild too describe DataObjects::Sqlite3::Result do it_should_behave_like 'a Result' end describe DataObjects::Sqlite3::Result do it_should_behave_like 'a Result which returns inserted key with sequences' end do_sqlite3-0.10.13/spec/encoding_spec.rb0000644000004100000410000000060112154173164020032 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/encoding_spec' describe DataObjects::Sqlite3::Connection do it_should_behave_like 'returning correctly encoded strings for the default database encoding' it_should_behave_like 'returning correctly encoded strings for the default internal encoding' end do_sqlite3-0.10.13/spec/connection_spec.rb0000644000004100000410000000171512154173164020412 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/connection_spec' describe DataObjects::Sqlite3::Connection do before :all do @driver = CONFIG.scheme @user = CONFIG.user @password = CONFIG.pass @host = CONFIG.host @port = CONFIG.port @database = CONFIG.database end it_should_behave_like 'a Connection' it_should_behave_like 'a Connection via JDNI' if JRUBY it_should_behave_like 'a Connection with JDBC URL support' if JRUBY unless JRUBY describe 'connecting with busy timeout' do it 'connects with a valid timeout' do DataObjects::Connection.new("#{CONFIG.uri}?busy_timeout=200").should_not be_nil end it 'raises an error when passed an invalid value' do lambda { DataObjects::Connection.new("#{CONFIG.uri}?busy_timeout=stuff") }. should raise_error(ArgumentError) end end end end do_sqlite3-0.10.13/README.markdown0000644000004100000410000000541712154173164016466 0ustar www-datawww-data# do_sqlite3 * ## Description A SQLite3 driver for DataObjects. ## Features/Problems This driver implements the DataObjects API for the SQLite3 relational database. ## Synopsis An example of usage: ```ruby @connection = DataObjects::Connection.new("sqlite3://employees") @reader = @connection.create_command('SELECT * FROM users').execute_reader @reader.next! ``` ## Requirements This driver is provided for the following platforms: * Ruby MRI (1.8.6/7), 1.9: tested on Linux, Mac OS X and Windows platforms. * JRuby 1.3.1 + (1.4+ recommended). * Rubinius (experimental). Additionally you should have the following prerequisites: * `data_objects` gem * `do_jdbc` gem (shared library), if running on JRuby. ## Install To install the gem: gem install do_sqlite3 To compile and install from source: * Install rake-compiler: `gem install rake-compiler`. * For MRI/Rubinius extensions: * Install the `gcc` compiler. On OS X, you should install XCode tools. On Ubuntu, run `apt-get install build-essential`. * Install Ruby and SQLite3. * Install the Ruby and SQLite3 development headers. * On Debian-Linux distributions, you can install the following packages with `apt`: `ruby-dev` `libsqlite3-dev`. * If you want to cross-compile for Windows: * Install MinGW: * On Debian-Linux distributions, you can install the following package with `apt`: `mingw32`. * On OS X, this can install the following package with MacPorts: `i386-mingw32-gcc`. * Run `rake-compiler cross-ruby`. * Run `rake-compiler update-config`. * For JRuby extensions: * Install the Java Development Kit (provided if you are on a recent version of Mac OS X) from . * Install a recent version of JRuby. Ensure `jruby` is in your `PATH` and/or you have configured the `JRUBY_HOME` environment variable to point to your JRuby installation. * Install `data_objects` and `do_jdbc` with `jruby -S rake install`. * Then, install this driver with `(jruby -S) rake install`. For more information, see the SQLite3 driver wiki page: . ## Developers Follow the above installation instructions. Additionally, you'll need: * `rspec` gem for running specs. * `YARD` gem for generating documentation. See the DataObjects wiki for more comprehensive information on installing and contributing to the JRuby-variant of this driver: . To run specs: rake spec To run specs without compiling extensions first: rake spec_no_compile To run individual specs: rake spec SPEC=spec/connection_spec.rb ## License This code is licensed under an **MIT (X11) License**. Please see the accompanying `LICENSE` file. do_sqlite3-0.10.13/ChangeLog.markdown0000644000004100000410000000460112154173164017352 0ustar www-datawww-data## 0.10.13 2013-05-27 * Windows binary for Ruby 2.0 ## 0.10.12 2013-01-21 * jdbc-sqlite3 driver loading fix * Improve handling of floats / doubles in sqlite3 on JRuby ## 0.10.11 2012-12-29 * Rename C symbols to prevent name collitions ## 0.10.10 2012-10-11 * Add support to C driver for busy\_timeout ## 0.10.9 2012-08-13 * Fix segfault when loading custom extensions ## 0.10.8 2012-02-10 * Ruby 1.9.3 compatibility on Windows * Fix issue with sqlite3_load_extension ## 0.10.7 2011-10-13 * Ruby 1.9.3 compatibility ## 0.10.6 2011-05-22 Bugfixes * Fix an issue on some platforms when multiple DO drivers are loaded ## 0.10.5 2011-05-03 Bugfixes * Fix an issue with DateTime ## 0.10.4 2011-04-28 New features * Add save point to transactions (all) * JRuby 1.9 mode support (encodings etc.) Bugfixes * Fix bug when using nested transactions in concurrent scenarios (all) * Use column aliases instead of names (jruby) * DST calculation fixes (all) Other * Refactor to DRY up the adapters (all) * Many style fixes * Switch back to RSpec ## 0.10.3 2011-01-30 * Reworked transactions * Fix a DST bug that could cause datetimes in the wrong timezone ## 0.10.2 2010-05-19 * Make Encoding.default_internal aware * Rework logging for making callbacks possible * Remove handling Object types directly ## 0.10.1.1 2010-01-24 * JRuby-only: Fix for handling boolean results with a TRUE value. ## 0.10.1 2010-01-08 * Support for Ruby 1.8 and 1.9 on Windows. * Switch to Jeweler for Gem building tasks (this change may be temporary). * Switch to using Bacon for running specs: This should make specs friendlier to new Ruby implementations that are not yet 100% MRI-compatible, and in turn, pave the road for our own IronRuby and MacRuby support. * Switch to the newly added rake-compiler `JavaExtensionTask` for compiling JRuby extensions, instead of our (broken) home-grown solution. ## 0.10.0 2009-09-15 * Improvements * JRuby Support (using *do_jdbc*) ## 0.9.12 2009-05-17 * Improvements * rake-compiler for Windows support ## 0.9.11 2009-01-19 * Improvements * Ruby 1.9 support * Fixes * Fix Windows gem ## 0.9.9 2008-11-27 * Improvements * Added cross compile rake tasks for Windows gems [Jonathan Stott, Luis Lavena] * Added initial support for Ruby 1.9 [John Harrison] * Bug Fixes * Removed sqlite3.dll from source gem [Dan Kubb] * Removed hard coded .bundle from source [Dirkjan Bussink] do_sqlite3-0.10.13/checksums.yaml.gz0000444000004100000410000000042212154173164017242 0ustar www-datawww-dataWRQm;ND1 EY؎?gM Βs~no/ |ݮO|zzk/jcN]YhM%+tT'HZɢZQb#U-MY5c瞺x.=4#]|~x23(x#Wd9DgacZ(wisVXY[ 9xnk%HBTTRD?4 njgMv·Ѡ1fAiLX9v6#) vdo_sqlite3-0.10.13/metadata.yml0000644000004100000410000000651012154173164016263 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: do_sqlite3 version: !ruby/object:Gem::Version version: 0.10.13 platform: ruby authors: - Dirkjan Bussink autorequire: bindir: bin cert_chain: [] date: 2013-05-27 00:00:00 Z dependencies: - !ruby/object:Gem::Dependency name: data_objects prerelease: false requirement: &id001 !ruby/object:Gem::Requirement requirements: - - "=" - !ruby/object:Gem::Version version: 0.10.13 type: :runtime version_requirements: *id001 - !ruby/object:Gem::Dependency name: rspec prerelease: false requirement: &id002 !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: "2.5" type: :development version_requirements: *id002 - !ruby/object:Gem::Dependency name: rake-compiler prerelease: false requirement: &id003 !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: "0.7" type: :development version_requirements: *id003 description: Implements the DataObjects API for Sqlite3 email: d.bussink@gmail.com executables: [] extensions: - ext/do_sqlite3/extconf.rb extra_rdoc_files: - ChangeLog.markdown - LICENSE - README.markdown files: - ChangeLog.markdown - LICENSE - README.markdown - Rakefile - ext/do_sqlite3/compat.h - ext/do_sqlite3/do_common.c - ext/do_sqlite3/do_common.h - ext/do_sqlite3/do_sqlite3.c - ext/do_sqlite3/do_sqlite3.h - ext/do_sqlite3/do_sqlite3_extension.c - ext/do_sqlite3/error.h - ext/do_sqlite3/extconf.rb - lib/do_sqlite3.rb - lib/do_sqlite3/transaction.rb - lib/do_sqlite3/version.rb - spec/command_spec.rb - spec/connection_spec.rb - spec/encoding_spec.rb - spec/error/sql_error_spec.rb - spec/reader_spec.rb - spec/result_spec.rb - spec/spec_helper.rb - spec/typecast/array_spec.rb - spec/typecast/bigdecimal_spec.rb - spec/typecast/boolean_spec.rb - spec/typecast/byte_array_spec.rb - spec/typecast/class_spec.rb - spec/typecast/date_spec.rb - spec/typecast/datetime_spec.rb - spec/typecast/float_spec.rb - spec/typecast/integer_spec.rb - spec/typecast/nil_spec.rb - spec/typecast/other_spec.rb - spec/typecast/range_spec.rb - spec/typecast/string_spec.rb - spec/typecast/time_spec.rb - tasks/compile.rake - tasks/release.rake - tasks/retrieve.rake - tasks/spec.rake homepage: licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - &id004 - ">=" - !ruby/object:Gem::Version version: "0" required_rubygems_version: !ruby/object:Gem::Requirement requirements: - *id004 requirements: [] rubyforge_project: dorb rubygems_version: 2.0.3 signing_key: specification_version: 3 summary: DataObjects Sqlite3 Driver test_files: - spec/command_spec.rb - spec/connection_spec.rb - spec/encoding_spec.rb - spec/error/sql_error_spec.rb - spec/reader_spec.rb - spec/result_spec.rb - spec/spec_helper.rb - spec/typecast/array_spec.rb - spec/typecast/bigdecimal_spec.rb - spec/typecast/boolean_spec.rb - spec/typecast/byte_array_spec.rb - spec/typecast/class_spec.rb - spec/typecast/date_spec.rb - spec/typecast/datetime_spec.rb - spec/typecast/float_spec.rb - spec/typecast/integer_spec.rb - spec/typecast/nil_spec.rb - spec/typecast/other_spec.rb - spec/typecast/range_spec.rb - spec/typecast/string_spec.rb - spec/typecast/time_spec.rb do_sqlite3-0.10.13/lib/0000755000004100000410000000000012154173164014524 5ustar www-datawww-datado_sqlite3-0.10.13/lib/do_sqlite3/0000755000004100000410000000000012154173164016572 5ustar www-datawww-datado_sqlite3-0.10.13/lib/do_sqlite3/version.rb0000644000004100000410000000010612154173164020601 0ustar www-datawww-datamodule DataObjects module Sqlite3 VERSION = '0.10.13' end end do_sqlite3-0.10.13/lib/do_sqlite3/transaction.rb0000644000004100000410000000060212154173164021442 0ustar www-datawww-data module DataObjects module Sqlite3 class Transaction < DataObjects::Transaction def begin_prepared raise NotImplementedError end def commit_prepared raise NotImplementedError end def rollback_prepared raise NotImplementedError end def prepare raise NotImplementedError end end end end do_sqlite3-0.10.13/lib/do_sqlite3.rb0000644000004100000410000000251712154173164017124 0ustar www-datawww-datarequire 'data_objects' if RUBY_PLATFORM =~ /java/ require 'do_jdbc' require 'java' module DataObjects module Sqlite3 JDBC_DRIVER = 'org.sqlite.JDBC' end end begin java.lang.Thread.currentThread.getContextClassLoader().loadClass(DataObjects::Sqlite3::JDBC_DRIVER, true) rescue java.lang.ClassNotFoundException require 'jdbc/sqlite3' # the JDBC driver, packaged as a gem Jdbc::SQLite3.load_driver if Jdbc::SQLite3.respond_to?(:load_driver) end # Another way of loading the JDBC Class. This seems to be more reliable # than Class.forName() or # Thread.currentThread.getContextClassLoader().loadClass() within the # data_objects.Connection Java class, which is currently not working as # expected. java_import DataObjects::Sqlite3::JDBC_DRIVER end begin require 'do_sqlite3/do_sqlite3' rescue LoadError if RUBY_PLATFORM =~ /mingw|mswin/ then RUBY_VERSION =~ /(\d+.\d+)/ require "do_sqlite3/#{$1}/do_sqlite3" else raise end end require 'do_sqlite3/version' require 'do_sqlite3/transaction' if RUBY_PLATFORM !~ /java/ if RUBY_PLATFORM =~ /java/ DataObjects::Sqlite3::Connection.class_eval do def self.pool_size # sqlite3 can have only one write access at a time, with this # concurrent write access will result in "Database locked" errors 1 end end end