rubify pg_check_result()

Issue #123 resolved
royaltm NA
created an issue

{{{ PG::Connection#get_last_result }}}

uses pg_check_result( ) from ext/pg_result.c to conditionally raise error on failed result.

on the other hand {{{ PG::Connection#get_result }}} leaves handling of errors to the user, which is actually good.

However it would be nice if pg_check_result was provided to ruby as class or instance method.

So we could use it like this:

{{{ result = conn.get_result ...# actually get the last result in some loop result.check_result # would rise error in a way pg_check_result does

}}} alternatively (which will be easier to implement) provide singleton method:

{{{ PG::Result.check_result(connection, result)


Comments (7)

  1. royaltm NA reporter

    This is also loosely related to #124 (but different in scope) in the context of providing developers with the means to maintain POLS in the upper layers created on top of Pg.

  2. Michael Granger repo owner

    New method: PG::Result#check. (fixes #123)

    This method exposes a previously internal-only function for checking the status of a PG::Result, primarily for people using the async interface. The check is done for you if you're using the synchronous interface, but there was no way to get the same behavior for results fetched via PG::Connection#get_result.

    This change also adds the PG::Connection associated with a result as an instance variable (@Luis Santana) on the PG::Result object.

    Thanks to @royaltm NA for the idea.


  3. royaltm NA reporter

    ...and thank you for this implementation.

    There is however a minor bug in the docs for Result#check:

     * call-seq:
     *    res.result -> nil
     * Raises appropriate exception if PG::Result is in a bad state.
    pg_result_check( VALUE self )

    it should be `res.check -> nil`

  4. Log in to comment