rdo-postgres 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,13 @@ def have_build_env
20
20
  end
21
21
 
22
22
  dir_config(
23
- "pgsql-server",
23
+ "postgres",
24
24
  config_value("includedir-server"),
25
25
  config_value("libdir")
26
26
  )
27
27
 
28
28
  dir_config(
29
- "pgsql-client",
29
+ "libpq",
30
30
  config_value("includedir"),
31
31
  config_value("libdir")
32
32
  )
@@ -1,5 +1,5 @@
1
1
  /*
2
- * RDO Postgres Driver.
2
+ * RDO—Ruby Data Objects.
3
3
  * Copyright © 2012 Chris Corbyn.
4
4
  *
5
5
  * See LICENSE file for details.
@@ -21,6 +21,49 @@
21
21
  #include <ruby.h>
22
22
  #include <ruby/encoding.h>
23
23
 
24
+ /**
25
+ * Convenience to call #to_s on any Ruby object.
26
+ */
27
+ #define RDO_OBJ_TO_S(obj) (rb_funcall(obj, rb_intern("to_s"), 0))
28
+
29
+ /**
30
+ * Raise an RDO::Exception with the given msg format and any number of parameters.
31
+ *
32
+ * @param (char *) msg
33
+ * a format string passed to rb_raise()
34
+ *
35
+ * @param (void *) ...
36
+ * args used to interpolate the error message
37
+ */
38
+ #define RDO_ERROR(...) (rb_raise(rb_path2class("RDO::Exception"), __VA_ARGS__))
39
+
40
+ /**
41
+ * Factory to return a new RDO::Result for an Enumerable object of tuples.
42
+ *
43
+ * @param VALUE (Enumerable) tuples
44
+ * an object that knows how to iterate all tuples
45
+ *
46
+ * @param VALUE (Hash)
47
+ * an optional hash of query info.
48
+ *
49
+ * @return VALUE (RDO::Result)
50
+ * a new Result object
51
+ */
52
+ #define RDO_RESULT(tuples, info) \
53
+ (rb_funcall(rb_path2class("RDO::Result"), rb_intern("new"), 2, tuples, info))
54
+
55
+ /**
56
+ * Wrap the given StatementExecutor in a RDO::Statement.
57
+ *
58
+ * @param VALUE
59
+ * any object that responds to #command and #execute
60
+ *
61
+ * @return VALUE
62
+ * an RDO::Statement
63
+ */
64
+ #define RDO_STATEMENT(executor) \
65
+ (rb_funcall(rb_path2class("RDO::Statement"), rb_intern("new"), 1, executor))
66
+
24
67
  /**
25
68
  * Convert a C string to a ruby String.
26
69
  *
@@ -33,9 +76,8 @@
33
76
  * @return VALUE (String)
34
77
  * a Ruby String
35
78
  */
36
- #define RDO_STRING(s, len, enc) ( \
37
- rb_enc_associate_index(rb_str_new(s, len), enc > 0 ? enc : 0) \
38
- )
79
+ #define RDO_STRING(s, len, enc) \
80
+ (rb_enc_associate_index(rb_str_new(s, len), enc > 0 ? enc : 0))
39
81
 
40
82
  /**
41
83
  * Convert a C string to a ruby String, assuming possible NULL bytes.
@@ -67,11 +109,9 @@
67
109
  * @return VALUE (Float)
68
110
  * a ruby Float
69
111
  */
70
- #define RDO_FLOAT(s) ( \
71
- rb_funcall(rb_path2class("RDO::Util"), \
72
- rb_intern("float"), 1, \
73
- rb_str_new2(s)) \
74
- )
112
+ #define RDO_FLOAT(s) \
113
+ (rb_funcall(rb_path2class("RDO::Util"), \
114
+ rb_intern("float"), 1, rb_str_new2(s)))
75
115
 
76
116
  /**
77
117
  * Convert a C string representing a precision decimal into a BigDecimal.
@@ -86,11 +126,9 @@
86
126
  * RDO_DECIMAL("1.234")
87
127
  * => #<BigDecimal:7feb42b2b6e8,'0.1234E1',18(18)>
88
128
  */
89
- #define RDO_DECIMAL(s) ( \
90
- rb_funcall(rb_path2class("RDO::Util"), \
91
- rb_intern("decimal"), 1, \
92
- rb_str_new2(s)) \
93
- )
129
+ #define RDO_DECIMAL(s) \
130
+ (rb_funcall(rb_path2class("RDO::Util"), \
131
+ rb_intern("decimal"), 1, rb_str_new2(s)))
94
132
 
95
133
  /**
96
134
  * Convert a C string representing a date into a Date.
@@ -105,11 +143,9 @@
105
143
  * RDO_DATE("431-09-22 BC")
106
144
  * #<Date: -0430-09-22 ((1564265j,0s,0n),+0s,2299161j)>
107
145
  */
108
- #define RDO_DATE(s) ( \
109
- rb_funcall(rb_path2class("RDO::Util"), \
110
- rb_intern("date"), 1, \
111
- rb_str_new2(s)) \
112
- )
146
+ #define RDO_DATE(s) \
147
+ (rb_funcall(rb_path2class("RDO::Util"), \
148
+ rb_intern("date"), 1, rb_str_new2(s)))
113
149
 
