oracle / quicksql

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

Quoter identifiers in QSQL are concatenated incorrectly #21

Closed vadim-tropashko closed 10 months ago

vadim-tropashko commented 10 months ago

Quoted identifiers example from small_tests.js:

output = quicksql.toDDL( 
        `"Test" 
            "CamelCase"
            x   [coMment]  
            2   --coMment2  
    `);

//console.log(output);
assert( " 0 < output.indexOf('create table \"Test\"') " );                                     
//assert( " 0 < output.indexOf('Test_id_pk') " );                                     
assert( " 0 < output.indexOf('\"CamelCase\"') " );                                     
assert( " 0 < output.indexOf('comment on column \"Test\".x is ') " );                                     
assert( " 0 < output.indexOf('comment on column \"Test\".x2 is ') " );   

The second, commented out assertion is broken. The full output is:

create table "Test" (
    id             number generated by default on null as identity
                   constraint "Test"_id_pk primary key,   -- broken
    "CamelCase"    varchar2(4000 char),
    x              varchar2(4000 char),
    x2             varchar2(4000 char)
);

comment on column "Test".x is 'coMment';

Presumably, there is a bug everywhere in the code where the name is concatenated. I suggest introducing a dedicated concat method which would handle quoted identifiers correctly.