pg 1.1.4 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/ChangeLog +0 -6595
  5. data/History.rdoc +77 -0
  6. data/Manifest.txt +3 -2
  7. data/README-Windows.rdoc +4 -4
  8. data/README.ja.rdoc +1 -2
  9. data/README.rdoc +43 -8
  10. data/Rakefile +7 -5
  11. data/Rakefile.cross +46 -44
  12. data/ext/errorcodes.def +64 -0
  13. data/ext/errorcodes.txt +18 -2
  14. data/ext/extconf.rb +6 -6
  15. data/ext/pg.c +132 -95
  16. data/ext/pg.h +20 -18
  17. data/ext/pg_binary_decoder.c +9 -9
  18. data/ext/pg_binary_encoder.c +13 -12
  19. data/ext/pg_coder.c +5 -5
  20. data/ext/pg_connection.c +388 -298
  21. data/ext/pg_copy_coder.c +5 -3
  22. data/ext/pg_record_coder.c +490 -0
  23. data/ext/pg_result.c +279 -127
  24. data/ext/pg_text_decoder.c +14 -8
  25. data/ext/pg_text_encoder.c +180 -48
  26. data/ext/pg_tuple.c +14 -6
  27. data/ext/pg_type_map.c +1 -1
  28. data/ext/pg_type_map_all_strings.c +4 -4
  29. data/ext/pg_type_map_by_class.c +4 -3
  30. data/ext/pg_type_map_by_column.c +7 -6
  31. data/ext/pg_type_map_by_mri_type.c +1 -1
  32. data/ext/pg_type_map_by_oid.c +3 -2
  33. data/ext/pg_type_map_in_ruby.c +1 -1
  34. data/ext/{util.c → pg_util.c} +5 -5
  35. data/ext/{util.h → pg_util.h} +0 -0
  36. data/lib/pg.rb +4 -4
  37. data/lib/pg/basic_type_mapping.rb +79 -16
  38. data/lib/pg/binary_decoder.rb +1 -0
  39. data/lib/pg/coder.rb +22 -1
  40. data/lib/pg/connection.rb +2 -2
  41. data/lib/pg/constants.rb +1 -0
  42. data/lib/pg/exceptions.rb +1 -0
  43. data/lib/pg/result.rb +13 -1
  44. data/lib/pg/text_decoder.rb +2 -3
  45. data/lib/pg/text_encoder.rb +8 -18
  46. data/lib/pg/type_map_by_column.rb +2 -1
  47. data/spec/helpers.rb +10 -8
  48. data/spec/pg/basic_type_mapping_spec.rb +150 -13
  49. data/spec/pg/connection_spec.rb +89 -50
  50. data/spec/pg/result_spec.rb +193 -3
  51. data/spec/pg/tuple_spec.rb +55 -2
  52. data/spec/pg/type_map_by_column_spec.rb +5 -1
  53. data/spec/pg/type_spec.rb +180 -6
  54. metadata +33 -32
  55. metadata.gz.sig +0 -0
@@ -2,7 +2,7 @@
2
2
  # errcodes.txt
3
3
  # PostgreSQL error codes
4
4
  #
5
- # Copyright (c) 2003-2018, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2019, PostgreSQL Global Development Group
6
6
  #
7
7
  # This list serves as the basis for generating source files containing error
8
8
  # codes. It is kept in a common format to make sure all these source files have
@@ -18,7 +18,7 @@
18
18
  # src/pl/tcl/pltclerrcodes.h
19
19
  # the same, for PL/Tcl
20
20
  #
21
- # doc/src/sgml/errcodes-list.sgml
21
+ # doc/src/sgml/errcodes-table.sgml
22
22
  # a SGML table of error codes for inclusion in the documentation
23
23
  #
24
24
  # The format of this file is one error code per line, with the following
@@ -206,6 +206,21 @@ Section: Class 22 - Data Exception
206
206
  2200N E ERRCODE_INVALID_XML_CONTENT invalid_xml_content
207
207
  2200S E ERRCODE_INVALID_XML_COMMENT invalid_xml_comment
208
208
  2200T E ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION invalid_xml_processing_instruction
