Permalink
Browse files

Cleaning up more warnings.

* Use LONG_LONG functions for sqlite3_int64 because long may be
  32bit. The maccro LONG_LONG is platform independent long long int.
  LONG_LONG is not always exist but sqlite3.h uses related items,
  so I assumed LONG_LONG exist and it is 64bit or larger.

* Add Bignum cases. On platforms whose long is 32bit, a bignum can
  be included in sqlite3_int64.
  • Loading branch information...
1 parent 217f6dc commit 7dbd82d3c40f547ef3417dd920ebfa0458489778 @nurse nurse committed Apr 28, 2010
Showing with 22 additions and 9 deletions.
  1. +10 −3 ext/sqlite3/database.c
  2. +12 −6 ext/sqlite3/statement.c
View
@@ -241,14 +241,14 @@ static VALUE last_insert_row_id(VALUE self)
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);
- return LONG2NUM(sqlite3_last_insert_rowid(ctx->db));
+ return LL2NUM(sqlite3_last_insert_rowid(ctx->db));
}
static VALUE sqlite3val2rb(sqlite3_value * val)
{
switch(sqlite3_value_type(val)) {
case SQLITE_INTEGER:
- return LONG2NUM(sqlite3_value_int64(val));
+ return LL2NUM(sqlite3_value_int64(val));
break;
case SQLITE_FLOAT:
return rb_float_new(sqlite3_value_double(val));
@@ -274,8 +274,15 @@ static void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result)
sqlite3_result_null(ctx);
break;
case T_FIXNUM:
- sqlite3_result_int64(ctx, NUM2LONG(result));
+ sqlite3_result_int64(ctx, FIX2LONG(result));
break;
+ case T_BIGNUM:
+#if SIZEOF_LONG < 8
+ if (RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8) {
+ sqlite3_result_int64(ctx, NUM2LL(result));
+ break;
+ }
+#endif
case T_FLOAT:
sqlite3_result_double(ctx, NUM2DBL(result));
break;
View
@@ -108,8 +108,11 @@ static VALUE step(VALUE self)
{
sqlite3StmtRubyPtr ctx;
sqlite3_stmt *stmt;
- int value, length, enc_index;
+ int value, length;
VALUE list;
+#ifdef HAVE_RUBY_ENCODING_H
+ int enc_index;
+#endif
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
@@ -138,7 +141,7 @@ static VALUE step(VALUE self)
for(i = 0; i < length; i++) {
switch(sqlite3_column_type(stmt, i)) {
case SQLITE_INTEGER:
- rb_ary_push(list, LONG2NUM(sqlite3_column_int64(stmt, i)));
+ rb_ary_push(list, LL2NUM(sqlite3_column_int64(stmt, i)));
break;
case SQLITE_FLOAT:
rb_ary_push(list, rb_float_new(sqlite3_column_double(stmt, i)));
@@ -249,14 +252,17 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
}
break;
case T_BIGNUM:
+#if SIZEOF_LONG < 8
+ if (RBIGNUM_LEN(result) * SIZEOF_BDIGITS <= 8) {
+ sqlite3_result_int64(ctx, NUM2LL(result));
+ break;
+ }
+#endif
case T_FLOAT:
status = sqlite3_bind_double(ctx->st, index, NUM2DBL(value));
break;
case T_FIXNUM:
- {
- long v = NUM2LONG(value);
- status = sqlite3_bind_int64(ctx->st, index, v);
- }
+ status = sqlite3_bind_int64(ctx->st, index, FIX2LONG(value));
break;
case T_NIL:
status = sqlite3_bind_null(ctx->st, index);

0 comments on commit 7dbd82d

Please sign in to comment.