A Shorthand Notation for SQL for Lazy ppl

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by max529 »

Pulni4kiya wrote:I have a question: why aren't you using mysqli?

And about the class... Maybe something like that is a good idea, yes. But an SQL query is more readable to me.

I don't like all those arrows (->). And it should be more intuitive.
yea..using mysqli is a good idea..but normal mysql functions are a little easier to use..

and about arrows.to me they are better than quotes...better than strings...and strings inside strings....

have you worked with jquery for javascript....do you like it?

thanks for replying anyway....
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by Pulni4kiya »

No I've not worked with jquery.

Others might like it that way. Maybe more people prefer it with arrows. It should be simpler and easyer to use, so...it's good :) Just not for me :)
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by max529 »

Pulni4kiya wrote:No I've not worked with jquery.

Others might like it that way. Maybe more people prefer it with arrows. It should be simpler and easyer to use, so...it's good :) Just not for me :)
So you havent used jquery..it is a widely used javascript library that can really make a difference...its syntax is some what less readable that normal javascript..you might want to try it..if you like that...chances are you will like this one too...
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by Pulni4kiya »

To be honest I hate javascript!
I leave everything JS/CSS/HTML-related to someone else. I'm interested in programming and these things have nothing to do with it. So I avoid doing anything connected to them. (Not that I don't understand them...just don't like them...). But I'll take a look at jquery. :)
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: A Shorthand Notation for SQL for Lazy ppl

Post by papa »

Pulni4kiya wrote:To be honest I hate javascript!
I leave everything JS/CSS/HTML-related to someone else. I'm interested in programming and these things have nothing to do with it. So I avoid doing anything connected to them. (Not that I don't understand them...just don't like them...). But I'll take a look at jquery. :)
So JS has nothing to do with programming ? Wow, news to me. :)
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: A Shorthand Notation for SQL for Lazy ppl

Post by temidayo »

@max529
I have not taken a look at the class beyond what have been posted here; I will do so shortly.

What you are trying to achieve is a good innovation and the concept is not entirely new.
It is similar to what is described in this thread viewtopic.php?f=28&t=48499
Namely, Queries without SQL
While that thread describe a way to do CRUD only. Your class seems to be more advanced in the queries
that is possible.

All you need is a community around the class and it could become something like:
http://phpuserclass.com/

I will take a look at the class and let you know what I think.
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by max529 »

temidayo wrote:@max529
I have not taken a look at the class beyond what have been posted here; I will do so shortly.

What you are trying to achieve is a good innovation and the concept is not entirely new.
It is similar to what is described in this thread viewtopic.php?f=28&t=48499
Namely, Queries without SQL
While that thread describe a way to do CRUD only. Your class seems to be more advanced in the queries
that is possible.

All you need is a community around the class and it could become something like:
http://phpuserclass.com/

I will take a look at the class and let you know what I think.
Thanks a ton for your message..As you said the concept is not new.It has been around for sometime, so are the magic methods functionality in php 5 ..And I always wonder why someone hasn't done this already...

its like we got wheels ,and we got engine..but no one would make a car....

is that a bad analogy....?? never mind...

Thanks again and eagerly looking forward for your views....
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: A Shorthand Notation for SQL for Lazy ppl

Post by John Cartwright »

I think it boils down to whether your library can efficently handle all SQL statements. Until that day comes, and I've dabbled with my share of SQL generators, it is pointless to partially abstract away from SQL. It simply doesn't make sense to me to abstract SQL generator only if I can use it sometimes and can be considered a code smell. Although, it is still good to have for higher level code when the SQL generated by other database access patterns (which generally only need simple SQL anyway).

Abstraction is meant to simplify, and not complicate. Therefore, if you are only solving simple SQL queries, you are not simplying anything since simple SQL statements are .. well .. simple. In fact, it only adds complexities (having to learn a new library) and inconsistencies to the code (raw sql and generated sql mixed).

Furthurmore, you need to be aware of the different SQL syntax, espaping, and other oddities using different SQL engines. I.e., Mysql vs Mssql on how they handle limit clauses.

Sorry if that is discouraging, but good luck reguardless.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: A Shorthand Notation for SQL for Lazy ppl

Post by Christopher »

I agree with John and would say that if you:

1. admit up front that you will only support simpler SQL statements,
2. only make it for one database driver,
3. like OO style SQL generation

then a library like this can be workable for you. Otherwise the law of diminishing returns comes in to play quickly.
(#10850)
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: A Shorthand Notation for SQL for Lazy ppl

Post by max529 »

John Cartwright wrote:I think it boils down to whether your library can efficently handle all SQL statements. Until that day comes, and I've dabbled with my share of SQL generators, it is pointless to partially abstract away from SQL.
I dont think will ever accomplish that.what i tried to accomplish here was to express a Query using PHPs Syntax.And that syntax has got limitations,when it is applied in a database context.
John Cartwright wrote:it is pointless to partially abstract away from SQL. It simply doesn't make sense to me to abstract SQL generator only if I can use it sometimes and can be considered a code smell.
we use clay for sculptures..but why ,for buildings we use it in the form of bricks..?
I see no point in arguing about this anyway.It is a matter of personal preference,and I respect that.
John Cartwright wrote:Abstraction is meant to simplify, and not complicate. Therefore, if you are only solving simple SQL queries, you are not simplying anything since simple SQL statements are .. well .. simple.
by simplyfy,i meant it makes the work done using much shorter constructs.

select `user_name` from `users` where `id`=10

is a simple query a shorter version using the class would be

$db->users(10)->user_name

select `user`.`name` as `u_name` ,`product`.`name` as `p_name` from `user` as `u` join `product` as `p` on `p`.`user_id`=`u`.`id` where `u`.`id`='10'

is also a simple query...a shorter version could be

echo $db->_join->user('u')->product('p')->_end->u_id(10)->u_name
echo $db->_join->user('u')->product('p')->_end->u_id(10)->p_name
John Cartwright wrote: In fact, it only adds complexities (having to learn a new library) and inconsistencies to the code (raw sql and generated sql mixed)
It will defenitly lead to inconsistant code...i have no answers for that...but will you give up curly braces as block delimiters and prefer blocks to be defined using indenting ,so that resulting code will be beautifuly formatted and readable?
and why do we have `mysql_fetch_array` and `mysql_fetch_object` functions..?
Furthurmore, you need to be aware of the different SQL syntax, espaping, and other oddities using different SQL engines. I.e., Mysql vs Mssql on how they handle limit clauses.
My knowledge and experience is limited to MySQL only....
John Cartwright wrote:Sorry if that is discouraging, but good luck reguardless.
It is not discouraging..It just the kind of response I need...

But I would like to know if you had actually gone through the documentation...if you have not you can do it with out downloading the whole thing at http://www.phpclasses.org/browse/file/26411.html

Thanks again for the comments...
Post Reply