| Propel help for beginners - version 1 [message #30399] |
Wed, 27 June 2007 22:41  |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
Hi all
Partly to give me an excuse to use version 1.0x, and partly to help beginners with the frustration of constructing Propel queries, I have written a small app to convert pseudo-SQL into Propel code. It also gives me a chance to put my new virtual host through its paces 
If anyone would like to, please have a go: simply put in a query, and hit the Generate button. If you have any feedback, feel free to post it here. Is the generated code correct? What would be the most useful first improvements for Propel beginners?
Remember Palestine
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #30506 is a reply to message #30399 ] |
Fri, 29 June 2007 16:08   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
OK, great. The main thing I need to fix is that defining a Criterion and then adding it separately is a bit lengthy when $c->add(column) in some cases will do the trick. But it's a start! When I get a moment here and there, I'll do a bit more on it.
Remember Palestine
|
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #30591 is a reply to message #30399 ] |
Mon, 02 July 2007 10:56   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
That's a good idea, I'll ask them; it would be simpler than trying to run a repository myself!
Remember Palestine
|
|
|
| Re: Propel help for beginners - version 1 [message #30705 is a reply to message #30399 ] |
Tue, 03 July 2007 21:29   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
Fabien has suggested that this ought to become a plugin, and as such has kindly made space available in the plugins section of the symfony SVN server.
I don't have time at present to figure out how to convert it, but hope to at some point. Should anyone like to see the code, or even make some improvements in a non-plugin form, they would be welcome to. The code as it stands is here. Tear it to shreds
[Updated on: Tue, 03 July 2007 21:31] Remember Palestine
|
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #32344 is a reply to message #30399 ] |
Thu, 26 July 2007 22:20   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
seppal: the bug you raised is now fixed, plus I've added support for additional operators. Potential contributors: I've not had a chance to convert it to a plugin yet, will do so soon.
Remember Palestine
|
|
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #32385 is a reply to message #30399 ] |
Fri, 27 July 2007 13:02   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
seppal: no probs 
Piwaï: I did consider that approach, and I'm not totally opposed to it. It's a convention in programming languages that AND and OR have the same mathematical precedence, much like plus and minus. On this basis, they would be evaluated left-to-right. (Edit: I have found that, in SQL Server, AND has a higher precedence.)
However, this change won't be very high on my priority list, as there is an acceptable work-around available (using brackets to indicate precedence) and meanwhile there are plenty of other features I'd like to work on first. Of course once I release the code as a plugin, if someone else wanted this, they would be welcome to code it.
| Quote: | For instance, your parser should be able to transform :
A OR B OR C -> A OR (B OR C) -> parsed into propel code.
|
AFAIK it should cope with both of those already, as they are logically equivalent.
| Quote: | You may do this using recursive functions.
|
Yes, that's how the parser works: one can see how the recursion stores the "subclauses" by ticking the "Show parse tree" option.
[Updated on: Fri, 27 July 2007 14:11] Remember Palestine
|
|
|
| Re: Propel help for beginners - version 1 [message #32475 is a reply to message #30399 ] |
Sun, 29 July 2007 18:25   |
Piwaï Messages: 40 Registered: July 2007 |
Member |
|
|
Just a quick note : you forgot negative numbers .
map_zone.X=0 AND map_zone.Y=-30 AND map_zone.ENABLED=1 LIMIT 1
-->
Error: The subclause 'map_zone.Y=-30' is not valid
It works putting 30 instead of -30.
Anyway, it's not really important since your tool is usefull to get the structure of the code.
Another small bug :
map_zone is parsed Map_zonePeer instead of MapZonePeer .
Another thing to get the code more clear :
$c = new Criteria();
$crit0 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit1 = $c->getNewCriterion(Map_zonePeer::Y, 30);
// Perform AND at level 2 ($crit0 $crit1 )
$crit0->addAnd($crit1);
$crit2 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit3 = $c->getNewCriterion(Map_zonePeer::Y, 30);
// Perform AND at level 2 ($crit2 $crit3 )
$crit2->addAnd($crit3);
$crit4 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit5 = $c->getNewCriterion(Map_zonePeer::Y, 30);
...
Should be :
$c = new Criteria();
$crit0 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit1 = $c->getNewCriterion(Map_zonePeer::Y, 30);
// Perform AND at level 2 ($crit0 $crit1 )
$crit0->addAnd($crit1);
$crit2 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit3 = $c->getNewCriterion(Map_zonePeer::Y, 30);
// Perform AND at level 2 ($crit2 $crit3 )
$crit2->addAnd($crit3);
$crit4 = $c->getNewCriterion(Map_zonePeer::X, 0);
$crit5 = $c->getNewCriterion(Map_zonePeer::Y, 30);
...
It was my first time using it for a real purpose. Very useful (note that the request I wrote to show the bug is not the one I wanted to parse, that would be too easy )
[Updated on: Sun, 29 July 2007 18:35]
|
|
|
|
| Re: Propel help for beginners - version 1 [message #32640 is a reply to message #30399 ] |
Wed, 01 August 2007 01:10   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
Thanks Piwaï - negative numbers issue should now be fixed.
Remember Palestine
|
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #32844 is a reply to message #30399 ] |
Fri, 03 August 2007 22:51   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
Some work has added: a choice to return arrays or ResultSet objects; a choice of ResultSets indexed by number or column name, and whether to include a demo loop in the code. Feel free to post bugs here.
Remember Palestine
|
|
|
| Re: Propel help for beginners - version 1 [message #45433 is a reply to message #30399 ] |
Wed, 13 February 2008 11:14   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
I have fixed Piwaï's bug, and improved the internal string handling in the Criteria Generator. Could people when they get a moment have a click around, to see if I have introduced some new bugs? I have some unit tests but I don't think they are particularly thorough.
I am not sure what to tackle next. I could do some easy ones (such as DISTINCT and LIMIT) but they probably aren't where people are getting stuck. I wonder whether I should consider 2-table joins (1:many) and after that, N-table joins, such as many:many?
One of these days I will add the code to the SVN repository (or if someone who knows how to do that, be my guest - the tarball is earlier in this thread). Perhaps that will encourage contributions from the community 
[Edit: I've just checked, as of today (13 Feb) the tarball is very out of date, I thought I'd fixed that. I recommend nothing is put into SVN for this until I sort that out, which will be ASAP].
[Updated on: Wed, 13 February 2008 11:19] Remember Palestine
|
|
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #45490 is a reply to message #30399 ] |
Thu, 14 February 2008 12:28   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
Thanks very much. This brings to light several bugs, although one item is not yet coded.
1 (a) I pasted your query just as it stands, and it turns out that the generator doesn't like the return characters - doh! That definitely needs to be fixed.
1. (b) Yes, the last clause will be invalid, as only strings and numbers are currently supported. I think this would be a good thing to work on next, as the criterions required are not obvious (requires Criteria::CUSTOM with custom comparison).
2. I simplified this statement to the smallest possible case that would fail, and got this:
regio_stagiair.REGIO_ID IN (26, 27, 30) OR opleiding_niveau_stagiair.OPLEIDING_NIVEAU_ID IN (14, 38, 56)
I believe this fails because, where an IN statement is found, the parser switches round brackets to square ones so that it can differentiate later on precedence brackets from IN brackets, but I think it could be switching the wrong ones. In fact if you use [] brackets for IN clauses (and remove all returns in the string) it will work 
Thanks for the reports, keep 'em coming.
Remember Palestine
|
|
|
| Re: Propel help for beginners - version 1 [message #45696 is a reply to message #30399 ] |
Mon, 18 February 2008 10:19   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
I've fixed problem 2 - regex problem. Next step is to fix 1 (a)!
Remember Palestine
|
|
|
|
|
| Re: Propel help for beginners - version 1 [message #46062 is a reply to message #30399 ] |
Thu, 21 February 2008 15:48   |
halfer Messages: 9535 Registered: January 2006 Location: West Midlands, UK |
Faithful Member |
|
|
I agree, and it's already in the bug list! - down as "Use $c->addAnd() or $c->addOr() rather than Criterions for boolean expressions at the first level of the expression hierarchy".
It's not high priority though, so if you want to give it a go...
Remember Palestine
|
|
|
|
|
|
|
|