209
+ 22030 E ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE duplicate_json_object_key_value
210
+ 22032 E ERRCODE_INVALID_JSON_TEXT invalid_json_text
211
+ 22033 E ERRCODE_INVALID_SQL_JSON_SUBSCRIPT invalid_sql_json_subscript
212
+ 22034 E ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM more_than_one_sql_json_item
213
+ 22035 E ERRCODE_NO_SQL_JSON_ITEM no_sql_json_item
214
+ 22036 E ERRCODE_NON_NUMERIC_SQL_JSON_ITEM non_numeric_sql_json_item
215
+ 22037 E ERRCODE_NON_UNIQUE_KEYS_IN_A_JSON_OBJECT non_unique_keys_in_a_json_object
216
+ 22038 E ERRCODE_SINGLETON_SQL_JSON_ITEM_REQUIRED singleton_sql_json_item_required
217
+ 22039 E ERRCODE_SQL_JSON_ARRAY_NOT_FOUND sql_json_array_not_found
218
+ 2203A E ERRCODE_SQL_JSON_MEMBER_NOT_FOUND sql_json_member_not_found
219
+ 2203B E ERRCODE_SQL_JSON_NUMBER_NOT_FOUND sql_json_number_not_found
220
+ 2203C E ERRCODE_SQL_JSON_OBJECT_NOT_FOUND sql_json_object_not_found
221
+ 2203D E ERRCODE_TOO_MANY_JSON_ARRAY_ELEMENTS too_many_json_array_elements
222
+ 2203E E ERRCODE_TOO_MANY_JSON_OBJECT_MEMBERS too_many_json_object_members
223
+ 2203F E ERRCODE_SQL_JSON_SCALAR_REQUIRED sql_json_scalar_required
209
224
 
210
225
  Section: Class 23 - Integrity Constraint Violation
211
226
 
@@ -401,6 +416,7 @@ Section: Class 55 - Object Not In Prerequisite State
401
416
  55006 E ERRCODE_OBJECT_IN_USE object_in_use
402
417
  55P02 E ERRCODE_CANT_CHANGE_RUNTIME_PARAM cant_change_runtime_param
403
418
  55P03 E ERRCODE_LOCK_NOT_AVAILABLE lock_not_available
419
+ 55P04 E ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE unsafe_new_enum_value_usage
404
420
 
405
421
  Section: Class 57 - Operator Intervention
406
422
 
@@ -73,13 +73,13 @@ end
73
73
  have_func 'PQsetSingleRowMode' or
74
74
  abort "Your PostgreSQL is too old. Either install an older version " +
75
75
  "of this gem or upgrade your database to at least PostgreSQL-9.2."
76
- have_func 'PQconninfo'
77
- have_func 'PQsslAttribute'
78
- have_func 'PQencryptPasswordConn'
76
+ have_func 'PQconninfo' # since PostgreSQL-9.3
77
+ have_func 'PQsslAttribute' # since PostgreSQL-9.5
78
+ have_func 'PQresultVerboseErrorMessage' # since PostgreSQL-9.6
79
+ have_func 'PQencryptPasswordConn' # since PostgreSQL-10
80
+ have_func 'PQresultMemorySize' # since PostgreSQL-12
79
81
  have_func 'timegm'
80
- have_func 'rb_gc_adjust_memory_usage'
81
-
82
- have_const 'PG_DIAG_TABLE_NAME', 'libpq-fe.h'
82
+ have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
83
83
 
84
84
  # unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
85
85
  have_header 'unistd.h'
data/ext/pg.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v 2d334508484a 2018/08/27 11:33:43 lars $
3
+ * $Id$
4
4
  *
5
5
  * Author/s:
6
6
  *
@@ -16,7 +16,7 @@
16
16
  * See Contributors.rdoc for the many additional fine people that have contributed
17
17
  * to this library over the years.
18
18
  *
19
- * Copyright (c) 1997-2016 by the authors.
19
+ * Copyright (c) 1997-2019 by the authors.
20
20
  *
21
21
  * You may redistribute this software under the same terms as Ruby itself; see
22
22
  * https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
@@ -331,8 +331,7 @@ pg_to_bool_int(VALUE value)
331
331
  * If your application initializes libssl and/or libcrypto libraries and libpq is
332
332
  * built with SSL support, you should call PG.init_openssl() to tell libpq that the
333
333
  * libssl and/or libcrypto libraries have been initialized by your application,
