Re: Getting a ResultSet for a refcursor element.

Поиск
Список
Период
Сортировка
От Nic Ferrier
Тема Re: Getting a ResultSet for a refcursor element.
Дата
Msg-id 87u1jw2xo3.fsf@pooh-sticks-bridge.tapsellferrier.co.uk
обсуждение исходный текст
Ответ на Re: Getting a ResultSet for a refcursor element.  (Dave Cramer <Dave@micro-automation.net>)
Ответы An error occured while getting the authentification request  (fabio viquez <kalamargigante@yahoo.com>)
Список pgsql-jdbc
Here's my context diff for getting ResultSet's whole from another
ResultSet (via a proc returning a refcursor).

Here's some example code:

import java.sql.*;


public class proctest
{
  public static void main (String[] argv) throws Exception
  {
    Class driver = Class.forName("org.postgresql.Driver");
    Connection con
       = DriverManager.getConnection("jdbc:postgresql:test",
                                        "someone",
                                        "something");
    Statement st = con.createStatement();
    con.setAutoCommit(false);
    // f() is a function that returns a refcursor.
    ResultSet rs = st.executeQuery("select f();");
    if (! rs.next())
      throw new SQLException("whoops! there were no rows.");
    try
      {
    Object v = rs.getObject(1);
    if (v instanceof ResultSet) {
      ResultSet rs2 = (ResultSet) v;
      while (rs2.next()) {
        System.out.println(rs2.getString(1));
      }
    }
      }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
    con.commit();
    st.close();
    con.close();
  }
}


Do I need to do a documentation patch? Does anybody else have a good
idea for how this should be described in the doc?


Nic


Here's the diff:

Index: src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.8
diff -c -r1.8 AbstractJdbc2ResultSet.java
*** src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java    2002/09/11 05:38:45    1.8
--- src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java    2002/10/09 01:21:13
***************
*** 142,147 ****
--- 142,158 ----
                  {
                      return getString(columnIndex);
                  }
+                 else if (type.equals("refcursor"))
+                 {
+                         // We must return a ResultSet with the results packaged.
+                         // We should probably check that auto commit is turned off.
+                         String cursorName = getString(columnIndex);
+                     Statement st
+                       = new Jdbc2Statement((Jdbc2Connection)this.connection);
+                     return st.executeQuery("FETCH ALL IN \""
+                                    + cursorName
+                                    + "\";");
+                 }
                  else
                  {
                      return connection.getObject(field.getPGType(), getString(columnIndex));

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Julian Brown"
Дата:
Сообщение: Re: I am totally lost
Следующее
От: fabio viquez
Дата:
Сообщение: An error occured while getting the authentification request