Recent

Author Topic: stored procedures  (Read 6597 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
stored procedures
« on: June 20, 2012, 02:12:14 am »
Hi everyone.

Postgres has stored procedures capability.

Using the Posgres specific vcl, it seems to me that capability may not be available.

I wonder if one were to use the ODBC driver, can stored procedures facilities be used?

Thanks.

goodname

  • Sr. Member
  • ****
  • Posts: 297
Re: stored procedures
« Reply #1 on: June 20, 2012, 04:11:20 am »
Don't know what "Posgres specific vcl" is. If you want to run a stored procedure or function it should as simple as running a select query that calls the procedure/function.

Scroll down to the examples section.
http://www.postgresql.org/docs/9.1/static/sql-createfunction.html
« Last Edit: June 20, 2012, 04:13:03 am by goodname »

circular

  • Hero Member
  • *****
  • Posts: 4462
    • Personal webpage
Re: stored procedures
« Reply #2 on: June 20, 2012, 07:03:03 am »
Does vcl = visual component library ? As far as I know a database is not visual.
Conscience is the debugger of the mind

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: stored procedures
« Reply #3 on: June 20, 2012, 07:25:43 am »
Does vcl = visual component library ? As far as I know a database is not visual.

I meant the vcl objects specific for connecting to Postgres databases.

I just want to know if using Lazarus with Postgres, one can implement and use stored procedures, and if there are (or not) limitations.

Thanks!

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: stored procedures
« Reply #4 on: June 20, 2012, 07:31:59 am »
Don't know what "Posgres specific vcl" is. If you want to run a stored procedure or function it should as simple as running a select query that calls the procedure/function.

Scroll down to the examples section.
http://www.postgresql.org/docs/9.1/static/sql-createfunction.html

Thanks for replying.

Correct me if not so. From your reply, as long as the query to call the procedure reaches the database server, it will perform it?

What about the capability to receive at the Lazarus application the returns of the stored procedure?

Do stored procedures with no output raise exceptions useable by the application code,  if failed?

Thanks!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: stored procedures
« Reply #5 on: June 20, 2012, 08:38:34 am »
You might try using select from as if it were a query if it returns results; use connection.executedirect (or similar) or sqlquery.execsql to just execute and not ask for result sets.
See http://wiki.lazarus.freepascal.org/Working_With_TSQLQuery

Edit: note: given what Ludo says about PostgreSQL: apparently an SP in PostgreSQL always returns data... On Firebird, an SP can but does not have to return data.
« Last Edit: June 20, 2012, 10:13:28 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: stored procedures
« Reply #6 on: June 20, 2012, 09:06:24 am »
Quote
Correct me if not so. From your reply, as long as the query to call the procedure reaches the database server, it will perform it?
Yes. No matter if the procedure is called with execsql, open or executedirect, as it does for every select statement.
Quote
What about the capability to receive at the Lazarus application the returns of the stored procedure?
Open will receive the result set as it does for every other select statement.
Quote
Do stored procedures with no output raise exceptions useable by the application code,  if failed?
Yes, exceptions on errors are raised as it does for every other select statement.

On postgres calling a stored procedure is just a select statement with your stored procedure called as if it where a function. So you get the same behavior as for every select statement. 

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: stored procedures
« Reply #7 on: June 20, 2012, 11:53:18 am »
Thangs, BigChimp, ludob, and goodname.

All you explained makes good sense to me.

I think I have a much better grasp on what to try to achieve now.

 :)

 

TinyPortal © 2005-2018