ADO Ref cursor return

ADO Ref cursor return

am 12.04.2006 01:55:06 von Sam Thukral

This is a multi-part message in MIME format.

------=_NextPart_000_0080_01C65D88.B0687910
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hello,



We are currently porting to Postgres from SQL Server and are experiencing
problems with ADO and returning refcursors. We currently use the
parameterized ADO methodology to return our data from procedures in the
database. After researching and converting over our database to postgres,
we are trying to re-use as much of our logic as we can. As currently
configured, we return a refcursor as an out parameter from the procedure,
and try to return the data into an ADO resultset. From further research, we
found methodology to call our procedure and return the cursor, and then
fetch the results into a resultset. Here is the current code:



Procedure:



CREATE OR REPLACE FUNCTION usp_commhost_get(IN sdomain "varchar", OUT
swv_refcur refcursor) AS

$BODY$

BEGIN

-- GET SUBDOMAIN COMMUNITY DETAILS

open swv_RefCur for SELECT C.ccPublicCommID FROM tbl_Comm C
WHERE(LOWER(C.ccDomain) = LOWER(sdomain) OR C.ccDomain = 'change_me')
AND(C.ccStatusID = 1);

RETURN;

END; $BODY$

LANGUAGE 'plpgsql' VOLATILE;

ALTER FUNCTION usp_commhost_get(IN sdomain "varchar", OUT swv_refcur
refcursor) OWNER TO postgres;



ASP code











<%

dim conn, rst, cmd



set conn = server.createobject("ADOdb.connection")

conn.open "Data
Source=pssam1;location=Connect3_0;UserID=username;password=p assword;"

Set cmd = Server.CreateObject("ADODB.Command")

cmd.ActiveConnection = conn

cmd.CommandText = "select usp_commhost_get('refcur', 'localhost'); FETCH ALL
IN refcur;"

set rst = server.createobject("ADOdb.recordset")

Set rst= cmd.Execute



do until rst.eof

response.write Server.HTMLEncode(rst.fields(0))&"
"

rst.movenext

loop

rst.Close

conn.Close



%>







We would like to convert this into a parameterized call to the procedure,
and not have to stipulate the cursor name to retrieve the data. Is this
possible? And if so, what is the proper format? Thank you for any help in
advance.



Sam Thukral

Centercode










------=_NextPart_000_0080_01C65D88.B0687910
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">


charset=3Dus-ascii">

namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
name=3D"place" downloadurl=3D"http://www.5iantlavalamp.com/"/>
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
name=3D"City" =
downloadurl=3D"http://www.5iamas-microsoft-com:office:smartt ags"/>









style=3D'font-size:10.0pt;
font-family:Arial'>Hello,



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>We are currently porting to Postgres from SQL Server =
and are
experiencing problems with w:st=3D"on">ADO
and returning refcursors.  We currently use the parameterized =
w:st=3D"on">ADO =
methodology to return
our data from procedures in the database.  After researching and
converting over our database to postgres, we are trying to re-use as =
much of
our logic as we can.  As currently configured, we return a =
refcursor as an
out parameter from the procedure, and try to return the data into an =
w:st=3D"on">ADO resultset. =
 From
further research, we found methodology to call our procedure and return =
the
cursor, and then fetch the results into a resultset.  Here is the =
current
code:



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Procedure:



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>CREATE OR REPLACE FUNCTION usp_commhost_get(IN =
sdomain
"varchar", OUT swv_refcur refcursor) =
AS



style=3D'font-size:10.0pt;
font-family:Arial'>$BODY$



style=3D'font-size:10.0pt;
font-family:Arial'>BEGIN



style=3D'font-size:10.0pt;
font-family:Arial'>-- GET SUBDOMAIN COMMUNITY =
DETAILS



style=3D'font-size:10.0pt;
font-family:Arial'>   open swv_RefCur for SELECT =
C.ccPublicCommID
FROM tbl_Comm C  WHERE(LOWER(C.ccDomain) =3D LOWER(sdomain) OR =
C.ccDomain =3D
'change_me') AND(C.ccStatusID =3D 1);



style=3D'font-size:10.0pt;
font-family:Arial'>   RETURN;



style=3D'font-size:10.0pt;
font-family:Arial'>END; $BODY$



style=3D'font-size:10.0pt;
font-family:Arial'>  LANGUAGE 'plpgsql' =
VOLATILE;



style=3D'font-size:10.0pt;
font-family:Arial'>ALTER FUNCTION usp_commhost_get(IN sdomain =
"varchar",
OUT swv_refcur refcursor) OWNER TO =
postgres;



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>ASP code



style=3D'font-size:10.0pt;
font-family:Arial'> 



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'><!--#include
virtual=3D"/global/constants.html"--> t>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'><html>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'><head></head>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'><body>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'><%



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>dim conn, rst, =
cmd



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'> 



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>set conn =3D
server.createobject("ADOdb.connection") >



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>conn.open =
"Data
Source=3Dpssam1;location=3DConnect3_0;UserID=3Dusername;pass word=3Dpasswo=
rd;"



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>Set cmd =3D
Server.CreateObject("ADODB.Command")
p>

face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>cmd.ActiveConnection =3D conn



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>cmd.CommandText =3D
"select usp_commhost_get('refcur', 'localhost'); FETCH ALL IN
refcur;"



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>set rst =3D
server.createobject("ADOdb.recordset")
=



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>Set rst=3D =
cmd.Execute



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'> 



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>do until =
rst.eof



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>  response.write
Server.HTMLEncode(rst.fields(0))&"<BR>" pan>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier New"'>  =
rst.movenext



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>loop



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>rst.Close



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>conn.Close



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'> 



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'>%>



face=3D"Courier New"> style=3D'font-size:10.0pt;font-family:"Courier =
New"'></body>



style=3D'font-size:10.0pt;
font-family:"Courier New"'></html>
face=3DArial> style=3D'font-size:10.0pt;font-family:Arial'> >

style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>We would like to convert this into a parameterized =
call to
the procedure, and not have to stipulate the cursor name to retrieve the =
data.  Is
this possible?  And if so, what is the proper format?  Thank =
you for
any help in advance.



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Sam Thukral



style=3D'font-size:10.0pt;
font-family:Arial'>Centercode



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 









------=_NextPart_000_0080_01C65D88.B0687910--