Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.7.0

Bug #4054 Parsing create: int(11) not recognized as type
Submitted: 2005-04-04 14:53 UTC
From: epte at ruffdogs dot com Assigned: epte
Status: Closed Package: SQL_Parser
PHP Version: 4.3.8 OS: Linux/Mandrake +pkgsrc
Roadmaps: (Not assigned)    

 [2005-04-04 14:53 UTC] epte at ruffdogs dot com
Description: ------------ The following code errors: Reproduce code: --------------- $sql = " CREATE TABLE schedules ( id int(11) NOT NULL auto_increment, target_id int(11) NOT NULL default '0', target_order int(11) NOT NULL default '0', minute varchar(255) NOT NULL default '', hour varchar(255) NOT NULL default '', dom varchar(255) NOT NULL default '', month varchar(255) NOT NULL default '', dow varchar(255) NOT NULL default '', keepdays int(11) default NULL, keepMB int(11) default NULL, simple tinyint(4) NOT NULL default '0', disabled tinyint(4) NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM;"; $_SQLParser = new SQL_Parser(NULL, 'MySQL'); $parseRes = $_SQLParser->parse($sql); Expected result: ---------------- Not sure yet ;-) Actual result: -------------- Parse error: Expected a valid type on line 13 id int(11) NOT NULL auto_increment, ^ found: "int(11)"


 [2005-04-04 15:08 UTC] epte at ruffdogs dot com
Hrm... It seems that my patch for lexing functions is messing with field types like 'int(11)'. It is unfortunate that field types and functions are lexical homonymns in SQL. There are three approaches I can think of to fix this: 1) On the lexical level, remember if we are in a CReATE statement or not. CREATE statements could then generate different lexical tokens than other statements. 2) expect an ident or function (consider 'int(11)' a function 3) Same as #1, but know rather that one is in a field-description list. #1 and #3 are unfortunate because the lexer shouldn't have to know any SQL language syntax to do its job. #2 is unfortunate because 'int(11)' really isn't a function. Maybe determination of 'function' is a syntactic decision rather than a lexical one...
 [2005-04-04 15:15 UTC] epte at ruffdogs dot com
Yeah, I'm thinking that 'function' is a syntactic decision. So, a function is ident + arglist A field type is ident + arglist (with exactly one numeric argument) But this brings up the whole question I was mulling over when doing functions: "What about recursion"? The lexer isn't really able to handle recursive tokens, and probably shouldn't. Is the question "What does this parenthesis contain?" a syntactic question, then?
 [2005-04-04 15:25 UTC] epte at ruffdogs dot com
Or rather, that a field type is an ident + arglist (with exactly one numeric argument) within a field list
 [2005-04-04 17:06 UTC] epte at ruffdogs dot com
So 'arglist' is probably also syntactic rather than lexical (since it must have the ability to be recursive).
 [2005-04-05 16:35 UTC] epte at ruffdogs dot com
I removed my function stuff on the lexical level, and 'int(11)' detected fine.
 [2006-12-23 20:12 UTC] cellog (Greg Beaver)
assigning to bug fixer for statistical purposes