rdo-postgres 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,11 +5,14 @@ This is the PostgreSQL driver for [RDO—Ruby Data Objects]
5
5
 
6
6
  [![Build Status](https://secure.travis-ci.org/d11wtq/rdo-postgres.png?branch=master)](http://travis-ci.org/d11wtq/rdo-postgres)
7
7
 
8
- Refer to the RDO project [README](https://github.com/d11wtq/rdo) for usage
9
- information.
8
+ Refer to the [RDO project README](https://github.com/d11wtq/rdo) for full
9
+ usage information.
10
10
 
11
- This driver cannot be used with PostgreSQL versions older than 7.4. Those
12
- versions are no longer supported by PostgreSQL in any case.
11
+ ## Supported PostgreSQL version
12
+
13
+ This driver supports PostgreSQL versions >= 7.4.
14
+
15
+ Older versions are no longer supported by PostgreSQL in any case.
13
16
 
14
17
  ## Installation
15
18
 
@@ -27,56 +30,87 @@ And install with Bundler:
27
30
 
28
31
  ## Usage
29
32
 
30
- The registered URI schemes are postgres:// and postgresql://
33
+ The registered URI schemes are postgres://, postgresql:// and psql://.
31
34
 
32
35
  ``` ruby
33
- require "rdo"
34
36
  require "rdo-postgres"
35
37
 
36
38
  conn = RDO.connect("postgres://user:pass@localhost/dbname?encoding=utf-8")
37
39
  ```
38
40
 
39
- Alternatively, give the driver name as "postgres" or "postgresql" in an
40
- options Hash.
41
-
42
- ``` ruby
43
- conn = RDO.connect(
44
- driver: "postgresql",
45
- host: "localhost",
46
- user: "user",
47
- passsword: "pass",
48
- database: "dbname",
49
- encoding: "utf-8"
50
- )
51
- ```
52
-
53
41
  ### Type Support
54
42
 
55
43
  If not listed below, the String form of the value will be returned. The
56
- currently mapped types are:
57
-
58
- - NULL -> nil
59
- - BOOLEAN -> TrueClass/FalseClass
60
- - TEXT -> String
61
- - VARCHAR -> String
62
- - CHAR -> String
63
- - BYTEA -> String
64
- - INTEGER -> Fixnum
65
- - INT2 -> Fixnum
66
- - INT4 -> Fixnum
67
- - INT8 -> Fixnum
68
- - FLOAT/REAL -> Float
69
- - FLOAT4 -> Float
70
- - FLOAT8 -> Float
71
- - NUMERIC/DECIMAL -> BigDecimal
72
- - DATE -> Date
73
- - TIMESTAMP -> DateTime (in the system time zone)
74
- - TIMESTAMPTZ -> DateTime (in the specified time zone)
75
-
76
- All **n-dimensional Arrays** of the above listed **are supported**. Support
77
- for custom-typed Arrays is coming.
78
-
79
- ### Bind parameters support
44
+ currently mapped types are tabled below:
45
+
46
+ <table>
47
+ <thead>
48
+ <tr>
49
+ <th>PostgreSQL Type</th>
50
+ <th>Ruby Type</th>
51
+ <th>Notes</th>
52
+ </tr>
53
+ </thead>
54
+ <tbody>
55
+ <tr>
56
+ <th>null</th>
57
+ <td>NilClass</td>
58
+ <td></td>
59
+ </tr>
60
+ <tr>
61
+ <th>boolean</th>
62
+ <td>TrueClass, FalseClass</td>
63
+ <td>The strings 't' and 'f' will work as inputs too</td>
64
+ </tr>
65
+ <tr>
66
+ <th>text, char, varchar</th>
67
+ <td>String</td>
68
+ <td>The encoding specified on the connection is used</td>
69
+ </tr>
70
+ <tr>
71
+ <th>bytea</th>
72
+ <td>String</td>
73
+ <td>The output encoding is set to ASCII-8BIT/BINARY</td>
74
+ </tr>
75
+ <tr>
76
+ <th>integer, int4, int2, int8</th>
77
+ <td>Fixnum</td>
78
+ <td>Ruby may use a Bignum, if needed</td>
79
+ </tr>
80
+ <tr>
81
+ <th>float, real, float4, float8</th>
82
+ <td>Float</td>
83
+ <td>NaN, Infinity and -Infinity are supported</td>
84
+ </tr>
85
+ <tr>
86
+ <th>numeric, decimal</th>
87
+ <td>BigDecimal</td>
88
+ <td>NaN is supported</td>
89
+ </tr>
90
+ <tr>
91
+ <th>date</th>
92
+ <td>Date</td>
93
+ <td></td>
94
+ </tr>
95
+ <tr>
96
+ <th>timestamp</th>
97
+ <td>DateTime</td>
98
+ <td>Input may also be a Time; output times are in the system time zone</td>
99
+ </tr>
100
+ <tr>
101
+ <th>timestamp with time zone</th>
102
+ <td>DateTime</td>
103
+ <td>Input may also be a Time</td>
104
+ </tr>
105
+ <tr>
106
+ <th>array</th>
107
+ <td>Array</td>
108
+ <td>n-dimensional arrays of the types listed above are supported</td>
109
+ </tr>
110
+ </tbody>
111
+ </table>
112
+
113
+ ### PostgreSQL style bind parameters
80
114
 
81
115
  PostgreSQL uses $1, $2 etc for bind parameters. RDO uses '?'. You can use
82
116
  either, but you **cannot** mix both styles in the same query, or you will
@@ -95,6 +129,16 @@ This is **not ok**:
95
129
  conn.execute("SELECT * FROM users WHERE banned = $1 AND created_at > ?", true, 1.week.ago)
96
130
  ```
97
131
 
132
+ ### HStore Operators
133
+
134
+ Some of the hstore operators in PostgreSQL use the '?' character. If you need
135
+ to use them, for now, you need to escape the '?' so RDO doesn't confuse them
136
+ for bind markers. I'd like to remove this restriction.
137
+
138
+ ``` ruby
139
+ conn.execute(%q{SELECT 'foo=>42,bar=>101'::hstore \? ?}, "foo")
140
+ ```
141
+
98
142
  ## Contributing
99
143
 
100
144
  If you find any bugs, please send a pull request if you think you can
@@ -105,8 +149,7 @@ custom types, such as ENUMs (this is done by reading from pg_type, in an
105
149
  efficient manner).
106
150
 
107
151
  When sending pull requests, please use topic branches—don't send a pull
108
- request from the master branch of your fork, as that may change
109
- unintentionally.
152
+ request from the master branch of your fork.
110
153
 
111
154
  Contributors will be credited in this README.
112
155
 
@@ -11,7 +11,7 @@
11
11
  #include <math.h>
12
12
 
13
13
  /** Get the strlen of the marker (e.g. $2) based on its index */
14
- #define RDO_PG_MARKER_LEN(n) (n >= 100 ? 4 : (n >= 10 ? 3 : 2))
14
+ #define RDO_PG_MARKER_LEN(n) (n > 0 ? (int) floor(log10(n)) + 2 : 2)
15
15
 
16
16
  /**
17
17
  * Replace e.g. "SELECT ? WHERE ?" with "SELECT $1 WHERE $2".
@@ -22,7 +22,7 @@
22
22
  */
23
23
  char * rdo_postgres_params_inject_markers(char * stmt) {
24
24
  int len = strlen(stmt);
25
- char * buf = malloc(sizeof(char) * len ? (len * (floor(log(len)) + 2)) : 0);
25
+ char * buf = malloc(sizeof(char) * len ? (len * (floor(log10(len)) + 2)) : 0);
26
26
  char * s = stmt;
27
27
  char * b = buf;
28
28
  int n = 0;
@@ -78,6 +78,13 @@ char * rdo_postgres_params_inject_markers(char * stmt) {
78
78
  }
79
79
  break;
80
80
 
81
+ case '\\':
82
+ if (!instr && !inident && !inmlcmt && !inslcmt && *(s + 1) == '?')
83
+ ++s;
84
+
85
+ *b = *s;
86
+ break;
87
+
81
88
  case '"':
82
89
  if (!instr && !inmlcmt && !inslcmt) {
83
90
  inident = !inident;
@@ -90,9 +97,9 @@ char * rdo_postgres_params_inject_markers(char * stmt) {
90
97
  case '?':
91
98
  if (!instr && !inident && !inmlcmt && !inslcmt) {
92
99
  sprintf(b, "$%i", ++n);
93
- b += RDO_PG_MARKER_LEN(n -1) - 1;
100
+ b += RDO_PG_MARKER_LEN(n) - 1;
94
101
  } else {
95
- *b= *s;
102
+ *b = *s;
96
103
  }
97
104
  break;
98
105
 
@@ -7,6 +7,6 @@
7
7
 
8
8
  module RDO
9
9
  module Postgres
10
- VERSION = "0.0.10"
10
+ VERSION = "0.0.11"
11
11
  end
12
12
  end
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.10
4
+ version: 0.0.11
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-18 00:00:00.000000000 Z
12
+ date: 2012-10-28 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.23
141
+ rubygems_version: 1.8.24
142
142
  signing_key:
143
143
  specification_version: 3
144
144
  summary: PostgreSQL Driver for RDO