Page 1 of 1
Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 8:19 am
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
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 9:32 am
by mk-soft
Code: Select all
#EnableSQLite = #True
CompilerIf #EnableSQLite
If Not UseSQLiteDatabase()
Debug "Error ..."
End
EndIf
CompilerEndIf
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 9:42 am
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.
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 9:58 am
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)
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 10:10 am
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.
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 11:03 am
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
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 12:42 pm
by infratec
Code: Select all
SQLite = UseSQLiteDatabase()
If SQLite
Debug "cool" ; Should be called
Else
Debug "uncool"
EndIf
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 12:48 pm
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.
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 1:31 pm
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
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 1:38 pm
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.
Re: Check if UseSQLiteDatabase is called
Posted: Fri Apr 19, 2024 2:53 pm
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