dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCursor Class / CursorName Property
Example

In This Topic
    CursorName Property
    In This Topic
    Gets the name of the cursor.
    Syntax
    'Declaration
     
    Public ReadOnly Property CursorName As String
    public string CursorName {get;}

    Property Value

    The name of the cursor.
    Example
    This example demonstrates usage of PgSqlCursor class. To execute this code you have to create the following function on the server:
    CREATE OR REPLACE FUNCTION refcursorfunc(OUT p refcursor) AS
    $BODY$ 
    DECLARE 
    v_refcursor refcursor; 
    BEGIN 
    OPEN v_refcursor FOR SELECT deptno FROM dept; 
    p := v_refcursor;
    END; 
    $BODY$
      LANGUAGE 'plpgsql' VOLATILE;
    
    PgSqlCommand cmd = new PgSqlCommand("refcursorfunc");
    cmd.Connection = myConnection;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.ParameterCheck = true;
    myConnection.Open();
    PgSqlTransaction t = myConnection.BeginTransaction();
    try {
      cmd.ExecuteNonQuery();
    PgSqlCursor cursor = cmd.Parameters["p"].PgSqlValue as PgSqlCursor;
    PgSqlCommand cursorCmd = new PgSqlCommand(String.Format("FETCH ALL FROM \"{0}\";", cursor.CursorName));
      cursorCmd.Connection = myConnection;
      using (PgSqlDataReader rd = cursorCmd.ExecuteReader()) {
        while (rd.Read())
          Console.WriteLine(rd.GetValue(0));
      }
    }
    finally {
      t.Commit();
      myConnection.Close();
    }
    Dim cmd As New PgSqlCommand("refcursorfunc")
    cmd.Connection = (Me.myConnection)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.ParameterCheck = True
    Me.myConnection.Open()
    Dim t As PgSqlTransaction = Me.myConnection.BeginTransaction
    Try
        cmd.ExecuteNonQuery()
    Dim cursor As PgSqlCursor = TryCast(cmd.Parameters("p").PgSqlValue, PgSqlCursor)
    Dim cursorCmd As New PgSqlCommand(String.Format("FETCH ALL FROM ""{0}"";", cursor.CursorName))
    cursorCmd.Connection = Me.myConnection
    Using rd As PgSqlDataReader = cursorCmd.ExecuteReader
            Do While rd.Read
                Console.WriteLine(rd.GetValue(0))
            Loop
        End Using
    Finally
        t.Commit()
        Me.myConnection.Close()
    End Try
    See Also