334
- * so that libpq will not also initialize those libraries. See
335
- * http://h71000.www7.hp.com/doc/83final/BA554_90007/ch04.html for details on the SSL API.
334
+ * so that libpq will not also initialize those libraries.
336
335
  *
337
336
  * When do_ssl is +true+, libpq will initialize the OpenSSL library before first
338
337
  * opening a database connection. When do_crypto is +true+, the libcrypto library
@@ -422,7 +421,7 @@ Init_pg_ext()
422
421
  rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
423
422
  /* Negotiating environment-driven parameter settings. */
424
423
  rb_define_const(rb_mPGconstants, "CONNECTION_SETENV", INT2FIX(CONNECTION_SETENV));
425
- /* Internal state: connect() needed. */
424
+ /* Internal state - PG.connect() needed. */
426
425
  rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
427
426
 
428
427
  /****** PG::Connection CLASS CONSTANTS: Nonblocking connection polling status ******/
@@ -438,26 +437,48 @@ Init_pg_ext()
438
437
 
439
438
  /****** PG::Connection CLASS CONSTANTS: Transaction Status ******/
440
439
 
441
- /* Transaction is currently idle (#transaction_status) */
440
+ /* Transaction is currently idle ( Connection#transaction_status ) */
442
441
  rb_define_const(rb_mPGconstants, "PQTRANS_IDLE", INT2FIX(PQTRANS_IDLE));
443
- /* Transaction is currently active; query has been sent to the server, but not yet completed. (#transaction_status) */
442
+ /* Transaction is currently active; query has been sent to the server, but not yet completed. ( Connection#transaction_status ) */
444
443
  rb_define_const(rb_mPGconstants, "PQTRANS_ACTIVE", INT2FIX(PQTRANS_ACTIVE));
445
- /* Transaction is currently idle, in a valid transaction block (#transaction_status) */
444
+ /* Transaction is currently idle, in a valid transaction block ( Connection#transaction_status ) */
446
445
  rb_define_const(rb_mPGconstants, "PQTRANS_INTRANS", INT2FIX(PQTRANS_INTRANS));
447
- /* Transaction is currently idle, in a failed transaction block (#transaction_status) */
446
+ /* Transaction is currently idle, in a failed transaction block ( Connection#transaction_status ) */
448
447
  rb_define_const(rb_mPGconstants, "PQTRANS_INERROR", INT2FIX(PQTRANS_INERROR));
449
- /* Transaction's connection is bad (#transaction_status) */
448
+ /* Transaction's connection is bad ( Connection#transaction_status ) */
450
449
  rb_define_const(rb_mPGconstants, "PQTRANS_UNKNOWN", INT2FIX(PQTRANS_UNKNOWN));
451
450
 
452
451
  /****** PG::Connection CLASS CONSTANTS: Error Verbosity ******/
453
452
 
454
- /* Terse error verbosity level (#set_error_verbosity) */
453
+ /* Error verbosity level ( Connection#set_error_verbosity ).
454
+ * In TERSE mode, returned messages include severity, primary text, and position only; this will normally fit on a single line. */
455
455
  rb_define_const(rb_mPGconstants, "PQERRORS_TERSE", INT2FIX(PQERRORS_TERSE));
456
- /* Default error verbosity level (#set_error_verbosity) */
456
+ /* Error verbosity level ( Connection#set_error_verbosity ).
457
+ * The DEFAULT mode produces messages that include the above plus any detail, hint, or context fields (these might span multiple lines). */
457
458
  rb_define_const(rb_mPGconstants, "PQERRORS_DEFAULT", INT2FIX(PQERRORS_DEFAULT));
458
- /* Verbose error verbosity level (#set_error_verbosity) */
459
+ /* Error verbosity level ( Connection#set_error_verbosity ).
460
+ * The VERBOSE mode includes all available fields. */
459
461
  rb_define_const(rb_mPGconstants, "PQERRORS_VERBOSE", INT2FIX(PQERRORS_VERBOSE));
460
462
 
