I was reading
madermans post about
Composing a SQL statement and I was reminded of some very peculiar software architecture I saw last year. As I started writing this I realised I had gone way offtopic, but I still wanted the monastary's opinion.
This system I was working on had introduced '
SQL abstraction layer' between the database functions layer and the database itself:
webserver
CGI layer
processing
DB functions layer
SQL abstraction layer
DBI/DBD
database
The
DB functions layer defined commonly used functions like 'add_user' 'add_transaction'. Such layers are common, and they allow you to cleanly change the database backend without worrying about the front. But in this case the DB functions layer didn't directly use SQL... Instead it called from an array of new functions derived from the level below, eg:
&my_db_connection->update(
table_name => $table_name,
keys => &my_db_connection->select(
table_name => $table_name,
return_field => 'userID',
select_field => 'userName',
value => $username),
update_field => 'userAddress',
update_value => $new_address);
The
select and
update methods would generate and execute the SQL. I was expecting to find a more direct generation of SQL, eg:
$sql = "UPDATE users SET userAddress='$new_address' WHERE userName='$
+username'"
The only advantages of this approach (IMHO) are:
- Security - malicious code has to navigate an extra layer of obscurity
- Safe development - Once the abstraction layer is written, developers working on higher levels are limited in the damage they can do (can't "DROP TABLE")
Whereas the disadvantages are:
- New set of functions - Developers had to learn these new functions, their SQL knowledge was useless.
- Extra complexity - extra bugs
- Less Efficient
- Less Flexibility
- Database locked to code - (yes, major rewrites were required if you added a DB column)
And of course all of the other issues that arise simply by virtue of writing an extra 2000 lines of code
Has anyone got
ANY ideas why the original developers might have done this ? ? ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.