dbTalk Databases Forums  

Re: dotnet stored procedures with postgresql

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: dotnet stored procedures with postgresql in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
George Weaver
 
Posts: n/a

Default Re: dotnet stored procedures with postgresql - 04-06-2004 , 10:26 AM






Hi Paul,

I'm not sure if this is what you're looking for, but hopefully it will point
you in the right direction.

Create a stored procedure in postgresql with parameters:

CREATE OR REPLACE FUNCTION uspGetParameter(varchar(20), int4, float4,
float4)
RETURNS float4
AS
'SELECT $3 * $4;'
STABLE
LANGUAGE SQL;
GRANT EXECUTE ON FUNCTION public."uspgetparameter"(varchar(20), int4,
float4, float4) TO PUBLIC;

Call the procedure from dotnet (VB in this case):

Dim Connection As String = "DRIVER={PostgreSQL}; SERVER=localhost;
UID=George Weaver; DATABASE=test; Readonly=0;"

Dim cnPgSQL As New OdbcConnection(Connection)

Dim myCmdString As String = "Select uspGetParameter(?, ?, ?, ?);"

Dim myCommand As New OdbcCommand(myCmdString, cnPgSQL)

Dim myParamCollection As OdbcParameterCollection = myCommand.Parameters

Dim p1 As New OdbcParameter("", OdbcType.Text)
p1.Value = "apple"
myParamCollection.Add(p1)

Dim p2 As New OdbcParameter("", OdbcType.Int)
p2.Value = 1
myParamCollection.Add(p2)

Dim p3 As New OdbcParameter("", OdbcType.Real)
p3.Value = 1.5
myParamCollection.Add(p3)

Dim p4 As New OdbcParameter("", OdbcType.Real)
p4.Value = 5.6
myParamCollection.Add(p4)

myCommand.CommandType = CommandType.StoredProcedure

cnPgSQL.Open()

Dim ReturnValue As Single
ReturnValue = CSng(myCommand.ExecuteScalar)

cnPgSQL.Close()

Should return the value of 8.4

Regards,
George


----- Original Message -----
From: "Paul Semenick" <PSemenick (AT) computer-systems (DOT) com>
To: <pgsql-novice (AT) postgresql (DOT) org>
Sent: Tuesday, March 30, 2004 5:10 PM
Subject: [NOVICE] dotnet stored procedures with postgresql


Looking for some examples of stored procedures with
parameters using dotnet, postgresql and odbc
Thanks,
Paul

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
PaulS
 
Posts: n/a

Default Re: dotnet stored procedures with postgresql - 04-06-2004 , 02:14 PM






George,
Yes this is exactly what I needed. I copied the vb code
from your post into vb.net and it worked on the second try.
On the first try I hadn't created the stored procedure
Thanks,
Paul

"George Weaver" <gweaver (AT) shaw (DOT) ca> wrote

Quote:
Hi Paul,

I'm not sure if this is what you're looking for, but hopefully it will
point
you in the right direction.

Create a stored procedure in postgresql with parameters:

CREATE OR REPLACE FUNCTION uspGetParameter(varchar(20), int4, float4,
float4)
RETURNS float4
AS
'SELECT $3 * $4;'
STABLE
LANGUAGE SQL;
GRANT EXECUTE ON FUNCTION public."uspgetparameter"(varchar(20), int4,
float4, float4) TO PUBLIC;

Call the procedure from dotnet (VB in this case):

Dim Connection As String = "DRIVER={PostgreSQL}; SERVER=localhost;
UID=George Weaver; DATABASE=test; Readonly=0;"

Dim cnPgSQL As New OdbcConnection(Connection)

Dim myCmdString As String = "Select uspGetParameter(?, ?, ?, ?);"

Dim myCommand As New OdbcCommand(myCmdString, cnPgSQL)

Dim myParamCollection As OdbcParameterCollection = myCommand.Parameters

Dim p1 As New OdbcParameter("", OdbcType.Text)
p1.Value = "apple"
myParamCollection.Add(p1)

Dim p2 As New OdbcParameter("", OdbcType.Int)
p2.Value = 1
myParamCollection.Add(p2)

Dim p3 As New OdbcParameter("", OdbcType.Real)
p3.Value = 1.5
myParamCollection.Add(p3)

Dim p4 As New OdbcParameter("", OdbcType.Real)
p4.Value = 5.6
myParamCollection.Add(p4)

myCommand.CommandType = CommandType.StoredProcedure

cnPgSQL.Open()

Dim ReturnValue As Single
ReturnValue = CSng(myCommand.ExecuteScalar)

cnPgSQL.Close()

Should return the value of 8.4

Regards,
George


----- Original Message -----
From: "Paul Semenick" <PSemenick (AT) computer-systems (DOT) com
To: <pgsql-novice (AT) postgresql (DOT) org
Sent: Tuesday, March 30, 2004 5:10 PM
Subject: [NOVICE] dotnet stored procedures with postgresql


Looking for some examples of stored procedures with
parameters using dotnet, postgresql and odbc
Thanks,
Paul

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.