Re: [SQLHat] Proposal

From: Date: Tue, 06 Apr 2004 09:33:31 +0000
Subject: Re: [SQLHat] Proposal
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-27079@lists.php.net to get a copy of this message
Kamen TOMOV wrote:
DESCRIPTION:
    What is SQLHat?
    SQLHat is a library and a test tool and it suggests a better
    aproach for quering databases with SQL queries.
    The traditional aproach is embedding the queries in the program by
    assigning them to variables as strings. It has several
    disadvantages:
    First of all this way we have to mix the program code with the SQL
    code. We have to pay atention to quotes and we usually can not use
    capabilities of an advanced editior such as syntax highlighting
    for the SQL code.
    Second of all there is no easy way to test the query without
    testing the program code. In order to test the query we have to
    copy it and paste it somewhere. The problem gets even bigger if
    this query contains parameters. In that case we have to edit it
    before even trying to execute.
    Finally if the language we use needs to be compiled each time we
    change the query we have to recompile the program.
    The suggested approach solves this problems and adds additional
    features that make the programming easier and faster.
    Testing the queries without testing of the rest of the code is
    possible because we isolate them in separate program files - each
    one in different .sql file.
    SQLHat allows using parameters in the queries and introduces 3
    parameter type definitions - string, int and float parameters.
    The last thing we add is the opportunity to wrap fragments of the
    query in blocks and to include them conditionally depending on the
    value of a condition.
Sounds like a good idea. However it seems to be you can reach this level of "abstraction" very easily with PHP. You simply place your queries in external files which you then include in your code. This would provide all the described benefits without requiring any other changes, leaving the choice of API to use total open. It would also allow to write a browser for all of these files and then run the queries with the given parameters.
    SQHat should be available in various programming languages (PHP,
    Perl, Python, Java,...) and should work with any databases.
Obviously using PHP syntax inside the files would mean that for other languages you would have to parse the files, but you seem to be doing this right now already so I dont see a new disadvantage there. Using PHP would also allow for some more complex things inside the files, which should probably discouraged, but will ensure that you dont suffer from any limitations from some custom scripting language (which right now only does parameter replacements and if's it seems (?)). Beyond that there would be the advantage of reducing the overhead as normal PHP files would also be cached using standard PHP bytecode caches (remember that reading files is not an insignificant overhead otherwise). regards, Lukas Smith smith@backendmedia.com _______________________________ BackendMedia www.backendmedia.com berlin@backendmedia.com Linn Zwoch Smith GbR Pariser Str. 44 D-10707 Berlin Tel +49 30 83 22 50 00 Fax +49 30 83 22 50 07

« previous php.pear.dev (#27079) next »