oracle / quicksql

A library for generating DDL SQL and entity-relationship-diagrams from Quick SQL code
Universal Permissive License v1.0
53 stars 11 forks source link

Escape character for /values #55

Closed simonhunt8475 closed 8 months ago

simonhunt8475 commented 9 months ago

Would it be possible to have a an escape character for text values? I recently wanted to add data for financial years e.g. 22/23, 23/24 and 24/25, which didn't work. I've had similar issues adding text values with a quote e.g. O'tool.
Examples using '^' as an escape character:

  1. financial_year /values 22^/23, 23^/24, 24^/25

  2. surname vc60 /values O^'Hara, O^'Tool, O^'Meara

  3. start_date /values to_date(^'01-MAR-2024^',^'DD-MON-YYYY^'), to_date(^'01-APR-2025^',^'DD-MON-YYYY^')

vadim-tropashko commented 9 months ago

I'm about to merge a fix where you'll have to use literals -- ordinary string literals or alternative ones. This would take care of the first two cases. The third case is handled with back quote literals, which are translated into SQL verbatim. Your example:

escape /insert 1
    financial_year /check '23/24', `'24/25'`
    surname vc60 /check 'O''Hara', q'{O'Tool}'  
    start_date /check  `to_date('01-APR-2025','DD-MON-YYYY')`

Output:

-- create tables

create table escape (
    id                number default on null to_number(sys_guid(), 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') 
                      constraint escape_id_pk primary key,
    financial_year    varchar2(4000 char) constraint escape_financial_year_ck
                      check (financial_year in ( '23/24','24/25')),
    surname           varchar2(60 char) constraint escape_surname_ck
                      check (surname in ( 'O''Hara',q'{O'Tool}')),
    start_date        date constraint escape_start_date_ck
                      check (start_date in ( to_date('01-APR-2025','DD-MON-YYYY')))
);

-- load data

insert into escape (
    id,
    financial_year,
    surname,
    start_date
) values (
    1,
    '24/25',
    q'{O'Tool}',
    to_date('01-APR-2025','DD-MON-YYYY')
);
neilfernandez commented 8 months ago

Resolved by #56