From: | Frank Jonislla <frank(dot)che88(at)gmail(dot)com> |
---|---|
To: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | cursores en procedimientos almacenados |
Date: | 2006-02-17 21:26:44 |
Message-ID: | 6436a9350602171326h13997e3fm@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Tengo dos funciones que devuelven cursores que practicamente son lo mismo
pero solo uno funciona cuando lo llamo a travez de una palicacio hecha en
punto .net
bueno estas son las dos funciones:
CREATE OR REPLACE FUNCTION testrefcursor()
RETURNS SETOF refcursor AS
$BODY$
DECLARE
ref1 refcursor;
ref2 refcursor;
BEGIN
OPEN ref1 FOR SELECT * FROM Clientes;
RETURN NEXT ref1;
OPEN ref2 FOR SELECT * FROM Pedidos;
RETURN next ref2;
RETURN;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION Clientes_TABM1()
RETURNS SETOF refcursor AS
$BODY$
DECLARE
ref1 refcursor;
ref2 refcursor;
BEGIN
OPEN ref1 FOR SELECT * FROM Clientes;
RETURN NEXT ref1;
OPEN ref2 FOR SELECT * FROM paises;
RETURN next ref2;
RETURN;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
este es el codigo
/*
* Created by SharpDevelop.
* User: mireya
* Date: 17/02/2006
* Time: 12:50
*
* To change this template use Tools | Options | Coding | Edit Standard
Headers.
*/
using System;
using System.Data;
using Npgsql;
using NpgsqlTypes;
namespace pruebaCursor
{
public class c
{
public static void Main(String[] args)
{
NpgsqlConnection conn = new
NpgsqlConnection("Server=127.0.0.1;Database=pachacamac;Password=necs;User
Id=necs");
conn.Open();
NpgsqlTransaction t = conn.BeginTransaction();
NpgsqlCommand command = new NpgsqlCommand("clientes_tabm1()", conn);
command.CommandType = CommandType.StoredProcedure;
NpgsqlDataReader dr = command.ExecuteReader();
while(dr.Read())
{
Console.WriteLine(dr.GetValue(0));
Console.WriteLine(dr.GetValue(1));
Console.WriteLine(dr.GetValue(2));
}
Console.ReadLine();
Console.ReadLine();
dr.NextResult();
while(dr.Read())
{
Console.WriteLine(dr.GetValue(0));
Console.WriteLine(dr.GetValue(1));
Console.WriteLine(dr.GetValue(2));
}
dr.Close();
t.Commit();
conn.Close();
}
}
}
este es el error que sale pero solo cuando llamo a la segunda funcion,
puesto que con la primera funciona perfectamente
Microsoft Windows XP [Versión 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
D:\Documents and Settings\mireya>cd D:\Documents and Settings\mireya\Mis
documen
tos\SharpDevelop Projects\pruebaCursor\bin\Debug
D:\Documents and Settings\mireya\Mis documentos\SharpDevelop
Projects\pruebaCurs
or\bin\Debug>pruebaCursor.exe
<unnamed portal 1>
Unhandled Exception: System.IndexOutOfRangeException: Column index out of
range
at Npgsql.NpgsqlDataReader.GetValue(Int32 Index)
at pruebaCursor.c.Main(String[] args) in d:\Documents and
Settings\mireya\Mis
documentos\SharpDevelop Projects\pruebaCursor\Main.cs:line 41
D:\Documents and Settings\mireya\Mis documentos\SharpDevelop
Projects\pruebaCurs
or\bin\Debug>
uso postgres 8.1.3 npgsql 7.0.1 windows xp y sharpdevelop 1.1
gracias por cualquier ayuda
--
.~.
( 0 0 )
/ V \
// \\ Frank Jonislla Pillaca
/(( _ ))\ AYACUCHO
oo0 0oo 9700982
From | Date | Subject | |
---|---|---|---|
Next Message | Grover Navia | 2006-02-17 21:26:48 | Error al insertar (UTF-8) |
Previous Message | Mario Soto Cordones - Venezuela | 2006-02-17 20:53:27 | Re: Problema con triger |