do_sqlite3 0.10.5-x86-mingw32 → 0.10.6-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.markdown +5 -0
- data/Rakefile +5 -0
- data/ext/do_sqlite3/do_common.c +60 -55
- data/ext/do_sqlite3/do_common.h +39 -76
- data/ext/do_sqlite3/do_sqlite3.c +62 -62
- data/ext/do_sqlite3/do_sqlite3_extension.c +6 -6
- data/ext/do_sqlite3/error.h +1 -1
- data/lib/do_sqlite3/1.8/do_sqlite3.so +0 -0
- data/lib/do_sqlite3/1.9/do_sqlite3.so +0 -0
- data/lib/do_sqlite3/version.rb +1 -1
- data/tasks/compile.rake +1 -1
- metadata +14 -14
    
        data/ChangeLog.markdown
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
    
        data/ext/do_sqlite3/do_common.c
    CHANGED
    
    | @@ -45,6 +45,11 @@ VALUE rb_cBigDecimal; | |
| 45 45 | 
             
             * Common Functions
         | 
| 46 46 | 
             
             */
         | 
| 47 47 |  | 
| 48 | 
            +
             | 
| 49 | 
            +
            VALUE data_objects_const_get(VALUE scope, const char *constant) {
         | 
| 50 | 
            +
              return rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant));
         | 
| 51 | 
            +
            }
         | 
| 52 | 
            +
             | 
| 48 53 | 
             
            void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) {
         | 
| 49 54 | 
             
              struct timeval stop;
         | 
| 50 55 | 
             
              VALUE message;
         | 
| @@ -57,7 +62,7 @@ void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) { | |
| 57 62 | 
             
              rb_funcall(connection, ID_LOG, 1, message);
         | 
| 58 63 | 
             
            }
         | 
| 59 64 |  | 
| 60 | 
            -
            void  | 
