From b50cc454b62e88bf03d681f731cdd98c23a42ffb Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 9 Apr 2022 21:47:21 +0200 Subject: [PATCH] Fix constraints handling in ddl2cpp (#437) Constraints got interpreted as (unknown) data types. This change should fix this most cases (simple test case added). --- scripts/ddl2cpp | 2 +- tests/scripts/ddl2cpp_sample_good.sql | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index b7d5c1df..e0b580fe 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -259,7 +259,7 @@ ddlCreateTable = pp.Group( + pp.Suppress(pp.Optional(ddlIfNotExists)) + ddlName.setResultsName("tableName") + ddlLeft - + pp.Group(pp.delimitedList(ddlColumn | pp.Suppress(ddlConstraint))).setResultsName( + + pp.Group(pp.delimitedList(pp.Suppress(ddlConstraint) | ddlColumn)).setResultsName( "columns" ) + ddlRight diff --git a/tests/scripts/ddl2cpp_sample_good.sql b/tests/scripts/ddl2cpp_sample_good.sql index b478567c..ac6b048c 100644 --- a/tests/scripts/ddl2cpp_sample_good.sql +++ b/tests/scripts/ddl2cpp_sample_good.sql @@ -28,12 +28,13 @@ CREATE TABLE tab_foo ( delta varchar(255), _epsilon bigint, - `omega` double + `omega` double, + CONSTRAINT uc_delta UNIQUE (delta, _epsilon) ); CREATE TABLE tab_bar ( - alpha bigint AUTO_INCREMENT, + alpha bigint AUTO_INCREMENT RRIMARY_KEY, beta varchar(255) NULL DEFAULT "", gamma bool NOT NULL, delta int