ruby-postgres 0.7.1.2005.11.27-mswin32 → 0.7.1.2005.12.19-mswin32

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 CHANGED
@@ -78,7 +78,8 @@ static VALUE rb_cPGlarge;
78
78
  static VALUE rb_cPGrow;
79
79
 
80
80
  static VALUE pgconn_lastval _((VALUE));
81
-
81
+ static VALUE pgresult_fields _((VALUE));
82
+ static VALUE pgresult_clear _((VALUE));
82
83
  static VALUE pgresult_result_with_clear _((VALUE));
83
84
  static VALUE pgresult_new _((PGresult*));
84
85
 
@@ -252,8 +253,8 @@ format_array_element(obj)
252
253
  VALUE obj;
253
254
  {
254
255
  if (TYPE(obj) == T_STRING) {
255
- obj = rb_funcall(obj, rb_intern("gsub"), 2, rb_reg_new("(?=[\\\\\"])", 9, 0), "\\");
256
- return rb_funcall(obj, rb_intern("gsub!"), 2, rb_reg_new("^|$", 3, 0), "\"");
256
+ obj = rb_funcall(obj, rb_intern("gsub"), 2, rb_reg_new("(?=[\\\\\"])", 9, 0), rb_str_new2("\\"));
257
+ return rb_funcall(obj, rb_intern("gsub!"), 2, rb_reg_new("^|$", 3, 0), rb_str_new2("\""));
257
258
  }
258
259
  else {
259
260
  return pgconn_s_format(NULL, obj);
@@ -546,7 +547,7 @@ pgconn_exec(argc, argv, obj)
546
547
  result = PQexecParams(conn, StringValuePtr(command), len, NULL, values, NULL, NULL, 0);
547
548
  #else
548
549
  for (i = 0; i < len; i++) {
549
- rb_ary_store(params, i, pgconn_s_quote(NULL, rb_ary_entry(params, i)));
550
+ rb_ary_push(params, pgconn_s_quote(NULL, rb_ary_entry(params, i)));
550
551
  }
551
552
  result = PQexecParams_compat(conn, command, params);
552
553
  #endif
@@ -1277,6 +1278,86 @@ pgresult_status(obj)
1277
1278
  * Returns an array of tuples (rows, which are themselves arrays) that represent the query result.
1278
1279
  */
1279
1280
 
1281
+ static VALUE
1282
+ fetch_pgrow(self, fields, row_num)
1283
+ VALUE self, fields;
1284
+ int row_num;
1285
+ {
1286
+ PGresult *result = get_pgresult(self);
1287
+ VALUE row = rb_funcall(rb_cPGrow, rb_intern("new"), 1, fields);
1288
+ int field_num;
1289
+ for (field_num = 0; field_num < RARRAY(fields)->len; field_num++) {
1290
+ rb_ary_push(row, fetch_pgresult(result, row_num, field_num));
1291
+ }
1292
+ return row;
1293
+ }
1294
+
1295
+ /*
1296
+ * call-seq:
1297
+ * conn.select_one(query, *bind_values)
1298
+ *
1299
+ * Return the first row of the query results.
1300
+ * Equivalent to conn.query(query, *bind_values).first
1301
+ */
1302
+ static VALUE
1303
+ pgconn_select_one(argc, argv, self)
1304
+ int argc;
1305
+ VALUE *argv;
1306
+ VALUE self;
1307
+ {
1308
+ VALUE result = pgconn_exec(argc, argv, self);
1309
+ VALUE row = fetch_pgrow(result, pgresult_fields(self), 0);
1310
+ pgresult_clear(result);
1311
+ return row;
1312
+ }
1313
+
1314
+ /*
1315
+ * call-seq:
1316
+ * conn.select_value(query, *bind_values)
1317
+ *
1318
+ * Return the first value of the first row of the query results.
1319
+ * Equivalent to conn.query(query, *bind_values).first.first
1320
+ */
1321
+ static VALUE
1322
+ pgconn_select_value(argc, argv, self)
1323
+ int argc;
1324
+ VALUE *argv;
1325
+ VALUE self;
1326
+ {
1327
+ PGresult *result = get_pgresult(pgconn_exec(argc, argv, self));
1328
+ VALUE value = fetch_pgresult(result, 0, 0);
1329
+ PQclear(result);
1330
+ return value;
1331
+ }
1332
+
1333
+ /*
1334
+ * call-seq:
1335
+ * conn.select_values(query, *bind_values)
1336
+ *
1337
+ * Equivalent to conn.query(query, *bind_values).flatten
1338
+ */
1339
+ static VALUE
1340
+ pgconn_select_values(argc, argv, self)
1341
+ int argc;
1342
+ VALUE *argv;
1343
+ VALUE self;
1344
+ {
1345
+ PGresult *result = get_pgresult(pgconn_exec(argc, argv, self));
1346
+ int ntuples = PQntuples(result);
1347
+ int nfields = PQnfields(result);
1348
+
1349
+ VALUE values = rb_ary_new2(ntuples * nfields);
1350
+ int row_num, field_num;
1351
+ for (row_num = 0; row_num < ntuples; row_num++) {
1352
+ for (field_num = 0; field_num < nfields; field_num++) {
1353
+ rb_ary_push(values, fetch_pgresult(result, row_num, field_num));
1354
+ }
1355
+ }
1356
+
1357
+ PQclear(result);
1358
+ return values;
1359
+ }
1360
+
1280
1361
  /*
1281
1362
  * call-seq:
1282
1363
  * res.each{ |tuple| ... }
@@ -1289,21 +1370,13 @@ static VALUE
1289
1370
  pgresult_each(self)
1290
1371
  VALUE self;
1291
1372
  {
1292
- int i, j;
1293
-
1294
1373
  PGresult *result = get_pgresult(self);
1295
- int nt = PQntuples(result);
1296
- int nf = PQnfields(result);
1297
- VALUE fields[1] = { rb_ary_new2(nf) };
1298
-
1299
- for (i = 0; i < nf; i++)
1300
- rb_ary_push(fields[0], rb_tainted_str_new2(PQfname(result, i)));
1374
+ int row_count = PQntuples(result);
1375
+ VALUE fields = pgresult_fields(self);
1301
1376
 
1302
- for (i=0; i<nt; i++) {
1303
- VALUE row = rb_funcall2(rb_cPGrow, rb_intern("new"), 1, fields);
1304
- for (j=0; j<nf; j++) {
1305
- rb_ary_store(row, j, fetch_pgresult(result, i, j));
1306
- }
1377
+ int row_num;
1378
+ for (row_num = 0; row_num < row_count; row_num++) {
1379
+ VALUE row = fetch_pgrow(self, fields, row_num);
1307
1380
  rb_yield(row);
1308
1381
  }
1309
1382
 
@@ -2261,8 +2334,13 @@ pgrow_aref(argc, argv, self)
2261
2334
  {
2262
2335
  if (TYPE(argv[0]) == T_STRING) {
2263
2336
  VALUE keys = pgrow_keys(self);
2264
- int index = NUM2INT(rb_funcall(keys, rb_intern("index"), 1, argv[0]));
2265
- return rb_ary_entry(self, index);
2337
+ VALUE index = rb_funcall(keys, rb_intern("index"), 1, argv[0]);
2338
+ if (index == Qnil) {
2339
+ rb_raise(rb_ePGError, "%s: field not found", StringValuePtr(argv[0]));
2340
+ }
2341
+ else {
2342
+ return rb_ary_entry(self, NUM2INT(index));
2343
+ }
2266
2344
  }
2267
2345
  else {
2268
2346
  return rb_call_super(argc, argv);
@@ -2418,6 +2496,7 @@ Init_postgres()
2418
2496
  rb_cDateTime = RUBY_CLASS("DateTime");
2419
2497
 
2420
2498
  rb_ePGError = rb_define_class("PGError", rb_eStandardError);
2499
+ rb_define_alias(rb_ePGError, "error", "message");
2421
2500
 
2422
2501
  rb_cPGconn = rb_define_class("PGconn", rb_cObject);
2423
2502
  #ifdef HAVE_RB_DEFINE_ALLOC_FUNC
@@ -2456,6 +2535,9 @@ Init_postgres()
2456
2535
  rb_define_method(rb_cPGconn, "untrace", pgconn_untrace, 0);
2457
2536
  rb_define_method(rb_cPGconn, "exec", pgconn_exec, -1);
2458
2537
  rb_define_method(rb_cPGconn, "query", pgconn_query, -1);
2538
+ rb_define_method(rb_cPGconn, "select_one", pgconn_select_one, -1);
2539
+ rb_define_method(rb_cPGconn, "select_value", pgconn_select_value, -1);
2540
+ rb_define_method(rb_cPGconn, "select_values", pgconn_select_values, -1);
2459
2541
  rb_define_method(rb_cPGconn, "async_exec", pgconn_async_exec, 1);
2460
2542
  rb_define_method(rb_cPGconn, "async_query", pgconn_async_query, 1);
2461
2543
  rb_define_method(rb_cPGconn, "get_notify", pgconn_get_notify, 0);
data/postgres.o CHANGED
Binary file
data/postgres.so CHANGED
Binary file
Binary file
data/tests/tc_postgres.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'postgres'
2
- require 'date'
3
2
  require 'test/unit'
4
3
 
5
4
  class PostgresTestCase < Test::Unit::TestCase
@@ -16,33 +15,26 @@ class PostgresTestCase < Test::Unit::TestCase
16
15
  query = <<-EOT
17
16
  select true as true_value,
18
17
  false as false_value,
19
- '12345\\\\111\\\\000\\\\111TEST'::bytea as bytea_value,
18
+ $1::bytea as bytea_value,
20
19
  '2005-11-30'::date as date_value,
21
20
  '12:00:00'::time as time_value,
22
- now() as date_time_value,
21
+ '2005-11-30 12:00:00'::timestamp as date_time_value,
23
22
  1.5::float as float_value,
24
23
  12345.5678::numeric as numeric_value,
25
24
  1234.56::numeric(10) as numeric_10_value,
26
25
  12345.12345::numeric(10,5) as numeric_10_5_value
27
26
  EOT
28
- res = @conn.exec(query)
27
+ res = @conn.exec(query, '12345\111\000\111TEST')
29
28
  assert_equal(res.num_tuples, 1)
30
29
  assert_equal(res.num_fields, 10)
31
- tuple = res.result[0]
32
- puts tuple
30
+ tuple = res.result.first
33
31
  assert_equal(true, tuple['true_value'])
34
32
  assert_equal(false, tuple['false_value'])
35
- assert_equal("12345\111\000\111TEST", tuple['bytea_value'])
36
- puts PGconn.escape_bytea(tuple['bytea_value'])
37
- assert_equal("12345I\\\\000ITEST", PGconn.escape_bytea(tuple['bytea_value']))
33
+ assert_equal("12345I\000ITEST", tuple['bytea_value'])
38
34
  assert_equal(Date.parse('2005-11-30'), tuple['date_value'])
39
- puts tuple['date_value']
40
- assert_kind_of(Time, tuple['time_value'])
41
- puts tuple['time_value']
42
- assert_kind_of(DateTime, tuple['date_time_value'])
43
- puts tuple['date_time_value']
35
+ assert_equal(Time.parse('12:00:00'), tuple['time_value'])
36
+ assert_equal(DateTime.parse('2005-11-30 12:00:00'), tuple['date_time_value'])
44
37
  assert_equal(1.5, tuple['float_value'])
45
- puts PGconn.quote(tuple['numeric_value'])
46
38
  assert_equal(BigDecimal("12345.5678"), tuple['numeric_value'])
47
39
  assert_equal(1235, tuple['numeric_10_value'])
48
40
  assert_kind_of(Integer, tuple['numeric_10_value'])
metadata CHANGED
@@ -1,13 +1,13 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
1
+ !ruby/object:Gem::Specification
2
+ 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.27
7
- date: 2005-11-27
6
+ version: 0.7.1.2005.12.19
7
+ date: 2005-12-19 00:00:00 -07:00
8
8
  summary: Ruby extension for PostgreSQL database coordination
9
9
  require_paths:
10
- - "."
10
+ - .
11
11
  email: davelee.com@gmail.com
12
12
  homepage: http://ruby.scripting.ca/postgres/
13
13
  rubyforge_project: ruby-postgres
@@ -18,46 +18,54 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: mswin32
26
+ signing_key:
27
+ cert_chain:
27
28
  authors:
28
- - "Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee"
29
+ - Yukihiro Matsumoto, Eiji Matsumoto, Noboru Saitou, Dave Lee
29
30
  files:
30
- - ChangeLog
31
- - Contributors
32
- - doc
33
- - extconf.rb
34
- - libpq-compat.c
35
- - Makefile
36
- - MANIFEST
37
- - mkmf.log
38
- - postgres.c
39
- - postgres.o
40
- - postgres.so
41
- - README
42
- - README.ja
43
- - ruby-postgres.gemspec
44
- - sample
45
- - tests
46
- - type-oids.h
47
- - doc/postgres.html
48
- - doc/postgres.jp.html
49
- - sample/losample.rb
50
- - sample/psql.rb
51
- - sample/psqlHelp.rb
52
- - sample/test1.rb
53
- - sample/test2.rb
54
- - sample/test4.rb
55
- - tests/tc_postgres.rb
31
+ - ChangeLog
32
+ - Contributors
33
+ - doc
34
+ - extconf.rb
35
+ - libpq-compat.c
36
+ - Makefile
37
+ - MANIFEST
38
+ - mkmf.log
39
+ - postgres.c
40
+ - postgres.o
41
+ - postgres.so
42
+ - README
43
+ - README.ja
44
+ - ruby-postgres-0.7.1.2005.12.19.gem
45
+ - ruby-postgres.gemspec
46
+ - sample
47
+ - tests
48
+ - type-oids.h
49
+ - doc/postgres.html
50
+ - doc/postgres.jp.html
51
+ - sample/losample.rb
52
+ - sample/psql.rb
53
+ - sample/psqlHelp.rb
54
+ - sample/test1.rb
55
+ - sample/test2.rb
56
+ - sample/test4.rb
57
+ - tests/tc_postgres.rb
56
58
  test_files: []
59
+
57
60
  rdoc_options: []
61
+
58
62
  extra_rdoc_files: []
63
+
59
64
  executables: []
65
+
60
66
  extensions: []
67
+
61
68
  requirements:
62
- - PostgreSQL libpq library and headers
63
- dependencies: []
69
+ - PostgreSQL libpq library and headers
70
+ dependencies: []
71
+