Skip to content

Commit d41e07a

Browse files
authored
Merge pull request #753 from larskanis/rm-pgsql-10
Remove some conditions for PostgreSQL-10
2 parents 2c4934e + 8e1ee8f commit d41e07a

6 files changed

Lines changed: 35 additions & 46 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Added:
44

55
- Add PG::Connection#embed_params and keyword `:typename` for its parameter casting. [#726](https://github.com/ged/ruby-pg/pull/726)
66
This allows to generate SQL strings with embedded parameters for easier debugging.
7-
- Add PG:Connection#full_protocol_version which is new in PostgreSQL-18 [#695](https://github.com/ged/ruby-pg/pull/695)
7+
- Add PG::Connection#full_protocol_version which is new in PostgreSQL-18 [#695](https://github.com/ged/ruby-pg/pull/695)
88
- Add PG::Result#each_tuple [#675](https://github.com/ged/ruby-pg/pull/675)
99
- Add PG::TypeMap#query_param_encoders to retrieve encoders. [#726](https://github.com/ged/ruby-pg/pull/726)
1010
- Deduplicate result field name strings for better performance. [#750](https://github.com/ged/ruby-pg/pull/750)

‎ext/extconf.rb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ module PG
304304
end
305305

306306
have_func 'PQencryptPasswordConn', 'libpq-fe.h' or # since PostgreSQL-10
307-
abort "Your PostgreSQL is too old. Either install an older version " +
308-
"of this gem or upgrade your database to at least PostgreSQL-10."
307+
abort "Your PostgreSQL client library (libpq) is too old. " +
308+
"Either install an older version of this gem " +
309+
"or upgrade your database to at least PostgreSQL-10."
309310
# optional headers/functions
310311
have_func 'PQresultMemorySize', 'libpq-fe.h' # since PostgreSQL-12
311312
have_func 'timegm'

‎ext/pg.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,10 @@ Init_pg_ext(void)
384384
rb_define_const(rb_mPGconstants, "CONNECTION_SSL_STARTUP", INT2FIX(CONNECTION_SSL_STARTUP));
385385
/* Internal state - PG.connect() needed. */
386386
rb_define_const(rb_mPGconstants, "CONNECTION_NEEDED", INT2FIX(CONNECTION_NEEDED));
387-
#if PG_MAJORVERSION_NUM >= 10
388-
/* Checking if session is read-write. Available since PostgreSQL-10. */
387+
/* Checking if session is read-write. */
389388
rb_define_const(rb_mPGconstants, "CONNECTION_CHECK_WRITABLE", INT2FIX(CONNECTION_CHECK_WRITABLE));
390-
#endif
391-
#if PG_MAJORVERSION_NUM >= 10
392-
/* Consuming any extra messages. Available since PostgreSQL-10. */
389+
/* Consuming any extra messages. */
393390
rb_define_const(rb_mPGconstants, "CONNECTION_CONSUME", INT2FIX(CONNECTION_CONSUME));
394-
#endif
395391
#if PG_MAJORVERSION_NUM >= 12
396392
/* Negotiating GSSAPI. Available since PostgreSQL-12. */
397393
rb_define_const(rb_mPGconstants, "CONNECTION_GSS_STARTUP", INT2FIX(CONNECTION_GSS_STARTUP));

‎ext/pg_connection.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ pgconn_protocol_version(VALUE self)
887887
* The 3.0 protocol is supported by PostgreSQL server versions 7.4 and above.
888888
*
889889
* PG::ConnectionBad is raised if the connection is bad.
890+
*
891+
* Available since PostgreSQL-18.
890892
*/
891893
static VALUE
892894
pgconn_full_protocol_version(VALUE self)

‎lib/pg/connection.rb‎

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -551,33 +551,30 @@ def pipeline_sync(*args)
551551
alias async_pipeline_sync pipeline_sync
552552
end
553553

554-
if method_defined? :sync_encrypt_password
555-
# call-seq:
556-
# conn.encrypt_password( password, username, algorithm=nil ) -> String
557-
#
558-
# This function is intended to be used by client applications that wish to send commands like <tt>ALTER USER joe PASSWORD 'pwd'</tt>.
559-
# It is good practice not to send the original cleartext password in such a command, because it might be exposed in command logs, activity displays, and so on.
560-
# Instead, use this function to convert the password to encrypted form before it is sent.
561-
#
562-
# The +password+ and +username+ arguments are the cleartext password, and the SQL name of the user it is for.
563-
# +algorithm+ specifies the encryption algorithm to use to encrypt the password.
564-
# Currently supported algorithms are +md5+ and +scram-sha-256+ (+on+ and +off+ are also accepted as aliases for +md5+, for compatibility with older server versions).
565-
# Note that support for +scram-sha-256+ was introduced in PostgreSQL version 10, and will not work correctly with older server versions.
566-
# If algorithm is omitted or +nil+, this function will query the server for the current value of the +password_encryption+ setting.
567-
# That can block, and will fail if the current transaction is aborted, or if the connection is busy executing another query.
568-
# If you wish to use the default algorithm for the server but want to avoid blocking, query +password_encryption+ yourself before calling #encrypt_password, and pass that value as the algorithm.
569-
#
570-
# Return value is the encrypted password.
571-
# The caller can assume the string doesn't contain any special characters that would require escaping.
572-
#
573-
# Available since PostgreSQL-10.
574-
# See also corresponding {libpq function}[https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQENCRYPTPASSWORDCONN].
575-
def encrypt_password( password, username, algorithm=nil )
576-
algorithm ||= exec("SHOW password_encryption").getvalue(0,0)
577-
sync_encrypt_password(password, username, algorithm)
578-
end
579-
alias async_encrypt_password encrypt_password
554+
# call-seq:
555+
# conn.encrypt_password( password, username, algorithm=nil ) -> String
556+
#
557+
# This function is intended to be used by client applications that wish to send commands like <tt>ALTER USER joe PASSWORD 'pwd'</tt>.
558+
# It is good practice not to send the original cleartext password in such a command, because it might be exposed in command logs, activity displays, and so on.
559+
# Instead, use this function to convert the password to encrypted form before it is sent.
560+
#
561+
# The +password+ and +username+ arguments are the cleartext password, and the SQL name of the user it is for.
562+
# +algorithm+ specifies the encryption algorithm to use to encrypt the password.
563+
# Currently supported algorithms are +md5+ and +scram-sha-256+ (+on+ and +off+ are also accepted as aliases for +md5+, for compatibility with older server versions).
564+
# Note that support for +scram-sha-256+ was introduced in PostgreSQL version 10, and will not work correctly with older server versions.
565+
# If algorithm is omitted or +nil+, this function will query the server for the current value of the +password_encryption+ setting.
566+
# That can block, and will fail if the current transaction is aborted, or if the connection is busy executing another query.
567+
# If you wish to use the default algorithm for the server but want to avoid blocking, query +password_encryption+ yourself before calling #encrypt_password, and pass that value as the algorithm.
568+
#
569+
# Return value is the encrypted password.
570+
# The caller can assume the string doesn't contain any special characters that would require escaping.
571+
#
572+
# See also corresponding {libpq function}[https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQENCRYPTPASSWORDCONN].
573+
def encrypt_password( password, username, algorithm=nil )
574+
algorithm ||= exec("SHOW password_encryption").getvalue(0,0)
575+
sync_encrypt_password(password, username, algorithm)
580576
end
577+
alias async_encrypt_password encrypt_password
581578

582579
# call-seq:
583580
# conn.reset()
@@ -971,7 +968,6 @@ def new(*args)
971968

972969
# Resolve DNS in Ruby to avoid blocking state while connecting.
973970
# Multiple comma-separated values are generated, if the hostname resolves to both IPv4 and IPv6 addresses.
974-
# This requires PostgreSQL-10+, so no DNS resolving is done on earlier versions.
975971
private def resolve_hosts(iopts)
976972
ihosts = iopts[:host].split(",", -1)
977973
iports = iopts[:port].split(",", -1)
@@ -1027,8 +1023,8 @@ def new(*args)
10271023
# So, pass params through and let libpq resolve the service, possibly blocking the Thread.scheduler.
10281024
# This ensures the processing order of libpq which is:
10291025
# connection string => service file => environment variable => compiled default
1030-
elsif iopts_with_defaults[:host] && !iopts_with_defaults[:host].empty? && PG.library_version >= 100000
1031-
# Do host resolution to avoid blocking Thread.scheduler while DNS queries.
1026+
elsif iopts_with_defaults[:host] && !iopts_with_defaults[:host].empty?
1027+
# Do host resolution in Ruby to avoid blocking Thread.scheduler while DNS queries in libpq.
10321028
iopts_for_reset = iopts_with_defaults
10331029
iopts = resolve_hosts(iopts_with_defaults)
10341030
else

‎spec/pg/connection_spec.rb‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,14 +2848,8 @@ def wait_check_socket(conn)
28482848
end
28492849

28502850
it "shouldn't type map params unless requested" do
2851-
if @conn.server_version < 100000
2852-
expect{
2853-
@conn.exec_params( "SELECT $1", [5] )
2854-
}.to raise_error(PG::IndeterminateDatatype){|err| expect(err).to have_attributes(connection: @conn) }
2855-
else
2856-
# PostgreSQL-10 maps to TEXT type (OID 25)
2857-
expect( @conn.exec_params( "SELECT $1", [5] ).ftype(0)).to eq(25)
2858-
end
2851+
# PostgreSQL maps to TEXT type (OID 25)
2852+
expect( @conn.exec_params( "SELECT $1", [5] ).ftype(0)).to eq(25)
28592853
end
28602854

28612855
it "should raise an error on invalid encoder to put_copy_data" do

0 commit comments

Comments
 (0)