@@ -44,7 +44,7 @@ export type TableStructure = {
4444 size : number ;
4545 columns : ColumnStructure [ ] ;
4646 completeSQL : string ;
47- type : ( "table" | "view" ) ;
47+ type : ( "table" | "view" ) ;
4848}
4949
5050export type DatabaseStructure = {
@@ -65,16 +65,16 @@ export class DatabaseTool {
6565
6666 databaseStructure : DatabaseStructure ;
6767
68- constructor ( private main : MainBase ) {
68+ constructor ( private main : MainBase ) {
6969
7070 }
7171
7272 initializeWorker ( template : Uint8Array , queries : string [ ] , callbackAfterInitializing ?: ( errors : string [ ] ) => void ,
7373 callbackAfterRetrievingStructure ?: ( ) => void ) {
74-
74+
7575 this . main . getWaitOverlay ( ) . show ( 'Bitte warten, die Datenbank wird initialisiert...' ) ;
76-
77- if ( this . worker != null ) {
76+
77+ if ( this . worker != null ) {
7878 this . worker . terminate ( ) ;
7979 }
8080
@@ -89,7 +89,7 @@ export class DatabaseTool {
8989 // }
9090
9191 // @ts -ignore
92- if ( window . jo_doc ) {
92+ if ( window . jo_doc ) {
9393 // In embedded mode inside iframe the calling domain is different, so web workers are not supported
9494 // because of browser security policy.
9595 // Use simulated worker instead.
@@ -134,21 +134,21 @@ export class DatabaseTool {
134134
135135 } ;
136136
137- if ( queries == null ) queries = [ ] ;
137+ if ( queries == null ) queries = [ ] ;
138138 queries = queries . slice ( ) ;
139139 queries . unshift ( "PRAGMA foreign_keys = OFF;" )
140140 queries . push ( "PRAGMA foreign_keys = ON;" )
141141 let queryCount = queries . length ;
142142
143143 let execQuery = ( ) => {
144144 if ( queries . length > 0 ) {
145- this . main . getWaitOverlay ( ) . setProgress ( `${ Math . round ( ( 1 - queries . length / queryCount ) * 100 ) + " %" } ` )
145+ this . main . getWaitOverlay ( ) . setProgress ( `${ Math . round ( ( 1 - queries . length / queryCount ) * 100 ) + " %" } ` )
146146 let query = queries . shift ( ) ;
147147 that . executeQuery ( query , ( result ) => {
148148 execQuery ( ) ;
149149 } , ( error ) => {
150150 errors . push ( "Error while setting up database: " + error + ", query: " + query ) ;
151- console . log ( { "error" : "Error while setting up database: " + error , "query" : query } ) ;
151+ console . log ( { "error" : "Error while setting up database: " + error , "query" : query } ) ;
152152 console . log ( )
153153 execQuery ( ) ;
154154 } )
@@ -220,7 +220,7 @@ export class DatabaseTool {
220220
221221 let id = this . queryId ++ ;
222222
223- this . querySuccessCallbacksMap . set ( id , ( results ) => { successCallback ( results [ 0 ] . buffer ) } ) ;
223+ this . querySuccessCallbacksMap . set ( id , ( results ) => { successCallback ( results [ 0 ] . buffer ) } ) ;
224224 this . queryErrorCallbackMap . set ( id , errorCallback ) ;
225225
226226 this . worker . postMessage ( {
@@ -231,7 +231,7 @@ export class DatabaseTool {
231231
232232 }
233233
234-
234+
235235
236236 getDirectoryEntries ( callback : ( entries : DatabaseDirectoryEntry [ ] ) => void ) {
237237 if ( this . databaseDirectoryEntries != null ) {
@@ -254,7 +254,7 @@ export class DatabaseTool {
254254 this . executeQuery ( sql , ( result ) => {
255255 let sql1 = "" ;
256256 let values = result [ 0 ] ?. values ;
257- let types : ( "table" | "view" ) [ ] = values ?. map ( value => value [ 2 ] ) ;
257+ let types : ( "table" | "view" ) [ ] = values ?. map ( value => value [ 2 ] ) ;
258258
259259 values ?. forEach ( value => sql1 += `PRAGMA table_info("${ value [ 0 ] } ");\nPRAGMA foreign_key_list("${ value [ 0 ] } ");\nselect count(*) from "${ value [ 0 ] } ";\n\n` )
260260
@@ -267,7 +267,7 @@ export class DatabaseTool {
267267
268268 callback ( that . databaseStructure ) ;
269269
270- } , ( error ) => {
270+ } , ( error ) => {
271271 console . log ( error ) ;
272272 that . databaseStructure = { tables : [ ] } ;
273273 callback ( that . databaseStructure ) ;
@@ -277,12 +277,17 @@ export class DatabaseTool {
277277 callback ( that . databaseStructure ) ;
278278 }
279279
280- } , ( error ) => { console . log ( error ) } ) ;
280+ } , ( error ) => {
281+ console . log ( error ) ;
282+ alert ( "Error retrieving database structure: " + error ) ;
283+ that . databaseStructure = { tables : [ ] } ;
284+ callback ( that . databaseStructure ) ;
285+ } ) ;
281286
282287
283288 }
284289
285- parseDatabaseStructure ( tables : QueryResult [ ] , columns : QueryResult [ ] , types : ( "table" | "view" ) [ ] ) : DatabaseStructure {
290+ parseDatabaseStructure ( tables : QueryResult [ ] , columns : QueryResult [ ] , types : ( "table" | "view" ) [ ] ) : DatabaseStructure {
286291 this . databaseStructure = {
287292 tables : [ ]
288293 } ;
@@ -328,11 +333,11 @@ export class DatabaseTool {
328333
329334 let enumValues : string [ ] = [ ] ;
330335
331- if ( type . indexOf ( "Enum" ) >= 0 ) {
336+ if ( type . indexOf ( "Enum" ) >= 0 ) {
332337 let rs = `"${ name } " ${ type } .* check\\("${ name } " in \\((.*)\\)\\)` ;
333338 let regEx = new RegExp ( rs ) ;
334339 let match = tableSQL . match ( regEx ) ;
335- if ( match != null ) {
340+ if ( match != null ) {
336341 enumValues = match [ 1 ] . split ( ", " ) ;
337342 }
338343 }
@@ -372,7 +377,7 @@ export class DatabaseTool {
372377 if ( cs . referencesRawData != null ) {
373378 let table = tableNameToStructureMap . get ( cs . referencesRawData [ 2 ] ?. toLocaleLowerCase ( ) ) ;
374379 // SQlite doesn't remove foreign key references to columns of a dropped table
375- if ( table == null ) continue ;
380+ if ( table == null ) continue ;
376381 let column = table . columns . find ( c => c . name . toLocaleLowerCase ( ) == cs . referencesRawData [ 4 ] . toLocaleLowerCase ( ) ) ;
377382 cs . references = column ;
378383 }
0 commit comments