www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Basic SQLite Application

reply harakim <harakim gmail.com> writes:
I'm creating an application in D to do some purchase management 
stuff and I ran into a snag pretty early on. I'm trying to use 
sqlite via [this 
library](https://github.com/adamdruppe/arsd/blob/master/sqlite.d).
I started trying to get it to compile in another directory 
structure but since I've switched to dub and made a few tweaks, 
it compiles and runs and returns some large negative number as an 
error without printing what's in the writeln.
Here is my dub file:
```
{
	"authors": [
		"onesadman"
	],
	"dflags" : ["-m64"],
	"copyright": "Copyright © 2022, onesadman",
	"description": "Costco Purchase History",
	"license": "proprietary",
	"name": "cph",
	"libs-windows": ["lib/sqlite3"],
	"copyFiles":["lib/sqlite3.lib"]
}
```

Here is my program:
```
import std.stdio;
import arsd.sqlite;

void main()
{
	writeln("Edit source/app.d to start your project.");
}
```
I also have database.d and sqlite.d in my source/arsd directory 
and a lib folder with sqlite3.lib in it. It is successfully 
copied to the root folder and I also copied sqlite3.dll from 
c:\windows\sysWOW64\winsqlite3.dll into the root folder just in 
case I was doing it wrong and that fixed it.

It seems I must be close as I have it compiling. I'm not sure 
where it's going to look for the lib folder.

I have run it with dub and with  dub build --arch=x86_64 and then 
running the cph.exe directly.

I won't rule out that my lib file is the wrong file as I don't 
know how to tell or find the right one.
May 31 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 1 June 2022 at 03:46:38 UTC, harakim wrote:
 I started trying to get it to compile in another directory 
 structure but since I've switched to dub
It should work the way you have it, just with dub you can also the dub version instead of copying the files: https://code.dlang.org/packages/arsd-official%3Asqlite both are supposed to work. anyway
 it compiles and runs and returns some large negative number as 
 an error without printing what's in the writeln.
What is the number? My guess is you might have gotten the wrong sqlite3.dll (it should come from the same source as the .lib file you used) or it is in the wrong place.
 I won't rule out that my lib file is the wrong file as I don't 
 know how to tell or find the right one.
That's possible too but it would normally fail to link entirely if this was it. My money is on the dll, especially since the main() doesn't even try to open the database, it must be a loading issue. Where did you get the .lib file anyway? BTW: "copyFiles":["lib/sqlite3.lib"] You don't need that, the .lib is only used while building. You might need to copyFiles the .dll though.
Jun 01 2022
parent reply harakim <harakim gmail.com> writes:
On Wednesday, 1 June 2022 at 10:57:11 UTC, Adam D Ruppe wrote:
 BTW:

 	"copyFiles":["lib/sqlite3.lib"]


 You don't need that, the .lib is only used while building. You 
 might need to copyFiles the .dll though.
It's been a long time since I did any C development, and I have never done any on windows, but I thought I could statically link to the .lib at compile time and then I wouldn't need a dll. I'm fine with using a dll, but I don't know how to get the corresponding .bin. I'm guessing there is just a c header file. Is this a case where I would need to make bindings? As to the issue at hand, I found that bin linked from another dlang thread where someone was trying to get sqlite working. It linked to this repository: https://github.com/buggins/ddbc/tree/master/libs/win64 So when you said it might be the wrong dll, what I did is I grabbed the dll from there also and it worked. <facepalm> Thanks for your help once again.
Jun 01 2022
next sibling parent reply Jesse Phillips <Jesse.K.Phillips+D gmail.com> writes:
On Wednesday, 1 June 2022 at 15:40:43 UTC, harakim wrote:
 It's been a long time since I did any C development, and I have 
 never done any on windows, but I thought I could statically 
 link to the .lib at compile time and then I wouldn't need a 
 dll. I'm fine with using a dll, but I don't know how to get the 
 corresponding .bin. I'm guessing there is just a c header file. 
 Is this a case where I would need to make bindings?
In this case this lib is the dynamic bindings to the dll.
Jun 01 2022
parent harakim <harakim gmail.com> writes:
On Wednesday, 1 June 2022 at 15:58:01 UTC, Jesse Phillips wrote:
 On Wednesday, 1 June 2022 at 15:40:43 UTC, harakim wrote:
 It's been a long time since I did any C development, and I 
 have never done any on windows, but I thought I could 
 statically link to the .lib at compile time and then I 
 wouldn't need a dll. I'm fine with using a dll, but I don't 
 know how to get the corresponding .bin. I'm guessing there is 
 just a c header file. Is this a case where I would need to 
 make bindings?
In this case this lib is the dynamic bindings to the dll.
Thanks for that reply. That makes sense.
Jun 01 2022
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 1 June 2022 at 15:40:43 UTC, harakim wrote:
 It's been a long time since I did any C development, and I have 
 never done any on windows, but I thought I could statically 
 link to the .lib at compile time and then I wouldn't need a dll.
You sometimes can, it depends on how the library is built. If it was built as a dll, you need to use it that way unless you recompile the library itself.
Jun 01 2022