detect if usesqlitedatabase() has been issued?

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

detect if usesqlitedatabase() has been issued?

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 6027
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: detect if usesqlitedatabase() has been issued?

Post 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()  
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: detect if usesqlitedatabase() has been issued?

Post by Cyllceaux »

I had the same question
https://www.purebasic.fr/english/viewtopic.php?p=619675

Short answer: no you can't
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: detect if usesqlitedatabase() has been issued?

Post by Fred »

Why not calling it again ? If it's already called, it just does nothing.
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: detect if usesqlitedatabase() has been issued?

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: detect if usesqlitedatabase() has been issued?

Post 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...
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: detect if usesqlitedatabase() has been issued?

Post by Fred »

I will take a closer look, a second call should do nothing.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: detect if usesqlitedatabase() has been issued?

Post 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.
Last edited by jassing on Tue May 21, 2024 8:15 pm, edited 1 time in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: detect if usesqlitedatabase() has been issued?

Post 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!
Post Reply