| 65 | 
            +
            void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, const char *message, VALUE query, VALUE state) {
         | 
| 61 66 | 
             
              const char *exception_type = "SQLError";
         | 
| 62 67 | 
             
              const struct errcodes *e;
         | 
| 63 68 |  | 
| @@ -72,7 +77,7 @@ void do_raise_error(VALUE self, const struct errcodes *errors, int errnum, const | |
| 72 77 | 
             
              VALUE uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0);
         | 
| 73 78 |  | 
| 74 79 | 
             
              VALUE exception = rb_funcall(
         | 
| 75 | 
            -
                 | 
| 80 | 
            +
                data_objects_const_get(mDO, exception_type),
         | 
| 76 81 | 
             
                ID_NEW,
         | 
| 77 82 | 
             
                5,
         | 
| 78 83 | 
             
                rb_str_new2(message),
         | 
| @@ -85,7 +90,7 @@ void do_raise_error(VALUE self, const struct errcodes *errors, int errnum, const | |
| 85 90 | 
             
              rb_exc_raise(exception);
         | 
| 86 91 | 
             
            }
         | 
| 87 92 |  | 
| 88 | 
            -
            char * | 
| 93 | 
            +
            char *data_objects_get_uri_option(VALUE query_hash, const char *key) {
         | 
| 89 94 | 
             
              VALUE query_value;
         | 
| 90 95 | 
             
              char *value = NULL;
         | 
| 91 96 |  | 
| @@ -102,7 +107,7 @@ char *get_uri_option(VALUE query_hash, const char *key) { | |
| 102 107 | 
             
              return value;
         | 
| 103 108 | 
             
            }
         | 
| 104 109 |  | 
| 105 | 
            -
            void  | 
| 110 | 
            +
            void data_objects_assert_file_exists(char *file, const char *message) {
         | 
| 106 111 | 
             
              if (file) {
         | 
| 107 112 | 
             
                if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_str_new2(file)) == Qfalse) {
         | 
| 108 113 | 
             
                  rb_raise(rb_eArgError, "%s", message);
         | 
| @@ -110,7 +115,7 @@ void assert_file_exists(char *file, const char *message) { | |
| 110 115 | 
             
              }
         | 
| 111 116 | 
             
            }
         | 
| 112 117 |  | 
| 113 | 
            -
            VALUE  | 
| 118 | 
            +
            VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args) {
         | 
| 114 119 | 
             
              VALUE array = rb_ary_new();
         | 
| 115 120 | 
             
              int i;
         | 
| 116 121 |  | 
| @@ -123,7 +128,7 @@ VALUE build_query_from_args(VALUE klass, int count, VALUE *args) { | |
| 123 128 |  | 
| 124 129 | 
             
            // Find the greatest common denominator and reduce the provided numerator and denominator.
         | 
| 125 130 | 
             
            // This replaces calles to Rational.reduce! which does the same thing, but really slowly.
         | 
| 126 | 
            -
            void  | 
| 131 | 
            +
            void data_objects_reduce(do_int64 *numerator, do_int64 *denominator) {
         | 
| 127 132 | 
             
              do_int64 a = *numerator, b = *denominator, c;
         | 
| 128 133 |  | 
| 129 134 | 
             
              while (a != 0) {
         | 
| @@ -137,7 +142,7 @@ void reduce(do_int64 *numerator, do_int64 *denominator) { | |
| 137 142 | 
             
            }
         | 
| 138 143 |  | 
| 139 144 | 
             
            // Generate the date integer which Date.civil_to_jd returns
         | 
| 140 | 
            -
            int  | 
| 145 | 
            +
            int data_objects_jd_from_date(int year, int month, int day) {
         | 
| 141 146 | 
             
              int a, b;
         | 
| 142 147 |  | 
| 143 148 | 
             
              if (month <= 2) {
         | 
| @@ -151,24 +156,24 @@ int jd_from_date(int year, int month, int day) { | |
| 151 156 | 
             
              return (int)(floor(365.25 * (year + 4716)) + floor(30.6001 * (month + 1)) + day + b - 1524);
         | 
| 152 157 | 
             
            }
         | 
| 153 158 |  | 
| 154 | 
            -
            VALUE  | 
| 159 | 
            +
            VALUE data_objects_seconds_to_offset(long seconds_offset) {
         | 
| 155 160 | 
             
              do_int64 num = seconds_offset;
         | 
| 156 161 | 
             
              do_int64 den = 86400;
         | 
| 157 162 |  | 
| 158 | 
            -
               | 
| 163 | 
            +
              data_objects_reduce(&num, &den);
         | 
| 159 164 | 
             
              return rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den));
         | 
| 160 165 | 
             
            }
         | 
| 161 166 |  | 
| 162 | 
            -
            VALUE  | 
| 167 | 
            +
            VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset) {
         | 
| 163 168 | 
             
              do_int64 seconds = 0;
         | 
| 164 169 |  | 
| 165 170 | 
             
              seconds += hour_offset * 3600;
         | 
| 166 171 | 
             
              seconds += minute_offset * 60;
         | 
| 167 172 |  | 
| 168 | 
            -
              return  | 
| 173 | 
            +
              return data_objects_seconds_to_offset(seconds);
         | 
| 169 174 | 
             
            }
         | 
| 170 175 |  | 
| 171 | 
            -
            VALUE  | 
| 176 | 
            +
            VALUE data_objects_parse_date(const char *date) {
         | 
| 172 177 | 
             
              static char const *const _fmt_date = "%4d-%2d-%2d";
         | 
| 173 178 | 
             
              int year = 0, month = 0, day = 0;
         | 
| 174 179 | 
             
              int jd, ajd;
         | 
| @@ -180,14 +185,14 @@ VALUE parse_date(const char *date) { | |
| 180 185 | 
             
                  return Qnil;
         | 
| 181 186 | 
             
              }
         | 
| 182 187 |  | 
| 183 | 
            -
              jd       =  | 
| 188 | 
            +
              jd       = data_objects_jd_from_date(year, month, day);
         | 
| 184 189 | 
             
              ajd      = (jd * 2) - 1;        // Math from Date.jd_to_ajd
         | 
| 185 190 | 
             
              rational = rb_funcall(rb_mKernel, ID_RATIONAL, 2, INT2NUM(ajd), INT2NUM(2));
         | 
| 186 191 |  | 
| 187 192 | 
             
              return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
         | 
| 188 193 | 
             
            }
         | 
| 189 194 |  | 
| 190 | 
            -
            VALUE  | 
| 195 | 
            +
            VALUE data_objects_parse_time(const char *date) {
         | 
| 191 196 | 
             
              static char const* const _fmt_datetime = "%4d-%2d-%2d %2d:%2d:%2d%7lf";
         | 
| 192 197 | 
             
              int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0;
         | 
| 193 198 | 
             
              double subsec = 0;
         | 
| @@ -208,7 +213,7 @@ VALUE parse_time(const char *date) { | |
| 208 213 | 
             
              return rb_funcall(rb_cTime, rb_intern("local"), 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), INT2NUM(usec));
         | 
| 209 214 | 
             
            }
         | 
| 210 215 |  | 
| 211 | 
            -
            VALUE  | 
| 216 | 
            +
            VALUE data_objects_parse_date_time(const char *date) {
         | 
| 212 217 | 
             
              static char const* const _fmt_datetime_tz_normal = "%4d-%2d-%2d%*c%2d:%2d:%2d%3d:%2d";
         | 
| 213 218 | 
             
              static char const* const _fmt_datetime_tz_subsec = "%4d-%2d-%2d%*c%2d:%2d:%2d.%*d%3d:%2d";
         | 
| 214 219 | 
             
              int tokens_read;
         | 
| @@ -294,7 +299,7 @@ VALUE parse_date_time(const char *date) { | |
| 294 299 | 
             
                  rb_raise(eDataError, "Couldn't parse date: %s", date);
         | 
| 295 300 | 
             
              }
         | 
| 296 301 |  | 
| 297 | 
            -
              jd =  | 
| 302 | 
            +
              jd = data_objects_jd_from_date(year, month, day);
         | 
| 298 303 |  | 
| 299 304 | 
             
              /*
         | 
| 300 305 | 
             
               * Generate ajd with fractional days for the time.
         | 
| @@ -306,47 +311,47 @@ VALUE parse_date_time(const char *date) { | |
| 306 311 | 
             
              num = (hour * 1440) + (min * 24);
         | 
| 307 312 | 
             
              num -= (hour_offset * 1440) + (minute_offset * 24);
         | 
| 308 313 | 
             
              den = (24 * 1440);
         | 
| 309 | 
            -
               | 
| 314 | 
            +
              data_objects_reduce(&num, &den);
         | 
| 310 315 |  | 
| 311 316 | 
             
              num = (num * 86400) + (sec * den);
         | 
| 312 317 | 
             
              den = den * 86400;
         | 
| 313 | 
            -
               | 
| 318 | 
            +
              data_objects_reduce(&num, &den);
         | 
| 314 319 |  | 
| 315 320 | 
             
              num += jd * den;
         | 
| 316 321 |  | 
| 317 322 | 
             
              num = (num * 2) - den;
         | 
| 318 323 | 
             
              den *= 2;
         | 
| 319 | 
            -
               | 
| 324 | 
            +
              data_objects_reduce(&num, &den);
         | 
| 320 325 |  | 
| 321 326 | 
             
              ajd = rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ull2inum(num), rb_ull2inum(den));
         | 
| 322 | 
            -
              offset =  | 
| 327 | 
            +
              offset = data_objects_timezone_to_offset(hour_offset, minute_offset);
         | 
| 323 328 |  | 
| 324 329 | 
             
              return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
         | 
| 325 330 | 
             
            }
         | 
| 326 331 |  | 
| 327 | 
            -
            VALUE  | 
| 332 | 
            +
            VALUE data_objects_cConnection_character_set(VALUE self) {
         | 
| 328 333 | 
             
              return rb_iv_get(self, "@encoding");
         | 
| 329 334 | 
             
            }
         | 
| 330 335 |  | 
| 331 | 
            -
            VALUE  | 
| 336 | 
            +
            VALUE data_objects_cConnection_is_using_socket(VALUE self) {
         | 
| 332 337 | 
             
              return rb_iv_get(self, "@using_socket");
         | 
| 333 338 | 
             
            }
         | 
| 334 339 |  | 
| 335 | 
            -
            VALUE  | 
| 340 | 
            +
            VALUE data_objects_cConnection_ssl_cipher(VALUE self) {
         | 
| 336 341 | 
             
              return rb_iv_get(self, "@ssl_cipher");
         | 
| 337 342 | 
             
            }
         | 
| 338 343 |  | 
| 339 | 
            -
            VALUE  | 
| 344 | 
            +
            VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value) {
         | 
| 340 345 | 
             
              return rb_funcall(value, ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'"));
         | 
| 341 346 | 
             
            }
         | 
| 342 347 |  | 
| 343 | 
            -
            VALUE  | 
| 348 | 
            +
            VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value) {
         | 
| 344 349 | 
             
              // TODO: Support non-local dates. we need to call #new_offset on the date to be
         | 
| 345 350 | 
             
              // quoted and pass in the current locale's date offset (self.new_offset((hours * 3600).to_r / 86400)
         | 
| 346 351 | 
             
              return rb_funcall(value, ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'"));
         | 
| 347 352 | 
             
            }
         | 
| 348 353 |  | 
| 349 | 
            -
            VALUE  | 
| 354 | 
            +
            VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value) {
         | 
| 350 355 | 
             
              return rb_funcall(value, ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d'"));
         | 
| 351 356 | 
             
            }
         | 
| 352 357 |  | 
| @@ -354,7 +359,7 @@ VALUE cConnection_quote_date(VALUE self, VALUE value) { | |
| 354 359 | 
             
             * Accepts an array of Ruby types (Fixnum, Float, String, etc...) and turns them
         | 
| 355 360 | 
             
             * into Ruby-strings so we can easily typecast later
         | 
| 356 361 | 
             
             */
         | 
| 357 | 
            -
            VALUE  | 
| 362 | 
            +
            VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self) {
         | 
| 358 363 | 
             
              VALUE type_strings = rb_ary_new();
         | 
| 359 364 | 
             
              VALUE array = rb_ary_new();
         | 
| 360 365 |  | 
| @@ -393,7 +398,7 @@ VALUE cCommand_set_types(int argc, VALUE *argv, VALUE self) { | |
| 393 398 | 
             
              return array;
         | 
| 394 399 | 
             
            }
         | 
| 395 400 |  | 
| 396 | 
            -
            VALUE  | 
| 401 | 
            +
            VALUE data_objects_cReader_values(VALUE self) {
         | 
| 397 402 | 
             
              VALUE state = rb_iv_get(self, "@opened");
         | 
| 398 403 | 
             
              VALUE values = rb_iv_get(self, "@values");
         | 
| 399 404 |  | 
| @@ -404,27 +409,27 @@ VALUE cReader_values(VALUE self) { | |
| 404 409 | 
             
              return rb_iv_get(self, "@values");
         | 
| 405 410 | 
             
            }
         | 
| 406 411 |  | 
| 407 | 
            -
            VALUE  | 
| 412 | 
            +
            VALUE data_objects_cReader_fields(VALUE self) {
         | 
| 408 413 | 
             
              return rb_iv_get(self, "@fields");
         | 
| 409 414 | 
             
            }
         | 
| 410 415 |  | 
| 411 | 
            -
            VALUE  | 
| 416 | 
            +
            VALUE data_objects_cReader_field_count(VALUE self) {
         | 
| 412 417 | 
             
              return rb_iv_get(self, "@field_count");
         | 
| 413 418 | 
             
            }
         | 
| 414 419 |  | 
| 415 | 
            -
            void  | 
| 420 | 
            +
            void data_objects_common_init(void) {
         | 
| 416 421 | 
             
              rb_require("bigdecimal");
         | 
| 417 422 | 
             
              rb_require("rational");
         | 
| 418 423 | 
             
              rb_require("date");
         | 
| 419 424 | 
             
              rb_require("data_objects");
         | 
| 420 425 |  | 
| 421 | 
            -
              // Needed by  | 
| 426 | 
            +
              // Needed by data_objects_const_get
         | 
| 422 427 | 
             
              ID_CONST_GET = rb_intern("const_get");
         | 
| 423 428 |  | 
| 424 429 | 
             
              // Get references classes needed for Date/Time parsing
         | 
| 425 | 
            -
              rb_cDate =  | 
| 426 | 
            -
              rb_cDateTime =  | 
| 427 | 
            -
              rb_cBigDecimal =  | 
| 430 | 
            +
              rb_cDate = data_objects_const_get(rb_mKernel, "Date");
         | 
| 431 | 
            +
              rb_cDateTime = data_objects_const_get(rb_mKernel, "DateTime");
         | 
| 432 | 
            +
              rb_cBigDecimal = data_objects_const_get(rb_mKernel, "BigDecimal");
         | 
| 428 433 |  | 
| 429 434 | 
             
              ID_NEW = rb_intern("new");
         | 
| 430 435 | 
             
            #ifdef RUBY_LESS_THAN_186
         | 
| @@ -439,22 +444,22 @@ void common_init(void) { | |
| 439 444 | 
             
              ID_LOG = rb_intern("log");
         | 
| 440 445 |  | 
| 441 446 | 
             
              // Get references to the Extlib module
         | 
| 442 | 
            -
              mExtlib =  | 
| 443 | 
            -
              rb_cByteArray =  | 
| 447 | 
            +
              mExtlib = data_objects_const_get(rb_mKernel, "Extlib");
         | 
| 448 | 
            +
              rb_cByteArray = data_objects_const_get(mExtlib, "ByteArray");
         | 
| 444 449 |  | 
| 445 450 | 
             
              // Get references to the DataObjects module and its classes
         | 
| 446 | 
            -
              mDO =  | 
| 447 | 
            -
              cDO_Quoting =  | 
| 448 | 
            -
              cDO_Connection =  | 
| 449 | 
            -
              cDO_Command =  | 
| 450 | 
            -
              cDO_Result =  | 
| 451 | 
            -
              cDO_Reader =  | 
| 452 | 
            -
              cDO_Logger =  | 
| 453 | 
            -
              cDO_Logger_Message =  | 
| 454 | 
            -
              cDO_Extension =  | 
| 455 | 
            -
             | 
| 456 | 
            -
              eConnectionError =  | 
| 457 | 
            -
              eDataError =  | 
| 451 | 
            +
              mDO = data_objects_const_get(rb_mKernel, "DataObjects");
         | 
| 452 | 
            +
              cDO_Quoting = data_objects_const_get(mDO, "Quoting");
         | 
| 453 | 
            +
              cDO_Connection = data_objects_const_get(mDO, "Connection");
         | 
| 454 | 
            +
              cDO_Command = data_objects_const_get(mDO, "Command");
         | 
| 455 | 
            +
              cDO_Result = data_objects_const_get(mDO, "Result");
         | 
| 456 | 
            +
              cDO_Reader = data_objects_const_get(mDO, "Reader");
         | 
| 457 | 
            +
              cDO_Logger = data_objects_const_get(mDO, "Logger");
         | 
| 458 | 
            +
              cDO_Logger_Message = data_objects_const_get(cDO_Logger, "Message");
         | 
| 459 | 
            +
              cDO_Extension = data_objects_const_get(mDO, "Extension");
         | 
| 460 | 
            +
             | 
| 461 | 
            +
              eConnectionError = data_objects_const_get(mDO, "ConnectionError");
         | 
| 462 | 
            +
              eDataError = data_objects_const_get(mDO, "DataError");
         | 
| 458 463 |  | 
| 459 464 | 
             
              rb_global_variable(&ID_NEW_DATE);
         | 
| 460 465 | 
             
              rb_global_variable(&ID_RATIONAL);
         | 
| @@ -480,7 +485,7 @@ void common_init(void) { | |
| 480 485 | 
             
            /*
         | 
| 481 486 | 
             
             * Common typecasting logic that can be used or overriden by Adapters.
         | 
| 482 487 | 
             
             */
         | 
| 483 | 
            -
            extern VALUE  | 
| 488 | 
            +
            extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding) {
         | 
| 484 489 | 
             
            #ifdef HAVE_RUBY_ENCODING_H
         | 
| 485 490 | 
             
              rb_encoding *internal_encoding = rb_default_internal_encoding();
         | 
| 486 491 | 
             
            #else
         | 
| @@ -491,7 +496,7 @@ extern VALUE do_typecast(const char *value, long length, const VALUE type, int e | |
| 491 496 | 
             
                return rb_cstr2inum(value, 10);
         | 
| 492 497 | 
             
              }
         | 
| 493 498 | 
             
              else if (type == rb_cString) {
         | 
| 494 | 
            -
                return  | 
| 499 | 
            +
                return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding);
         | 
| 495 500 | 
             
              }
         | 
| 496 501 | 
             
              else if (type == rb_cFloat) {
         | 
| 497 502 | 
             
                return rb_float_new(rb_cstr_to_dbl(value, Qfalse));
         | 
| @@ -500,13 +505,13 @@ extern VALUE do_typecast(const char *value, long length, const VALUE type, int e | |
| 500 505 | 
             
                return rb_funcall(rb_cBigDecimal, ID_NEW, 1, rb_str_new(value, length));
         | 
| 501 506 | 
             
              }
         | 
| 502 507 | 
             
              else if (type == rb_cDate) {
         | 
| 503 | 
            -
                return  | 
| 508 | 
            +
                return data_objects_parse_date(value);
         | 
| 504 509 | 
             
              }
         | 
| 505 510 | 
             
              else if (type == rb_cDateTime) {
         | 
| 506 | 
            -
                return  | 
| 511 | 
            +
                return data_objects_parse_date_time(value);
         | 
| 507 512 | 
             
              }
         | 
| 508 513 | 
             
              else if (type == rb_cTime) {
         | 
| 509 | 
            -
                return  | 
| 514 | 
            +
                return data_objects_parse_time(value);
         | 
| 510 515 | 
             
              }
         | 
| 511 516 | 
             
              else if (type == rb_cTrueClass) {
         | 
| 512 517 | 
             
                return (!value || strcmp("0", value) == 0) ? Qfalse : Qtrue;
         | 
| @@ -521,6 +526,6 @@ extern VALUE do_typecast(const char *value, long length, const VALUE type, int e | |
| 521 526 | 
             
                return Qnil;
         | 
| 522 527 | 
             
              }
         | 
| 523 528 | 
             
              else {
         | 
| 524 | 
            -
                return  | 
| 529 | 
            +
                return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding);
         | 
| 525 530 | 
             
              }
         | 
| 526 531 | 
             
            }
         | 
    
        data/ext/do_sqlite3/do_common.h
    CHANGED
    
    | @@ -3,18 +3,24 @@ | |
| 3 3 |  | 
| 4 4 | 
             
            #include <ruby.h>
         | 
| 5 5 |  | 
| 6 | 
            +
            // Needed for defining error.h
         | 
| 7 | 
            +
            struct errcodes {
         | 
| 8 | 
            +
              int error_no;
         | 
| 9 | 
            +
              const char *error_name;
         | 
| 10 | 
            +
              const char *exception;
         | 
| 11 | 
            +
            };
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            #define ERRCODE(name,message)   {name, #name, message}
         | 
| 14 | 
            +
             | 
| 6 15 | 
             
            #ifdef _WIN32
         | 
| 7 | 
            -
            #define cCommand_execute cCommand_execute_sync
         | 
| 8 16 | 
             
            typedef signed __int64 do_int64;
         | 
| 9 17 | 
             
            #else
         | 
| 10 | 
            -
            #define cCommand_execute cCommand_execute_async
         | 
| 11 18 | 
             
            typedef signed long long int do_int64;
         | 
| 12 19 | 
             
            #endif
         | 
| 13 20 |  | 
| 14 21 | 
             
            #ifdef HAVE_RUBY_ENCODING_H
         | 
| 15 22 | 
             
            #include <ruby/encoding.h>
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            #define DO_STR_NEW2(str, encoding, internal_encoding) \
         | 
| 23 | 
            +
            #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \
         | 
| 18 24 | 
             
              ({ \
         | 
| 19 25 | 
             
                VALUE _string = rb_str_new2((const char *)str); \
         | 
| 20 26 | 
             
                if(encoding != -1) { \
         | 
| @@ -26,7 +32,7 @@ typedef signed long long int do_int64; | |
| 26 32 | 
             
                _string; \
         | 
| 27 33 | 
             
              })
         | 
| 28 34 |  | 
| 29 | 
            -
            #define  | 
| 35 | 
            +
            #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \
         | 
| 30 36 | 
             
              ({ \
         | 
| 31 37 | 
             
                VALUE _string = rb_str_new((const char *)str, (long)len); \
         | 
| 32 38 | 
             
                if(encoding != -1) { \
         | 
| @@ -38,24 +44,15 @@ typedef signed long long int do_int64; | |
| 38 44 | 
             
                _string; \
         | 
| 39 45 | 
             
              })
         | 
| 40 46 |  | 
| 41 | 
            -
            # | 
| 47 | 
            +
            #else
         | 
| 42 48 |  | 
| 43 | 
            -
            #define  | 
| 49 | 
            +
            #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \
         | 
| 44 50 | 
             
              rb_str_new2((const char *)str)
         | 
| 45 51 |  | 
| 46 | 
            -
            #define  | 
| 52 | 
            +
            #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \
         | 
| 47 53 | 
             
              rb_str_new((const char *)str, (long)len)
         | 
| 48 54 | 
             
            #endif
         | 
| 49 55 |  | 
| 50 | 
            -
            // Needed for defining error.h
         | 
| 51 | 
            -
            struct errcodes {
         | 
| 52 | 
            -
              int error_no;
         | 
| 53 | 
            -
              const char *error_name;
         | 
| 54 | 
            -
              const char *exception;
         | 
| 55 | 
            -
            };
         | 
| 56 | 
            -
             | 
| 57 | 
            -
            #define ERRCODE(name,message)   {name, #name, message}
         | 
| 58 | 
            -
             | 
| 59 56 | 
             
            // To store rb_intern values
         | 
| 60 57 | 
             
            extern ID ID_NEW;
         | 
| 61 58 | 
             
            extern ID ID_NEW_DATE;
         | 
| @@ -89,71 +86,37 @@ extern VALUE rb_cDateTime; | |
| 89 86 | 
             
            extern VALUE rb_cBigDecimal;
         | 
| 90 87 |  | 
| 91 88 | 
             
            extern void data_objects_debug(VALUE connection, VALUE string, struct timeval *start);
         | 
| 92 | 
            -
            extern char * | 
| 93 | 
            -
            extern void  | 
| 94 | 
            -
            extern VALUE  | 
| 95 | 
            -
             | 
| 96 | 
            -
            extern void reduce(do_int64 *numerator, do_int64 *denominator);
         | 
| 97 | 
            -
            extern int jd_from_date(int year, int month, int day);
         | 
| 98 | 
            -
            extern VALUE seconds_to_offset(long seconds_offset);
         | 
| 99 | 
            -
            extern VALUE timezone_to_offset(int hour_offset, int minute_offset);
         | 
| 100 | 
            -
             | 
| 101 | 
            -
            extern VALUE parse_date(const char *date);
         | 
| 102 | 
            -
            extern VALUE parse_time(const char *date);
         | 
| 103 | 
            -
            extern VALUE parse_date_time(const char *date);
         | 
| 104 | 
            -
             | 
| 105 | 
            -
            extern VALUE cConnection_character_set(VALUE self);
         | 
| 106 | 
            -
            extern VALUE cConnection_is_using_socket(VALUE self);
         | 
| 107 | 
            -
            extern VALUE cConnection_ssl_cipher(VALUE self);
         | 
| 108 | 
            -
            extern VALUE cConnection_quote_time(VALUE self, VALUE value);
         | 
| 109 | 
            -
            extern VALUE cConnection_quote_date_time(VALUE self, VALUE value);
         | 
| 110 | 
            -
            extern VALUE cConnection_quote_date(VALUE self, VALUE value);
         | 
| 111 | 
            -
             | 
| 112 | 
            -
            extern VALUE cCommand_set_types(int argc, VALUE *argv, VALUE self);
         | 
| 113 | 
            -
             | 
| 114 | 
            -
            extern VALUE cReader_values(VALUE self);
         | 
| 115 | 
            -
            extern VALUE cReader_fields(VALUE self);
         | 
| 116 | 
            -
            extern VALUE cReader_field_count(VALUE self);
         | 
| 117 | 
            -
             | 
| 118 | 
            -
            extern void common_init(void);
         | 
| 119 | 
            -
             | 
| 120 | 
            -
            static inline VALUE do_const_get(VALUE scope, const char *constant) {
         | 
| 121 | 
            -
              return rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant));
         | 
| 122 | 
            -
            }
         | 
| 89 | 
            +
            extern char *data_objects_get_uri_option(VALUE query_hash, const char *key);
         | 
| 90 | 
            +
            extern void data_objects_assert_file_exists(char *file, const char *message);
         | 
| 91 | 
            +
            extern VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args);
         | 
| 123 92 |  | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 93 | 
            +
            extern void data_objects_reduce(do_int64 *numerator, do_int64 *denominator);
         | 
| 94 | 
            +
            extern int data_objects_jd_from_date(int year, int month, int day);
         | 
| 95 | 
            +
            extern VALUE data_objects_seconds_to_offset(long seconds_offset);
         | 
| 96 | 
            +
            extern VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset);
         | 
| 126 97 |  | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
              }
         | 
| 98 | 
            +
            extern VALUE data_objects_parse_date(const char *date);
         | 
| 99 | 
            +
            extern VALUE data_objects_parse_time(const char *date);
         | 
| 100 | 
            +
            extern VALUE data_objects_parse_date_time(const char *date);
         | 
| 131 101 |  | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 102 | 
            +
            extern VALUE data_objects_cConnection_character_set(VALUE self);
         | 
| 103 | 
            +
            extern VALUE data_objects_cConnection_is_using_socket(VALUE self);
         | 
| 104 | 
            +
            extern VALUE data_objects_cConnection_ssl_cipher(VALUE self);
         | 
| 105 | 
            +
            extern VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value);
         | 
| 106 | 
            +
            extern VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value);
         | 
| 107 | 
            +
            extern VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value);
         | 
| 136 108 |  | 
| 137 | 
            -
             | 
| 138 | 
            -
            }
         | 
| 109 | 
            +
            extern VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self);
         | 
| 139 110 |  | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 111 | 
            +
            extern VALUE data_objects_cReader_values(VALUE self);
         | 
| 112 | 
            +
            extern VALUE data_objects_cReader_fields(VALUE self);
         | 
| 113 | 
            +
            extern VALUE data_objects_cReader_field_count(VALUE self);
         | 
| 142 114 |  | 
| 143 | 
            -
             | 
| 144 | 
            -
                if(encoding != -1) {
         | 
| 145 | 
            -
                  rb_enc_associate_index(new_string, encoding);
         | 
| 146 | 
            -
                }
         | 
| 147 | 
            -
             | 
| 148 | 
            -
                if(internal_encoding) {
         | 
| 149 | 
            -
                  new_string = rb_str_export_to_enc(new_string, internal_encoding);
         | 
| 150 | 
            -
                }
         | 
| 151 | 
            -
            #endif
         | 
| 115 | 
            +
            extern void data_objects_common_init(void);
         | 
| 152 116 |  | 
| 153 | 
            -
             | 
| 154 | 
            -
            }
         | 
