osalabs / osafw-php

Business Applications Web Framework, PHP
MIT License
3 stars 3 forks source link

SQL formatting convetion: UPPERCASE #21

Closed vladsavchuk closed 5 years ago

vladsavchuk commented 6 years ago

Should we UPPERCASE all SQL key words in code? SELECT, WHERE, ORDER BY etc.

$row = $this->db->row("select * from ".$this->table_name." where id=".$this->db->quote($id));
$row = $this->db->row("SELECT * FROM ".$this->table_name." WHERE id=".$this->db->quote($id));
$sql = "select {$sql_select} where {$sql_where} group by {$sql_group} order by {$sql_order}";
$sql = "SELECT {$sql_select} WHERE {$sql_where} GROUP BY {$sql_group} ORDER BY {$sql_order}";

I find UPPERCASE formatting is more readable especially with huge queries. It's also better when reading logs in terminal without any highlighting:

select lcc.*, c.iname as 'contacts.iname', c.status as 'contacts.status',
ca.iname as 'cars.iname', ca.iyear as 'cars.iyear', ca.licenseno as 'cars.licenseno', ca.status as 'cars.status'
from link_cars_contacts lcc
left join contacts c on c.id = lcc.contacts_id
left join cars ca on ca.id = lcc.cars_id
where lcc.cars_id='473'
order by lcc.itype
SELECT lcc.*, c.iname AS 'contacts.iname', c.status AS 'contacts.status',
ca.iname AS 'cars.iname', ca.iyear AS 'cars.iyear', ca.licenseno AS 'cars.licenseno', ca.status AS 'cars.status'
FROM link_cars_contacts lcc
LEFT JOIN contacts c ON c.id = lcc.contacts_id
LEFT JOIN cars ca ON ca.id = lcc.cars_id
WHERE lcc.cars_id='473'
ORDER BY lcc.itype
vladsavchuk commented 6 years ago

Also, the Atom editor respects UPPERCASE SQL-statements for syntax highlighting.

osalabs commented 6 years ago

well, it's up to developer which case to use, but I am OK to have all framework code UPPERCASE by default. Could you change it in all files and submit pull request (low priority)?

vladsavchuk commented 6 years ago

Okay, I'll do it next week and submit a pull request.