@@ -79,18 +79,29 @@ IDB.showDatabases = function (like, cb) {
7979
8080IDB . createDatabase = async function ( ixdbid , args , ifnotexists , dbid , cb ) {
8181 const found = await _databaseExists ( ixdbid ) . catch ( err => {
82- if ( cb ) cb ( null , err ) ;
82+ if ( cb ) {
83+ cb ( null , err ) ;
84+ return null ;
85+ }
8386 throw err ;
8487 } ) ;
8588
89+ if ( found === null ) {
90+ return ; // Error already handled via callback
91+ }
92+
8693 if ( found ) {
8794 if ( ifnotexists ) {
8895 cb && cb ( 0 ) ;
8996 } else {
9097 const err = new Error (
9198 `IndexedDB: Cannot create new database "${ ixdbid } " because it already exists`
9299 ) ;
93- if ( cb ) cb ( null , err ) ;
100+ if ( cb ) {
101+ cb ( null , err ) ;
102+ return ;
103+ }
104+ throw err ;
94105 }
95106 } else {
96107 const request = indexedDB . open ( ixdbid , 1 ) ;
@@ -103,10 +114,17 @@ IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
103114
104115IDB . dropDatabase = async function ( ixdbid , ifexists , cb ) {
105116 const found = await _databaseExists ( ixdbid ) . catch ( err => {
106- if ( cb ) cb ( null , err ) ;
117+ if ( cb ) {
118+ cb ( null , err ) ;
119+ return null ;
120+ }
107121 throw err ;
108122 } ) ;
109123
124+ if ( found === null ) {
125+ return ; // Error already handled via callback
126+ }
127+
110128 if ( found ) {
111129 const request = indexedDB . deleteDatabase ( ixdbid ) ;
112130 request . onsuccess = ( ) => {
@@ -116,26 +134,39 @@ IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
116134 if ( ifexists ) {
117135 cb && cb ( 0 ) ;
118136 } else {
119- cb &&
137+ if ( cb ) {
120138 cb (
121139 null ,
122- new Error ( `IndexedDB: Cannot drop new database "${ ixdbid } " because it does not exist' ` )
140+ new Error ( `IndexedDB: Cannot drop database "${ ixdbid } " because it does not exist` )
123141 ) ;
142+ return ;
143+ }
144+ throw new Error ( `IndexedDB: Cannot drop database "${ ixdbid } " because it does not exist` ) ;
124145 }
125146 }
126147} ;
127148
128149IDB . attachDatabase = async function ( ixdbid , dbid , args , params , cb ) {
129150 const found = await _databaseExists ( ixdbid ) . catch ( err => {
130- if ( cb ) cb ( null , err ) ;
151+ if ( cb ) {
152+ cb ( null , err ) ;
153+ return null ;
154+ }
131155 throw err ;
132156 } ) ;
133157
158+ if ( found === null ) {
159+ return ; // Error already handled via callback
160+ }
161+
134162 if ( ! found ) {
135163 const err = new Error (
136164 `IndexedDB: Cannot attach database "${ ixdbid } " because it does not exist`
137165 ) ;
138- if ( cb ) cb ( null , err ) ;
166+ if ( cb ) {
167+ cb ( null , err ) ;
168+ return ;
169+ }
139170 throw err ;
140171 }
141172
@@ -172,15 +203,25 @@ IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
172203IDB . createTable = async function ( databaseid , tableid , ifnotexists , cb ) {
173204 const ixdbid = alasql . databases [ databaseid ] . ixdbid ;
174205 const found = await _databaseExists ( ixdbid ) . catch ( err => {
175- if ( cb ) cb ( null , err ) ;
206+ if ( cb ) {
207+ cb ( null , err ) ;
208+ return null ;
209+ }
176210 throw err ;
177211 } ) ;
178212
213+ if ( found === null ) {
214+ return ; // Error already handled via callback
215+ }
216+
179217 if ( ! found ) {
180218 const err = new Error (
181219 'IndexedDB: Cannot create table in database "' + ixdbid + '" because it does not exist'
182220 ) ;
183- if ( cb ) cb ( null , err ) ;
221+ if ( cb ) {
222+ cb ( null , err ) ;
223+ return ;
224+ }
184225 throw err ;
185226 }
186227
@@ -206,15 +247,25 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
206247IDB . dropTable = async function ( databaseid , tableid , ifexists , cb ) {
207248 const ixdbid = alasql . databases [ databaseid ] . ixdbid ;
208249 const found = await _databaseExists ( ixdbid ) . catch ( err => {
209- if ( cb ) cb ( null , err ) ;
250+ if ( cb ) {
251+ cb ( null , err ) ;
252+ return null ;
253+ }
210254 throw err ;
211255 } ) ;
212256
257+ if ( found === null ) {
258+ return ; // Error already handled via callback
259+ }
260+
213261 if ( ! found ) {
214262 const err = new Error (
215263 'IndexedDB: Cannot drop table in database "' + ixdbid + '" because it does not exist'
216264 ) ;
217- if ( cb ) cb ( null , err ) ;
265+ if ( cb ) {
266+ cb ( null , err ) ;
267+ return ;
268+ }
218269 throw err ;
219270 }
220271
0 commit comments