January 29, 2017
On Sunday, 29 January 2017 at 04:13:17 UTC, Nestor wrote:
> On Sunday, 29 January 2017 at 03:11:34 UTC, Stefan Koch wrote:
>> On Sunday, 29 January 2017 at 02:59:12 UTC, Nestor wrote:
>>> On Sunday, 29 January 2017 at 02:55:04 UTC, Adam D. Ruppe wrote:
>>>> [...]
>>>
>>> In the case of Windows, where libraries are usually dlls, how could this be achieved, using your wrapper for example?
>>
>> dmd can link to dlls now. if just specify them on the commandline.
>
> Can dlls be embedded as well? I mean can I make a static dmd executable with the functionality of the library embedded and not just stored as a resource to be extracted and run at runtime?

Not sure with a static libs you should.
January 29, 2017
On Saturday, 28 January 2017 at 19:01:48 UTC, Adam D. Ruppe wrote:
> On Friday, 27 January 2017 at 12:01:30 UTC, Nestor wrote:
>> Is there any other native D implementation of sqlite reader?
>
> My sqlite.d and database.d from here can do it too:
> https://github.com/adamdruppe/arsd
>
> Just download those two files and compile them together with your file:
>
> dmd yourfile.d database.d sqlite.d
>
> However, my thing requires the C library, sqlite3, to be available already so it might not work out of the box for you either.
>
> import arsd.sqlite;
> auto db = new Sqlite("filename");
> foreach(row; db.query("select * from foo"))
>   writeln(row[0], row["name"]);

I have just tried your way and I get some errors:

OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
app.obj(app)
 Error 42: Symbol Undefined _D4arsd8database3Row7opIndexMFkAyaiZAya
app.obj(app)
 Error 42: Symbol Undefined _D4arsd8database3Row7opIndexMFAyaAyaiZAya
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite6__ctorMFAyaiZC4arsd6sqlite6Sqlite
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite7__ClassZ
app.obj(app)
 Error 42: Symbol Undefined _D4arsd8database8Database5queryMFAyaYC4arsd8database9ResultSet
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite12__ModuleInfoZ
Error: linker exited with status 163184408
January 29, 2017
On Sunday, 29 January 2017 at 16:26:30 UTC, Nestor wrote:
>> dmd yourfile.d database.d sqlite.d
> I have just tried your way and I get some errors:
>  Error 42: Symbol Undefined _D4arsd8database3Row7opIndexMFkAyaiZAya

Are you sure you passed those two database.d and sqlite.d modules to the compiler?
January 30, 2017
On Sunday, 29 January 2017 at 17:36:45 UTC, Adam D. Ruppe wrote:
> On Sunday, 29 January 2017 at 16:26:30 UTC, Nestor wrote:
>>> dmd yourfile.d database.d sqlite.d
>> I have just tried your way and I get some errors:
>>  Error 42: Symbol Undefined _D4arsd8database3Row7opIndexMFkAyaiZAya
>
> Are you sure you passed those two database.d and sqlite.d modules to the compiler?

I wasn't doing it explicitly. However I just did that and still encountered a few errors, which I removed with this patch:

--- original\sqlite.d	2017-01-29 10:53:35 -0100
+++ modified\sqlite.d	2017-01-29 19:00:23 -0100
@@ -22 +22,2 @@
-import std.c.stdlib;
+import core.stdc.string : strlen;
+import core.stdc.stdlib : malloc, free;
@@ -143 +144 @@
-		sizediff_t a = std.c.string.strlen(mesg);
+		sizediff_t a = strlen(mesg);
@@ -164 +165 @@
-			sizediff_t a = std.c.string.strlen(mesg);
+			sizediff_t a = strlen(mesg);
@@ -285 +286 @@
-					sizediff_t l = std.c.string.strlen(str);
+					sizediff_t l = strlen(str);
@@ -335 +336 @@
-						sizediff_t l = std.c.string.strlen(str);
+						sizediff_t l = strlen(str);
@@ -558 +559 @@
-		p = std.c.stdlib.malloc(sz);
+		p = malloc(sz);
@@ -569 +570 @@
-		    std.c.stdlib.free(p);
+		    free(p);
@@ -626 +627 @@
-		sizediff_t b = std.c.string.strlen(columns[a]);
+		sizediff_t b = strlen(columns[a]);
@@ -632 +633 @@
-		sizediff_t d = std.c.string.strlen(text[a]);
+		sizediff_t d = strlen(text[a]);

However a couple of errors remain with database.d which I don't know how to fix:

arsd\database.d(644): Error: function std.json.JSONValue.type () const is not callable using argument types (JSON_TYPE)
arsd\database.d(647): Error: function std.json.JSONValue.type () const is not callable using argument types (JSON_TYPE)