| 117 | 
            +
            extern VALUE data_objects_const_get(VALUE scope, const char *constant);
         | 
| 155 118 |  | 
| 156 | 
            -
            static inline void  | 
| 119 | 
            +
            static inline void data_objects_define_errors(VALUE scope, const struct errcodes *errors) {
         | 
| 157 120 | 
             
              const struct errcodes *e;
         | 
| 158 121 |  | 
| 159 122 | 
             
              for (e = errors; e->error_name; e++) {
         | 
| @@ -161,9 +124,9 @@ static inline void do_define_errors(VALUE scope, const struct errcodes *errors) | |
| 161 124 | 
             
              }
         | 
| 162 125 | 
             
            }
         | 
| 163 126 |  | 
| 164 | 
            -
            extern void  | 
| 127 | 
            +
            extern void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, const char *message, VALUE query, VALUE state);
         | 
| 165 128 |  | 
| 166 | 
            -
            extern VALUE  | 
| 129 | 
            +
            extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding);
         | 
| 167 130 |  | 
| 168 131 | 
             
            #define RSTRING_NOT_MODIFIED
         | 
| 169 132 |  | 
    
        data/ext/do_sqlite3/do_sqlite3.c
    CHANGED
    
    | @@ -4,10 +4,10 @@ | |