463
+ /* PQERRORS_SQLSTATE was introduced in PG-12 together with PQresultMemorySize() */
464
+ #ifdef HAVE_PQRESULTMEMORYSIZE
465
+ /* Error verbosity level ( Connection#set_error_verbosity ).
466
+ * The SQLSTATE mode includes only the error severity and the SQLSTATE error code, if one is available (if not, the output is like TERSE mode).
467
+ *
468
+ * Available since PostgreSQL-12.
469
+ */
470
+ rb_define_const(rb_mPGconstants, "PQERRORS_SQLSTATE", INT2FIX(PQERRORS_SQLSTATE));
471
+ #endif
472
+
473
+ #ifdef HAVE_PQRESULTVERBOSEERRORMESSAGE
474
+ /* See Connection#set_error_context_visibility */
475
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_NEVER", INT2FIX(PQSHOW_CONTEXT_NEVER));
476
+ /* See Connection#set_error_context_visibility */
477
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ERRORS", INT2FIX(PQSHOW_CONTEXT_ERRORS));
478
+ /* See Connection#set_error_context_visibility */
479
+ rb_define_const(rb_mPGconstants, "PQSHOW_CONTEXT_ALWAYS", INT2FIX(PQSHOW_CONTEXT_ALWAYS));
480
+ #endif
481
+
461
482
  /****** PG::Connection CLASS CONSTANTS: Check Server Status ******/
462
483
 
463
484
  /* Server is accepting connections. */
@@ -471,141 +492,156 @@ Init_pg_ext()
471
492
 
472
493
  /****** PG::Connection CLASS CONSTANTS: Large Objects ******/
473
494
 
474
- /* Flag for #lo_creat, #lo_open -- open for writing */
495
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for writing */
475
496
  rb_define_const(rb_mPGconstants, "INV_WRITE", INT2FIX(INV_WRITE));
476
- /* Flag for #lo_creat, #lo_open -- open for reading */
497
+ /* Flag for Connection#lo_creat, Connection#lo_open -- open for reading */
477
498
  rb_define_const(rb_mPGconstants, "INV_READ", INT2FIX(INV_READ));
478
- /* Flag for #lo_lseek -- seek from object start */
499
+ /* Flag for Connection#lo_lseek -- seek from object start */
479
500
  rb_define_const(rb_mPGconstants, "SEEK_SET", INT2FIX(SEEK_SET));
480
- /* Flag for #lo_lseek -- seek from current position */
501
+ /* Flag for Connection#lo_lseek -- seek from current position */
481
502
  rb_define_const(rb_mPGconstants, "SEEK_CUR", INT2FIX(SEEK_CUR));
482
- /* Flag for #lo_lseek -- seek from object end */
503
+ /* Flag for Connection#lo_lseek -- seek from object end */
483
504
  rb_define_const(rb_mPGconstants, "SEEK_END", INT2FIX(SEEK_END));
484
505
 
485
506
  /****** PG::Result CONSTANTS: result status ******/
486
507
 
487
- /* #result_status constant: The string sent to the server was empty. */
508
+ /* Result#result_status constant - The string sent to the server was empty. */
488
509
  rb_define_const(rb_mPGconstants, "PGRES_EMPTY_QUERY", INT2FIX(PGRES_EMPTY_QUERY));
489
- /* #result_status constant: Successful completion of a command returning no data. */
510
+ /* Result#result_status constant - Successful completion of a command returning no data. */
490
511
  rb_define_const(rb_mPGconstants, "PGRES_COMMAND_OK", INT2FIX(PGRES_COMMAND_OK));
491
- /* #result_status constant: Successful completion of a command returning data
492
- (such as a SELECT or SHOW). */
512
+ /* Result#result_status constant - Successful completion of a command returning data (such as a SELECT or SHOW). */
493
513
  rb_define_const(rb_mPGconstants, "PGRES_TUPLES_OK", INT2FIX(PGRES_TUPLES_OK));
494
- /* #result_status constant: Copy Out (from server) data transfer started. */
514
+ /* Result#result_status constant - Copy Out (from server) data transfer started. */
495
515
  rb_define_const(rb_mPGconstants, "PGRES_COPY_OUT", INT2FIX(PGRES_COPY_OUT));
496
- /* #result_status constant: Copy In (to server) data transfer started. */
516
+ /* Result#result_status constant - Copy In (to server) data transfer started. */
497
517
  rb_define_const(rb_mPGconstants, "PGRES_COPY_IN", INT2FIX(PGRES_COPY_IN));
498
- /* #result_status constant: The server’s response was not understood. */
518
+ /* Result#result_status constant - The server’s response was not understood. */
499
519
  rb_define_const(rb_mPGconstants, "PGRES_BAD_RESPONSE", INT2FIX(PGRES_BAD_RESPONSE));
