downpour 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/downpour/connection.c +9 -2
- data/ext/downpour/{drizzle.c → downpour.c} +4 -4
- data/ext/downpour/{drizzle.h → downpour.h} +8 -1
- data/ext/downpour/extconf.rb +8 -2
- data/ext/downpour/helpers.c +2 -2
- data/ext/downpour/module.c +7 -6
- data/ext/downpour/result.c +37 -5
- data/ext/downpour/status.c +23 -14
- data/lib/downpour/version.rb +2 -2
- data/spec/bootstrap.sql +6 -0
- data/spec/downpour/insert_spec.rb +19 -0
- data/spec/downpour/module_spec.rb +12 -0
- data/spec/{query_spec.rb → downpour/query_spec.rb} +2 -2
- data/spec/downpour/select_spec.rb +52 -0
- metadata +13 -11
- data/spec/module_spec.rb +0 -5
- data/spec/smoke_spec.rb +0 -61
data/ext/downpour/connection.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
3
|
#define SELF_TYPE drizzle_con_st
|
4
4
|
|
@@ -13,7 +13,14 @@ static VALUE query(VALUE self, VALUE query)
|
|
13
13
|
|
14
14
|
CHECK_OK(retptr);
|
15
15
|
|
16
|
-
return
|
16
|
+
return downpour_result_constructor(result, self);
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE downpour_connection_constructor(drizzle_con_st *self_ptr, VALUE status)
|
20
|
+
{
|
21
|
+
VALUE ret = Data_Wrap_Struct(DrizzleConnection, NULL, drizzle_con_free, self_ptr);
|
22
|
+
rb_iv_set(ret, "@status", status);
|
23
|
+
return ret;
|
17
24
|
}
|
18
25
|
|
19
26
|
void init_drizzle_connection()
|
@@ -1,18 +1,18 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
|
-
VALUE
|
3
|
+
VALUE DownpourModule;
|
4
4
|
VALUE DrizzleStatus;
|
5
5
|
VALUE DrizzleConnection;
|
6
6
|
VALUE DrizzleResult;
|
7
7
|
|
8
|
-
void
|
8
|
+
void init_downpour_module();
|
9
9
|
void init_drizzle_status();
|
10
10
|
void init_drizzle_connection();
|
11
11
|
void init_drizzle_result();
|
12
12
|
|
13
13
|
void Init_downpour()
|
14
14
|
{
|
15
|
-
|
15
|
+
init_downpour_module();
|
16
16
|
init_drizzle_status();
|
17
17
|
init_drizzle_connection();
|
18
18
|
init_drizzle_result();
|
@@ -5,11 +5,16 @@
|
|
5
5
|
#include <libdrizzle/drizzle.h>
|
6
6
|
#include <libdrizzle/drizzle_client.h>
|
7
7
|
|
8
|
-
extern VALUE
|
8
|
+
extern VALUE DownpourModule;
|
9
9
|
extern VALUE DrizzleStatus;
|
10
10
|
extern VALUE DrizzleConnection;
|
11
11
|
extern VALUE DrizzleResult;
|
12
12
|
|
13
|
+
// All Constructors
|
14
|
+
VALUE downpour_constructor(drizzle_st *self_ptr);
|
15
|
+
VALUE downpour_connection_constructor(drizzle_con_st *self_ptr, VALUE status);
|
16
|
+
VALUE downpour_result_constructor(drizzle_result_st *self_ptr, VALUE connection);
|
17
|
+
|
13
18
|
VALUE drizzle_gem_create_class_with_private_constructor(const char *name, VALUE super);
|
14
19
|
void drizzle_gem_assert_value_is_ok(drizzle_return_t value);
|
15
20
|
VALUE drizzle_gem_to_string_array(char **array, long count);
|
@@ -20,5 +25,7 @@ const char *drizzle_gem_read_string_with_default(VALUE string, const char *defau
|
|
20
25
|
#define CHECK_OK(value) drizzle_gem_assert_value_is_ok(value)
|
21
26
|
#define rb_call(self, string) rb_funcall(self, rb_intern(string), 0)
|
22
27
|
#define read_string(value, default_value) drizzle_gem_read_string_with_default(value, default_value)
|
28
|
+
#define drizzle_alloc(type) ((type *) malloc(sizeof(type)))
|
29
|
+
#define unset_option(value, bit) if(value->options & bit) value->options ^= bit
|
23
30
|
|
24
31
|
#endif
|
data/ext/downpour/extconf.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
+
libdrizzle = 'libdrizzle-1.0'
|
4
|
+
|
3
5
|
extension_name = 'downpour'
|
4
6
|
dir_config(extension_name)
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
if(!system("pkg-config #{libdrizzle}"))
|
9
|
+
raise "Cannot find pkg-config or #{libdrizzle}"
|
10
|
+
end
|
11
|
+
|
12
|
+
$LDFLAGS += " " + `pkg-config --libs #{libdrizzle}`
|
13
|
+
$CFLAGS += " " + `pkg-config --cflags #{libdrizzle}`
|
8
14
|
|
9
15
|
create_makefile(extension_name)
|
data/ext/downpour/helpers.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
3
|
static VALUE do_not_use_this_constructor(VALUE self)
|
4
4
|
{
|
@@ -18,7 +18,7 @@ VALUE drizzle_gem_to_string_array(char **array, long count)
|
|
18
18
|
|
19
19
|
VALUE drizzle_gem_create_class_with_private_constructor(const char *name, VALUE super)
|
20
20
|
{
|
21
|
-
VALUE ret = rb_define_class_under(
|
21
|
+
VALUE ret = rb_define_class_under(DownpourModule, name, super);
|
22
22
|
rb_define_method(ret, "initialize", do_not_use_this_constructor, 0);
|
23
23
|
return ret;
|
24
24
|
}
|
data/ext/downpour/module.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
3
|
static VALUE version(VALUE self)
|
4
4
|
{
|
@@ -8,12 +8,13 @@ static VALUE version(VALUE self)
|
|
8
8
|
static VALUE create(VALUE self)
|
9
9
|
{
|
10
10
|
drizzle_st *ptr = drizzle_create(NULL);
|
11
|
-
|
11
|
+
unset_option(ptr, DRIZZLE_FREE_OBJECTS);
|
12
|
+
return downpour_constructor(ptr);
|
12
13
|
}
|
13
14
|
|
14
|
-
void
|
15
|
+
void init_downpour_module()
|
15
16
|
{
|
16
|
-
|
17
|
-
rb_define_singleton_method(
|
18
|
-
rb_define_singleton_method(
|
17
|
+
DownpourModule = rb_define_module("Downpour");
|
18
|
+
rb_define_singleton_method(DownpourModule, "drizzle_version", version, 0);
|
19
|
+
rb_define_singleton_method(DownpourModule, "create", create, 0);
|
19
20
|
}
|
data/ext/downpour/result.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
3
|
#define SELF_TYPE drizzle_result_st
|
4
4
|
|
@@ -48,21 +48,38 @@ static VALUE wrap_row(drizzle_result_st *self_ptr, drizzle_row_t row)
|
|
48
48
|
if(row == NULL)
|
49
49
|
return Qnil;
|
50
50
|
|
51
|
-
// TODO: wrap this in a Ruby Object. It should be freed
|
52
51
|
return drizzle_gem_to_string_array(row, do_column_count(self_ptr));
|
53
52
|
}
|
54
53
|
|
55
54
|
static VALUE next_row_buffered(drizzle_result_st *self_ptr)
|
56
55
|
{
|
57
|
-
|
56
|
+
drizzle_row_t result = drizzle_row_next(self_ptr);
|
57
|
+
return wrap_row(self_ptr, result);
|
58
58
|
}
|
59
59
|
|
60
|
-
static
|
60
|
+
static void buffer_column_if_needed(drizzle_result_st *self_ptr)
|
61
|
+
{
|
62
|
+
if(self_ptr->options & DRIZZLE_RESULT_BUFFER_COLUMN)
|
63
|
+
return;
|
64
|
+
CHECK_OK(drizzle_column_buffer(self_ptr));
|
65
|
+
}
|
66
|
+
|
67
|
+
static drizzle_row_t do_drizzle_row_buffer(drizzle_result_st *self_ptr)
|
61
68
|
{
|
62
69
|
drizzle_return_t ret;
|
63
70
|
drizzle_row_t result = drizzle_row_buffer(self_ptr, &ret);
|
64
71
|
CHECK_OK(ret);
|
65
|
-
return
|
72
|
+
return result;
|
73
|
+
}
|
74
|
+
|
75
|
+
static VALUE next_row_unbuffered(drizzle_result_st *self_ptr)
|
76
|
+
{
|
77
|
+
buffer_column_if_needed(self_ptr);
|
78
|
+
drizzle_row_t result = do_drizzle_row_buffer(self_ptr);
|
79
|
+
VALUE parsed = wrap_row(self_ptr, result);
|
80
|
+
if(result)
|
81
|
+
drizzle_row_free(self_ptr, result);
|
82
|
+
return parsed;
|
66
83
|
}
|
67
84
|
|
68
85
|
static VALUE next_row(VALUE self)
|
@@ -81,6 +98,20 @@ static VALUE column_count(VALUE self)
|
|
81
98
|
return UINT2NUM(do_column_count(self_ptr));
|
82
99
|
}
|
83
100
|
|
101
|
+
static VALUE insert_id(VALUE self)
|
102
|
+
{
|
103
|
+
read_self_ptr();
|
104
|
+
|
105
|
+
return UINT2NUM(drizzle_result_insert_id(self_ptr));
|
106
|
+
}
|
107
|
+
|
108
|
+
VALUE downpour_result_constructor(drizzle_result_st *self_ptr, VALUE connection)
|
109
|
+
{
|
110
|
+
VALUE ret = Data_Wrap_Struct(DrizzleResult, NULL, drizzle_result_free, self_ptr);
|
111
|
+
rb_iv_set(ret, "@connection", connection);
|
112
|
+
return ret;
|
113
|
+
}
|
114
|
+
|
84
115
|
void init_drizzle_result()
|
85
116
|
{
|
86
117
|
DrizzleResult = drizzle_gem_create_class_with_private_constructor("Result", rb_cObject);
|
@@ -89,4 +120,5 @@ void init_drizzle_result()
|
|
89
120
|
rb_define_method(DrizzleResult, "buffer!", buffer_if_needed, 0);
|
90
121
|
rb_define_method(DrizzleResult, "buffered?", is_buffered, 0);
|
91
122
|
rb_define_method(DrizzleResult, "next_row", next_row, 0);
|
123
|
+
rb_define_method(DrizzleResult, "insert_id", insert_id, 0);
|
92
124
|
}
|
data/ext/downpour/status.c
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
#include "
|
1
|
+
#include "downpour.h"
|
2
2
|
|
3
3
|
#define SELF_TYPE drizzle_st
|
4
4
|
|
5
|
-
static VALUE clone_status(VALUE self)
|
6
|
-
{
|
7
|
-
read_self_ptr();
|
8
|
-
drizzle_st *cloned = drizzle_clone(NULL, self_ptr);
|
9
|
-
return Data_Wrap_Struct(DrizzleStatus, NULL, drizzle_free, cloned);
|
10
|
-
}
|
11
|
-
|
12
5
|
static in_port_t get_port(VALUE port)
|
13
6
|
{
|
14
7
|
if(port == Qnil)
|
@@ -17,7 +10,6 @@ static in_port_t get_port(VALUE port)
|
|
17
10
|
return NUM2UINT(port);
|
18
11
|
}
|
19
12
|
|
20
|
-
|
21
13
|
static VALUE add_tcp_connection(int argc, VALUE *argv, VALUE self)
|
22
14
|
{
|
23
15
|
read_self_ptr();
|
@@ -34,10 +26,7 @@ static VALUE add_tcp_connection(int argc, VALUE *argv, VALUE self)
|
|
34
26
|
read_string(passwd, ""),
|
35
27
|
read_string(db, "test"),
|
36
28
|
DRIZZLE_CON_NONE);
|
37
|
-
|
38
|
-
VALUE val = Data_Wrap_Struct(DrizzleConnection, NULL, NULL, connection);
|
39
|
-
rb_iv_set(val, "@status", self);
|
40
|
-
return val;
|
29
|
+
return downpour_connection_constructor(connection, self);
|
41
30
|
}
|
42
31
|
|
43
32
|
static VALUE error(VALUE self)
|
@@ -57,11 +46,31 @@ static VALUE set_verbose(VALUE self, VALUE newVerbocity)
|
|
57
46
|
return newVerbocity;
|
58
47
|
}
|
59
48
|
|
49
|
+
static VALUE get_verbose(VALUE self)
|
50
|
+
{
|
51
|
+
read_self_ptr();
|
52
|
+
|
53
|
+
return UINT2NUM(drizzle_verbose(self_ptr));
|
54
|
+
}
|
55
|
+
|
56
|
+
static VALUE verbose_name(VALUE self)
|
57
|
+
{
|
58
|
+
read_self_ptr();
|
59
|
+
|
60
|
+
return rb_str_new2(drizzle_verbose_name(drizzle_verbose(self_ptr)));
|
61
|
+
}
|
62
|
+
|
63
|
+
VALUE downpour_constructor(drizzle_st *self_ptr)
|
64
|
+
{
|
65
|
+
return Data_Wrap_Struct(DrizzleStatus, NULL, drizzle_free, self_ptr);
|
66
|
+
}
|
67
|
+
|
60
68
|
void init_drizzle_status()
|
61
69
|
{
|
62
70
|
DrizzleStatus = drizzle_gem_create_class_with_private_constructor("Status", rb_cObject);
|
63
|
-
rb_define_method(DrizzleStatus, "clone", clone_status, 0);
|
64
71
|
rb_define_method(DrizzleStatus, "add_tcp_connection", add_tcp_connection, -1);
|
65
72
|
rb_define_method(DrizzleStatus, "error", error, 0);
|
66
73
|
rb_define_method(DrizzleStatus, "verbose=", set_verbose, 1);
|
74
|
+
rb_define_method(DrizzleStatus, "verbose", get_verbose, 0);
|
75
|
+
rb_define_method(DrizzleStatus, "verbose_name", verbose_name, 0);
|
67
76
|
}
|
data/lib/downpour/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Downpour
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/spec/bootstrap.sql
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "insert query" do
|
2
|
+
|
3
|
+
def count_of_test2
|
4
|
+
@conn.query("select * from Test2").row_count
|
5
|
+
end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@status = Downpour.create
|
9
|
+
@conn = create_connection(@status)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should increment the row count by one" do
|
13
|
+
lambda { @conn.query "insert into Test2 (name) values ('foo')" }.should change(self, :count_of_test2).by(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get id after inserting" do
|
17
|
+
@conn.query("insert into Test2 (name) values ('foo')").insert_id.should == count_of_test2
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe Downpour do
|
2
|
+
it "should have the version number set" do
|
3
|
+
Downpour.drizzle_version.should eq("7")
|
4
|
+
end
|
5
|
+
|
6
|
+
it "should set the verbose level" do
|
7
|
+
st = Downpour.create
|
8
|
+
st.verbose = 5
|
9
|
+
st.verbose.should == 5
|
10
|
+
st.verbose_name.should == "CRAZY"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
describe "select query" do
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@status = Downpour.create
|
5
|
+
@conn = create_connection(@status)
|
6
|
+
@results = @conn.query "select * from Test1"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should count records" do
|
10
|
+
@results.row_count.should == 3
|
11
|
+
@results.should be_buffered
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should buffer records" do
|
15
|
+
@results.should_not be_buffered
|
16
|
+
@results.buffer!
|
17
|
+
@results.should be_buffered
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should only buffer records once" do
|
21
|
+
@results.buffer!.should be_true
|
22
|
+
@results.buffer!.should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should count columns" do
|
26
|
+
@results.column_count.should == 1
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not buffer when reading a single row" do
|
30
|
+
@results.next_row
|
31
|
+
@results.should_not be_buffered
|
32
|
+
end
|
33
|
+
|
34
|
+
shared_examples_for "a read query" do
|
35
|
+
it "should read all rows" do
|
36
|
+
@results.next_row.should == ["foo"]
|
37
|
+
@results.next_row.should == ["bar"]
|
38
|
+
@results.next_row.should == ["baz"]
|
39
|
+
@results.next_row.should be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "without buffering" do
|
44
|
+
it_should_behave_like "a read query"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with buffering" do
|
48
|
+
before(:each) { @results.buffer! }
|
49
|
+
|
50
|
+
it_should_behave_like "a read query"
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: downpour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tejas Dinkar
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-30 00:00:00 +05:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -46,8 +46,8 @@ extra_rdoc_files:
|
|
46
46
|
files:
|
47
47
|
- downpour.gemspec
|
48
48
|
- ext/downpour/connection.c
|
49
|
-
- ext/downpour/
|
50
|
-
- ext/downpour/
|
49
|
+
- ext/downpour/downpour.c
|
50
|
+
- ext/downpour/downpour.h
|
51
51
|
- ext/downpour/extconf.rb
|
52
52
|
- ext/downpour/helpers.c
|
53
53
|
- ext/downpour/module.c
|
@@ -55,12 +55,13 @@ files:
|
|
55
55
|
- ext/downpour/status.c
|
56
56
|
- lib/downpour.rb
|
57
57
|
- lib/downpour/version.rb
|
58
|
-
- README.rdoc
|
59
58
|
- spec/bootstrap.sql
|
60
|
-
- spec/
|
61
|
-
- spec/
|
62
|
-
- spec/
|
59
|
+
- spec/downpour/insert_spec.rb
|
60
|
+
- spec/downpour/module_spec.rb
|
61
|
+
- spec/downpour/query_spec.rb
|
62
|
+
- spec/downpour/select_spec.rb
|
63
63
|
- spec/spec_helper.rb
|
64
|
+
- README.rdoc
|
64
65
|
has_rdoc: true
|
65
66
|
homepage: http://github.com/gja/downpour
|
66
67
|
licenses: []
|
@@ -92,7 +93,8 @@ specification_version: 3
|
|
92
93
|
summary: A simple, fast Mysql and Drizzle library for Ruby, binding to libdrizzle
|
93
94
|
test_files:
|
94
95
|
- spec/bootstrap.sql
|
95
|
-
- spec/
|
96
|
-
- spec/
|
97
|
-
- spec/
|
96
|
+
- spec/downpour/insert_spec.rb
|
97
|
+
- spec/downpour/module_spec.rb
|
98
|
+
- spec/downpour/query_spec.rb
|
99
|
+
- spec/downpour/select_spec.rb
|
98
100
|
- spec/spec_helper.rb
|
data/spec/module_spec.rb
DELETED
data/spec/smoke_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
describe Drizzle do
|
2
|
-
|
3
|
-
before(:each) do
|
4
|
-
@status = Drizzle.create
|
5
|
-
@conn = create_connection(@status)
|
6
|
-
end
|
7
|
-
|
8
|
-
context "select query" do
|
9
|
-
before(:each) do
|
10
|
-
@results = @conn.query "select * from Test1"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should count records" do
|
14
|
-
@results.row_count.should == 3
|
15
|
-
@results.should be_buffered
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should buffer records" do
|
19
|
-
@results.should_not be_buffered
|
20
|
-
@results.buffer!
|
21
|
-
@results.should be_buffered
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should only buffer records once" do
|
25
|
-
@results.buffer!.should be_true
|
26
|
-
@results.buffer!.should be_false
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should count columns" do
|
30
|
-
@results.column_count.should == 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should not buffer when reading a single row" do
|
34
|
-
@results.next_row
|
35
|
-
@results.should_not be_buffered
|
36
|
-
end
|
37
|
-
|
38
|
-
shared_examples_for "a read query" do
|
39
|
-
it "should read all rows" do
|
40
|
-
@results.next_row.should == ["foo"]
|
41
|
-
@results.next_row.should == ["bar"]
|
42
|
-
@results.next_row.should == ["baz"]
|
43
|
-
@results.next_row.should be_nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "without buffering" do
|
48
|
-
it_should_behave_like "a read query"
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with buffering" do
|
52
|
-
before(:each) { @results.buffer! }
|
53
|
-
|
54
|
-
it_should_behave_like "a read query"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
after(:each) do
|
59
|
-
#puts @status.error
|
60
|
-
end
|
61
|
-
end
|