| 4 4 | 
             
            #include "do_common.h"
         | 
| 5 5 |  | 
| 6 6 | 
             
            VALUE mSqlite3;
         | 
| 7 | 
            -
            VALUE  | 
| 8 | 
            -
            VALUE  | 
| 9 | 
            -
            VALUE  | 
| 10 | 
            -
            VALUE  | 
| 7 | 
            +
            VALUE cSqlite3Connection;
         | 
| 8 | 
            +
            VALUE cSqlite3Command;
         | 
| 9 | 
            +
            VALUE cSqlite3Result;
         | 
| 10 | 
            +
            VALUE cSqlite3Reader;
         | 
| 11 11 |  | 
| 12 12 | 
             
            VALUE OPEN_FLAG_READONLY;
         | 
| 13 13 | 
             
            VALUE OPEN_FLAG_READWRITE;
         | 
| @@ -15,15 +15,15 @@ VALUE OPEN_FLAG_CREATE; | |
| 15 15 | 
             
            VALUE OPEN_FLAG_NO_MUTEX;
         | 
| 16 16 | 
             
            VALUE OPEN_FLAG_FULL_MUTEX;
         | 
| 17 17 |  | 
| 18 | 
            -
            void  | 
| 18 | 
            +
            void do_sqlite3_raise_error(VALUE self, sqlite3 *result, VALUE query) {
         | 
| 19 19 | 
             
              int errnum = sqlite3_errcode(result);
         | 
| 20 20 | 
             
              const char *message = sqlite3_errmsg(result);
         | 
| 21 21 | 
             
              VALUE sql_state = rb_str_new2("");
         | 
| 22 22 |  | 
| 23 | 
            -
               | 
| 23 | 
            +
              data_objects_raise_error(self, do_sqlite3_errors, errnum, message, query, sql_state);
         | 
| 24 24 | 
             
            }
         | 