500
- /* #result_status constant: A nonfatal error (a notice or warning) occurred. */
520
+ /* Result#result_status constant - A nonfatal error (a notice or warning) occurred. */
501
521
  rb_define_const(rb_mPGconstants, "PGRES_NONFATAL_ERROR",INT2FIX(PGRES_NONFATAL_ERROR));
502
- /* #result_status constant: A fatal error occurred. */
522
+ /* Result#result_status constant - A fatal error occurred. */
503
523
  rb_define_const(rb_mPGconstants, "PGRES_FATAL_ERROR", INT2FIX(PGRES_FATAL_ERROR));
504
- /* #result_status constant: Copy In/Out data transfer in progress. */
524
+ /* Result#result_status constant - Copy In/Out data transfer in progress. */
505
525
  rb_define_const(rb_mPGconstants, "PGRES_COPY_BOTH", INT2FIX(PGRES_COPY_BOTH));
506
- /* #result_status constant: Single tuple from larger resultset. */
526
+ /* Result#result_status constant - Single tuple from larger resultset. */
507
527
  rb_define_const(rb_mPGconstants, "PGRES_SINGLE_TUPLE", INT2FIX(PGRES_SINGLE_TUPLE));
508
528
 
509
529
  /****** Result CONSTANTS: result error field codes ******/
510
530
 
511
- /* #result_error_field argument constant: The severity; the field contents
512
- * are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE,
513
- * DEBUG, INFO, or LOG (in a notice message), or a localized translation
514
- * of one of these. Always present.
531
+ /* Result#result_error_field argument constant
532
+ *
533
+ * The severity; the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a localized translation
534
+ * of one of these.
535
+ * Always present.
515
536
  */
516
537
  rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY", INT2FIX(PG_DIAG_SEVERITY));
517
538
 
518
- /* #result_error_field argument constant: The SQLSTATE code for the
519
- * error. The SQLSTATE code identies the type of error that has occurred;
520
- * it can be used by front-end applications to perform specic operations
521
- * (such as er- ror handling) in response to a particular database
522
- * error. For a list of the possible SQLSTATE codes, see Appendix A.
523
- * This eld is not localizable, and is always present.
539
+ #ifdef PG_DIAG_SEVERITY_NONLOCALIZED
540
+ /* Result#result_error_field argument constant
541
+ *
542
+ * The severity; the field contents are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message).
543
+ * This is identical to the PG_DIAG_SEVERITY field except that the contents are never localized.
544
+ *
545
+ * Available since PostgreSQL-9.6
546
+ */
547
+ rb_define_const(rb_mPGconstants, "PG_DIAG_SEVERITY_NONLOCALIZED", INT2FIX(PG_DIAG_SEVERITY_NONLOCALIZED));
548
+ #endif
549
+ /* Result#result_error_field argument constant
550
+ *
551
+ * The SQLSTATE code for the error.
552
+ * The SQLSTATE code identies the type of error that has occurred; it can be used by front-end applications to perform specic operations (such as error handling) in response to a particular database error.
553
+ * For a list of the possible SQLSTATE codes, see Appendix A.
554
+ * This field is not localizable, and is always present.
524
555
  */
525
556
  rb_define_const(rb_mPGconstants, "PG_DIAG_SQLSTATE", INT2FIX(PG_DIAG_SQLSTATE));
526
-
527
- /* #result_error_field argument constant: The primary human-readable
528
- * error message (typically one line). Always present. */
557
+ /* Result#result_error_field argument constant
558
+ *
559
+ * The primary human-readable error message (typically one line).
560
+ * Always present. */
529
561
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_PRIMARY", INT2FIX(PG_DIAG_MESSAGE_PRIMARY));
530
-
531
- /* #result_error_field argument constant: Detail: an optional secondary
532
- * error message carrying more detail about the problem. Might run to
533
- * multiple lines.
562
+ /* Result#result_error_field argument constant
563
+ *
564
+ * Detail: an optional secondary error message carrying more detail about the problem.
565
+ * Might run to multiple lines.
534
566
  */
