@@ -447,19 +447,23 @@ let tree = (function(){
447447 parentPref = parent . parseName ( ) + '_' ;
448448 const parent_child = concatNames ( parentPref , this . parseName ( ) ) ;
449449
450- let values = this . getValues ( 'check' ) ;
451- values = '(' + values + ')' ;
452450 let offset = tab ;
453451 if ( parent != null )
454452 offset = ' ' . repeat ( parent . maxChildNameLen ( ) ) ;
455- if ( this . children != null && 0 < this . children . length ) { // table level
456- ret += tab + 'constraint ' + concatNames ( ddl . objPrefix ( ) , parent_child , '_ck' ) ;
457- ret += ' check ' + values + ',\n' ;
458- } else {
459- ret += ' constraint ' + concatNames ( ddl . objPrefix ( ) , parent_child , '_ck' ) + '\n' ;
460- ret += tab + tab + offset + 'check (' + this . parseName ( ) + ' in ' + values + ')' ;
453+ let constr = this . getGeneralConstraint ( ) ;
454+ if ( constr != null ) {
455+ if ( this . children != null && 0 < this . children . length ) { // (general) table level constraint
456+ ret += tab + 'constraint ' + concatNames ( ddl . objPrefix ( ) , parent_child , '_ck' ) ;
457+ ret += ' check ' + constr + ',\n' ;
458+ } else { // general column level constraint
459+ ret += ' constraint ' + concatNames ( ddl . objPrefix ( ) , parent_child , '_ck' ) + '\n' ;
460+ ret += tab + tab + offset + 'check ' + constr + '' ;
461+ }
462+ return ret ;
461463 }
462-
464+ const values = this . getValues ( 'check' ) ;
465+ ret += ' constraint ' + concatNames ( ddl . objPrefix ( ) , parent_child , '_ck' ) + '\n' ;
466+ ret += tab + tab + offset + 'check (' + this . parseName ( ) + ' in (' + values + '))' ;
463467 }
464468 return ret ;
465469 }
@@ -564,9 +568,27 @@ let tree = (function(){
564568 return null ;
565569 } ;
566570
571+ this . getGeneralConstraint = function ( ) { // parenthesized constraint to return verbatim, e.g. c1 /check (c1 in ('A','B','C'))
572+ let from = this . indexOf ( 'check' ) ;
573+ if ( 0 < from && this . src [ from - 1 ] . value == '/' &&
574+ ( this . src [ from + 1 ] . value == '(' || this . src [ from + 1 ] . value . toLowerCase ( ) == 'not' )
575+ ) {
576+ let i = from + 2
577+ for ( ; i < this . src . length && this . src [ i ] . value != '/' && this . src [ i ] . value != '[' ; )
578+ i ++ ;
579+ let ret = this . content . substring ( this . src [ from + 1 ] . begin , this . src [ i - 1 ] . end ) ;
580+ if ( ret . charAt ( 0 ) != '(' )
581+ ret = '(' + ret + ')' ;
582+ return ret ;
583+ }
584+
585+ return null ;
586+ }
587+
567588 this . listValues = function ( check_or_values ) {
568589 let ret = [ ] ;
569590 let from = this . indexOf ( check_or_values ) ;
591+
570592 let separator = ' ' ; // e.g. status /check open completed closed /values open, open, open, open, closed, completed
571593 for ( let i = from + 1 ; i < this . src . length && this . src [ i ] . value != '/' && this . src [ i ] . value != '[' ; i ++ )
572594 if ( this . src [ i ] . value == ',' ) {
0 commit comments