| 25 25 |  | 
| 26 | 
            -
            VALUE  | 
| 26 | 
            +
            VALUE do_sqlite3_typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) {
         | 
| 27 27 | 
             
              int original_type = sqlite3_column_type(stmt, i);
         | 
| 28 28 | 
             
              int length = sqlite3_column_bytes(stmt, i);
         | 
| 29 29 |  | 
| @@ -61,7 +61,7 @@ VALUE typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) { | |
| 61 61 | 
             
                return LL2NUM(sqlite3_column_int64(stmt, i));
         | 
| 62 62 | 
             
              }
         | 
| 63 63 | 
             
              else if (type == rb_cString) {
         | 
| 64 | 
            -
                return  | 
| 64 | 
            +
                return DATA_OBJECTS_STR_NEW((char*)sqlite3_column_text(stmt, i), length, encoding, internal_encoding);
         | 
| 65 65 | 
             
              }
         | 
| 66 66 | 
             
              else if (type == rb_cFloat) {
         | 
| 67 67 | 
             
                return rb_float_new(sqlite3_column_double(stmt, i));
         | 
| @@ -70,13 +70,13 @@ VALUE typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) { | |
| 70 70 | 
             
                return rb_funcall(rb_cBigDecimal, ID_NEW, 1, rb_str_new((char*)sqlite3_column_text(stmt, i), length));
         | 
| 71 71 | 
             
              }
         | 
| 72 72 | 
             
              else if (type == rb_cDate) {
         | 
| 73 | 
            -
                return  | 
| 73 | 
            +
                return data_objects_parse_date((char*)sqlite3_column_text(stmt, i));
         | 
| 74 74 | 
             
              }
         | 
| 75 75 | 
             
              else if (type == rb_cDateTime) {
         | 
| 76 | 
            -
                return  | 
| 76 | 
            +
                return data_objects_parse_date_time((char*)sqlite3_column_text(stmt, i));
         | 
| 77 77 | 
             
              }
         | 
| 78 78 | 
             
              else if (type == rb_cTime) {
         | 
| 79 | 
            -
                return  | 
| 79 | 
            +
                return data_objects_parse_time((char*)sqlite3_column_text(stmt, i));
         | 
| 80 80 | 
             
              }
         | 
| 81 81 | 
             
              else if (type == rb_cTrueClass) {
         | 
| 82 82 | 
             
                return strcmp((char*)sqlite3_column_text(stmt, i), "t") == 0 ? Qtrue : Qfalse;
         | 
| @@ -91,7 +91,7 @@ VALUE typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) { | |
| 91 91 | 
             
                return Qnil;
         | 
| 92 92 | 
             
              }
         | 
| 93 93 | 
             
              else {
         | 
| 94 | 
            -
                return  | 
| 94 | 
            +
                return DATA_OBJECTS_STR_NEW((char*)sqlite3_column_text(stmt, i), length, encoding, internal_encoding);
         | 
| 95 95 | 
             
              }
         | 
| 96 96 | 
             
            }
         | 
