tomazos has asked for the wisdom of the Perl Monks concerning the following question:
When preparing SQL statements to send to the server, DBI circumvents the problem of different SQL syntaxes across all the different SQL servers (Oracle, Sybase, MySQL etc) by simply taking the statement as a raw string and letting the SQL server tell you whether the syntax is valid or not.
The problem with this is that you don't find out until deep into runtime whether there is a problem with your SQL - even something simple such as a typo.
I appreciate that it would be really hard to write a layer over SQL that was general across all servers, but I'm really only interested in MySQL's specific syntax to get my job done.
With that as a given, I think it should be possible to write something (perhaps like a CGI.pm style interface to HTML) that will allow you to compile-time check MySQL specific SQL syntax, and perhaps even check if you are refering to real databases and tables.
I was thinking something like:
$sth->prepare( table{users}->select( all, where( like{name}->quote('%john%') ) ) )
would be equivilant to:
$sth->prepare( << 'EOS' ); select * from users where name like '%john%' EOS
Obviously for this simple example the extra layer is not worth the overhead for clarity's sake - but for a more complex real world situation the compile time syntax checking would be worth it.
Has anyone got any thoughts further to this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL/DBI
by Zaxo (Archbishop) on Oct 20, 2001 at 10:43 UTC | |
|
Re: SQL/DBI
by lhoward (Vicar) on Oct 20, 2001 at 14:55 UTC | |
|
Re: SQL/DBI
by jepri (Parson) on Oct 20, 2001 at 10:51 UTC | |
by Arguile (Hermit) on Oct 20, 2001 at 11:22 UTC | |
by jepri (Parson) on Oct 20, 2001 at 11:58 UTC | |
by Arguile (Hermit) on Oct 20, 2001 at 14:50 UTC | |
by Aristotle (Chancellor) on Oct 20, 2001 at 19:43 UTC |