Skip to content

Commit efff461

Browse files
Merge pull request #56 from oracle/2024/2/28
Resolves #51, #55, #59
2 parents 73ed4ae + a5100b2 commit efff461

14 files changed

+2311
-2155
lines changed

dist/quick-erd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ class de {
739739
e.rearrangeDiagram(3, !1), this.paperScroller.centerContent();
740740
}
741741
}
742-
const ue = "1.2.6", fe = {
742+
const ue = "1.2.9", fe = {
743743
Diagram: de,
744744
version: ue
745745
};

dist/quick-erd.umd.cjs

+1-1
Large diffs are not rendered by default.

dist/quick-sql.js

+1,719-1,662
Large diffs are not rendered by default.

dist/quick-sql.umd.cjs

+199-201
Large diffs are not rendered by default.

doc/user/quick-sql-grammar.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<!-- markdownlint-disable MD013 -->
5252
| Type | DB Type |
5353
| ------------------------------------------- | ----------------------------- |
54+
| boolean, bool | BOOLEAN |
5455
| num, number | NUMBER |
5556
| int, integer | INTEGER |
5657
| d, date | DATE |
@@ -228,6 +229,14 @@ Generate PL/SQL APIs on all tables for create, insert, update, delete and query.
228229
Adds an additional created, created_by, updated and updated_by columns to every
229230
table created.
230231

232+
### boolean
233+
234+
**Possible Values**: `yn`, `native`
235+
**Default Value**: inferred from #db
236+
237+
Set boolean to legacy char(1) or new 23c native boolean value. This setting has priority
238+
over db:23c, so that the user can override db seting (which influences other functionality)
239+
231240
### compress
232241

233242
**Possible Values**: `true`, `false`
@@ -262,8 +271,8 @@ setting to override this default.
262271

263272
### db
264273

265-
**Possible Values**: `11g`, `12c`, `19c`, `21c`
266-
**Default Value**: `21c`
274+
**Possible Values**: `11g`, `12c`, `19c`, `21c`, `23c`
275+
**Default Value**: `19c`
267276

268277
Specifies the database version the syntax should be compatible with.
269278

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oracle/quicksql",
3-
"version": "1.2.6",
3+
"version": "1.2.9",
44
"description": "Quick SQL to DDL and ERD translator",
55
"main": "./dist/quick-sql.umd.cjs",
66
"module": "./dist/quick-sql.js",

src/ddl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ export const quicksql = (function () {
2020
createdbycol: {label: 'Created By Column Name', value: 'created_by'},
2121
updatedcol: {label: 'Updated Column Name', value: 'updated'},
2222
updatedbycol: {label: 'Updated By Column Name', value: 'updated_by'},
23+
boolean: {label: 'Boolean Datatype', value:'not set',check:['yn','native']},
2324
genpk: {label:'Auto Primary Key', value:'yes',check:['yes','no']},
2425
semantics: {label: 'Character Strings',value:'CHAR',check:['BYTE','CHAR','Default']},
2526
language: {label: 'Data Language', value:'EN',check:['EN','JP','KO']},
2627
datalimit: {label: 'Data Limit Rows', value: 10000},
2728
date: {label: 'Date Data Type', value:'DATE',check:['DATE','TIMESTAMP',tswtz,tswltz]},
28-
db: {label: 'DB', value:'no',check:['not used']},
29+
db: {label: 'Database Version', value:'not set'},
2930
dv: {label: 'Duality View', value:'no',check:['yes','no']}, // switched default to 'no' until thorough development&testig
3031
drop: {label: 'Include Drops', value:'no',check:['yes','no']},
3132
editionable: {label: 'Editinable', value:'no',check:['yes','no']},
@@ -510,6 +511,7 @@ quicksql.version = qsql_version;
510511
quicksql.toDDL = toDDL;
511512
quicksql.toERD = toERD;
512513
quicksql.toErrors = toErrors;
513-
quicksql.fromJSON = fromJSON;
514+
quicksql.fromJSON = fromJSON;
515+
quicksql.lexer = lexer;
514516

515517
export default quicksql;

src/errorMsgs.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ const findErrors = (function () {
3333
const node = descendants[i];
3434
if( ddl.optionEQvalue('genpk', true) && descendants[i].parseName() == 'id' ) {
3535
const depth = node.content.toLowerCase().indexOf('id');
36-
ret.push(new SyntaxError( messages.duplicateId, new Offset(node.line, depth) ));
36+
ret.push(new SyntaxError( messages.duplicateId, new Offset(node.line, depth), new Offset(node.line, depth+2) ));
3737
continue;
3838
}
3939
const src2 = node.src[2];
4040
if( 2 < node.src.length && src2.value == '-' ) {
4141
const depth = src2.begin;
42-
ret.push(new SyntaxError( messages.invalidDatatype, new Offset(node.line,depth) ));
42+
ret.push(new SyntaxError( messages.invalidDatatype, new Offset(node.line,depth), new Offset(node.line, depth+2) ));
4343
continue;
4444
}
4545
const src1 = node.src[1];
@@ -66,7 +66,8 @@ const findErrors = (function () {
6666
if( tbl == null ) {
6767
ret.push( new SyntaxError(
6868
messages.undefinedObject+chunks[j].value,
69-
new Offset(node.line, chunks[j].begin)
69+
new Offset(node.line, chunks[j].begin),
70+
new Offset(node.line, chunks[j].begin+chunks[j].value.length)
7071
));
7172
}
7273
}
@@ -88,7 +89,8 @@ const findErrors = (function () {
8889
if( tbl == null ) {
8990
ret.push( new SyntaxError(
9091
messages.undefinedObject+node.src[pos].value,
91-
new Offset(node.line, node.src[pos].begin)
92+
new Offset(node.line, node.src[pos].begin),
93+
new Offset(node.line, node.src[pos].begin+node.src[pos].value.length)
9294
));
9395
}
9496
}

src/lexer.js

+10-52
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ var lexer = (function(){
1111
this.toString = function() {
1212
return '{type:'+type+',value:'+value+'}';
1313
};
14+
this.getValue = function() {
15+
if( this.value == null || this.value.length < 2 )
16+
return this.value;
17+
if( this.value.charAt(0) == '`' ) {
18+
let ret = this.value.substring(1,this.value.length-1);
19+
ret = "q'[" + ret + "]'";
20+
}
21+
return this.value;
22+
};
1423
this.isStandardLiteral = function () {
1524
// fast fail
1625
if( this.value.length < 2 )
@@ -77,7 +86,7 @@ var lexer = (function(){
7786
var line = 0;
7887
var col = 0;
7988
for( var i = 0; i < chunks.length; i++ ) {
80-
var token = chunks[i]/*.intern()*/;
89+
var token = chunks[i];
8190
var last = null;
8291

8392
if ( ret.length > 0 )
@@ -95,22 +104,6 @@ var lexer = (function(){
95104
}
96105
pos += token.length;
97106
// comments
98-
99-
if ( isWrapped ) { // nuke everything between WRAPPED and /
100-
if ( '/'==token && last != null && '\n'==last.value ) {
101-
var marker = '"/"';
102-
ret.push( new LexerToken( marker, pos-marker.length, pos, 'identifier', line, col ) );
103-
isWrapped = false;
104-
continue;
105-
} else if ( '\n' == token ) {
106-
ret.push( new LexerToken(token, pos-token.length, pos, 'ws', line, col ) );
107-
continue;
108-
} else {
109-
if ( '\n' == last.value )
110-
last.value = '?';
111-
continue;
112-
}
113-
}
114107
if( last != null && last.type == 'comment' && (last.value.lastIndexOf('*/')!=last.value.length-2 || last.value == '/*/') ) {
115108
if( '*' == token || '/' == token )
116109
last.value = last.value + token;
@@ -173,20 +166,6 @@ var lexer = (function(){
173166
last.type = 'line-comment';
174167
continue;
175168
}
176-
if( ('REM'==token.toUpperCase() || 'REMA'==token.toUpperCase() || 'REMAR'==token.toUpperCase() || 'REMARK'==token.toUpperCase()
177-
||'PRO'==token.toUpperCase() || 'PROM'==token.toUpperCase() || 'PROMP'==token.toUpperCase() || 'PROMPT'==token.toUpperCase()
178-
) && (last == null || ('\n' == last.value||'\r' == last.value)) ) {
179-
ret.push(new LexerToken(token, pos-token.length, -9, 'line-comment', line, col));
180-
continue;
181-
}
182-
if( ('SODA'==token.toUpperCase() ) && (last == null || ('\n' == last.value||'\r' == last.value)) ) {
183-
ret.push(new LexerToken(token, pos-token.length, -9, 'dbtools-command', line, col));
184-
continue;
185-
}
186-
/*if( "@".equalsIgnoreCase(token) && (last == null || "\n" == last.value||"\r" == last.value ) ) { //$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
187-
ret.push(new LexerToken(token, pos-1, -11, "identifier"));
188-
continue;
189-
}*/
190169

191170
if( last != null && last.type == 'identifier' && last.end == -11 && last.value.indexOf('@')==0 && !('\n' == token||'\r' == token) ) { //$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
192171
last.value = last.value + token;
@@ -243,27 +222,6 @@ var lexer = (function(){
243222
}
244223
continue;
245224
}
246-
/* TODO:
247-
* if( "WRAPPED" == token.toUpperCase() && last != null ) {
248-
Iterator<LexerToken> descIter = ret.descendingIterator();
249-
boolean sawId = false;
250-
while(descIter.hasNext()) {
251-
LexerToken t = descIter.next();
252-
if( sawId && ("PROCEDURE" == t.value.toUpperCase() || "FUNCTION" == t.value.toUpperCase() || "TRIGGER" == t.value.toUpperCase() ||
253-
"TYPE" == t.value.toUpperCase() || "PACKAGE"==t.value.toUpperCase() ||
254-
"BODY" == t.value.toUpperCase() ) {
255-
isWrapped = true;
256-
break;
257-
}
258-
if( t.type == "ws" || t.type == "comment" )
259-
continue;
260-
if( t.type == "identifier" ) {
261-
sawId = true;
262-
continue;
263-
}
264-
break;
265-
}
266-
}*/
267225

268226
var type = 'identifier';
269227

src/sample.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Chance from 'chance';
2+
//import lexer from './lexer.js';
23

34

45
export function generateSample( lTable, lColumn, lType, values ) {
@@ -11,15 +12,17 @@ export function generateSample( lTable, lColumn, lType, values ) {
1112
if( values != null && 0 < values.length ) {
1213
let min = 0;
1314
let max = values.length;
14-
var optQuote = '\'';
15-
if( type.startsWith('INTEGER') || type.startsWith('NUMBER') || type.startsWith('DATE') )
16-
optQuote = '';
1715
let value = values[Math.floor(seededRandom() * (max - min)) + min];
18-
if( value.toLowerCase && value.toLowerCase() == 'null' )
19-
optQuote = '';
20-
if( value.replaceAll )
21-
value = value.replaceAll('\'','\'\'');
22-
return optQuote+value+optQuote;
16+
if( !type.startsWith('INTEGER') && !type.startsWith('NUMBER') && !type.startsWith('DATE')
17+
&& (!value.toLowerCase || value.toLowerCase() != 'null')
18+
&& ( !value.charAt || (value.charAt(0) != 'q' && value.charAt(1) != '\'') )
19+
) {
20+
if( value.charAt && value.charAt(0) == '\'' )
21+
value = value.substring(1,value.length-1);
22+
value = value.replaceAll('\'','\'\'');
23+
value = "'"+value+"'";
24+
}
25+
return value;
2326
}
2427

2528
if( column == 'NAME' && 0 <= table.indexOf('DEPARTMENT') ) {

0 commit comments

Comments
 (0)