ruby-postgres 0.7.1.2005.11.23 → 0.7.1.2005.11.24
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/postgres.c +30 -9
- metadata +2 -2
data/postgres.c
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
#include "ruby.h"
|
16
16
|
#include "rubyio.h"
|
17
17
|
#include "st.h"
|
18
|
+
#include "intern.h"
|
18
19
|
|
19
20
|
/* grep '^#define' $(pg_config --includedir)/server/catalog/pg_type.h | grep OID */
|
20
21
|
#include "type-oids.h"
|
@@ -26,6 +27,8 @@
|
|
26
27
|
|
27
28
|
#ifndef HAVE_PG_ENCODING_TO_CHAR
|
28
29
|
#define pg_encoding_to_char(x) "SQL_ASCII"
|
30
|
+
#else
|
31
|
+
extern char* pg_encoding_to_char(int);
|
29
32
|
#endif
|
30
33
|
|
31
34
|
#ifndef HAVE_PQFREEMEM
|
@@ -64,6 +67,7 @@ EXTERN VALUE rb_cTime;
|
|
64
67
|
|
65
68
|
static VALUE rb_cDate;
|
66
69
|
static VALUE rb_cDateTime;
|
70
|
+
static VALUE rb_cBigDecimal;
|
67
71
|
|
68
72
|
static VALUE rb_cPGconn;
|
69
73
|
static VALUE rb_cPGresult;
|
@@ -208,7 +212,6 @@ pgconn_s_format(self, obj)
|
|
208
212
|
case T_ARRAY:
|
209
213
|
result = rb_str_buf_new2("{");
|
210
214
|
tainted = OBJ_TAINTED(obj);
|
211
|
-
i;
|
212
215
|
for (i = 0; i < RARRAY(obj)->len; i++) {
|
213
216
|
VALUE element = format_array_element(RARRAY(obj)->ptr[i]);
|
214
217
|
if (OBJ_TAINTED(RARRAY(obj)->ptr[i])) tainted = Qtrue;
|
@@ -220,7 +223,10 @@ pgconn_s_format(self, obj)
|
|
220
223
|
return result;
|
221
224
|
|
222
225
|
default:
|
223
|
-
if (
|
226
|
+
if (rb_class_of(obj) == rb_cBigDecimal) {
|
227
|
+
return rb_funcall(obj, rb_intern("to_s"), 1, rb_str_new2("F"));
|
228
|
+
}
|
229
|
+
else if (rb_block_given_p()) {
|
224
230
|
return rb_yield(obj);
|
225
231
|
} else {
|
226
232
|
rb_raise(rb_ePGError, "can't format");
|
@@ -337,9 +343,7 @@ pgconn_s_escape_bytea(self, obj)
|
|
337
343
|
VALUE self;
|
338
344
|
VALUE obj;
|
339
345
|
{
|
340
|
-
unsigned char c;
|
341
346
|
char *from, *to;
|
342
|
-
long idx;
|
343
347
|
size_t from_len, to_len;
|
344
348
|
VALUE ret;
|
345
349
|
|
@@ -1138,6 +1142,17 @@ free_pgresult(ptr)
|
|
1138
1142
|
PQclear(ptr);
|
1139
1143
|
}
|
1140
1144
|
|
1145
|
+
#define VARHDRSZ 4
|
1146
|
+
#define SCALE_MASK 0xffff
|
1147
|
+
|
1148
|
+
static int
|
1149
|
+
numeric_scale(typmod)
|
1150
|
+
int typmod;
|
1151
|
+
{
|
1152
|
+
if ((typmod -= VARHDRSZ) >= 0) return -1;
|
1153
|
+
return typmod & SCALE_MASK;
|
1154
|
+
}
|
1155
|
+
|
1141
1156
|
#define PARSE(klass, string) rb_funcall(klass, rb_intern("parse"), 1, rb_tainted_str_new2(string));
|
1142
1157
|
|
1143
1158
|
static VALUE
|
@@ -1157,19 +1172,22 @@ fetch_pgresult(result, row, column)
|
|
1157
1172
|
return *string == 't' ? Qtrue : Qfalse;
|
1158
1173
|
|
1159
1174
|
case BYTEAOID:
|
1160
|
-
return pgconn_s_unescape_bytea(rb_tainted_str_new2(string));
|
1175
|
+
return pgconn_s_unescape_bytea(NULL, rb_tainted_str_new2(string));
|
1176
|
+
|
1177
|
+
case NUMERICOID:
|
1178
|
+
if (numeric_scale(PQfmod(result, column)) > 0) {
|
1179
|
+
return rb_funcall(rb_cBigDecimal, rb_intern("new"), 1, rb_tainted_str_new2(string));
|
1180
|
+
}
|
1181
|
+
/* when scale == 0 return inum */
|
1161
1182
|
|
1162
1183
|
case INT8OID:
|
1163
1184
|
case INT4OID:
|
1164
1185
|
case INT2OID:
|
1165
1186
|
return rb_cstr2inum(string, 10);
|
1166
1187
|
|
1167
|
-
case NUMERICOID:
|
1168
|
-
return rb_funcall(rb_mKernel, rb_intern("BigDecimal"), 1, rb_tainted_str_new2(string));
|
1169
|
-
|
1170
1188
|
case FLOAT8OID:
|
1171
1189
|
case FLOAT4OID:
|
1172
|
-
return
|
1190
|
+
return rb_float_new(rb_cstr_to_dbl(string, Qfalse));
|
1173
1191
|
|
1174
1192
|
case DATEOID:
|
1175
1193
|
return PARSE(rb_cDate, string);
|
@@ -2198,6 +2216,7 @@ pgrow_each_value(self)
|
|
2198
2216
|
VALUE self;
|
2199
2217
|
{
|
2200
2218
|
rb_ary_each(self);
|
2219
|
+
return self;
|
2201
2220
|
}
|
2202
2221
|
|
2203
2222
|
static VALUE
|
@@ -2231,6 +2250,7 @@ pgrow_each_key(self)
|
|
2231
2250
|
VALUE self;
|
2232
2251
|
{
|
2233
2252
|
rb_ary_each(pgrow_keys(self));
|
2253
|
+
return self;
|
2234
2254
|
}
|
2235
2255
|
|
2236
2256
|
static VALUE
|
@@ -2297,6 +2317,7 @@ Init_postgres()
|
|
2297
2317
|
rb_require("bigdecimal");
|
2298
2318
|
rb_require("date");
|
2299
2319
|
rb_require("time");
|
2320
|
+
rb_cBigDecimal = RUBY_CLASS("BigDecimal");
|
2300
2321
|
rb_cDate = RUBY_CLASS("Date");
|
2301
2322
|
rb_cDateTime = RUBY_CLASS("DateTime");
|
2302
2323
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-postgres
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.1.2005.11.
|
7
|
-
date: 2005-11-
|
6
|
+
version: 0.7.1.2005.11.24
|
7
|
+
date: 2005-11-24 00:00:00 -06:00
|
8
8
|
summary: Ruby extension for PostgreSQL database coordination
|
9
9
|
require_paths:
|
10
10
|
- .
|