[solved] sqlcipher.dll problem

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [solved] sqlcipher.dll problem

Post by infratec »

The example is not wrong, but at the wrong place :wink:

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.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [solved] sqlcipher.dll problem

Post 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?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: sqlcipher.dll problem

Post by Kiffi »

skywalk wrote: Mon Aug 07, 2023 4:35 pm Is this help file example wrong?
No.

Image
Hygge
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: [solved] sqlcipher.dll problem

Post by jassing »

Another thing no one pointed out, is when using an external dll - you should do:

Code: Select all

If UseSQLiteDatabase("myExternal.DLL")
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: [solved] sqlcipher.dll problem

Post 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.
Hygge
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [solved] sqlcipher.dll problem

Post by skywalk »

Thanks kiffi and infratec.
This nuance confused me with nested complex updates from a select query.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [solved] sqlcipher.dll problem

Post by infratec »

You can not nest queries,

You have to find the right SQL way, or you have to use a different DB handle.
Boulcat
User
User
Posts: 28
Joined: Fri Feb 28, 2020 11:51 am

Re: [solved] sqlcipher.dll problem

Post 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
Boulcat
User
User
Posts: 28
Joined: Fri Feb 28, 2020 11:51 am

Re: [solved] sqlcipher.dll problem

Post by Boulcat »

Kiffi wrote: Tue Aug 08, 2023 12:07 am UseSQLiteDatabase("myExternal.DLL") has no return value. See https://www.purebasic.com/documentation ... abase.html.
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 ?
Post Reply