535
567
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_DETAIL", INT2FIX(PG_DIAG_MESSAGE_DETAIL));
536
-
537
- /* #result_error_field argument constant: Hint: an optional suggestion
538
- * what to do about the problem. This is intended to differ from detail
539
- * in that it offers advice (potentially inappropriate) rather than
540
- * hard facts. Might run to multiple lines.
568
+ /* Result#result_error_field argument constant
569
+ *
570
+ * Hint: an optional suggestion what to do about the problem.
571
+ * This is intended to differ from detail in that it offers advice (potentially inappropriate) rather than hard facts.
572
+ * Might run to multiple lines.
541
573
  */
542
-
543
574
  rb_define_const(rb_mPGconstants, "PG_DIAG_MESSAGE_HINT", INT2FIX(PG_DIAG_MESSAGE_HINT));
544
- /* #result_error_field argument constant: A string containing a decimal
545
- * integer indicating an error cursor position as an index into the
546
- * original statement string. The rst character has index 1, and
547
- * positions are measured in characters not bytes.
575
+ /* Result#result_error_field argument constant
576
+ *
577
+ * A string containing a decimal integer indicating an error cursor position as an index into the original statement string.
578
+ *
579
+ * The first character has index 1, and positions are measured in characters not bytes.
548
580
  */
549
-
550
581
  rb_define_const(rb_mPGconstants, "PG_DIAG_STATEMENT_POSITION", INT2FIX(PG_DIAG_STATEMENT_POSITION));
551
- /* #result_error_field argument constant: This is dened the same as
552
- * the PG_DIAG_STATEMENT_POSITION eld, but it is used when the cursor
553
- * position refers to an internally generated command rather than the
554
- * one submitted by the client. The PG_DIAG_INTERNAL_QUERY eld will
555
- * always appear when this eld appears.
582
+ /* Result#result_error_field argument constant
583
+ *
584
+ * This is defined the same as the PG_DIAG_STATEMENT_POSITION field, but it is used when the cursor position refers to an internally generated command rather than the one submitted by the client.
585
+ * The PG_DIAG_INTERNAL_QUERY field will always appear when this field appears.
556
586
  */
557
-
558
587
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_POSITION", INT2FIX(PG_DIAG_INTERNAL_POSITION));
559
- /* #result_error_field argument constant: The text of a failed
560
- * internally-generated command. This could be, for example, a SQL
561
- * query issued by a PL/pgSQL function.
588
+ /* Result#result_error_field argument constant
589
+ *
590
+ * The text of a failed internally-generated command.
591
+ * This could be, for example, a SQL query issued by a PL/pgSQL function.
562
592
  */
563
-
564
593
  rb_define_const(rb_mPGconstants, "PG_DIAG_INTERNAL_QUERY", INT2FIX(PG_DIAG_INTERNAL_QUERY));
565
- /* #result_error_field argument constant: An indication of the context
566
- * in which the error occurred. Presently this includes a call stack
567
- * traceback of active procedural language functions and internally-generated
568
- * queries. The trace is one entry per line, most recent rst.
594
+ /* Result#result_error_field argument constant
595
+ *
596
+ * An indication of the context in which the error occurred.
597
+ * Presently this includes a call stack traceback of active procedural language functions and internally-generated queries.
598
+ * The trace is one entry per line, most recent first.
569
599
  */
570
-
571
600
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONTEXT", INT2FIX(PG_DIAG_CONTEXT));
572
- /* #result_error_field argument constant: The le name of the source-code
573
- * location where the error was reported. */
601
+ /* Result#result_error_field argument constant
602
+ *
603
+ * The file name of the source-code location where the error was reported. */
574
604
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FILE", INT2FIX(PG_DIAG_SOURCE_FILE));
575
605
 
576
- /* #result_error_field argument constant: The line number of the
577
- * source-code location where the error was reported. */
606
+ /* Result#result_error_field argument constant
607
+ *
608
+ * The line number of the source-code location where the error was reported. */
578
609
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_LINE", INT2FIX(PG_DIAG_SOURCE_LINE));
579
610
 
580
- /* #result_error_field argument constant: The name of the source-code
581
- * function reporting the error. */
611
+ /* Result#result_error_field argument constant
612
+ *
613
+ * The name of the source-code function reporting the error. */
582
614
  rb_define_const(rb_mPGconstants, "PG_DIAG_SOURCE_FUNCTION", INT2FIX(PG_DIAG_SOURCE_FUNCTION));
583
615
 
