Skip Menu |

This queue is for tickets about the SQL-Beautify CPAN distribution.

Report information
The Basics
Id: 52844
Status: open
Priority: 0/
Queue: SQL-Beautify

People
Owner: Nobody in particular
Requestors: lecar_red [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.03
Fixed in: 0.03



Subject: Improperly formats data type declarations and functions
Data type declarations get reformatted on multiple lines. And I would expect the primary key declaration to be on the same line. Input: create table department ( dept_id smallint unsigned not null auto_increment, name varchar(20) not null, constraint pk_department primary key (dept_id) ) Output: create table department ( dept_id smallint unsigned not null auto_increment, name varchar ( 20 ) not null, constraint pk_department primary key ( dept_id ) ) Expected: create table department ( dept_id smallint unsigned not null auto_increment, name varchar(20) not null, constraint pk_department primary key (dept_id) ) Or a common function 'count' gets formatted very oddly. Input: select count(*) from department Output: select count ( * ) from department Expected: select count(*) from department Looking at making a patch I think the best way to do it would be to special case the parans that add new lines after a certain set of SQL keywords. I think SELECT IN FROM but I'm not sure how to catch the CREATE case. It might require a state flag (_in_create) or something similar. What do you think? I can put together another patch with this update and test cases if you'd like.
On Wed Dec 16 15:11:44 2009, lecar_red@yahoo.com wrote: Show quoted text
> Looking at making a patch I think the best way to do it would be to > special case the parans that add new lines after a certain set of SQL > keywords. I think SELECT IN FROM but I'm not sure how to catch the > CREATE case. It might require a state flag (_in_create) or something > similar.
Adding extra conditionals for parens are a bit tough, i wrote some test cases and found there to be lots of edge cases. count(*) and varchar(xx) cannot have spaces but select ( xxx ) and primary key (id) should have spaces. Also, I've found that keeping track of the indent level along with the new line stuff is a bit of pain. I have a patch (but its a bit rough) and some test cases, let me know if you'd like both or just the test cases. I've tried to add some more complex examples with update, insert and create options. This required me to add some more keywords to the constant. BTW, I've been doing most of the work of a git clone so I have your more recent changes. Thanks again for a sweet module, glad I didn't have start it from scratch!