rickywu-posh / php-sql-parser

Automatically exported from code.google.com/p/php-sql-parser
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Support for parsing the CREATE TABLE SQL statement #33

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I would like to see the parser support the CREATE TABLE statement.

Original issue reported on code.google.com by preston....@gmail.com on 2 Mar 2012 at 6:45

GoogleCodeExporter commented 8 years ago
I would like to have it too :-)

Original comment by pho...@gmx.de on 4 Mar 2012 at 9:05

GoogleCodeExporter commented 8 years ago

Original comment by greenlion@gmail.com on 12 Mar 2012 at 10:13

GoogleCodeExporter commented 8 years ago
You can follow the progress on this issue on 
http://php-sql-parser.googlecode.com/svn/branches/create-table.
Let me some days to think about a solution.

Original comment by pho...@gmx.de on 23 Mar 2012 at 9:50

GoogleCodeExporter commented 8 years ago
Can you provide an example of your CREATE statements? If I implement all 
features of the MySQL statement, I will have to do till Xmas. Which feature 
subset would help you?

Original comment by pho...@gmx.de on 23 Mar 2012 at 10:15

GoogleCodeExporter commented 8 years ago
I tried it, and find useful - but I cant see other things, like "ENGINE", 
"CHARSET", "ROW_FORMAT" in case of showing create table, am I doing something 
wrong?

Original comment by kilobyte...@gmail.com on 16 Feb 2013 at 12:29

GoogleCodeExporter commented 8 years ago
Not sure if i am not using the branch correctly but i still get the same result 
as with the main branch that does not support CREATE.

Lets say i have this create statement:

CREATE TABLE "cachetable01" (
  "sp_id" varchar(240) DEFAULT NULL,
  "ro" varchar(240) DEFAULT NULL,
  "balance" varchar(240) DEFAULT NULL,
  "last_cache_timestamp" varchar(25) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1

It would be awesome if i can just get the field names and the field attributes 
separated. 

Original comment by cmptrwiz...@gmail.com on 19 Sep 2013 at 1:14

GoogleCodeExporter commented 8 years ago
I had started the branch during a travel by rail, but the CREATE TABLE support 
isn't finished yet. There were a lot of open problems.

Original comment by pho...@gmx.de on 25 Oct 2013 at 7:37

GoogleCodeExporter commented 8 years ago
The parser supports now 
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_tbl_name;
See r496. The LIKE must not set inset parenthesis.

Actually I can close the issue, we have CREATE TABLE support now .... LOL.

Original comment by pho...@gmx.de on 9 Nov 2013 at 2:11

GoogleCodeExporter commented 8 years ago
It's r502, I forgot to check-in a file.

Original comment by pho...@gmx.de on 9 Nov 2013 at 2:19

GoogleCodeExporter commented 8 years ago
r515 knows all the table options like ENGINE or CHARACTER SET.

Original comment by pho...@gmx.de on 11 Nov 2013 at 9:04

GoogleCodeExporter commented 8 years ago
r525 generates some column-def output for the example above. But there is still 
a lot to do.

Original comment by pho...@gmx.de on 15 Nov 2013 at 8:43

GoogleCodeExporter commented 8 years ago
Yesterday I had time to implement some things. The parser knows now datatypes 
and columns. There are some errors but the test cases for issue 33 should 
output some helpful thing.

Original comment by pho...@gmx.de on 27 Nov 2013 at 8:13

GoogleCodeExporter commented 8 years ago
I want to parse sql statements from sqlite_master.
They have de form:
CREATE TABLE turma(id text NOT NULL ,
nome text NOT NULL ,
nota1 int NOT NULL ,
nota2 int NOT NULL 
)

The current stable release does that?
I am getting the following error:
[06-Dec-2013 11:31:31] PHP Fatal error:  Uncaught exception 
'UnableToCalculatePositionException' with message 'cannot calculate position of 
id text NOT NULL within ' in 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php:188
Stack trace:
#0 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php(204): 
PositionCalculator->lookForBaseExpression('CREATE TABLE tu...', 101, Array, 0, 
Array)
#1 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php(204): 
PositionCalculator->lookForBaseExpression('CREATE TABLE tu...', 101, Array, 
'sub_tree', Array)
#2 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php(204): 
PositionCalculator->lookForBaseExpression('CREATE TABLE tu...', 101, Array, 
'create-def', Array)
#3 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php(204): 
PositionCalculator->lookForBaseExpression('CREATE TABLE tu...', 101, Array, 
'TABLE', Array)
#4 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php(71): 
PositionCalculator->lookFor in 
/Applications/MAMP/htdocs/PHP-SQL-Parser/classes/position-calculator.php on 
line 188

TIA
jcr

Original comment by zzgli...@gmail.com on 6 Dec 2013 at 11:39

GoogleCodeExporter commented 8 years ago
Hm, the issue has not been fixed. Try to disable the position calculator with 
$parser->parse($sql, false). I have not tested the CREATE statement with the 
position calculator, so there are possible problems.

Original comment by pho...@gmx.de on 6 Dec 2013 at 11:53

GoogleCodeExporter commented 8 years ago
@zzglider

I have to enhance the position calculator with the new ExpressionType 
constants. In your example the type "create-def" is not known within the 
calculator and results in a wrong output. For the CREATE TABLE statement I have 
defined a lot of new types, so after the parser is complete for CREATE TABLE, I 
will come back to the calculator.

Because the parser output still is not finished, it makes no sense to enhance 
the calculator now. Please wait some days or try to implement your own solution 
:-)

Original comment by pho...@gmx.de on 6 Dec 2013 at 12:12

GoogleCodeExporter commented 8 years ago
I have fixed some problems in r623, you can test CREATE TABLE statements in 
your client code. These things are open:

1. union keywords doesn't work
2. partition handling doesn't work
3. CREATE TABLE followed by SELECT doesn't work
4. PositionCalculator doesn't work with CREATE TABLE
5. Creator doesn't know CREATE TABLE statements

All other features should be okay. I would handle point 3 till 5 now, the other 
are a lot of work, they will be done on the next release.

Original comment by pho...@gmx.de on 8 Dec 2013 at 1:29

GoogleCodeExporter commented 8 years ago
Parser should now understand SELECT statements which follow a CREATE TABLE. See 
r631.

Original comment by pho...@gmx.de on 10 Dec 2013 at 12:28

GoogleCodeExporter commented 8 years ago
Parser can calculate the positions for CREATE TABLE statements now. See r725.

Original comment by pho...@gmx.de on 11 Dec 2013 at 12:38

GoogleCodeExporter commented 8 years ago
The current tag 2014-01-08 contains the point 3 till 5 (see comment #16). I'll 
start with partition handling soon.

Original comment by pho...@gmx.de on 8 Jan 2014 at 2:28

GoogleCodeExporter commented 8 years ago
Some PARTITION output is available in r988.

Original comment by pho...@gmx.de on 10 Jan 2014 at 2:56

GoogleCodeExporter commented 8 years ago
There are some problems within the partition-definition, don't use it at the 
moment. Partition-options should be fine.

Original comment by pho...@gmx.de on 23 Jan 2014 at 3:07

GoogleCodeExporter commented 8 years ago
The parser output for partitions and subpartitions have been finished. The 
parser can also calculate the string positions. The Creator can not build the 
clauses at the moment.

From the list above, we still have open the first point, the UNION keyword.

Original comment by pho...@gmx.de on 24 Jan 2014 at 1:59