Page 1 of 1

[Done] 6.40 Beta 1 crashes when attempting any database operation on a non-existant table

Posted: Sat Feb 28, 2026 12:13 am
by DeanH
I have triggered a consistent bug in 6.40 Beta 1 using the x64 ASM compiler and the C backend compiler.

With the debugger on, the program crashes when it tries to DataBaseUpdate on a SQLite database table that does not exist. Either a debugger error pops up or an Invalid memory access error is reported.

Without the debugger, the program opens and quickly closes.

When compiled using 6.30, a result of 0 is returned by the DatabaseUpdate function along with a "no such table" database error, as expected.

The test program is:

Code: Select all

UseSQLiteDatabase()

Procedure.i TableExists(dbn,table$)
	Protected a$,t$,r
	If IsDatabase(dbn)
		;Get list of tables and see if table$ is in the list, return #False if not
		a$="SELECT name FROM sqlite_master WHERE type='table';"
		If DatabaseQuery(dbn,a$)
			While NextDatabaseRow(dbn)
				t$ = GetDatabaseString(dbn,0)
				If t$=table$
					r=#True
					Break
				EndIf
			Wend
			FinishDatabaseQuery(dbn)
		EndIf
	EndIf
	ProcedureReturn r
EndProcedure

Debug "Delete records from tables"

Debug "Create database file"
If CreateFile(0,"Test.db")
	CloseFile(0)
	Debug ""
EndIf

Debug "Open database"
If OpenDatabase(1,"Test.db","","",#PB_Database_SQLite)
	Debug "Creating tables"
	Debug DatabaseUpdate(1,"CREATE TABLE TableA (FieldA TEXT PRIMARY KEY ASC)")
;	Debug DatabaseUpdate(1,"CREATE TABLE TableB (FieldB TEXT PRIMARY KEY ASC)")	;causes crash if rem'd out
	CloseDatabase(1)
	Debug ""
EndIf
Delay(500)

If OpenDatabase(2,"Test.db","","",#PB_Database_SQLite)
	Debug "Inserting data"
	For i=1 To 3
		Debug DatabaseUpdate(2,"INSERT INTO TableA VALUES ('" + Str(i) + "')")
	Next
	;Will crash if TableB does not exist
	For i=4 To 6
		Debug DatabaseUpdate(2,"INSERT INTO TableB VALUES ('" + Str(i) + "')")
	Next
	CloseDatabase(2)
	Debug ""
EndIf
Delay(500)

;Deliberately drop the table even if created above
If OpenDatabase(4,"Test.db","","",#PB_Database_SQLite)
	DatabaseUpdate(4,"DROP TABLE TableB")
	CloseDatabase(4)
	Debug ""
EndIf
Delay(500)

If OpenDatabase(3,"Test.db","","",#PB_Database_SQLite)
	Debug "Check for TableA"
	Debug TableExists(3,"TableA")
	Debug "Delete data from TableA"
	Debug DatabaseUpdate(3,"DELETE FROM TableA")
	Debug "Check for TableB"
	Debug TableExists(3,"TableB")
	Debug "Delete TableB"
	Debug DatabaseUpdate(3,"DELETE FROM TableB")		;crashes here if TableB does not exist
	Debug DatabaseError()
	CloseDatabase(3)
	Debug ""
EndIf

Re: 6.40 Beta 1 crashes when attempting any database operation on a non-existant table

Posted: Mon Mar 09, 2026 10:43 am
by Fred
Fixed.