[Vtigercrm-developers] Postgres Integration in 4.2.5

Mike Fedyk mfedyk at mikefedyk.com
Tue Mar 14 11:09:55 PST 2006


http://vtiger.fosslabs.com/cgi-bin/trac.cgi/changeset/3775

This changeset shows the format I typically use.  It puts major keywords 
at the beginning of the line and only uses indenting where it is needed 
-- typically when the parts related to the keyword are long.

$query = "SELECT <select list>
                 FROM <table1>
                 INNER JOIN <table2> ON <clause>
                 WHERE <clause1>
                 AND <clause2>
                 AND ( <clause3> || <clause4> 
			|| <clause5>)
		 GROUP BY <clause>
                 ORDER BY <order>";

If there was no <clause5> then there would be no additional 
indentation.  IMO the capitalized keywords is enough for identification.

Comments?

Allan Bush wrote:

>I usually write queries in a slightly more compact format:
>
>$query = "SELECT <select list>
>                 FROM <table1>
>                           INNER JOIN <table2>
>                                     ON <clause>
>                 WHERE <clause1>
>                           AND <clause2>
>                 GROUP BY <clause>
>                 ORDER BY <order>";
>
>The uppercase SQL commands and lower case tables/columns is definitely
>a must though.  Also for short queries I find putting everything in
>one line to be reasonable, as a rule of thumb if the query doesn't
>wrap in an 80 character wide terminal I usually put it in one line.
>
>On 3/14/06, Jeff Kowalczyk <jtk at yahoo.com> wrote:
>  
>
>>Sergio A. Kessler wrote:
>>    
>>
>>>I always write queries like this:
>>>
>>>$query = <<<END
>>>    select
>>>        *
>>>    from
>>>        table1,
>>>        table2,
>>>    where
>>>        foo = ?
>>>        and
>>>        zeta = ?
>>>    group by
>>>        tita
>>>    order by
>>>        zeta
>>>END;
>>>      
>>>
>>I usually don't go the extra mile to indent, but your way is the clearest
>>and most diff-friendly, by far.
>>
>>I do like to capitalize SQL keywords though, could we agree on adding that
>>to the style standard?
>>
>> $query = <<<END
>>     SELECT
>>         *
>>     FROM
>>         table1,
>>         table2,
>>     WHERE
>>         foo = ?
>>         AND
>>         zeta = ?
>>     GROUP BY
>>         tita
>>     ORDER BY
>>         zeta
>> END;
>>
>>+1 on reformatting SQL queries according to a strict style standard.
>>
>>Once consensus is reached on a style, a trac ticket should be created, and
>>each reformat-only commit should include 'refs #XX' in the checkin
>>message
>>
>>_______________________________________________
>>This vtiger.com email is sponsored by Zoho Planner. Still scribbling down your To-Do's on bits of paper & palms of your hands? Try the AJAX enabled, personal organizer online, Zoho Planner for FREE instead! http://zohoplanner.com/?vt
>>
>>    
>>
>
>_______________________________________________
>This vtiger.com email is sponsored by Zoho Planner. Still scribbling down your To-Do's on bits of paper & palms of your hands? Try the AJAX enabled, personal organizer online, Zoho Planner for FREE instead! http://zohoplanner.com/?vt 
>
>  
>



More information about the vtigercrm-developers mailing list