RE: Using q() to define a query



From: Carville, Stephen" <scarville@xxxxxxxxxx>
I've tried several different ways, global variables, local variables,
modules but, FWIW, I've found putting long scripts in a subroutine
works pretty well from a maintenance standpoint: (This is from an
older report. Now I encourage the poor guy who has to maintain my
stuff to use ? instead of %s whenever practical)

sub some_descriptive_script_name {

While prototypes are generaly not recommended this is a perfect case
for the empty prototype

sub some_descriptive_script_name () {

which will basicaly turn the subroutine into a constant that can be
inlined.

return qq{

Looks to me like you are not interpolating any variables there so q{}
would probably be better.

Of course it would definitely be preferred to use placeholders
instead if inserting the data into the SQL with sprinf(). It's safer
and more efficient (allows the database to cache execution plans).

If supported by the database, stored procedures would work even
better. Especially if you enforce a rule that all database access is
doen via stored procedures and therefore the DBA has a chance to see
all SQL used against his database and can optimize the queries and/or
indexes and schema.

Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

.



Relevant Pages

  • Re: Serious errors with Create view command
    ... the database is opened? ... There's no database on earth that behaves that way! ... What on EARTH does the option of 'Edit Stored procedures' do? ... I can't paste it INTO the view designer sql view ...
    (microsoft.public.fox.helpwanted)
  • Re: Transaction Oriented Architecture (TOA)
    ... OOP is not required to wrap SQL. ... of stored procedures to act as an API for application programmers ... writing code against the database. ... With a well-defined API in place, ...
    (comp.object)
  • Re: Get all stored procedures
    ... For SQLSERVER, we can use the following SQL statement to query the SP ... objects of a certain database: ... Microsoft Online Support ... | Thread-Topic: Get all stored procedures ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cannot Open SQL Server Table in Access.ADP File.
    ... I dont think that SQL Server will take 'veiw dependencies' into effect; ... Generate Script Wizard did not work on my original database, ... After fixing some of my tables and a few stored procedures and views, ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Serious errors with Create view command
    ... However the REASON I thought it should work on 'opening' the database was ... Why should I have asssumed that an SQL statement which works ... Stored procedures are nothing more than procedures that are stored in the ... There's no database on earth that behaves that way! ...
    (microsoft.public.fox.helpwanted)