Subject | RE: [firebird-support] Building query strings in stored procedures? |
---|---|
Author | Tim Gahnström |
Post date | 2005-05-20T06:54:16Z |
> -----Original Message-----You could pass arrays to a stored procedure (I don't know how) and build the query string inside your SP and use the EXECUTE STATEMENT as Ann suggested. It will give you the flexibility you are looking for but not any speed increase.
> > Using something like PHP it is possible to build up an sql query
> > string to perform on the database, depending on what
> filters, how many
> > filters, and the values within the filters, the user chooses ...
> >
> > What I would like to be able to do is replicate this within
> a stored
> > procedure ...
> > also I'm finding SPs appreciably faster)
> Check the EXECUTE STATEMENT statement. You can build up a
> SQL statement in a procedure then execute it.
The reason SPs are faster is because they are compiled and optimized in advance and this is not possible using the EXECUTE STATEMENT.
This is a drawback but it also means that you can just as well build your query string on the clientside (in php) and pass it as a string to the SP. This way you don't have to pass in and parse an array annd you can keep most of the logic in PHP.
If you really need the speed your option is to skip the EXECUTE STATEMENT and only use ordinary IF statements etc in your SP.
Tim