Module: PG

Includes:
Constants
Defined in:
lib/pg.rb,
lib/pg/coder.rb,
lib/pg/version.rb,
lib/pg/exceptions.rb,
lib/pg/text_decoder/date.rb,
lib/pg/text_decoder/inet.rb,
lib/pg/text_decoder/json.rb,
lib/pg/text_encoder/date.rb,
lib/pg/text_encoder/inet.rb,
lib/pg/text_encoder/json.rb,
lib/pg/binary_decoder/date.rb,
lib/pg/text_decoder/numeric.rb,
lib/pg/text_encoder/numeric.rb,
lib/pg/text_decoder/timestamp.rb,
lib/pg/text_encoder/timestamp.rb,
lib/pg/binary_decoder/timestamp.rb,
lib/pg/binary_encoder/timestamp.rb,
ext/pg.c

Overview

-*- ruby -*- frozen_string_literal: true

Defined Under Namespace

Modules: BinaryDecoder, BinaryEncoder, Constants, TextDecoder, TextEncoder, TruffleFixWarn Classes: BasicTypeMapBasedOnResult, BasicTypeMapForQueries, BasicTypeMapForResults, BasicTypeRegistry, Coder, CompositeCoder, CompositeDecoder, CompositeEncoder, Connection, ConnectionBad, CopyCoder, CopyDecoder, CopyEncoder, Error, InvalidChangeOfResultFields, InvalidResultStatus, LostCopyState, NoResultError, NotAllCopyDataRetrieved, NotInBlockingMode, RecordCoder, RecordDecoder, RecordEncoder, Result, RollbackTransaction, ServerError, SimpleCoder, SimpleDecoder, SimpleEncoder, Tuple, TypeMap, TypeMapAllStrings, TypeMapByClass, TypeMapByColumn, TypeMapByMriType, TypeMapByOid, TypeMapInRuby, UnableToSend

Constant Summary collapse

POSTGRESQL_LIB_PATH =
bundled_libpq_path
VERSION =

Library version

'1.5.9'
ERROR_CLASSES =
rb_hErrors

Constants included from Constants

Constants::CONNECTION_AUTH_OK, Constants::CONNECTION_AWAITING_RESPONSE, Constants::CONNECTION_BAD, Constants::CONNECTION_CHECK_STANDBY, Constants::CONNECTION_CHECK_TARGET, Constants::CONNECTION_CHECK_WRITABLE, Constants::CONNECTION_CONSUME, Constants::CONNECTION_GSS_STARTUP, Constants::CONNECTION_MADE, Constants::CONNECTION_NEEDED, Constants::CONNECTION_OK, Constants::CONNECTION_SETENV, Constants::CONNECTION_SSL_STARTUP, Constants::CONNECTION_STARTED, Constants::DEF_PGPORT, Constants::INVALID_OID, Constants::INV_READ, Constants::INV_WRITE, Constants::InvalidOid, Constants::PGRES_BAD_RESPONSE, Constants::PGRES_COMMAND_OK, Constants::PGRES_COPY_BOTH, Constants::PGRES_COPY_IN, Constants::PGRES_COPY_OUT, Constants::PGRES_EMPTY_QUERY, Constants::PGRES_FATAL_ERROR, Constants::PGRES_NONFATAL_ERROR, Constants::PGRES_PIPELINE_ABORTED, Constants::PGRES_PIPELINE_SYNC, Constants::PGRES_POLLING_FAILED, Constants::PGRES_POLLING_OK, Constants::PGRES_POLLING_READING, Constants::PGRES_POLLING_WRITING, Constants::PGRES_SINGLE_TUPLE, Constants::PGRES_TUPLES_OK, Constants::PG_DIAG_COLUMN_NAME, Constants::PG_DIAG_CONSTRAINT_NAME, Constants::PG_DIAG_CONTEXT, Constants::PG_DIAG_DATATYPE_NAME, Constants::PG_DIAG_INTERNAL_POSITION, Constants::PG_DIAG_INTERNAL_QUERY, Constants::PG_DIAG_MESSAGE_DETAIL, Constants::PG_DIAG_MESSAGE_HINT, Constants::PG_DIAG_MESSAGE_PRIMARY, Constants::PG_DIAG_SCHEMA_NAME, Constants::PG_DIAG_SEVERITY, Constants::PG_DIAG_SEVERITY_NONLOCALIZED, Constants::PG_DIAG_SOURCE_FILE, Constants::PG_DIAG_SOURCE_FUNCTION, Constants::PG_DIAG_SOURCE_LINE, Constants::PG_DIAG_SQLSTATE, Constants::PG_DIAG_STATEMENT_POSITION, Constants::PG_DIAG_TABLE_NAME, Constants::PQERRORS_DEFAULT, Constants::PQERRORS_SQLSTATE, Constants::PQERRORS_TERSE, Constants::PQERRORS_VERBOSE, Constants::PQPING_NO_ATTEMPT, Constants::PQPING_NO_RESPONSE, Constants::PQPING_OK, Constants::PQPING_REJECT, Constants::PQSHOW_CONTEXT_ALWAYS, Constants::PQSHOW_CONTEXT_ERRORS, Constants::PQSHOW_CONTEXT_NEVER, Constants::PQTRANS_ACTIVE, Constants::PQTRANS_IDLE, Constants::PQTRANS_INERROR, Constants::PQTRANS_INTRANS, Constants::PQTRANS_UNKNOWN, Constants::PQ_PIPELINE_ABORTED, Constants::PQ_PIPELINE_OFF, Constants::PQ_PIPELINE_ON, Constants::SEEK_CUR, Constants::SEEK_END, Constants::SEEK_SET

