Check if UseSQLiteDatabase is called

Just starting out? Need help? Post your questions and find answers here.
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Check if UseSQLiteDatabase is called

Post by Cyllceaux »

Hey there,

Is there a possibility to check if UseSQLiteDatabase() was called? I want to activate or deactivate some features in my libs depending of UseSQLiteDatabase was called.

Something like that:

Code: Select all

CompilerIf Defined(UseSQLiteDatabase, #PB_Use)
    Debug "UseSQLiteDatabase is used"
CompilerEndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check if UseSQLiteDatabase is called

Post by mk-soft »

Code: Select all

#EnableSQLite = #True
  
CompilerIf #EnableSQLite
  If Not UseSQLiteDatabase()
    Debug "Error ..."
    End
  EndIf
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Check if UseSQLiteDatabase is called

Post by Cyllceaux »

hello mk-soft...

that's not what I'm looking for. I write my own framework for saving data.

Code: Select all

Enumeration _own_db_format
	#OWN_DB_FORMAT_INMEMORY
	#OWN_DB_FORMAT_OWN
	#OWN_DB_FORMAT_XML
	#OWN_DB_FORMAT_JSON		
	CompilerIf Defined(UseSQLiteDatabase, #PB_Use)
		#OWN_DB_FORMAT_SQLITE
	CompilerEndIf
EndEnumeration
Declare ownDB(path.s="",encoding=#PB_Unicode,format=#OWN_DB_FORMAT_INMEMORY,flags.i=0)
I don't want to use a global variable or constant to do something like that.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Check if UseSQLiteDatabase is called

Post by mk-soft »

maybe ...

Code: Select all

#EnableSQLite = #False
  
CompilerIf #EnableSQLite
  #UseSQLiteDatabase = #True
  If Not UseSQLiteDatabase()
    Debug "Error ..."
    End
  EndIf
CompilerEndIf

Enumeration _own_db_format
	#OWN_DB_FORMAT_INMEMORY
	#OWN_DB_FORMAT_OWN
	#OWN_DB_FORMAT_XML
	#OWN_DB_FORMAT_JSON		
	CompilerIf Defined(UseSQLiteDatabase, #PB_Constant)
		#OWN_DB_FORMAT_SQLITE
	CompilerEndIf
EndEnumeration

Debug #OWN_DB_FORMAT_SQLITE

Declare ownDB(path.s="",encoding=#PB_Unicode,format=#OWN_DB_FORMAT_INMEMORY,flags.i=0)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Check if UseSQLiteDatabase is called

Post by Cyllceaux »

Ok... I think there is a misunderstanding.

Code: Select all

CompilerIf Defined(UseSQLiteDatabase, #PB_Use)
	Debug "cool"
CompilerElse
	Debug "uncool" ; Should be called
CompilerEndIf


UseSQLiteDatabase()

CompilerIf Defined(UseSQLiteDatabase, #PB_Use)
	Debug "cool" ; Should be called
CompilerElse
	Debug "uncool"
CompilerEndIf
I wrote my own Module for saving informations. This Module is used by a lot of my tools and programs. Mostly my tools don't use a database. This is fine. So I don't want to compile the sqlite-lib into these tools. ATM I use the Defined and a constant like you do for solving this. BUT!!! It's not cool, cause I use a constant in all my tools only for enabling a feature of my module. So I hoped I can do this without declare a extra constant. And NO, I don't want to write 2 different Modules for that.

#PB_Use is only for the reason, cause I don't know if there is a other constant for that.
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Check if UseSQLiteDatabase is called

Post by Caronte3D »

I think the use of a constants is the better way, but...
Maybe you can write a tool for PB that executed each time the code is compiled and by reading the source code you can determine if SQLite is used or not and take the needed actions
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Check if UseSQLiteDatabase is called

Post by infratec »

Code: Select all

SQLite = UseSQLiteDatabase()

If SQLite
	Debug "cool" ; Should be called
Else
	Debug "uncool"
EndIf
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Check if UseSQLiteDatabase is called

Post by Cyllceaux »

@Caronte3D: I thought so... But I hoped there were some PB-Functions to solve this
@infratec: No, that's still not good. It's cross project and it's not good to declare hundreds of global variables or constants in all of the projects, just to use different kinds of Modules and libs
@mk-soft: I thought about a extreme dirty way. something like this:

Code: Select all

DeclareModule SQLiteDB:UseSQLiteDatabase():EndDeclareModule:Module SQLiteDB:EndModule

CompilerIf Defined(SQLiteDB,#PB_Module)
	Debug "cool"
CompilerEndIf
And adding the Module in every project, which uses UseSQLiteDatabase(). But I don't like this... I don't want to create empty modules for every "Use*"-Methode in PB.
Axolotl
Addict
Addict
Posts: 873
Joined: Wed Dec 31, 2008 3:36 pm

Re: Check if UseSQLiteDatabase is called

Post by Axolotl »

just my 2 cents, probably not what you are looking for......
Explanation: I use the compiler permission that you can define constants as often as you want, as long as they are assigned the same value.

Code: Select all

; need a different name to avoid recursive calls 
;
Macro UseSQLiteDatabaseEx() 
  UseSQLiteDatabase() : #SQLite_Enabled = #True : Debug "Do SQLite....."  
EndMacro 

If UseSQLiteDatabaseEx() 
  Debug "Yes " 
EndIf 

CompilerIf Defined(SQLite_Enabled, #PB_Constant) 
  Debug "#SQLite_Enabled is defined (and true) " 
CompilerElse 
  Debug "#SQLite_Enabled is not defined " 
CompilerEndIf 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Check if UseSQLiteDatabase is called

Post by Cyllceaux »

@Axolotl: Yes... I know... But this means I have to do this in every program.

My Problem is, there are a Lot of "Use*" Libs, not only Database, but Image, Cypher and others, too.
To Make for every "Use*" Lib a Macro, Constant, Module... or other Solutions is to much. And then you have write Differences. "#SQLite_Enabled", "#SQLiteEnabled", "SQLite_DB"... what ever. And then I give my Libs or Modules to others and the First thing is to say: "Declare 50 Constants, which feature of PB you are using". This is not really good.
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Check if UseSQLiteDatabase is called

Post by skywalk »

Before I compile various apps, I have to configure them. So why not force the issue with settable constants?
Here is example to force the use of USESQLITE

Code: Select all

CompilerIf Defined(MY_EXE, #PB_Constant)
  ; Do nothing.
CompilerElse
  #MY_EXE                                         = 0
CompilerEndIf
CompilerIf #MY_EXE
  #SQLITE_USE_DLL                                 = 0    ; 0=use static lib, 1=use custom dll.
  ; SET = 1 if necessary to use external, smaller sqlite3.dll.
  ; v573b3+ updated SQLite to v33 which fixed JOIN query bug.
CompilerElse
  #SQLITE_USE_DLL                                 = 0    ; 0=use static lib, 1=use custom dll.
CompilerEndIf
;
;LATER ON...
;
CompilerIf #SQLITE_USE_DLL  ;-! USE sqlite3.dll
  #SQLITE_DLL_FNPATH$ = "C:\db\sqlite3.dll"
  ;#SQLITE_DLL_FNPATH$ = "C:\DB Browser for SQLite\sqlite3.dll"
  ;#SQLITE_DLL_FNPATH$ = "C:\DB Browser for SQLite\sqlcipher.dll"
  UseSQLiteDatabase(#SQLITE_DLL_FNPATH$)
;...more stuff...
CompilerElse
  #SQLITE_DLL_FNPATH$ = #Empty$
  ;BUG;UseSQLiteDatabase(#SQLITE_DLL_FNPATH$)
  UseSQLiteDatabase()
CompilerEndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply