rdo-postgres 0.0.9 → 0.0.10
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/README.md +3 -3
- data/ext/rdo_postgres/driver.c +6 -0
- data/ext/rdo_postgres/driver.h +1 -0
- data/ext/rdo_postgres/statements.c +21 -5
- data/lib/rdo/postgres/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -100,9 +100,9 @@ conn.execute("SELECT * FROM users WHERE banned = $1 AND created_at > ?", true, 1
|
|
100
100
|
If you find any bugs, please send a pull request if you think you can
|
101
101
|
fix it, or file in an issue in the issue tracker.
|
102
102
|
|
103
|
-
I'm particulary interested in patches surrounding support for
|
104
|
-
|
105
|
-
|
103
|
+
I'm particulary interested in patches surrounding support for arrays of
|
104
|
+
custom types, such as ENUMs (this is done by reading from pg_type, in an
|
105
|
+
efficient manner).
|
106
106
|
|
107
107
|
When sending pull requests, please use topic branches—don't send a pull
|
108
108
|
request from the master branch of your fork, as that may change
|
data/ext/rdo_postgres/driver.c
CHANGED
@@ -14,7 +14,12 @@
|
|
14
14
|
|
15
15
|
/** During GC, free any stranded connection */
|
16
16
|
static void rdo_postgres_driver_free(RDOPostgresDriver * driver) {
|
17
|
+
if (driver->ref_count > 0)
|
18
|
+
return;
|
19
|
+
|
17
20
|
PQfinish(driver->conn_ptr);
|
21
|
+
driver->is_open = 0;
|
22
|
+
driver->conn_ptr = NULL;
|
18
23
|
free(driver);
|
19
24
|
}
|
20
25
|
|
@@ -26,6 +31,7 @@ static VALUE rdo_postgres_driver_allocate(VALUE klass) {
|
|
26
31
|
RDOPostgresDriver * driver = malloc(sizeof(RDOPostgresDriver));
|
27
32
|
|
28
33
|
driver->conn_ptr = NULL;
|
34
|
+
driver->ref_count = 0;
|
29
35
|
driver->is_open = 0;
|
30
36
|
driver->stmt_count = 0;
|
31
37
|
driver->encoding = -1;
|
data/ext/rdo_postgres/driver.h
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
#include <stdlib.h>
|
14
14
|
#include <libpq-fe.h>
|
15
15
|
#include "types.h"
|
16
|
+
#include <string.h>
|
16
17
|
|
17
18
|
/** I don't like magic numbers */
|
18
19
|
#define RDO_PG_NO_OIDS 0
|
@@ -35,11 +36,23 @@ typedef struct {
|
|
35
36
|
int nparams;
|
36
37
|
Oid * param_types;
|
37
38
|
RDOPostgresDriver * driver;
|
39
|
+
VALUE driver_obj;
|
38
40
|
} RDOPostgresStatementExecutor;
|
39
41
|
|
42
|
+
/** Claim ownership of driver during GC */
|
43
|
+
static void rdo_postgres_statement_executor_mark(RDOPostgresStatementExecutor * executor) {
|
44
|
+
rb_gc_mark(executor->driver_obj);
|
45
|
+
}
|
46
|
+
|
40
47
|
/** Free memory associated with the StatementExecutor during GC */
|
41
|
-
static void rdo_postgres_statement_executor_free(
|
42
|
-
|
48
|
+
static void rdo_postgres_statement_executor_free(RDOPostgresStatementExecutor * executor) {
|
49
|
+
if (executor->driver->is_open) {
|
50
|
+
char dealloc_cmd[strlen(executor->stmt_name) + 12];
|
51
|
+
sprintf(dealloc_cmd, "DEALLOCATE %s", executor->stmt_name);
|
52
|
+
PQclear(PQexec(executor->driver->conn_ptr, dealloc_cmd));
|
53
|
+
}
|
54
|
+
|
55
|
+
executor->driver->ref_count--;
|
43
56
|
free(executor->stmt_name);
|
44
57
|
free(executor->cmd);
|
45
58
|
free(executor->param_types);
|
@@ -120,13 +133,17 @@ VALUE rdo_postgres_statement_executor_new(VALUE driver, VALUE cmd, VALUE name) {
|
|
120
133
|
malloc(sizeof(RDOPostgresStatementExecutor));
|
121
134
|
|
122
135
|
Data_Get_Struct(driver, RDOPostgresDriver, executor->driver);
|
136
|
+
executor->driver_obj = driver;
|
123
137
|
executor->stmt_name = strdup(RSTRING_PTR(name));
|
124
138
|
executor->cmd = strdup(RSTRING_PTR(cmd));
|
125
139
|
executor->nparams = 0;
|
126
140
|
executor->param_types = NULL;
|
141
|
+
executor->driver->ref_count++;
|
127
142
|
|
128
|
-
VALUE self = Data_Wrap_Struct(rdo_postgres_cStatementExecutor,
|
129
|
-
|
143
|
+
VALUE self = Data_Wrap_Struct(rdo_postgres_cStatementExecutor,
|
144
|
+
&rdo_postgres_statement_executor_mark,
|
145
|
+
rdo_postgres_statement_executor_free,
|
146
|
+
executor);
|
130
147
|
|
131
148
|
rb_obj_call_init(self, 1, &driver);
|
132
149
|
|
@@ -135,7 +152,6 @@ VALUE rdo_postgres_statement_executor_new(VALUE driver, VALUE cmd, VALUE name) {
|
|
135
152
|
|
136
153
|
/** Initialize the StatementExecutor with the given driver and command */
|
137
154
|
static VALUE rdo_postgres_statement_executor_initialize(VALUE self, VALUE driver) {
|
138
|
-
rb_iv_set(self, "driver", driver); // GC safety
|
139
155
|
rdo_postgres_statement_executor_prepare(self);
|
140
156
|
return self;
|
141
157
|
}
|
data/lib/rdo/postgres/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.10
|
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-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdo
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.23
|
142
142
|
signing_key:
|
143
143
|
specification_version: 3
|
144
144
|
summary: PostgreSQL Driver for RDO
|