Re^3: No stored procedure bashing on my watch!
by Thilosophy (Curate) on Dec 17, 2004 at 11:44 UTC
|
don't use any SQL code in your applications (except for calling stored procedures). Ever.
Shameless plug:
DBIx::ProcedureCall makes Perl wrappers for stored procedures, eliminating the SQL to call them from your application source code as well. Only works for Oracle at the moment, though (contributions for other DBMS always welcome). | [reply] |
Re^3: No stored procedure bashing on my watch!
by perrin (Chancellor) on Dec 16, 2004 at 21:38 UTC
|
I don't buy it. Change the data structures around in a significant way and hide it all with stored procs? You'd end up with something messy and slow, just like all of those awful "we'll fix it with a view" solutions.
Many DBAs are reluctant to give out permission for developers to modify stored procs. They see it as a way to make sure that all SQL is filtered through them. The problem is, they tend not to have any time to look at your SQL either, so the vetting process becomes a bottleneck.
That sort of thing can be fixed, albeit slowly and painfully, but it doesn't change the fact that stored procs normally use crippled languages. I wouldn't want to use them for anything with actual programming logic in it.
| [reply] |
|
|
Anything you can do from embedded SQL, you can do from a stored procedure. Instead of preparing and executing the SQL, you invoke the SP that does it for and returns the same results.
No extra programming logic needs to be written in the SP language. It can be, often saving the need to ship large volumes of data between the DBM and the application program, and then back again, but it doesn't need to be.
The difference is that that when the schema changes, the application program(s) don't. When a new schema is being developed, the SPs get modified in step and tested in isolation of any applications. When the switchover comes to pass, the existing DB is renamed and the new DB renamed to the old name. Next connection, all the applications using SPs are automatically using the new schema without a single line of their code needing to change.
It is exactly the same process of encapsulation that using objects gives you: OO-101: Tenent 1: Isolate the data format from the caller.
It also provides for an isolation layer between the application code and the DBM vendor. Provided the new DBM vendor also supports SPs and the DBI interface allows access to them, then you simply write the equivalent SP with the same name in the new vendor SP language and again, the applications don't need any modification.
It also allows the SPs to make use of vendor specific optimisations and extensions without fear of lock-in.
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail
"Time is a poor substitute for thought"--theorbtwo
"Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] |
|
|
I'm aware that stored procs don't have to include programming logic, but they often do.
Your point about isolation from vendor-specific SQL makes a lot of sense, although I wonder how standardized the details of calling procedures is across databases in DBI. Typically, database portability only really matters to people who are shipping a product that must support multiple dbs. Other people are not willing to spend the time and money that portability requires.
I still don't buy the idea that stored procs can provide protection from schema changes of any significance. If there was a good reason to make the change, it must mean the available data is now different, which means the programs using it need to change. Little things like adding columns don't break SQL -- big things like merging or splitting tables and changing relationships do. Trying to hide changes like that behind stored procs and let programs continue as if nothing happened will surely result in slow and complicated joins and the like.
| [reply] |
|
|
|
|
Re^3: No stored procedure bashing on my watch!
by BrowserUk (Patriarch) on Dec 16, 2004 at 17:08 UTC
|
...don't use any SQL code in your applications (except for calling stored procedures). Ever.
Abso-bloody-lutely!
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail
"Time is a poor substitute for thought"--theorbtwo
"Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] |
Re^3: No stored procedure bashing on my watch!
by punkish (Priest) on Dec 16, 2004 at 21:18 UTC
|
I feel like poor Paco.
I fully understand the value of storedProcs, and the value of abstracting, and the value of not using SQLs in the scripts, etc. I merely wanted to find out how to replicate a multi-command SQL proc in my script, because, well..., because I wanted to.
I have come to the conclusion that it is messy to do so because DBI doesn't seem to provide the ability of abstracting the transactions for me, but that is a good and valuable conclusion.
Now, I have a minor quibble to pick with the above post.
Besides from the reasons given by other people, it gives database people the opportunity to re-organize the data layout (add/delete columns, split tables) without having to modify an unknown number of programs - all that's needed is to change the relevant stored procedures.
Well, what the heck are storeprocs other than an "unknown number of programs?" I can't see how the db structure can be changed, and yet storedProcs can prevent any pain? Whether I get to the data via a SQL statement in my Perl script, or via a storedProc in the database called from my Perl script, somewhere, someone will have to change something.
I think the dba types tend to think one way only -- that the world depends on the database they are custodians of. While that may be true in their realm, there are tons of small programs and processes that are run using databases where the dba can't do everything. The programmer has to find ways to do things in a variety of ways.
That is the kind of situation I ran into.
Anyway, thanks everyone for the input. Every bit helps. | [reply] |
|
|
Well, what the heck are storeprocs other than an "unknown number of programs?"
They are a known number of programs, all written in the same language, and stored centrally. Given a database, it's very easy to extract out all its stored procedures - and its quite easy to find out which tables each stored procedure touches. But if the SQL is scattered around over many applications, written in a myriad of languages, all running somewhere on the network (and for some organizations, the "network" can consist of thousands of machines), it's much harder to get everything updated if the schemas change.
| [reply] |
|
|
| [reply] |