Book a Demo

Author Topic: DDL generation for column constraints  (Read 4215 times)

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
DDL generation for column constraints
« on: March 02, 2015, 11:19:27 pm »
Hi
I am using EA V12

I am trying to add a column constraint and the generate the ddl for the table
So I used the constraints button on the Table Detail of the tab of the table properties dialog.
I entered the required information and assigned the required column. However, when I generate the DDL the constraint is missing

The db schema I  am trying to replicate is
Code: [Select]
CREATE TABLE JobDetails(
    Job Name TEXT NOT NULL,
    JobType TEXT NOT NULL DEFAULT 'M' CHECK(JobType IN ('M','R'))
)

I have tried to reverse engineer the table but still no constraints.

Can anyone please help me to understand why this is not working

Thanks

Using V12

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: DDL generation for column constraints
« Reply #1 on: March 04, 2015, 11:44:46 am »
Have you tried using the Database Builder (Tools | Database Builder) for this? Someone posted a short while ago that they could not get either method to work, but we have had two more releases since then. Let us know if you have success (or not) with the Database Builder.
Best Regards, Roy

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Re: DDL generation for column constraints
« Reply #2 on: March 04, 2015, 08:14:39 pm »
Reported this as a bug
EA support replied with a fix to the DDL code generation templates for sqlite

Add the following to the DDL Create Table template
Code: [Select]
$tableContent += "\n"
$tableContent += %list="DDLTableConstraint" @separator="\n" @indent="\t" constraintProperty:"TYPE" == "check"%

Replace the contents of the DDL Check Constraint with
Code: [Select]
$comment = "Note: SQLite only supports check constraint defined inline with a column or table definition "
 
%PI=" "%
 
$checkStatement = %constraintProperty:"CHECKSTATEMENT"%
 
%if $checkStatement != ""%
CHECK($checkStatement)
%PI("I", "")%
,
%endIf%

Add the following in ‘DDL Create Table Constraints’
Code: [Select]
and constraintProperty:"TYPE" != "check"

Cheers
Using V12