| 97 97 |  | 
| @@ -99,7 +99,7 @@ VALUE typecast(sqlite3_stmt *stmt, int i, VALUE type, int encoding) { | |
| 99 99 |  | 
| 100 100 | 
             
            #define FLAG_PRESENT(query_values, flag) !NIL_P(rb_hash_aref(query_values, flag))
         | 
| 101 101 |  | 
| 102 | 
            -
            int  | 
| 102 | 
            +
            int do_sqlite3_flags_from_uri(VALUE uri) {
         | 
| 103 103 | 
             
              VALUE query_values = rb_funcall(uri, rb_intern("query"), 0);
         | 
| 104 104 | 
             
              int flags = 0;
         | 
| 105 105 |  | 
| @@ -139,19 +139,19 @@ int flags_from_uri(VALUE uri) { | |
| 139 139 |  | 
| 140 140 | 
             
            /****** Public API ******/
         | 
| 141 141 |  | 
| 142 | 
            -
            VALUE  | 
| 142 | 
            +
            VALUE do_sqlite3_cConnection_initialize(VALUE self, VALUE uri) {
         | 
| 143 143 | 
             
              VALUE path = rb_funcall(uri, rb_intern("path"), 0);
         | 
| 144 144 | 
             
              sqlite3 *db = NULL;
         | 
| 145 145 | 
             
              int ret;
         | 
| 146 146 |  | 
| 147 147 | 
             
            #ifdef HAVE_SQLITE3_OPEN_V2
         | 
| 148 | 
            -
              ret = sqlite3_open_v2(StringValuePtr(path), &db,  | 
| 148 | 
            +
              ret = sqlite3_open_v2(StringValuePtr(path), &db, do_sqlite3_flags_from_uri(uri), 0);
         | 
| 149 149 | 
             
            #else
         | 
| 150 150 | 
             
              ret = sqlite3_open(StringValuePtr(path), &db);
         | 
| 151 151 | 
             
            #endif
         | 
| 152 152 |  | 
| 153 153 | 
             
              if (ret != SQLITE_OK) {
         | 
| 154 | 
            -
                 | 
| 154 | 
            +
                do_sqlite3_raise_error(self, db, Qnil);
         | 
| 155 155 | 
             
              }
         | 
| 156 156 |  | 
| 157 157 | 
             
              rb_iv_set(self, "@uri", uri);
         | 
| @@ -165,7 +165,7 @@ VALUE cConnection_initialize(VALUE self, VALUE uri) { | |
| 165 165 | 
             
              return Qtrue;
         | 
| 166 166 | 
             
            }
         | 
| 167 167 |  | 
| 168 | 
            -
            VALUE  | 
| 168 | 
            +
            VALUE do_sqlite3_cConnection_dispose(VALUE self) {
         | 
| 169 169 | 
             
              VALUE connection_container = rb_iv_get(self, "@connection");
         | 
| 170 170 |  | 
| 171 171 | 
             
              if (connection_container == Qnil) {
         | 
| @@ -183,11 +183,11 @@ VALUE cConnection_dispose(VALUE self) { | |
| 183 183 | 
             
              return Qtrue;
         | 
| 184 184 | 
             
            }
         | 
| 185 185 |  | 
| 186 | 
            -
            VALUE  | 
| 186 | 
            +
            VALUE do_sqlite3_cConnection_quote_boolean(VALUE self, VALUE value) {
         | 
| 187 187 | 
             
              return rb_str_new2(value == Qtrue ? "'t'" : "'f'");
         | 
| 188 188 | 
             
            }
         | 
| 189 189 |  | 
| 190 | 
            -
            VALUE  | 
| 190 | 
            +
            VALUE do_sqlite3_cConnection_quote_string(VALUE self, VALUE string) {
         | 
| 191 191 | 
             
              const char *source = rb_str_ptr_readonly(string);
         | 
| 192 192 |  | 
| 193 193 | 
             
              // Wrap the escaped string in single-quotes, this is DO's convention
         | 
| @@ -206,7 +206,7 @@ VALUE cConnection_quote_string(VALUE self, VALUE string) { | |
| 206 206 | 
             
              return result;
         | 
| 207 207 | 
             
            }
         | 
| 208 208 |  | 
| 209 | 
            -
            VALUE  | 
| 209 | 
            +
            VALUE do_sqlite3_cConnection_quote_byte_array(VALUE self, VALUE string) {
         | 
| 210 210 | 
             
              VALUE source = StringValue(string);
         | 
| 211 211 | 
             
              VALUE array = rb_funcall(source, rb_intern("unpack"), 1, rb_str_new2("H*"));
         | 
| 212 212 |  | 
| @@ -215,7 +215,7 @@ VALUE cConnection_quote_byte_array(VALUE self, VALUE string) { | |
| 215 215 | 
             
              return rb_ary_join(array, Qnil);
         | 
| 216 216 | 
             
            }
         | 
| 217 217 |  | 
| 218 | 
            -
            VALUE  | 
| 218 | 
            +
            VALUE do_sqlite3_cConnection_enable_load_extension(VALUE self, VALUE value) {
         | 
| 219 219 | 
             
              VALUE connection = rb_iv_get(self, "@connection");
         | 
| 220 220 |  | 
| 221 221 | 
             
              if (connection == Qnil) {
         | 
| @@ -236,7 +236,7 @@ VALUE cConnection_enable_load_extension(VALUE self, VALUE value) { | |
| 236 236 | 
             
              return Qtrue;
         | 
| 237 237 | 
             
            }
         | 
| 238 238 |  | 
| 239 | 
            -
            VALUE  | 
| 239 | 
            +
            VALUE do_sqlite3_cConnection_load_extension(VALUE self, VALUE string) {
         | 
| 240 240 | 
             
              VALUE connection = rb_iv_get(self, "@connection");
         | 
| 241 241 |  | 
| 242 242 | 
             
              if (connection == Qnil) {
         | 
| @@ -259,8 +259,8 @@ VALUE cConnection_load_extension(VALUE self, VALUE string) { | |
| 259 259 | 
             
              return Qtrue;
         | 
| 260 260 | 
             
            }
         | 
| 261 261 |  | 
| 262 | 
            -
            VALUE  | 
| 263 | 
            -
              VALUE query =  | 
| 262 | 
            +
            VALUE do_sqlite3_cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) {
         | 
| 263 | 
            +
              VALUE query = data_objects_build_query_from_args(self, argc, argv);
         | 
| 264 264 | 
             
              VALUE connection = rb_iv_get(self, "@connection");
         | 
| 265 265 | 
             
              VALUE sqlite3_connection = rb_iv_get(connection, "@connection");
         | 
| 266 266 |  | 
| @@ -280,7 +280,7 @@ VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) { | |
| 280 280 | 
             
              status = sqlite3_exec(db, rb_str_ptr_readonly(query), 0, 0, &error_message);
         | 
| 281 281 |  | 
| 282 282 | 
             
              if (status != SQLITE_OK) {
         | 
| 283 | 
            -
                 | 
| 283 | 
            +
                do_sqlite3_raise_error(self, db, query);
         | 
| 284 284 | 
             
              }
         | 
| 285 285 |  | 
| 286 286 | 
             
              data_objects_debug(connection, query, &start);
         | 
| @@ -288,11 +288,11 @@ VALUE cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) { | |
| 288 288 | 
             
              int affected_rows = sqlite3_changes(db);
         | 
| 289 289 | 
             
              do_int64 insert_id = sqlite3_last_insert_rowid(db);
         | 
| 290 290 |  | 
| 291 | 
            -
              return rb_funcall( | 
| 291 | 
            +
              return rb_funcall(cSqlite3Result, ID_NEW, 3, self, INT2NUM(affected_rows), INT2NUM(insert_id));
         | 
| 292 292 | 
             
            }
         | 
| 293 293 |  | 
| 294 | 
            -
            VALUE  | 
| 295 | 
            -
              VALUE query =  | 
| 294 | 
            +
            VALUE do_sqlite3_cCommand_execute_reader(int argc, VALUE *argv, VALUE self) {
         | 
| 295 | 
            +
              VALUE query = data_objects_build_query_from_args(self, argc, argv);
         | 
| 296 296 | 
             
              VALUE connection = rb_iv_get(self, "@connection");
         | 
| 297 297 | 
             
              VALUE sqlite3_connection = rb_iv_get(connection, "@connection");
         | 
| 298 298 |  | 
| @@ -313,11 +313,11 @@ VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) { | |
| 313 313 | 
             
              data_objects_debug(connection, query, &start);
         | 
| 314 314 |  | 
| 315 315 | 
             
              if (status != SQLITE_OK) {
         | 
| 316 | 
            -
                 | 
| 316 | 
            +
                do_sqlite3_raise_error(self, db, query);
         | 
| 317 317 | 
             
              }
         | 
| 318 318 |  | 
| 319 319 | 
             
              int field_count = sqlite3_column_count(sqlite3_reader);
         | 
| 320 | 
            -
              VALUE reader = rb_funcall( | 
| 320 | 
            +
              VALUE reader = rb_funcall(cSqlite3Reader, ID_NEW, 0);
         | 
| 321 321 |  | 
| 322 322 | 
             
              rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, sqlite3_reader));
         | 
| 323 323 | 
             
              rb_iv_set(reader, "@field_count", INT2NUM(field_count));
         | 
| @@ -347,7 +347,7 @@ VALUE cCommand_execute_reader(int argc, VALUE *argv, VALUE self) { | |
| 347 347 | 
             
              return reader;
         | 
| 348 348 | 
             
            }
         | 
| 349 349 |  | 
| 350 | 
            -
            VALUE  | 
| 350 | 
            +
            VALUE do_sqlite3_cReader_close(VALUE self) {
         | 
| 351 351 | 
             
              VALUE reader_obj = rb_iv_get(self, "@reader");
         | 
| 352 352 |  | 
| 353 353 | 
             
              if (reader_obj != Qnil) {
         | 
| @@ -362,7 +362,7 @@ VALUE cReader_close(VALUE self) { | |
| 362 362 | 
             
              return Qfalse;
         | 
| 363 363 | 
             
            }
         | 
| 364 364 |  | 
| 365 | 
            -
            VALUE  | 
| 365 | 
            +
            VALUE do_sqlite3_cReader_next(VALUE self) {
         | 
| 366 366 | 
             
              if (rb_iv_get(self, "@done") == Qtrue) {
         | 
| 367 367 | 
             
                return Qfalse;
         | 
| 368 368 | 
             
              }
         | 
| @@ -399,7 +399,7 @@ VALUE cReader_next(VALUE self) { | |
| 399 399 |  | 
| 400 400 | 
             
              for (i = 0; i < field_count; i++) {
         | 
| 401 401 | 
             
                field_type = rb_ary_entry(field_types, i);
         | 
| 402 | 
            -
                value =  | 
| 402 | 
            +
                value = do_sqlite3_typecast(reader, i, field_type, enc);
         | 
| 403 403 | 
             
                rb_ary_push(arr, value);
         | 
| 404 404 | 
             
              }
         | 
| 405 405 |  | 
| @@ -407,7 +407,7 @@ VALUE cReader_next(VALUE self) { | |
| 407 407 | 
             
              return Qtrue;
         | 
| 408 408 | 
             
            }
         | 
| 409 409 |  | 
| 410 | 
            -
            VALUE  | 
| 410 | 
            +
            VALUE do_sqlite3_cReader_values(VALUE self) {
         | 
| 411 411 | 
             
              VALUE state = rb_iv_get(self, "@state");
         | 
| 412 412 |  | 
| 413 413 | 
             
              if (state == Qnil || NUM2INT(state) != SQLITE_ROW) {
         | 
| @@ -419,36 +419,36 @@ VALUE cReader_values_sqlite(VALUE self) { | |
| 419 419 | 
             
            }
         | 
| 420 420 |  | 
| 421 421 | 
             
            void Init_do_sqlite3() {
         | 
| 422 | 
            -
               | 
| 422 | 
            +
              data_objects_common_init();
         | 
| 423 423 |  | 
| 424 424 | 
             
              mSqlite3 = rb_define_module_under(mDO, "Sqlite3");
         | 
| 425 425 |  | 
| 426 | 
            -
               | 
| 427 | 
            -
              rb_define_method( | 
| 428 | 
            -
              rb_define_method( | 
| 429 | 
            -
              rb_define_method( | 
| 430 | 
            -
              rb_define_method( | 
| 431 | 
            -
              rb_define_method( | 
| 432 | 
            -
              rb_define_method( | 
| 433 | 
            -
              rb_define_method( | 
| 434 | 
            -
              rb_define_method( | 
| 435 | 
            -
             | 
| 436 | 
            -
               | 
| 437 | 
            -
              rb_define_method( | 
| 438 | 
            -
              rb_define_method( | 
| 439 | 
            -
              rb_define_method( | 
| 440 | 
            -
             | 
| 441 | 
            -
               | 
| 442 | 
            -
             | 
| 443 | 
            -
               | 
| 444 | 
            -
              rb_define_method( | 
| 445 | 
            -
              rb_define_method( | 
| 446 | 
            -
              rb_define_method( | 
| 447 | 
            -
              rb_define_method( | 
| 448 | 
            -
              rb_define_method( | 
| 449 | 
            -
             | 
| 450 | 
            -
              rb_global_variable(& | 
| 451 | 
            -
              rb_global_variable(& | 
| 426 | 
            +
              cSqlite3Connection = rb_define_class_under(mSqlite3, "Connection", cDO_Connection);
         | 
| 427 | 
            +
              rb_define_method(cSqlite3Connection, "initialize", do_sqlite3_cConnection_initialize, 1);
         | 
| 428 | 
            +
              rb_define_method(cSqlite3Connection, "dispose", do_sqlite3_cConnection_dispose, 0);
         | 
| 429 | 
            +
              rb_define_method(cSqlite3Connection, "quote_boolean", do_sqlite3_cConnection_quote_boolean, 1);
         | 
| 430 | 
            +
              rb_define_method(cSqlite3Connection, "quote_string", do_sqlite3_cConnection_quote_string, 1);
         | 
| 431 | 
            +
              rb_define_method(cSqlite3Connection, "quote_byte_array", do_sqlite3_cConnection_quote_byte_array, 1);
         | 
| 432 | 
            +
              rb_define_method(cSqlite3Connection, "character_set", data_objects_cConnection_character_set, 0);
         | 
| 433 | 
            +
              rb_define_method(cSqlite3Connection, "enable_load_extension", do_sqlite3_cConnection_enable_load_extension, 1);
         | 
| 434 | 
            +
              rb_define_method(cSqlite3Connection, "load_extension", do_sqlite3_cConnection_load_extension, 1);
         | 
| 435 | 
            +
             | 
| 436 | 
            +
              cSqlite3Command = rb_define_class_under(mSqlite3, "Command", cDO_Command);
         | 
| 437 | 
            +
              rb_define_method(cSqlite3Command, "set_types", data_objects_cCommand_set_types, -1);
         | 
| 438 | 
            +
              rb_define_method(cSqlite3Command, "execute_non_query", do_sqlite3_cCommand_execute_non_query, -1);
         | 
| 439 | 
            +
              rb_define_method(cSqlite3Command, "execute_reader", do_sqlite3_cCommand_execute_reader, -1);
         | 
| 440 | 
            +
             | 
| 441 | 
            +
              cSqlite3Result = rb_define_class_under(mSqlite3, "Result", cDO_Result);
         | 
| 442 | 
            +
             | 
| 443 | 
            +
              cSqlite3Reader = rb_define_class_under(mSqlite3, "Reader", cDO_Reader);
         | 
| 444 | 
            +
              rb_define_method(cSqlite3Reader, "close", do_sqlite3_cReader_close, 0);
         | 
| 445 | 
            +
              rb_define_method(cSqlite3Reader, "next!", do_sqlite3_cReader_next, 0);
         | 
| 446 | 
            +
              rb_define_method(cSqlite3Reader, "values", do_sqlite3_cReader_values, 0); // TODO: DRY?
         | 
| 447 | 
            +
              rb_define_method(cSqlite3Reader, "fields", data_objects_cReader_fields, 0);
         | 
| 448 | 
            +
              rb_define_method(cSqlite3Reader, "field_count", data_objects_cReader_field_count, 0);
         | 
| 449 | 
            +
             | 
| 450 | 
            +
              rb_global_variable(&cSqlite3Result);
         | 
| 451 | 
            +
              rb_global_variable(&cSqlite3Reader);
         | 
| 452 452 |  | 
| 453 453 | 
             
              OPEN_FLAG_READONLY = rb_str_new2("read_only");
         | 
| 454 454 | 
             
              rb_global_variable(&OPEN_FLAG_READONLY);
         | 
| @@ -463,5 +463,5 @@ void Init_do_sqlite3() { | |
| 463 463 |  | 
| 464 464 | 
             
              Init_do_sqlite3_extension();
         | 
| 465 465 |  | 
| 466 | 
            -
               | 
| 466 | 
            +
              data_objects_define_errors(mSqlite3, do_sqlite3_errors);
         | 
| 467 467 | 
             
            }
         | 
| @@ -2,13 +2,13 @@ | |
| 2 2 | 
             
            #include "do_common.h"
         | 
| 3 3 | 
             
            #include "do_sqlite3.h"
         | 
| 4 4 |  | 
| 5 | 
            -
            VALUE  | 
| 5 | 
            +
            VALUE cSqlite3Extension;
         | 
| 6 6 |  | 
| 7 7 | 
             
            /*****************************************************/
         | 
| 8 8 | 
             
            /* File used for providing extensions on the default */
         | 
| 9 9 | 
             
            /* API that are driver specific.                     */
         | 
| 10 10 | 
             
            /*****************************************************/
         | 
| 11 | 
            -
            VALUE  | 
| 11 | 
            +
            VALUE do_sqlite3_cExtension_enable_load_extension(VALUE self, VALUE on) {
         | 
| 12 12 | 
             
              VALUE id_connection = rb_intern("connection");
         | 
| 13 13 | 
             
              VALUE connection = rb_funcall(self, id_connection, 0);
         | 
| 14 14 |  | 
| @@ -34,7 +34,7 @@ VALUE cExtension_enable_load_extension(VALUE self, VALUE on) { | |
| 34 34 | 
             
              return Qtrue;
         | 
| 35 35 | 
             
            }
         | 
| 36 36 |  | 
| 37 | 
            -
            VALUE  | 
| 37 | 
            +
            VALUE do_sqlite3_cExtension_load_extension(VALUE self, VALUE path) {
         | 
| 38 38 | 
             
              VALUE id_connection = rb_intern("connection");
         | 
| 39 39 | 
             
              VALUE connection = rb_funcall(self, id_connection, 0);
         | 
| 40 40 |  | 
| @@ -71,7 +71,7 @@ VALUE cExtension_load_extension(VALUE self, VALUE path) { | |
| 71 71 | 
             
            }
         | 
| 72 72 |  | 
| 73 73 | 
             
            void Init_do_sqlite3_extension() {
         | 
| 74 | 
            -
               | 
| 75 | 
            -
              rb_define_method( | 
| 76 | 
            -
              rb_define_method( | 
| 74 | 
            +
              cSqlite3Extension = rb_define_class_under(mSqlite3, "Extension", cDO_Extension);
         | 
| 75 | 
            +
              rb_define_method(cSqlite3Extension, "load_extension", do_sqlite3_cExtension_load_extension, 1);
         | 
| 76 | 
            +
              rb_define_method(cSqlite3Extension, "enable_load_extension", do_sqlite3_cExtension_enable_load_extension, 1);
         | 
| 77 77 | 
             
            }
         | 
    
        data/ext/do_sqlite3/error.h
    CHANGED
    
    
| Binary file | 
| Binary file | 
    
        data/lib/do_sqlite3/version.rb
    CHANGED
    
    
    
        data/tasks/compile.rake
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: do_sqlite3
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 5 | 
            -
              prerelease:  | 
| 4 | 
            +
              hash: 59
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 10
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.10. | 
| 9 | 
            +
              - 6
         | 
| 10 | 
            +
              version: 0.10.6
         | 
| 11 11 | 
             
            platform: x86-mingw32
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Dirkjan Bussink
         | 
| @@ -19,22 +19,23 @@ date: 2011-03-29 00:00:00 +02:00 | |
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              type: :runtime
         | 
| 22 23 | 
             
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 23 24 | 
             
                none: false
         | 
| 24 25 | 
             
                requirements: 
         | 
| 25 26 | 
             
                - - "="
         | 
| 26 27 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 27 | 
            -
                    hash:  | 
| 28 | 
            +
                    hash: 59
         | 
| 28 29 | 
             
                    segments: 
         | 
| 29 30 | 
             
                    - 0
         | 
| 30 31 | 
             
                    - 10
         | 
| 31 | 
            -
                    -  | 
| 32 | 
            -
                    version: 0.10. | 
| 33 | 
            -
              type: :runtime
         | 
| 32 | 
            +
                    - 6
         | 
| 33 | 
            +
                    version: 0.10.6
         | 
| 34 34 | 
             
              name: data_objects
         | 
| 35 | 
            -
              prerelease: false
         | 
| 36 35 | 
             
              version_requirements: *id001
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 37 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 38 | 
            +
              type: :development
         | 
| 38 39 | 
             
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 39 40 | 
             
                none: false
         | 
| 40 41 | 
             
                requirements: 
         | 
| @@ -45,11 +46,11 @@ dependencies: | |
| 45 46 | 
             
                    - 2
         | 
| 46 47 | 
             
                    - 5
         | 
| 47 48 | 
             
                    version: "2.5"
         | 
| 48 | 
            -
              type: :development
         | 
| 49 49 | 
             
              name: rspec
         | 
| 50 | 
            -
              prerelease: false
         | 
| 51 50 | 
             
              version_requirements: *id002
         | 
| 51 | 
            +
              prerelease: false
         | 
| 52 52 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 53 | 
            +
              type: :development
         | 
| 53 54 | 
             
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 54 55 | 
             
                none: false
         | 
| 55 56 | 
             
                requirements: 
         | 
| @@ -60,10 +61,9 @@ dependencies: | |
| 60 61 | 
             
                    - 0
         | 
| 61 62 | 
             
                    - 7
         | 
| 62 63 | 
             
                    version: "0.7"
         | 
| 63 | 
            -
              type: :development
         | 
| 64 64 | 
             
              name: rake-compiler
         | 
| 65 | 
            -
              prerelease: false
         | 
| 66 65 | 
             
              version_requirements: *id003
         | 
| 66 | 
            +
              prerelease: false
         | 
| 67 67 | 
             
            description: Implements the DataObjects API for Sqlite3
         | 
| 68 68 | 
             
            email: d.bussink@gmail.com
         | 
| 69 69 | 
             
            executables: []
         | 
| @@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 164 164 | 
             
            requirements: []
         | 
| 165 165 |  | 
| 166 166 | 
             
            rubyforge_project: dorb
         | 
| 167 | 
            -
            rubygems_version: 1. | 
| 167 | 
            +
            rubygems_version: 1.5.2
         | 
| 168 168 | 
             
            signing_key: 
         | 
| 169 169 | 
             
            specification_version: 3
         | 
| 170 170 | 
             
            summary: DataObjects Sqlite3 Driver
         |