584
- #ifdef HAVE_CONST_PG_DIAG_TABLE_NAME
585
- /* #result_error_field argument constant: If the error was associated with a
586
- * specific database object, the name of the schema containing that object, if any. */
616
+ #ifdef PG_DIAG_TABLE_NAME
617
+ /* Result#result_error_field argument constant
618
+ *
619
+ * If the error was associated with a specific database object, the name of the schema containing that object, if any. */
587
620
  rb_define_const(rb_mPGconstants, "PG_DIAG_SCHEMA_NAME", INT2FIX(PG_DIAG_SCHEMA_NAME));
588
621
 
589
- /* #result_error_field argument constant: If the error was associated with a
590
- *specific table, the name of the table. (When this field is present, the schema name
591
- * field provides the name of the table's schema.) */
622
+ /* Result#result_error_field argument constant
623
+ *
624
+ * If the error was associated with a specific table, the name of the table.
625
+ * (When this field is present, the schema name field provides the name of the table's schema.) */
592
626
  rb_define_const(rb_mPGconstants, "PG_DIAG_TABLE_NAME", INT2FIX(PG_DIAG_TABLE_NAME));
593
627
 
594
- /* #result_error_field argument constant: If the error was associated with a
595
- * specific table column, the name of the column. (When this field is present, the
596
- * schema and table name fields identify the table.) */
628
+ /* Result#result_error_field argument constant
629
+ *
630
+ * If the error was associated with a specific table column, the name of the column.
631
+ * (When this field is present, the schema and table name fields identify the table.) */
597
632
  rb_define_const(rb_mPGconstants, "PG_DIAG_COLUMN_NAME", INT2FIX(PG_DIAG_COLUMN_NAME));
598
633
 
599
- /* #result_error_field argument constant: If the error was associated with a
600
- * specific datatype, the name of the datatype. (When this field is present, the
601
- * schema name field provides the name of the datatype's schema.) */
634
+ /* Result#result_error_field argument constant
635
+ *
636
+ * If the error was associated with a specific datatype, the name of the datatype.
637
+ * (When this field is present, the schema name field provides the name of the datatype's schema.) */
602
638
  rb_define_const(rb_mPGconstants, "PG_DIAG_DATATYPE_NAME", INT2FIX(PG_DIAG_DATATYPE_NAME));
603
639
 
604
- /* #result_error_field argument constant: If the error was associated with a
605
- * specific constraint, the name of the constraint. The table or domain that the
606
- * constraint belongs to is reported using the fields listed above. (For this
607
- * purpose, indexes are treated as constraints, even if they weren't created with
608
- * constraint syntax.) */
640
+ /* Result#result_error_field argument constant
641
+ *
642
+ * If the error was associated with a specific constraint, the name of the constraint.
643
+ * The table or domain that the constraint belongs to is reported using the fields listed above.
644
+ * (For this purpose, indexes are treated as constraints, even if they weren't created with constraint syntax.) */
609
645
  rb_define_const(rb_mPGconstants, "PG_DIAG_CONSTRAINT_NAME", INT2FIX(PG_DIAG_CONSTRAINT_NAME));
610
646
  #endif
611
647
 
@@ -635,6 +671,7 @@ Init_pg_ext()
635
671
  init_pg_binary_encoder();
636
672
  init_pg_binary_decoder();
637
673
  init_pg_copycoder();
674
+ init_pg_recordcoder();
638
675
  init_pg_tuple();
639
676
  }
640
677
 
data/ext/pg.h CHANGED
@@ -78,6 +78,8 @@ typedef long suseconds_t;
78
78
  #define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
79
79
  #endif
80
80
 
81
+ #define PG_ENC_IDX_BITS 28
82
+
81
83
  /* The data behind each PG::Connection object */
