Page 1 of 1
detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 3:40 am
by jassing
Is there a trick to determine if UseSQLiteDatabase() has already been called?
I have a module that uses sqlite internally, and I don't want to re-issue UseSQLiteDatabase() again if the main code has already called it.
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 4:38 am
by idle
Isn't that just a directive to link it?
but if it causes any odd side effects you could use a macro
Code: Select all
Global usesqlite
Procedure _UseSQLiteDatabase()
If Not usesqlite
usesqlite = UseSQLiteDatabase()
Else
Debug "in use"
EndIf
EndProcedure
Macro UseSQLiteDatabase()
_UseSQLiteDatabase()
EndMacro
UseSQLiteDatabase()
UseSQLiteDatabase()
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 4:45 am
by Cyllceaux
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 1:28 pm
by Fred
Why not calling it again ? If it's already called, it just does nothing.
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 6:18 pm
by Cyllceaux
In my case I want to activate features which is only needed if there is UseSQLiteDatabase() called. But most the time it is not necessary.
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 7:21 pm
by jassing
Fred wrote: Tue May 21, 2024 1:28 pm
Why not calling it again ? If it's already called, it just does nothing.
You need a different version of sqlite's DLL
Code: Select all
UseSQLiteDatabase("c:\pbincludes\sqlite3.dll")
h2=OpenDatabase(-1,":memory:","","")
If DatabaseQuery(h2,"select sqlite_version();")
If NextDatabaseRow(h2)
Debug GetDatabaseString(h2,0)
EndIf
FinishDatabaseQuery(h2)
EndIf
UseSQLiteDatabase()
h1=OpenDatabase(-1,":memory:","","")
If DatabaseQuery(h1,"select sqlite_version();")
If NextDatabaseRow(h1)
Debug GetDatabaseString(h1,0)
EndIf
FinishDatabaseQuery(h1)
EndIf
Result:
Crash
Or more simply:
Code: Select all
UseSQLiteDatabase("c:\pbincludes\sqlite3.dll")
h2=OpenDatabase(-1,":memory:","","")
If DatabaseQuery(h2,"select sqlite_version();")
If NextDatabaseRow(h2)
Debug GetDatabaseString(h2,0)
EndIf
FinishDatabaseQuery(h2)
EndIf
UseSQLiteDatabase()
If DatabaseQuery(h2,"select sqlite_version();")
If NextDatabaseRow(h2)
Debug GetDatabaseString(h2,0)
EndIf
FinishDatabaseQuery(h2)
EndIf
Result:
IMA
Would be nice if
any of the "use...()" resulted in a corresponding subsystem() query...
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 7:50 pm
by Fred
I will take a closer look, a second call should do nothing.
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 8:06 pm
by jassing
Cyllceaux wrote: Tue May 21, 2024 6:18 pm
In my case I want to activate features which is only needed if there is UseSQLiteDatabase() called. But most the time it is not necessary.
This is why I would like to use use..() appear as results of subsystem() or somethings similar.
While FAR from ideal..
Code: Select all
If OpenDatabase(0,":memory:","","",#PB_Database_SQLite)
MessageRequester("test","Used")
Else
MessageRequester("test","not Used")
EndIf
in the IDE w/debugger, it will error but 'continue' works as expected.
In a compiled exe or w/o debugger, it works as expected.
I've had the same sort of need for which image formats to save (jpg,png) based on if the use...() was issued.
Re: detect if usesqlitedatabase() has been issued?
Posted: Tue May 21, 2024 8:06 pm
by jassing
Fred wrote: Tue May 21, 2024 7:50 pm
I will take a closer look, a second call should do nothing.
Thank you!