Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ab9c72
commit f7580a7
Showing
8 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
#include <deebee.h> | |||
|
|||
VALUE cDeeBeeStatement; | |||
|
|||
static VALUE each(VALUE self) | |||
{ | |||
sqlite3_stmt *stmt; | |||
|
|||
Data_Get_Struct(self, sqlite3_stmt, stmt); | |||
int value = sqlite3_step(stmt); | |||
while(value != SQLITE_DONE) { | |||
switch(value) { | |||
case SQLITE_ROW: | |||
{ | |||
int length = sqlite3_column_count(stmt); | |||
VALUE list = rb_ary_new2(length); | |||
|
|||
int i; | |||
for(i = 0; i < length; i++) { | |||
switch(sqlite3_column_type(stmt, i)) { | |||
case SQLITE_INTEGER: | |||
rb_ary_push(list, INT2NUM(sqlite3_column_int(stmt, i))); | |||
break; | |||
case SQLITE_FLOAT: | |||
rb_ary_push(list, rb_float_new(sqlite3_column_double(stmt, i))); | |||
break; | |||
case SQLITE_TEXT: | |||
rb_ary_push(list, rb_str_new2(sqlite3_column_text(stmt, i))); | |||
break; | |||
case SQLITE_BLOB: | |||
rb_ary_push(list, rb_str_new2(sqlite3_column_blob(stmt, i))); | |||
break; | |||
case SQLITE_NULL: | |||
rb_ary_push(list, Qnil); | |||
break; | |||
default: | |||
rb_raise(rb_eRuntimeError, "oh no!"); | |||
} | |||
} | |||
rb_yield(list); | |||
} | |||
break; | |||
default: | |||
rb_raise(rb_eRuntimeError, "oh no!"); | |||
} | |||
value = sqlite3_step(stmt); | |||
} | |||
return self; | |||
} | |||
|
|||
void init_deebee_statement() | |||
{ | |||
cDeeBeeStatement = rb_define_class_under(cDeeBee, "Statement", rb_cObject); | |||
|
|||
rb_define_method(cDeeBeeStatement, "each", each, 0); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
#ifndef DEEBEE_STATEMENT | |||
#define DEEBEE_STATEMENT | |||
|
|||
#include <deebee.h> | |||
|
|||
extern VALUE cDeeBeeStatement; | |||
|
|||
void init_deebee_statement(); | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,12 @@ | |||
require 'deebee/deebee' | require 'deebee/deebee' | ||
require 'deebee/statement' | |||
|
|
||
module SQLite3 | module SQLite3 | ||
class DeeBee | class DeeBee | ||
VERSION = '1.0.0' | VERSION = '1.0.0' | ||
|
|||
def encoding | |||
Encoding.find(encoding_str) | |||
end | |||
end | end | ||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
module SQLite3 | |||
class DeeBee | |||
class Statement | |||
include Enumerable | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
require "test/unit" | |||
require "deebee" | |||
require 'tmpdir' | |||
|
|||
class TestStatement < Test::Unit::TestCase | |||
def test_step | |||
db = SQLite3::DeeBee.open(File.join(Dir.tmpdir, 'foo.db')) | |||
stmt = db.prepare('PRAGMA encoding') | |||
called = false | |||
stmt.each { |row| called = true } | |||
assert called | |||
end | |||
end |