@@ -227,21 +227,6 @@ ddlAutoKeywords = [
227
227
]
228
228
ddlAutoValue = pp .Or (map (pp .CaselessLiteral , sorted (ddlAutoKeywords , reverse = True )))
229
229
230
- ddlColumn = pp .Group (
231
- ddlName ("name" )
232
- + ddlType ("type" )
233
- + pp .Suppress (pp .Optional (ddlWidth ))
234
- + pp .Suppress (pp .Optional (ddlTimezone ))
235
- + pp .ZeroOrMore (
236
- ddlUnsigned ("isUnsigned" )
237
- | ddlNotNull ("notNull" )
238
- | pp .CaselessLiteral ("null" )
239
- | ddlAutoValue ("hasAutoValue" )
240
- | ddlDefaultValue ("hasDefaultValue" )
241
- | pp .Suppress (ddlExpression )
242
- )
243
- )
244
-
245
230
ddlConstraintKeywords = [
246
231
"CONSTRAINT" ,
247
232
"PRIMARY" ,
@@ -258,6 +243,22 @@ ddlConstraint = pp.Group(
258
243
+ ddlExpression
259
244
).setResultsName ("isConstraint" )
260
245
246
+ ddlColumn = pp .Group (
247
+ ddlName ("name" )
248
+ + ddlType ("type" )
249
+ + pp .Suppress (pp .Optional (ddlWidth ))
250
+ + pp .Suppress (pp .Optional (ddlTimezone ))
251
+ + pp .ZeroOrMore (
252
+ ddlUnsigned ("isUnsigned" )
253
+ | ddlNotNull ("notNull" )
254
+ | pp .CaselessLiteral ("null" )
255
+ | ddlAutoValue ("hasAutoValue" )
256
+ | ddlDefaultValue ("hasDefaultValue" )
257
+ | pp .Suppress (pp .OneOrMore (pp .Or (map (pp .CaselessLiteral , sorted (ddlConstraintKeywords , reverse = True )))))
258
+ | pp .Suppress (ddlExpression )
259
+ )
260
+ )
261
+
261
262
# CREATE TABLE parser
262
263
ddlIfNotExists = pp .Group (
263
264
pp .CaselessLiteral ("IF" ) + pp .CaselessLiteral ("NOT" ) + pp .CaselessLiteral ("EXISTS" )
@@ -403,6 +404,23 @@ def testTable():
403
404
"""
404
405
result = ddlCreateTable .parseString (text , parseAll = True )
405
406
407
+ def testPrimaryKeyAutoIncrement ():
408
+ for text in [
409
+ "CREATE TABLE tab (col INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY)" , # mysql
410
+ "CREATE TABLE tab (col INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT)" , # mysql
411
+ "CREATE TABLE tab (col INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)" , # sqlite
412
+ ]:
413
+ result = ddlCreateTable .parseString (text , parseAll = True )
414
+ assert len (result ) == 1
415
+ table = result [0 ]
416
+ assert table .tableName == "tab"
417
+ assert len (table .columns ) == 1
418
+ column = table .columns [0 ]
419
+ assert not column .isConstraint
420
+ assert column .name == "col"
421
+ assert column .type == "integer"
422
+ assert column .notNull
423
+ assert column .hasAutoValue
406
424
407
425
def testParser ():
408
426
testBoolean ()
@@ -420,6 +438,7 @@ def testParser():
420
438
testMathExpression ()
421
439
testRational ()
422
440
testTable ()
441
+ testPrimaryKeyAutoIncrement ()
423
442
424
443
425
444
# CODE GENERATOR
0 commit comments