Page 2 of 2
Re: [solved] sqlcipher.dll problem
Posted: Mon Aug 07, 2023 6:54 pm
by infratec
The example is not wrong, but at the wrong place
In the example DatabaseQuery() is shown and not DatabaseUpdate()
The last example shows DatabaseUpdate() and this is done without FinishDatabaseQuery()
There is no FinishDatabaseUpdate().
All in all: the help for DatabaseUpdate() should be modified.
Re: [solved] sqlcipher.dll problem
Posted: Mon Aug 07, 2023 11:14 pm
by skywalk
Haha, now I am confused.
I found 1 or 2 instances where I close with a FinishDatabaseQuery() but not necessarily on a SELECT statement.
Any harm calling FinishDatabaseQuery() in this manner?
Will I create a memory leak?
Or just wasted code?
Re: sqlcipher.dll problem
Posted: Mon Aug 07, 2023 11:17 pm
by Kiffi
skywalk wrote: Mon Aug 07, 2023 4:35 pm
Is this help file example wrong?
No.

Re: [solved] sqlcipher.dll problem
Posted: Mon Aug 07, 2023 11:22 pm
by jassing
Another thing no one pointed out, is when using an external dll - you should do:
Code: Select all
If UseSQLiteDatabase("myExternal.DLL")
Re: [solved] sqlcipher.dll problem
Posted: Tue Aug 08, 2023 12:07 am
by Kiffi
jassing wrote: Mon Aug 07, 2023 11:22 pm
Another thing no one pointed out, is when using an external dll - you should do:
Code: Select all
If UseSQLiteDatabase("myExternal.DLL")
UseSQLiteDatabase() has no return value. See
https://www.purebasic.com/documentation ... abase.html.
Re: [solved] sqlcipher.dll problem
Posted: Tue Aug 08, 2023 3:14 am
by skywalk
Thanks kiffi and infratec.
This nuance confused me with nested complex updates from a select query.
Re: [solved] sqlcipher.dll problem
Posted: Tue Aug 08, 2023 6:47 am
by infratec
You can not nest queries,
You have to find the right SQL way, or you have to use a different DB handle.
Re: [solved] sqlcipher.dll problem
Posted: Tue Aug 08, 2023 10:53 am
by Boulcat
menschmarkus_ wrote: Tue Aug 08, 2023 8:16 am
It may need to be reviewed?
Why did you create a new Topic bug ? As for Infratec (Thanks for libcrypto-1_1-x64.dll), it works here too:
I don't understand your problem on your system, it's probably unrelated to PB, I guess
I'd like to understand, I try
I've added debug almost everywhere. Can you try it out and give us the debug output ?
sqlcipher_demo.pb below to be tested with sqlcipher.dll and libcrypto-1_1-x64.dll
downloaded and extracted next to it and then use Compil/Run (F5)
Code: Select all
; sqlcipher_demo.pb
; It needs sqlcipher.dll and libcrypto-1_1-x64.dll downloaded/extracted from https://download.sqlitebrowser.org/DB.Browser.for.SQLite-3.12.2-win64.zip
; - both dll next to exe directory
; - or next to sqlcipher_demo.pb in Debug mode with Compil/Run (F5)
; In Debug, better to have CompileSourceDirectory compiler option enabled
EnableExplicit
Define.i FileExitsAlready
Define Filename$, Result$
UseSQLiteDatabase("sqlcipher.dll")
Debug "CurrentDirectory: " + GetCurrentDirectory()
Debug "sqlcipher.dll size: " + Str(FileSize("sqlcipher.dll"))
Debug "libcrypto-1_1-x64.dll size: " + Str(FileSize("libcrypto-1_1-x64.dll"))
Filename$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".sqlite"
If FileSize(Filename$) = -1
If CreateFile(0, Filename$)
CloseFile(0)
EndIf
Debug "File: " + Filename$ + " Created"
Else
Debug "File: " + Filename$ + " Already Exist"
FileExitsAlready = #True
EndIf
If OpenDatabase(0, Filename$, "", "")
Debug "OpenDatabase OK"
If DatabaseUpdate(0, "PRAGMA key = 'passkey';")
Debug "DatabaseUpdate Set Key OK"
If Not FileExitsAlready
If DatabaseUpdate(0,"CREATE TABLE test (field1 INTEGER,field2 INTEGER);")
Debug "DatabaseUpdate Create Table OK"
If DatabaseUpdate(0,"INSERT INTO test (field1,field2) VALUES (1,1),(2,2),(3,3);")
Debug "DatabaseUpdate Insert Data OK"
Else
Debug "DatabaseUpdate Insert Data Error: " + DatabaseError()
EndIf
Else
Debug "DatabaseUpdate Create Table Error: " + DatabaseError()
EndIf
EndIf
If DatabaseQuery(0,"SELECT field1, field2 FROM test;")
Debug "DatabaseQuery OK"
While NextDatabaseRow(0)
Result$ + GetDatabaseString(0, 0) + " , " + GetDatabaseString(0, 1) + #LF$
Wend
FinishDatabaseQuery(0)
Debug "*** DatabaseQuery Result ***" + #CRLF$ + Result$
Else
Debug "DatabaseQuery Error: " + DatabaseError()
EndIf
Else
Debug "DatabaseUpdate Set Key Error: " + DatabaseError()
EndIf
CloseDatabase(0)
Else
Debug "OpenDatabase Error: " + DatabaseError()
EndIf
; IDE Options = PureBasic 6.02 LTS (Windows - x64)
; Compiler = PureBasic 6.02 LTS (Windows - x64)
; EnableXP
; Executable = sqlcipher_demo.exe
; CompileSourceDirectory
Re: [solved] sqlcipher.dll problem
Posted: Tue Aug 08, 2023 12:02 pm
by Boulcat
In a feature request, wouldn't it be good to have a return value and a DatabaseError(), it would help here ?
Isn't it possible to know if the dll is properly loaded and the database environment properly initialized ?