January 30, 2017
On Monday, 30 January 2017 at 00:06:00 UTC, Nestor wrote:
> I wasn't doing it explicitly. However I just did that and still encountered a few errors, which I removed with this patch:

Where did you get that ancient version? The latest versions of the files work just fine out of the box, and they have for about a year now.

these links work:

https://github.com/adamdruppe/arsd/blob/master/database.d
https://github.com/adamdruppe/arsd/blob/master/sqlite.d
January 30, 2017
On Monday, 30 January 2017 at 02:25:40 UTC, Adam D. Ruppe wrote:
> On Monday, 30 January 2017 at 00:06:00 UTC, Nestor wrote:
>> I wasn't doing it explicitly. However I just did that and still encountered a few errors, which I removed with this patch:
>
> Where did you get that ancient version? The latest versions of the files work just fine out of the box, and they have for about a year now.
>
> these links work:
>
> https://github.com/adamdruppe/arsd/blob/master/database.d
> https://github.com/adamdruppe/arsd/blob/master/sqlite.d

Well, I had downloaded the github version a few days back but yesterday managed to get dub to fetch properly, so I just fetched package arsd, and took the units from there.

Anyway, I have just downloaded from github the files you recomend, but...

d:\prj\sqltest2\source>dmd app
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite6__ctorMFAyaiZC4arsd6sqlite6Sqlite
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite7__ClassZ
app.obj(app)
 Error 42: Symbol Undefined _D4arsd6sqlite12__ModuleInfoZ
Error: linker exited with status 163488904

If I specify all source files, there are even more problems:

d:\prj\sqltest2\source>dmd app.d arsd\sqlite.d arsd\database.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_open
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_finalize
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_prepare_v2
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_mprintf
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_free
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_exec
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_last_insert_rowid
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_changes
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_errmsg
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_close
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_reset
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_blob
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_bytes
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_int
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_name
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_step
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_text
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_double
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_type
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_count
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_null
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_blob
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_double
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_int
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_text
Error: linker exited with status 211947944

Source of app.d couldn't be simpler:

import std.stdio;
void main() {
  import arsd.sqlite;
  auto db = new Sqlite("data.db");
}

Files sqlite3.{def|dll|lib} are on both source/ and source/arsd/ (just in case)
I also moved your files to the same location of app.d but it makes no difference.
January 30, 2017
On Monday, 30 January 2017 at 02:46:34 UTC, Nestor wrote:
> Well, I had downloaded the github version a few days back but yesterday managed to get dub to fetch properly, so I just fetched package arsd, and took the units from there.

Oh, that is ancient and not even mine - I don't have access to it, it was set up by a third party years ago!


> d:\prj\sqltest2\source>dmd app

That is always wrong unless your entire program consists *only* of app.d. When compiling, you need to have imported modules available or you'll see "module foo is found in file foo.d that cannot be found", and when linking, you need to have the code available or you'll see "Symbol Undefined". Since compiling and linking are done in the same step unless you ask it not to, missing modules may lead to one, the other, or both.

The easiest solution is to pass all the modules to the compiler at once. Then it will be able to find them for import and will compile and link them automatically. If you link separately (such as to a .lib or .dll), you can specify them rather than all the .d files, but it still needs the .d for the import!

Whether it is library modules or another module in your own file, it is the same, they all need to be there.


> If I specify all source files, there are even more problems:
>  Error 42: Symbol Undefined _sqlite3_open

It apparently couldn't find sqlite3.lib.

> Files sqlite3.{def|dll|lib} are on both source/ and source/arsd/ (just in case)

Try specifying it on the command line too:

dmd app.d database.d sqlite.d sqlite3.lib

Though this may still require sqlite3.dll there too, unless it was built statically.
January 30, 2017
On Monday, 30 January 2017 at 03:07:22 UTC, Adam D. Ruppe wrote:
>> If I specify all source files, there are even more problems:
>>  Error 42: Symbol Undefined _sqlite3_open
>
> It apparently couldn't find sqlite3.lib.
>
>> Files sqlite3.{def|dll|lib} are on both source/ and source/arsd/ (just in case)
>
> Try specifying it on the command line too:
>
> dmd app.d database.d sqlite.d sqlite3.lib
>
> Though this may still require sqlite3.dll there too, unless it was built statically.

I found out the cause of the problem.

First I tried to verify if the linker was able to find sqlite3.lib using Process Monitor by Mark Russinovich, and at least there were IRP_MJ_CREATE, FASTIO_QUERY_INFORMATION, IRP_MJ_READ and FASTIO_READ operations with the correct path to sqlite3.lib where the result was SUCCESS, so apparently the linker could find the file.

So I opened sqlite3.bn in notepad++ just to see the name of the symbols and not even one started with an underscore, so I created sqlite3.lib again with these arguments and this time it compiled:

implib /system sqlite3.lib sqlite3.dll
1 2 3
Next ›   Last »