82
84
  typedef struct {
83
85
  PGconn *pgconn;
@@ -94,15 +96,14 @@ typedef struct {
94
96
  VALUE type_map_for_results;
95
97
  /* IO object internally used for the trace stream */
96
98
  VALUE trace_stream;
97
- /* Cached Encoding object */
98
- VALUE external_encoding;
99
99
  /* Kind of PG::Coder object for casting ruby values to COPY rows */
100
100
  VALUE encoder_for_put_copy_data;
101
101
  /* Kind of PG::Coder object for casting COPY rows to ruby values */
102
102
  VALUE decoder_for_get_copy_data;
103
-
104
- /* enable/disable guessing size of PGresult's allocated memory */
105
- int guess_result_memsize;
103
+ /* Ruby encoding index of the client/internal encoding */
104
+ int enc_idx : PG_ENC_IDX_BITS;
105
+ /* flags controlling Symbol/String field names */
106
+ unsigned int flags : 2;
106
107
 
107
108
  #if defined(_WIN32)
108
109
  /* File descriptor to be used for rb_w32_unwrap_io_handle() */
@@ -128,10 +129,16 @@ typedef struct {
128
129
  */
129
130
  t_typemap *p_typemap;
130
131
 
132
+ /* Ruby encoding index of the client/internal encoding */
133
+ int enc_idx : PG_ENC_IDX_BITS;
134
+
131
135
  /* 0 = PGresult is cleared by PG::Result#clear or by the GC
132
136
  * 1 = PGresult is cleared internally by libpq
133
137
  */
134
- int autoclear;
138
+ unsigned int autoclear : 1;
139
+
140
+ /* flags controlling Symbol/String field names */
141
+ unsigned int flags : 2;
135
142
 
136
143
  /* Number of fields in fnames[] .
137
144
  * Set to -1 if fnames[] is not yet initialized.
@@ -147,7 +154,7 @@ typedef struct {
147
154
  /* Hash with fnames[] to field number mapping. */
148
155
  VALUE field_map;
149
156
 
150
- /* List of field names as frozen String objects.
157
+ /* List of field names as frozen String or Symbol objects.
151
158
  * Only valid if nfields != -1
152
159
  */
153
160
  VALUE fnames[0];
@@ -163,6 +170,10 @@ typedef VALUE (* t_pg_typecast_result)(t_typemap *, VALUE, int, int);
163
170
  typedef t_pg_coder *(* t_pg_typecast_query_param)(t_typemap *, VALUE, int);
164
171
  typedef VALUE (* t_pg_typecast_copy_get)( t_typemap *, VALUE, int, int, int );
165
172
 
173
+ #define PG_RESULT_FIELD_NAMES_MASK 0x03
174
+ #define PG_RESULT_FIELD_NAMES_SYMBOL 0x01
175
+ #define PG_RESULT_FIELD_NAMES_STATIC_SYMBOL 0x02
176
+
166
177
  #define PG_CODER_TIMESTAMP_DB_UTC 0x0
167
178
  #define PG_CODER_TIMESTAMP_DB_LOCAL 0x1
168
179
  #define PG_CODER_TIMESTAMP_APP_UTC 0x0
@@ -275,6 +286,7 @@ void init_pg_type_map_by_oid _(( void ));
275
286
  void init_pg_type_map_in_ruby _(( void ));
276
287
  void init_pg_coder _(( void ));
277
288
  void init_pg_copycoder _(( void ));
289
+ void init_pg_recordcoder _(( void ));
278
290
  void init_pg_text_encoder _(( void ));
279
291
  void init_pg_text_decoder _(( void ));
280
292
  void init_pg_binary_encoder _(( void ));
@@ -305,11 +317,6 @@ char *pg_rb_str_ensure_capa _(( VALUE, long, char *,
305
317
  (curr_ptr) = (end_ptr) = RSTRING_PTR(str) \
306
318
  )
307
319
 
308
- #define PG_RB_TAINTED_STR_NEW( str, curr_ptr, end_ptr ) ( \
309
- (str) = rb_tainted_str_new( NULL, 0 ), \
310
- (curr_ptr) = (end_ptr) = RSTRING_PTR(str) \
311
- )
312
-
313
320
  VALUE pg_typemap_fit_to_result _(( VALUE, VALUE ));
314
321
  VALUE pg_typemap_fit_to_query _(( VALUE, VALUE ));
315
322
  int pg_typemap_fit_to_copy_get _(( VALUE ));
@@ -333,12 +340,7 @@ VALUE pg_tuple_new _(( VALUE, int ));
333
340
  static inline t_pg_result *
334
341
  pgresult_get_this( VALUE self )
335
342
  {
336
- t_pg_result *this = RTYPEDDATA_DATA(self);
337
-
338
- if( this == NULL )
339
- rb_raise(rb_ePGerror, "result has been cleared");
340
-
341
- return this;
343
+ return RTYPEDDATA_DATA(self);
342
344
  }
343
345
 
344
346