Class Method Summary collapse

Class Method Details

.connect(*args, &block) ⇒ Object

Convenience alias for PG::Connection.new.



62
63
64
# File 'lib/pg.rb', line 62

def self.connect( *args, &block )
	Connection.new( *args, &block )
end

.init_openssl(do_ssl, do_crypto) ⇒ nil

Allows applications to select which security libraries to initialize.

If your application initializes libssl and/or libcrypto libraries and libpq is built with SSL support, you should call PG.init_openssl() to tell libpq that the libssl and/or libcrypto libraries have been initialized by your application, so that libpq will not also initialize those libraries.

When do_ssl is true, libpq will initialize the OpenSSL library before first opening a database connection. When do_crypto is true, the libcrypto library will be initialized. By default (if PG.init_openssl() is not called), both libraries are initialized. When SSL support is not compiled in, this function is present but does nothing.

If your application uses and initializes either OpenSSL or its underlying libcrypto library, you must call this function with false for the appropriate parameter(s) before first opening a database connection. Also be sure that you have done that initialization before opening a database connection.

Returns:

  • (nil)


303
304
305
306
307
308
309
# File 'ext/pg.c', line 303

static VALUE
pg_s_init_openssl(VALUE self, VALUE do_ssl, VALUE do_crypto)
{
	UNUSED( self );
	PQinitOpenSSL(pg_to_bool_int(do_ssl), pg_to_bool_int(do_crypto));
	return Qnil;
}

.init_ssl(do_ssl) ⇒ nil

Allows applications to select which security libraries to initialize.

This function is equivalent to PG.init_openssl(do_ssl, do_ssl) . It is sufficient for applications that initialize both or neither of OpenSSL and libcrypto.

Returns:

  • (nil)


321
322
323
324
325
326
327
# File 'ext/pg.c', line 321

static VALUE
pg_s_init_ssl(VALUE self, VALUE do_ssl)
{
	UNUSED( self );
	PQinitSSL(pg_to_bool_int(do_ssl));
	return Qnil;
}

.isthreadsafeBoolean .is_threadsafe?Boolean .threadsafe?Boolean

Returns true if libpq is thread-safe, false otherwise.

Overloads:

  • .isthreadsafeBoolean

    Returns:

    • (Boolean)
  • .is_threadsafe?Boolean

    Returns:

    • (Boolean)
  • .threadsafe?Boolean

    Returns:

    • (Boolean)


261
262
263
264
265
266
# File 'ext/pg.c', line 261

static VALUE
pg_s_threadsafe_p(VALUE self)
{
	UNUSED( self );
	return PQisthreadsafe() ? Qtrue : Qfalse;
}

.library_versionInteger

Get the version of the libpq library in use. The number is formed by converting the major, minor, and revision numbers into two-decimal- digit numbers and appending them together. For example, version 7.4.2 will be returned as 70402, and version 8.1 will be returned as 80100 (leading zeroes are not shown). Zero is returned if the connection is bad.

Returns:

  • (Integer)


245
246
247
248
249
250
# File 'ext/pg.c', line 245

static VALUE
pg_s_library_version(VALUE self)
{
	UNUSED( self );
	return INT2NUM(PQlibVersion());
}

.make_shareable(obj) ⇒ Object



67
68
69
# File 'lib/pg.rb', line 67

def self.make_shareable(obj)
	Ractor.make_shareable(obj)
end

.require_bigdecimal_without_warningObject

Ruby-3.4+ prints a warning, if bigdecimal is required but not in the Gemfile. But it’s a false positive, since we enable bigdecimal depending features only if it’s available. And most people don’t need these features.



132
133
134
135
136
137
# File 'lib/pg.rb', line 132

def self.require_bigdecimal_without_warning
	oldverb, $VERBOSE = $VERBOSE, nil
	require "bigdecimal"
ensure
	$VERBOSE = oldverb
end

.version_string(include_buildnum = nil) ⇒ Object

Get the PG library version.

include_buildnum is no longer used and any value passed will be ignored.



56
57
58
# File 'lib/pg.rb', line 56

def self.version_string( include_buildnum=nil )
	"%s %s" % [ self.name, VERSION ]
end