"postgres" module needs work, author gone, patch included

The “postgres” module is old and it’s been a long time since there’s
been a release. The module has the following problems:

  • uses PQescapeString() and PQescapeBytea(), both of which are long-
    since deprecated, and provides no interface to the newer functions
    (which have been around for a long time).

  • uses wrong quoting routine to quote connection string arguments.

  • release version doesn’t provide any interface to PQexecParams().

  • snapshot introduces some ruby array to PG array type-awareness, but
    it’s broken

I tried to contact the maintainer, [email protected], but got no
response. I tried to contact the previous maintainer,
[email protected], and got a bounce.

I wrote a patch that makes the following changes to the module from the
snapshot version:

  • added instance methods “escape” and “escape_bytea” which use
    PQescapeStringConn() and PQescapeByteaConn(). The class methods by the
    same names should be deprecated, but I left them in for compatibility.

  • added the instance method “unescape_bytea”, which is the same as the
    class method by the same name. This didn’t strictly need to be done, but
    I did this for consistency with “escape_bytea” which is now an instance
    method.

  • added an instance and class method “quote_ident” to quote identifiers.

  • wrote separate quoting routine (not exported) to properly quote
    connection string arguments according to the documented quoting rules
    for the connection string arguments. The old code did this by using the
    same routine as for quoting values passed to a SQL string, which is
    wrong.

  • removed code that tried to convert ruby arrays into postgresql arrays.
    It was broken (in the quote method, did not actually quote the array),
    and the code should be substantially refactored to better enable more
    intelligent type awareness from ruby to postgresql. I could reintroduce
    this if people care about more type awareness.

I’d like to do some more serious refactoring, but I just wanted to get
some feedback first. Who uses this module, and what do you think about
my changes? How old of a client library do we want to support? The
current module uses ugly #define directives to bolt on support for
ancient versions of libpq, is this necessary?

Should I fork and put a project on RAA, or should I try to take over the
current “postgres” module?

Regards,
Jeff D.

I’d like to do some more serious refactoring, but I just wanted to get
some feedback first.

Actually I tried to use it but somehow I didnt even finished compiling.
After looking at some info in it (Readme, the website) I decided to
skip this and stick to sqlite or mysql instead, perhaps.

Nice to see I didnt happen to be the only one that tried it :slight_smile:

Jeff D. wrote:

The “postgres” module is old and it’s been a long time since there’s
been a release. The module has the following problems:

I talked to Dave L. a while back and he indicated to me that a new
release was imminent. Mind you, I think that was a few months ago now,
so I’m not sure what happened. I’ll try to contact him again and let
you know what happens.

Worst case scenario is I give you admin rights on the DBI project, and
we bundle the postgres driver with dbd-postgres directly.

Regards,

Dan

On Sat, 2007-01-20 at 10:38 +0900, Jeff D. wrote:

I’d like to do some more serious refactoring, but I just wanted to get
some feedback first. Who uses this module, and what do you think about
my changes? How old of a client library do we want to support? The
current module uses ugly #define directives to bolt on support for
ancient versions of libpq, is this necessary?

I use it with PostgreSQL 8.2 and I’ve been pretty happy with it.
Haven’t looked at any of the code, though. Sounds like you’re bringing
it up to speed, which is great!

Yours,

Tom

Marc H. wrote:

I’d like to do some more serious refactoring, but I just wanted to get
some feedback first.

Actually I tried to use it but somehow I didnt even finished compiling.
After looking at some info in it (Readme, the website) I decided to
skip this and stick to sqlite or mysql instead, perhaps.

Nice to see I didnt happen to be the only one that tried it :slight_smile:

Ouch, you avoided postgresql because the ruby driver was that bad?

Can you please send me the info in the form of a bug report? That is,
include platform, versions, exact errors, etc. If you’re having a
problem, a lot of people are, and I’d like to make postgresql a
first-class supported database in Ruby.

Regards,
Jeff D.

Daniel B. wrote:

Worst case scenario is I give you admin rights on the DBI project, and
we bundle the postgres driver with dbd-postgres directly.

Please let me know if you get more information from Dave L…

Also let me know if ruby-dbi needs anything in particular from the
driver.

Regards,
Jeff D.

Jeff D. wrote:

The “postgres” module is old and it’s been a long time since there’s
been a release. The module has the following problems:

I use postgres on openbsd and netbsd without incident, but recently got
a macbook, where it does nothing. I’m using postgres-pr there, but there
are differences - notably between #escape and #quote. It is less than
ideal to account for them.

I haven’t looked into the problem too deeply (read: at all) yet, but I’d
be glad to help with any effort to improve the postgres lib.

Jeff D. wrote:

I don’t know anything about making the module portable to OS X, but it
doesn’t sound hard to do after I have some more details.

I’ll keep hacking away, and I’ll set up a site and an SVN repo, and I’ll
make an announcement. It sounds like there’s demand. Thanks for your input.

I’m on board; a couple notes:
http://ruby.scripting.ca/postgres/ appears to be the homepage for the
project, and offers a snapshot dated 2005.12.21.

http://rubyforge.org/frs/download.php/9553 offers a snapshot dated
2006.04.06. This package forms the basis for the openbsd port, and will
be the one I will be patching against and testing. If all is well, I
will submit an updated port for openbsd including your patch.

The project homepage also specifies that `this library works with
PostgreSQL 6.4-8.1’, and the macbook is running postgresql 8.2.1. This
may, or may not have something to do with it’s refusal to work. :stuck_out_tongue:

I will confirm this with an update to pgsql 8.2.1 on the openbsd
machines
and get back to you.

I use the postgres driver everywhere - Windows, Linux, Mac, production,
dev. It seems to work from ActiveRecord, but that’s about all I can tell
you. Sometimes the gem install deletes the binary after creating it, but
I just go into that directory and ‘make’ it again.

Long story short, yes someone uses it.

Jason LaRiviere wrote:

I haven’t looked into the problem too deeply (read: at all) yet, but I’d
be glad to help with any effort to improve the postgres lib.

What would help me the most is to do one or more of the following:

(1) Test my patch against the snapshot version available from the
‘postgres’ module website, see if it fixes the problem
(2) If the problem is not fixed, send a more detailed report. If it is
fixed, let me know.
(3) Let me know of any extra things you’d like the driver to do, or any
behaviors you’d like to change. In particular what do you expect from
“escape” and “quote”.

I don’t know anything about making the module portable to OS X, but it
doesn’t sound hard to do after I have some more details.

I’ll keep hacking away, and I’ll set up a site and an SVN repo, and I’ll
make an announcement. It sounds like there’s demand. Thanks for your
input.

Regards,
Jeff D.

Jason LaRiviere wrote:

PostgreSQL 6.4-8.1’, and the macbook is running postgresql 8.2.1. This
may, or may not have something to do with it’s refusal to work. :stuck_out_tongue:

I will confirm this with an update to pgsql 8.2.1 on the openbsd machines
and get back to you.

Find attatched a diff that applies cleanly to the 2006.04.06 source.
Also, all teh cool kids are using unified diffs. :stuck_out_tongue:

It builds just fine. Further testing is pending…

Kevin W. wrote:

Sometimes the gem install deletes the binary after creating it, but
I just go into that directory and ‘make’ it again.

Ha. I’ve never come across that before, but indeed that is what happened
with the gem install on os x. I’m now off postgres-pr and back on
ruby-postgres all around.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs