A Shorthand Notation for SQL for Lazy ppl
Posted: Wed Apr 01, 2009 7:36 am
Hi all,
I am attaching a class file on which I have spent a lot of time ,and I desperately need some comments about
whether it is as useful (as i think it is) or not.This class exports a short hand like syntax for SQL.This means you can
do more with less code,and with less errors.
If you ever skipped checking for an existing username ,just before adding a new username to a table,just because
of the trouble of writing the required query, Then this class might solve some problems for you .
We can Consider a database table to be two dimensional php array.The first index of the array being the primary
key field,Second index,the column names .Now ,when you want to store something in an array ,you dont write
small scripts(like SQL) ,instead you write
Then why,every time you want to get or set ,the `name` field for n'th row from the `user` table ,you have to write
an SQL query to do that?I mean you could express the requirement, which is to get the name field from 10th row
of user table by using a simpler syntax ,a syntax native to php.like
This class exports a syntax that enables you to do just that,and more. It allows you to specify what you want from
your database with a lot fewer words.
It can be seen as a high level query language because ,It does to SQL what C does to Assembly language.
A few things this class can do for you...
1.Reduces the code required to carryout an sql operation
for example to insert a row into a table `user` you can do as
to get the `name` column from table user with primary key value 10
to update name column from table user with primary key value 10 ,to 'user_2'
2.Reduces errors by eliminating the strings inside strings ie, constructs Like "name='user' ",this is bad because a missing single quote in a double quoted string is hard to detect.
For example,to get the id of the user with name='user' from table user ,
now if you miss that single quote around user ,the editor ,if it supports syntax checking will find that out as soon as you
finish typing it...
3.Automatically renames columns in a join
This feature is helpful if two tables in join contains the fields with same name,ex id field..
4.Automatically escapes the double quotes in string values .
The class only escapes a double quote only if t has not already been escaped.ie it does not do the usuall get_magic_quotes
to find out wether the string has been already escaped.
Please see the howto.html in the rar file for more features,and there are lots of them......
Download from I need some comments on this desperately...so any one reading this,please leave some comments.
Regards,
Max
I am attaching a class file on which I have spent a lot of time ,and I desperately need some comments about
whether it is as useful (as i think it is) or not.This class exports a short hand like syntax for SQL.This means you can
do more with less code,and with less errors.
If you ever skipped checking for an existing username ,just before adding a new username to a table,just because
of the trouble of writing the required query, Then this class might solve some problems for you .
We can Consider a database table to be two dimensional php array.The first index of the array being the primary
key field,Second index,the column names .Now ,when you want to store something in an array ,you dont write
small scripts(like SQL) ,instead you write
Code: Select all
$array[10]['name']='user_1';Then why,every time you want to get or set ,the `name` field for n'th row from the `user` table ,you have to write
an SQL query to do that?I mean you could express the requirement, which is to get the name field from 10th row
of user table by using a simpler syntax ,a syntax native to php.like
Code: Select all
$name=$user[10]->name;your database with a lot fewer words.
It can be seen as a high level query language because ,It does to SQL what C does to Assembly language.
A few things this class can do for you...
1.Reduces the code required to carryout an sql operation
for example to insert a row into a table `user` you can do as
Code: Select all
$db->user= array('name'=>'user_1','no'=>45);to get the `name` column from table user with primary key value 10
Code: Select all
$name=$db->user(10)->name;Code: Select all
$db->user(10)->name ='user_2' ;2.Reduces errors by eliminating the strings inside strings ie, constructs Like "name='user' ",this is bad because a missing single quote in a double quoted string is hard to detect.
For example,to get the id of the user with name='user' from table user ,
Code: Select all
$id=$db->user->name('user')->id;finish typing it...
3.Automatically renames columns in a join
This feature is helpful if two tables in join contains the fields with same name,ex id field..
Code: Select all
$rows=$db->_join->user('u')->comments('c')->end;
echo $rows->u_id(10)->u_name;
// the name of user with id =10 from user table,aliased as 'u' becomes u_name.The `id` in user table aliased as 'u' becomes u_id.
echo $rows->u_id(10)->c_comment
// the comment field in comments table becomes c_comment.The class only escapes a double quote only if t has not already been escaped.ie it does not do the usuall get_magic_quotes
to find out wether the string has been already escaped.
Please see the howto.html in the rar file for more features,and there are lots of them......
Download from I need some comments on this desperately...so any one reading this,please leave some comments.
Regards,
Max