114
150
  /**
115
151
  * Convert a C string representing a date & time with no time zone into a DateTime.
@@ -124,11 +160,9 @@
124
160
  * RDO_DATE_TIME_WITHOUT_ZONE("2012-09-22 04:36:12")
125
161
  * #<DateTime: 2012-09-22T04:36:12+10:00 ((2456192j,66972s,0n),+36000s,2299161j)>
126
162
  */
127
- #define RDO_DATE_TIME_WITHOUT_ZONE(s) ( \
128
- rb_funcall(rb_path2class("RDO::Util"), \
129
- rb_intern("date_time_without_zone"), 1, \
130
- rb_str_new2(s)) \
131
- )
163
+ #define RDO_DATE_TIME_WITHOUT_ZONE(s) \
164
+ (rb_funcall(rb_path2class("RDO::Util"), \
165
+ rb_intern("date_time_without_zone"), 1, rb_str_new2(s)))
132
166
 
133
167
  /**
134
168
  * Convert a C string representing a date & time that includes a time zone into a DateTime.
@@ -143,11 +177,9 @@
143
177
  * RDO_DATE_TIME_WITHOUT_ZONE("2012-09-22 04:36:12+10:00")
144
178
  * #<DateTime: 2012-09-22T04:36:12+10:00 ((2456192j,66972s,0n),+36000s,2299161j)>
145
179
  */
146
- #define RDO_DATE_TIME_WITH_ZONE(s) ( \
147
- rb_funcall(rb_path2class("RDO::Util"), \
148
- rb_intern("date_time_with_zone"), 1, \
149
- rb_str_new2(s)) \
150
- )
180
+ #define RDO_DATE_TIME_WITH_ZONE(s) \
181
+ (rb_funcall(rb_path2class("RDO::Util"), \
182
+ rb_intern("date_time_with_zone"), 1, rb_str_new2(s)))
151
183
 
152
184
  /**
153
185
  * Convert a boolean string to TrueClass/FalseClass.
@@ -159,22 +191,3 @@
159
191
  * the boolean representation
160
192
  */
161
193
  #define RDO_BOOL(s) ((s[0] == 't') ? Qtrue : Qfalse)
162
-
163
- /**
164
- * Wrap the given StatementExecutor in a RDO::Statement.
165
- *
166
- * @param VALUE
167
- * any object that responds to #command and #execute
168
- *
169
- * @return VALUE
170
- * an RDO::Statement
171
- */
172
- #define RDO_STATEMENT(executor) ( \
173
- rb_funcall(rb_path2class("RDO::Statement"), \
174
- rb_intern("new"), 1, executor) \
175
- )
176
-
177
- /**
178
- * Convenience to call #to_s on any Ruby object.
179
- */
180
- #define RDO_OBJ_TO_S(obj) (rb_funcall(obj, rb_intern("to_s"), 0))
@@ -207,6 +207,7 @@ static VALUE rdo_postgres_statement_executor_execute(int argc, VALUE * args,
207
207
  ExecStatusType status = PQresultStatus(res);
208
208
 
209
209
  if (status == PGRES_BAD_RESPONSE || status == PGRES_FATAL_ERROR) {
210
+ PQclear(res);
210
211
  rb_raise(rb_path2class("RDO::Exception"),
211
212
  "Failed to execute statement: %s", PQresultErrorMessage(res));
212
213
  }
@@ -7,6 +7,6 @@
7
7
 
8
8
  module RDO
9
9
  module Postgres
10
- VERSION = "0.0.2"
10
+ VERSION = "0.0.3"
11
11
  end
12
12
  end
data/lib/rdo/postgres.rb CHANGED
@@ -13,6 +13,6 @@ require "rdo/postgres/driver"
13
13
  require "rdo_postgres/rdo_postgres"
14
14
 
15
15
  # Register name variants for postgresql schemes
16
- %w[postgres postgresql].each do |name|
16
+ %w[postgres postgresql pgsql psql].each do |name|
17
17
  RDO::Connection.register_driver(name, RDO::Postgres::Driver)
18
18
  end
data/rdo-postgres.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["d11wtq"]
6
6
  gem.email = ["chris@w3style.co.uk"]
7
7
  gem.description = "Provides access to PostgreSQL using the RDO interface"
8
- gem.summary = "PostgreSQL Adapter for RDO"
8
+ gem.summary = "PostgreSQL Driver for RDO"
9
9
  gem.homepage = "https://github.com/d11wtq/rdo-postgres"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdo-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdo
@@ -118,7 +118,7 @@ rubyforge_project:
118
118
  rubygems_version: 1.8.24
119
119
  signing_key:
120
120
  specification_version: 3
121
- summary: PostgreSQL Adapter for RDO
121
+ summary: PostgreSQL Driver for RDO
122
122
  test_files:
123
123
  - spec/postgres/bind_params_spec.rb
124
124
  - spec/postgres/driver_spec.rb