Re: Basic SQLite Application
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.
Re: Basic SQLite Application
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.
Re: Basic SQLite Application
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.
Re: Basic SQLite Application
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. Thanks for your help once again.
Re: Basic SQLite Application
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.
Basic SQLite Application
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.
Re: Setting SQLite compile time parameters from etc.c.sqlite3
On Tuesday, 1 March 2022 at 20:59:46 UTC, data pulverizer wrote: Hello all, I'm not sure how to set the compile time parameters in D's SQLite module particular the items that take multiple parameters, for example in the C API manual `SQLITE_CONFIG_MMAP_SIZE` takes two `sqlite3_int64`. How do I set these? Okay it seems like you are supposed to use the function `sqlite3_config` to configure those elements, for example: ``` sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 10_000_000_000, 30_000_000_000); ```
Re: Setting SQLite compile time parameters from etc.c.sqlite3
On Tue, Mar 01, 2022 at 08:59:46PM +, data pulverizer via Digitalmars-d-learn wrote: > Hello all, > > I'm not sure how to set the compile time parameters in D's SQLite > module particular the items that take multiple parameters, for example > in the C API manual `SQLITE_CONFIG_MMAP_SIZE` takes two > `sqlite3_int64`. How do I set these? These are not compile-time parameters. According to SQLite's documentation, they are set at runtime using the sqlite3_config() API, which is a C-style variadic function, so you can just pass however many arguments are needed for that configuration item. I.e.: sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 10_000_000_000, 30_000_000_000); Since sqlite3_config is not thread-safe (according to the docs), you must initialize it before any threads are started: shared static this() { sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 10_000_000_000, 30_000_000_000); } T -- When solving a problem, take care that you do not become part of the problem.
Setting SQLite compile time parameters from etc.c.sqlite3
Hello all, I'm not sure how to set the compile time parameters in D's SQLite module particular the items that take multiple parameters, for example in the C API manual `SQLITE_CONFIG_MMAP_SIZE` takes two `sqlite3_int64`. How do I set these? Do I just write something like ``` enum SQLITE_CONFIG_MMAP_SIZE = [10_000_000_000, 30_000_000_000]; ``` ? Writing this doesn't cause an error but I don't think it works because its supposed to speed up write times and I'm not observing any performance change. Thanks in advance!
Re: How to connect to SQLITE?
On Saturday, 28 November 2020 at 17:50:43 UTC, kdevel wrote: On Saturday, 28 November 2020 at 13:29:50 UTC, Ferhat Kurtulmuş wrote: On Saturday, 28 November 2020 at 12:01:59 UTC, Alex NL wrote: Is there libs for SQLITE? How to use it? thanks. https://github.com/aferust/GtkD-examples-for-TreeView-and-ListBox IMNSHO the code in example1.d string sql = format("UPDATE User SET %s = '%s' WHERE id = %s;", field, text, curId); db.query(sql); and that in example2.d string sql = format("UPDATE User SET %s = '%s' WHERE id = %d;", field, value, cid); db.query(sql); is prone to SQL injection attacks. Why don't you use ? as placeholder as in the example db.query("INSERT INTO people (id, name) VALUES (?, ?)", 5, "Adam"); of http://dpldocs.info/experimental-docs/arsd.database.html If your database is compromised you can blame the arsd.database author(s) for publishing a buggy db.escape function ;-) I just didn't care about security vulnerability there. My focus was on GtkD functions. But you are right. It may mislead newbies. Library functions must have been used, not format, so that auto escape can work. I am too lazy to fix it :)
Re: How to connect to SQLITE?
On Saturday, 28 November 2020 at 13:29:50 UTC, Ferhat Kurtulmuş wrote: On Saturday, 28 November 2020 at 12:01:59 UTC, Alex NL wrote: Is there libs for SQLITE? How to use it? thanks. https://github.com/aferust/GtkD-examples-for-TreeView-and-ListBox IMNSHO the code in example1.d string sql = format("UPDATE User SET %s = '%s' WHERE id = %s;", field, text, curId); db.query(sql); and that in example2.d string sql = format("UPDATE User SET %s = '%s' WHERE id = %d;", field, value, cid); db.query(sql); is prone to SQL injection attacks. Why don't you use ? as placeholder as in the example db.query("INSERT INTO people (id, name) VALUES (?, ?)", 5, "Adam"); of http://dpldocs.info/experimental-docs/arsd.database.html If your database is compromised you can blame the arsd.database author(s) for publishing a buggy db.escape function ;-)
Re: How to connect to SQLITE?
On Saturday, 28 November 2020 at 12:01:59 UTC, Alex NL wrote: Is there libs for SQLITE? How to use it? thanks. https://github.com/aferust/GtkD-examples-for-TreeView-and-ListBox
Re: How to connect to SQLITE?
On Saturday, 28 November 2020 at 12:01:59 UTC, Alex NL wrote: Is there libs for SQLITE? How to use it? thanks. You may use google translate, https://d-land.sepany.de/tutorials/datenbanken/sqlite-erste-schritte/ Here I describe how to use Sqlite using dub package arsd-official. Kind regards Andre
How to connect to SQLITE?
Is there libs for SQLITE? How to use it? thanks.
Re: SQLite 3 support?
On Wednesday, 26 February 2020 at 20:06:20 UTC, mark wrote: There seems to be some support for SQLite 3 in std. lib. etc when looking at the stable docs: https://dlang.org/phobos/etc_c_sqlite3.html But this isn't visible when looking at stable (ddox). Is this the best SQLite 3 library to use or is a third-party library best? For example https://github.com/biozic/d2sqlite3 I use d2sqlite3 regularly, no problems at all with it. I have no experience with the std. lib one. Jordan
Re: SQLite 3 support?
On Wednesday, 26 February 2020 at 20:06:20 UTC, mark wrote: There seems to be some support for SQLite 3 in std. lib. etc when looking at the stable docs: https://dlang.org/phobos/etc_c_sqlite3.html But this isn't visible when looking at stable (ddox). Is this the best SQLite 3 library to use or is a third-party library best? For example https://github.com/biozic/d2sqlite3 What's in the Phobos is just D binding to the sqlite3 C api. Probably not much up to date too. I've been using d2sqlite3 a lot some time ago and I'd definitelly recommend it. It also provides nice higher level API that helps to work with it in a more D friendly and productive way. But I'm not following sqlite3 updates much nowadays.
SQLite 3 support?
There seems to be some support for SQLite 3 in std. lib. etc when looking at the stable docs: https://dlang.org/phobos/etc_c_sqlite3.html But this isn't visible when looking at stable (ddox). Is this the best SQLite 3 library to use or is a third-party library best? For example https://github.com/biozic/d2sqlite3
Re: Is there any working SQLite driver for windows?
On Wednesday, 26 December 2018 at 12:13:27 UTC, Suliman wrote: On Wednesday, 26 December 2018 at 11:06:02 UTC, Andre Pany wrote: On Wednesday, 26 December 2018 at 08:19:03 UTC, Suliman wrote: Yesterday I tried several sqlite drivers and all of them have some issue that make it's build on Windows impossible. Few examples https://github.com/huntlabs/hunt-database/issues/24 https://github.com/biozic/d2sqlite3/issues/51 You can look here. It is a on German but Google translator does a good job http://d-land.sepany.de/tutorials/datenbanken/sqlite-erste-schritte/ Kind regards Andre Thanks, but also do not working https://github.com/adamdruppe/arsd/issues/180 My mistake. Adam's lib works.
Re: Is there any working SQLite driver for windows?
On Wednesday, 26 December 2018 at 11:06:02 UTC, Andre Pany wrote: On Wednesday, 26 December 2018 at 08:19:03 UTC, Suliman wrote: Yesterday I tried several sqlite drivers and all of them have some issue that make it's build on Windows impossible. Few examples https://github.com/huntlabs/hunt-database/issues/24 https://github.com/biozic/d2sqlite3/issues/51 You can look here. It is a on German but Google translator does a good job http://d-land.sepany.de/tutorials/datenbanken/sqlite-erste-schritte/ Kind regards Andre Thanks, but also do not working https://github.com/adamdruppe/arsd/issues/180
Re: Is there any working SQLite driver for windows?
On Wednesday, 26 December 2018 at 08:19:03 UTC, Suliman wrote: Yesterday I tried several sqlite drivers and all of them have some issue that make it's build on Windows impossible. Few examples https://github.com/huntlabs/hunt-database/issues/24 https://github.com/biozic/d2sqlite3/issues/51 You can look here. It is a on German but Google translator does a good job http://d-land.sepany.de/tutorials/datenbanken/sqlite-erste-schritte/ Kind regards Andre
Is there any working SQLite driver for windows?
Yesterday I tried several sqlite drivers and all of them have some issue that make it's build on Windows impossible. Few examples https://github.com/huntlabs/hunt-database/issues/24 https://github.com/biozic/d2sqlite3/issues/51
Re: Any sample how to use Sqlite-d?
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote: I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name); auto table = db.table(tableName); auto rows = table.findRows!(format!"(id,date) => id == %s"(id)); (i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful. Also have a look at https://github.com/biozic/d2sqlite3 (documentation: http://biozic.github.io/d2sqlite3/d2sqlite3.html).
Re: Any sample how to use Sqlite-d?
On Wednesday, 17 January 2018 at 13:36:26 UTC, Marc wrote: I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name); auto table = db.table(tableName); auto rows = table.findRows!(format!"(id,date) => id == %s"(id)); (i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful. Hello Marc, I am the author of sqlite-d, since it is a very low level library it does correlate rows and names. I would need to see the schema to tell you which rows to compare. Otherwise there is an code example in the repo call example_app.d
Re: Any sample how to use Sqlite-d?
On Wed, Jan 17, 2018 at 01:36:26PM +, Marc via Digitalmars-d-learn wrote: > I was looking for a library to use SQLite with D, found this > (https://code.dlang.org/packages/sqlite-d) but it has no documentation > or code example. I looked into files in the source code and wrote > this: > > > Database db = Database(name); > > auto table = db.table(tableName); > > auto rows = table.findRows!(format!"(id,date) => id == %s"(id)); > (i'm aware of sql injection above) > > but it doesnt work, it seems the library has changed. If happen to > that library author see this, would be very helpful. You might want to try this instead: https://github.com/adamdruppe/arsd/blob/master/sqlite.d I've used it myself, and can vouch for its ease-of-use, depending on what you want to do. The equivalent of your code above is: Database db = new SQLite(filename); auto rows = db.query("SELECT * FROM " ~ tableName ~ " WHERE id=?", id); // Note: no SQL injection issue here foreach (row; rows) { ... } T -- Leather is waterproof. Ever see a cow with an umbrella?
Any sample how to use Sqlite-d?
I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name); auto table = db.table(tableName); auto rows = table.findRows!(format!"(id,date) => id == %s"(id)); (i'm aware of sql injection above) but it doesnt work, it seems the library has changed. If happen to that library author see this, would be very helpful.
Re: Problems compiling sqlite-d
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
Re: Problems compiling sqlite-d
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.
Re: Problems compiling sqlite-d
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.
Re: Problems compiling sqlite-d
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
Re: Problems compiling sqlite-d
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)
Re: Problems compiling sqlite-d
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?
Re: Problems compiling sqlite-d
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
Re: Problems compiling sqlite-d
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.
Re: Problems compiling sqlite-d
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: On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least for building self-contained applications. Sometimes true, but sqlite can be easily embedded and statically linked, so your binary is still self-contained, there's just a small compile time dependency on the sqlite3.lib. Also, one can learn more advanced features of the language studying them. Oh, certainly, writing and studying it is a good thing. 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?
Re: Problems compiling sqlite-d
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: On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least for building self-contained applications. Sometimes true, but sqlite can be easily embedded and statically linked, so your binary is still self-contained, there's just a small compile time dependency on the sqlite3.lib. Also, one can learn more advanced features of the language studying them. Oh, certainly, writing and studying it is a good thing. 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.
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 02:55:04 UTC, Adam D. Ruppe wrote: On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least for building self-contained applications. Sometimes true, but sqlite can be easily embedded and statically linked, so your binary is still self-contained, there's just a small compile time dependency on the sqlite3.lib. Also, one can learn more advanced features of the language studying them. Oh, certainly, writing and studying it is a good thing. In the case of Windows, where libraries are usually dlls, how could this be achieved, using your wrapper for example?
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least for building self-contained applications. Sometimes true, but sqlite can be easily embedded and statically linked, so your binary is still self-contained, there's just a small compile time dependency on the sqlite3.lib. Also, one can learn more advanced features of the language studying them. Oh, certainly, writing and studying it is a good thing.
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 01:02:07 UTC, Ali Çehreli wrote: Agreed but there can be happy surprises. :) Just because it's fresh in my mind: Jon Degenhardt implemented D versions of existing C, Go, and Rust tool kits in D and saw 3 to 10 times performance increase in many cases (not all). Yeah, but those are relatively simple tools, not a heavily used database like sqlite. I support the creation of sqlite-d, it does some cool stuff and there is potential for more, but I just don't agree that using the C functions should be a dealbreaker (or even a serious negative, given sqlite's nature especially)
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 01:53:30 UTC, Stefan Koch wrote: On Sunday, 29 January 2017 at 01:47:44 UTC, Nestor wrote: On Saturday, 28 January 2017 at 21:09:25 UTC, Stefan Koch wrote: On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: [...] Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. [...] I think you have to remove the app.d that comes with sqlite-d file if you want to use it. Because that tries to open views/test-2.3.sqlite. Please try to read the source-code in app.d and in test.d that come with sqlite-d. If you have questions about that I am happy to answer them. Sqlite-d is a work in progress and I have not used it for an actual project. Currently I am busy with improving the ctfe engine. So I don't have to many resources should sqlite-d need improvements. Thanks for your willingness to help. Removing app.d from the library seems to make no difference. I just made an empty project as before (specifying your package as a dependency), like this: dub init sqlite-test Then I try to build using simply dub without parameters. However I get this message: Fetching sqlite-d 0.1.0 (getting selected version)... Non-optional dependency sqlite-d of sqlite-test not found in dependency tree!?. Am I missing a parameter or something? I just called dub fetch and see what the problem is. I am going to push an update to fix it. should be there in a minute Thanks, it compiled now. However keep in mind there was a warning for sqlited.d: C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.5\sqlite-d\source\sqlited.d(743,5): Deprecation: Implicit string concatenation is deprecated, use "I do not expect us to ever get here\x0a" ~ "If we ever do, uncomment the two lines below and delete this assert" instead
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 01:47:44 UTC, Nestor wrote: On Saturday, 28 January 2017 at 21:09:25 UTC, Stefan Koch wrote: On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: [...] Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. [...] I think you have to remove the app.d that comes with sqlite-d file if you want to use it. Because that tries to open views/test-2.3.sqlite. Please try to read the source-code in app.d and in test.d that come with sqlite-d. If you have questions about that I am happy to answer them. Sqlite-d is a work in progress and I have not used it for an actual project. Currently I am busy with improving the ctfe engine. So I don't have to many resources should sqlite-d need improvements. Thanks for your willingness to help. Removing app.d from the library seems to make no difference. I just made an empty project as before (specifying your package as a dependency), like this: dub init sqlite-test Then I try to build using simply dub without parameters. However I get this message: Fetching sqlite-d 0.1.0 (getting selected version)... Non-optional dependency sqlite-d of sqlite-test not found in dependency tree!?. Am I missing a parameter or something? I just called dub fetch and see what the problem is. I am going to push an update to fix it. should be there in a minute
Re: Problems compiling sqlite-d
On Saturday, 28 January 2017 at 21:09:25 UTC, Stefan Koch wrote: On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: [...] Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. [...] I think you have to remove the app.d that comes with sqlite-d file if you want to use it. Because that tries to open views/test-2.3.sqlite. Please try to read the source-code in app.d and in test.d that come with sqlite-d. If you have questions about that I am happy to answer them. Sqlite-d is a work in progress and I have not used it for an actual project. Currently I am busy with improving the ctfe engine. So I don't have to many resources should sqlite-d need improvements. Thanks for your willingness to help. Removing app.d from the library seems to make no difference. I just made an empty project as before (specifying your package as a dependency), like this: dub init sqlite-test Then I try to build using simply dub without parameters. However I get this message: Fetching sqlite-d 0.1.0 (getting selected version)... Non-optional dependency sqlite-d of sqlite-test not found in dependency tree!?. Am I missing a parameter or something?
Re: Problems compiling sqlite-d
On 01/28/2017 04:14 PM, Adam D. Ruppe wrote: On Saturday, 28 January 2017 at 21:03:08 UTC, Stefan Koch wrote: It's not native though. It's a mistake to ask for native D implementations of mature C libraries, especially a public domain one like sqlite. There's just no advantage in production use to rewrite it. Agreed but there can be happy surprises. :) Just because it's fresh in my mind: Jon Degenhardt implemented D versions of existing C, Go, and Rust tool kits in D and saw 3 to 10 times performance increase in many cases (not all). http://forum.dlang.org/thread/o6c9tj$2bdp$1...@digitalmars.com Ali
Re: Problems compiling sqlite-d
On Sunday, 29 January 2017 at 00:14:02 UTC, Adam D. Ruppe wrote: On Saturday, 28 January 2017 at 21:03:08 UTC, Stefan Koch wrote: It's not native though. It's a mistake to ask for native D implementations of mature C libraries, especially a public domain one like sqlite. There's just no advantage in production use to rewrite it. Well, native implementations are useful at least for building self-contained applications. Also, one can learn more advanced features of the language studying them. On the other hand, while for example C has a low overhead, I believe a properly optimized implementation in D could match and perhaps even surpass C code in terms of performance and safety, so at least for me, if someone has the knowledge and time to reimplement mature libraries in D, kudos to him/her, as a mere ignorant mortal I will certainly appreciate the effort. ;)
Re: Problems compiling sqlite-d
On Saturday, 28 January 2017 at 21:03:08 UTC, Stefan Koch wrote: It's not native though. It's a mistake to ask for native D implementations of mature C libraries, especially a public domain one like sqlite. There's just no advantage in production use to rewrite it.
Re: Problems compiling sqlite-d
On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: [...] Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. [...] I think you have to remove the app.d that comes with sqlite-d file if you want to use it. Because that tries to open views/test-2.3.sqlite. Please try to read the source-code in app.d and in test.d that come with sqlite-d. If you have questions about that I am happy to answer them. Sqlite-d is a work in progress and I have not used it for an actual project. Currently I am busy with improving the ctfe engine. So I don't have to many resources should sqlite-d need improvements.
Re: Problems compiling sqlite-d
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"]); It's not native though.
Re: Problems compiling sqlite-d
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"]);
Re: Problems compiling sqlite-d
On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: You have to compile the library with your app. or better yet use dub replace app.d with your app.d and run dub Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. The first occured because I am using a proxy which allows me to use only the browser, so I downloaded the git repository to a directory and made tests there. However finally I moved the library to the proper location, which in Windows 7 is this: C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0 Now, when I tried build your default app, it complained about the path: C:\>dub run sqlite-d Building package sqlite-d in C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0\sqlite-d\ Performing "debug" build using dmd for x86. sqlite-d ~master: building configuration "application"... Linking... Running .\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0\sqlite-d\sqlite-d.exe opening file views/test-2.3.sqlite std.file.FileException@std\file.d(358): views/test-2.3.sqlite: El sistema no puede encontrar la ruta especificada. 0x00425CC1 in @trusted bool std.file.cenforce!(bool).cenforce(bool, const(char)[], const(wchar)*, immutable(char)[], uint) 0x004074C2 in @safe void[] std.file.read!(immutable(char)[]).read(immutable(char)[], uint) at C:\dmd2\Windows\bin\..\..\src\phobos\std\file.d(228) 0x0040B947 in ref sqlited.Database sqlited.Database.__ctor(immutable(char)[], bool) 0x004022E9 in _Dmain at C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0\sqlite-d\source\app.d(19) 0x0041CC8B in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 0x0041CC4F in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x0041CB50 in _d_run_main 0x00408644 in main at C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0\sqlite-d\source\api_user.d(7) 0x0045BC45 in mainCRTStartup 0x754733CA in BaseThreadInitThunk 0x77309ED2 in RtlInitializeExceptionChain 0x77309EA5 in RtlInitializeExceptionChain Program exited with code 1 "El sistema no puede encontrar la ruta especificada" simply means "System can't find specified path" However, it compiles correctly if I run the command from C:\Users\nestor\AppData\Roaming\dub\packages\sqlite-d-0.1.0\sqlite-d\ The second issue was perhaps related, I tried to make a new project using your library as a dependency: { "name": "sqlite-test", "authors": [ "Nestor Perez" ], "dependencies": { "sqlite-d": "~>0.1.0" }, "description": "Simple sqlite-d test application", "copyright": "Copyright (c) 2017, Nestor Perez", "license": "Boost" } However I get this error when i try to run dub: Fetching sqlite-d 0.1.0 (getting selected version)... Non-optional dependency sqlite-d of sqlite-test not found in dependency tree!?. I also tried copying sqlite-d directory to source/ of my project, but same thing happens. I confess I have no experience making new projects with dub, so if you can spare a little patience, what would be the proper way to use your library for a new project?
Re: Problems compiling sqlite-d
On Friday, 27 January 2017 at 12:21:29 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:06:33 UTC, Stefan Koch wrote: On Friday, 27 January 2017 at 12:04:06 UTC, Stefan Koch wrote: I take it you build without dub ? Have you specified source/sqlite.d on your compile commandline ? That was supposed to say. sqlite-d/source/sqlited.d Please feel free to post here or contact me directly regarding the usage of sqlite-d. Yes I was building withoug dub. What I did was simply: copy data.db to sqlite-d/source cd to sqlite-d/source copy api_user.d to z1_app.d modify z1_app.d (as shown before) compile z1_app without additional parameters. Shouldn't it work? This was with dmd v2.072.2 on Windows 7 SP1 x86-64 You have to compile the library with your app. or better yet use dub replace app.d with your app.d and run dub
Re: Problems compiling sqlite-d
On Friday, 27 January 2017 at 12:06:33 UTC, Stefan Koch wrote: On Friday, 27 January 2017 at 12:04:06 UTC, Stefan Koch wrote: I take it you build without dub ? Have you specified source/sqlite.d on your compile commandline ? That was supposed to say. sqlite-d/source/sqlited.d Please feel free to post here or contact me directly regarding the usage of sqlite-d. Yes I was building withoug dub. What I did was simply: copy data.db to sqlite-d/source cd to sqlite-d/source copy api_user.d to z1_app.d modify z1_app.d (as shown before) compile z1_app without additional parameters. Shouldn't it work? This was with dmd v2.072.2 on Windows 7 SP1 x86-64
Re: Problems compiling sqlite-d
On Friday, 27 January 2017 at 12:04:06 UTC, Stefan Koch wrote: I take it you build without dub ? Have you specified source/sqlite.d on your compile commandline ? That was supposed to say. sqlite-d/source/sqlited.d Please feel free to post here or contact me directly regarding the usage of sqlite-d.
Re: Problems compiling sqlite-d
On Friday, 27 January 2017 at 12:01:30 UTC, Nestor wrote: Hi, I was trying to use https://github.com/UplinkCoder/sqlite-d Unfortunately even something as simple as this doesn´t compile (at least on Windows): import std.stdio, sqlited; void main(string[] args) { string filename = (args.length == 2 ? args[1] : "data.db"); Database db = Database(filename); } See the error: OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html z1_app.obj(z1_app) Error 42: Symbol Undefined _D7sqlited8Database6__initZ z1_app.obj(z1_app) Error 42: Symbol Undefined _D7sqlited8Database6__ctorMFNcAyabZS7sqlited8Database Error: linker exited with status 107814472 Is there any other native D implementation of sqlite reader? I take it you build without dub ? Have you specified source/sqlite.d on your compile commandline ?
Problems compiling sqlite-d
Hi, I was trying to use https://github.com/UplinkCoder/sqlite-d Unfortunately even something as simple as this doesn´t compile (at least on Windows): import std.stdio, sqlited; void main(string[] args) { string filename = (args.length == 2 ? args[1] : "data.db"); Database db = Database(filename); } See the error: OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html z1_app.obj(z1_app) Error 42: Symbol Undefined _D7sqlited8Database6__initZ z1_app.obj(z1_app) Error 42: Symbol Undefined _D7sqlited8Database6__ctorMFNcAyabZS7sqlited8Database Error: linker exited with status 107814472 Is there any other native D implementation of sqlite reader?
Re: SQLite
On Friday, 21 October 2016 at 10:50:30 UTC, Vadim Lopatin wrote: On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman wrote: Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. However, for any reason, there is no code snippets or sample codes available there. So, I am stucked. I have the following sample structure table: sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );"; Can you pls provide a code snippet or some hints to the following job: - Create a table with the layout above - Iterate through the records given a basic SELECT WHERE Query Thanks in advance, AN Snippet how to do it using DDBC library https://github.com/buggins/ddbc import ddbc; string url = "sqlite:testdb.sqlite"; // creating Connection auto conn = createConnection(url); scope(exit) conn.close(); // creating Statement auto stmt = conn.createStatement(); scope(exit) stmt.close(); // execute simple queries to create and fill table stmt.executeUpdate("CREATE TABLE COMPANY (ID int, NAME varchar, AGE int,ADDRESS varchar, SALARY double)"); string[] statements = [ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 2.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Allen', 25, 'Texas', 15000.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, 'Teddy', 23, 'Norway', 2.00 )" ]; foreach(sql; statements) stmt.executeUpdate(sql); Hello Vadim, I used dub to register DDBC. After that, I tried to do some tests, but I received the following error: Fetching ddbc ~master... Placing ddbc ~master to C:\Users\Alfred\AppData\Roaming\dub\packages\... Performing "release" build using dmd for x86. ddbc ~master: building configuration "full"... Copying files for ddbc... compiling C:\...\Projects\stingray.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 sqlite3.lib Warning 2: File Not Found sqlite3.lib C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(mysqlddbc) Error 42: Symbol Undefined _D5mysql10connection12__ModuleInfoZ C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(pgsqlddbc) Error 42: Symbol Undefined _D8derelict2pq2pq12__ModuleInfoZ C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(sqliteddbc) Error 42: Symbol Undefined _sqlite3_data_count ... _D5mysql8protocol8commands7Command11__xopEqualsFKxS5mysql8protocol8commands7CommandKxS5mysql8protocol8commands7CommandZb --- errorlevel 67 error: the process (dmd) has returned the signal 67 C:\...\Projects\stingray.d has not been compiled Notice that sqlite3.lib is located at my folder C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\libs\win64 What am I doing wrong ? Cheers
Re: SQLite
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman wrote: Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. However, for any reason, there is no code snippets or sample codes available there. So, I am stucked. I have the following sample structure table: sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );"; Can you pls provide a code snippet or some hints to the following job: - Create a table with the layout above - Iterate through the records given a basic SELECT WHERE Query Thanks in advance, AN Snippet how to do it using DDBC library https://github.com/buggins/ddbc import ddbc; string url = "sqlite:testdb.sqlite"; // creating Connection auto conn = createConnection(url); scope(exit) conn.close(); // creating Statement auto stmt = conn.createStatement(); scope(exit) stmt.close(); // execute simple queries to create and fill table stmt.executeUpdate("CREATE TABLE COMPANY (ID int, NAME varchar, AGE int,ADDRESS varchar, SALARY double)"); string[] statements = [ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 2.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Allen', 25, 'Texas', 15000.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, 'Teddy', 23, 'Norway', 2.00 )" ]; foreach(sql; statements) stmt.executeUpdate(sql);
Re: SQLite
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman wrote: Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. However, for any reason, there is no code snippets or sample codes available there. So, I am stucked. etc.c.sqlite3 is just a C wrapper, take a look at C examples for sqlite3. The D docs don't usually include documentation for simple C wrappers. If you want a proper D library for sqlite3, try d2sqlite3 from dub. IMO it's really easy to use and works really well. Your example using d2sqlite3: auto stmt = db.prepare("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) VALUES (:id, :name, :age, :address, :salary)"); stmt.inject(1, "Paul", 32, "California", 2); stmt.inject(2, "Allen", 25, "Texas", 15000); stmt.inject(3, "Teddy", 23, "Norway", 2); stmt.inject(4, "Mark", 25, "Rich-Mond", 65000);
Re: SQLite
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman wrote: Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. [...] I've never used SQLite from D, but Adam Ruppe has an interface with an example here: https://github.com/adamdruppe/arsd/blob/master/sqlite.d
SQLite
Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. However, for any reason, there is no code snippets or sample codes available there. So, I am stucked. I have the following sample structure table: sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );"; Can you pls provide a code snippet or some hints to the following job: - Create a table with the layout above - Iterate through the records given a basic SELECT WHERE Query Thanks in advance, AN
Re: Interfacing Chromium & SQLite
On Saturday, 5 September 2015 at 13:32:04 UTC, Mike McKee wrote: On Saturday, 5 September 2015 at 11:43:16 UTC, Mike McKee wrote: On a Mac (Yosemite version), how would I create a window in D, embed Chromium, use D to show a local SQLite test database (id, firstname, lastname) inside Chromium, and let someone have a small search form to do like a "full name" search that goes back to D to query the database again? Note: I'm not asking for source code examples, just wondering what technologies I would have to use to connect these pieces together? These libraries might help.. http://code.dlang.org/packages/derelict-cef http://code.dlang.org/packages/d2sqlite3 Other option might be to write a vibe.d (http://vibed.org/) web server as a front end for your DB
Re: Interfacing Chromium & SQLite
On Saturday, 5 September 2015 at 13:32:04 UTC, Mike McKee wrote: Note: I'm not asking for source code examples, just wondering what technologies I would have to use to connect these pieces together? I would basically look up how you'd do it in C and follow the same steps in D. I haven't used Chrominum though so I don't know more than that...
Re: Interfacing Chromium & SQLite
On Saturday, 5 September 2015 at 11:43:16 UTC, Mike McKee wrote: On a Mac (Yosemite version), how would I create a window in D, embed Chromium, use D to show a local SQLite test database (id, firstname, lastname) inside Chromium, and let someone have a small search form to do like a "full name" search that goes back to D to query the database again? Note: I'm not asking for source code examples, just wondering what technologies I would have to use to connect these pieces together?
Interfacing Chromium & SQLite
On a Mac (Yosemite version), how would I create a window in D, embed Chromium, use D to show a local SQLite test database (id, firstname, lastname) inside Chromium, and let someone have a small search form to do like a "full name" search that goes back to D to query the database again?
Re: Sqlite
On Sunday, 25 January 2015 at 18:19:47 UTC, Tobias Pankrath wrote: Only string literals convert to const(char)*, because only for them it is guaranteed that they are null terminated. For everything else use toStringz. So, as a trivial example, is this how it's done?: string semiC = ";"; const char *sqlStatement = toStringz("CREATE TABLE people(id INT PRIMARY KEY NOT NULL, surname TEXT NOT NULL)"~semiC); Seems rather ugly but I guess it's a result of interfacing with C...
Re: Sqlite
On Sunday, 25 January 2015 at 18:15:21 UTC, Paul wrote: I'd like to vary the query based on input but if I try to move the string out of the sqlite3_exec call like this: string sqlStatement = "CREATE TABLE people(id INT PRIMARY KEY NOT NULL, surname TEXT NOT NULL);"; result = sqlite3_exec(db, sqlStatement, &aCallback, null, &msg); ...it won't compile: Error: function etc.c.sqlite3.sqlite3_exec (sqlite3*, const(char)* sql,... is not callable using argument types (sqlite3*, string,... I can assign using: const char *sqlStatement = "CREATE TABLE... So how do I get a constant character pointer that can be modified at runtime? Paul Only string literals convert to const(char)*, because only for them it is guaranteed that they are null terminated. For everything else use toStringz.
Re: Sqlite
I'd like to vary the query based on input but if I try to move the string out of the sqlite3_exec call like this: string sqlStatement = "CREATE TABLE people(id INT PRIMARY KEY NOT NULL, surname TEXT NOT NULL);"; result = sqlite3_exec(db, sqlStatement, &aCallback, null, &msg); ...it won't compile: Error: function etc.c.sqlite3.sqlite3_exec (sqlite3*, const(char)* sql,... is not callable using argument types (sqlite3*, string,... I can assign using: const char *sqlStatement = "CREATE TABLE... So how do I get a constant character pointer that can be modified at runtime? Paul
Re: Sqlite
On Sunday, 11 January 2015 at 22:19:28 UTC, Tobias Pankrath wrote: Hint: Put the SQL in a file create_people.sql and import it into your code via the import statement: string sql = import("create_people.sql"); // you'll need a correct -J compiler switch That way you can easily test if it's correct on the commandline. It's .read in the sqlite3 shell. Neat, thank you!
Re: Sqlite
On Sunday, 11 January 2015 at 20:30:41 UTC, Paul wrote: On Sunday, 11 January 2015 at 20:20:21 UTC, ketmar via Digitalmars-d-learn wrote: note the single quotes in your code: that is where it all goes wrong. i don't know where you got that quotes from, but this is not a valid SQL syntax for `CREATE TABLE`. ;-) Thank you, I thought it might be something obvious - that will teach me to cut and paste code! :D Hint: Put the SQL in a file create_people.sql and import it into your code via the import statement: string sql = import("create_people.sql"); // you'll need a correct -J compiler switch That way you can easily test if it's correct on the commandline. It's .read in the sqlite3 shell.
Re: Sqlite
On Sunday, 11 January 2015 at 20:20:21 UTC, ketmar via Digitalmars-d-learn wrote: note the single quotes in your code: that is where it all goes wrong. i don't know where you got that quotes from, but this is not a valid SQL syntax for `CREATE TABLE`. ;-) Thank you, I thought it might be something obvious - that will teach me to cut and paste code! :D
Re: Sqlite
On Sun, 11 Jan 2015 20:00:03 + Paul via Digitalmars-d-learn wrote: > Can someone please tell me what I'm doing wrong here, the sql > INSERT statement fails for some reason. I don't fully understand > the callback function yet (I borrowed this from a C tutorial on > the subject), maybe that is the source of the problem? > > > import etc.c.sqlite3; > import std.stdio; > > //stub > extern(C) int aCallback(void *n, int c, char **v, char **col) > { >return 0; > } > > void main(){ > > sqlite3 *db; > int result = sqlite3_open("myDatabase.db", &db); > > if (result) { > writeln("Failed to open database"); > return; > } > > //create table > char *msg = null; > result = sqlite3_exec(db, "CREATE TABLE people('id INT PRIMARY > KEY NOT NULL, surname TEXT NOT NULL');", &aCallback, null, &msg); > if (result) { > writeln("Failed to create table"); > > //tidy up on exit > sqlite3_close(db); > return; > } > > //insert record > msg = null; > result = sqlite3_exec(db, "INSERT INTO people (id, surname) > VALUES (1, 'Smith');", &aCallback, null, &msg); > if (result) { > writeln("Failed to insert record"); > > //tidy up on exit > sqlite3_close(db); > return; > > } > > sqlite3_free(msg); > sqlite3_close(db); > > } > > Many thanks > > Paul if you'll output the error message, you'll see something unusual here: if (result) { import std.conv : to; writeln("Failed to insert record: ", to!string(msg)); //tidy up on exit sqlite3_close(db); return; } "Failed to insert record: table people has no column named id" wow! but it has! or isn't it? yep, it hasn't. the error is here: > result = sqlite3_exec(db, "CREATE TABLE people('id INT PRIMARY > KEY NOT NULL, surname TEXT NOT NULL');", &aCallback, null, &msg); `CREATE TABLE people('...')` is not the syntax you want. i don't know why sqlite is not rejecting it, but the correct one is this: result = sqlite3_exec(db, "CREATE TABLE people(id INT PRIMARY "~ "KEY NOT NULL, surname TEXT NOT NULL);", &aCallback, null, &msg); note the single quotes in your code: that is where it all goes wrong. i don't know where you got that quotes from, but this is not a valid SQL syntax for `CREATE TABLE`. ;-) signature.asc Description: PGP signature
Sqlite
Can someone please tell me what I'm doing wrong here, the sql INSERT statement fails for some reason. I don't fully understand the callback function yet (I borrowed this from a C tutorial on the subject), maybe that is the source of the problem? import etc.c.sqlite3; import std.stdio; //stub extern(C) int aCallback(void *n, int c, char **v, char **col) { return 0; } void main(){ sqlite3 *db; int result = sqlite3_open("myDatabase.db", &db); if (result) { writeln("Failed to open database"); return; } //create table char *msg = null; result = sqlite3_exec(db, "CREATE TABLE people('id INT PRIMARY KEY NOT NULL, surname TEXT NOT NULL');", &aCallback, null, &msg); if (result) { writeln("Failed to create table"); //tidy up on exit sqlite3_close(db); return; } //insert record msg = null; result = sqlite3_exec(db, "INSERT INTO people (id, surname) VALUES (1, 'Smith');", &aCallback, null, &msg); if (result) { writeln("Failed to insert record"); //tidy up on exit sqlite3_close(db); return; } sqlite3_free(msg); sqlite3_close(db); } Many thanks Paul
Re: Compiling with SQLite
On Tuesday, 18 November 2014 at 05:06:59 UTC, impatient-dev wrote: On Tuesday, 18 November 2014 at 03:41:42 UTC, uri wrote: Are you linking with libsqlite3.a? For example: $ dmd prog.d -L-lsqlite3 That worked, thanks. I didn't know you had to anything special to link with code in the standard library; is there documentation for this somewhere? D doesn't have the whole implementation of SQLite. It is implemented as a library, and the sqlite3 module hooks up to library's functions. So, you should give your program the library ie. implementation of SQLite.
Re: Compiling with SQLite
On Tuesday, 18 November 2014 at 03:41:42 UTC, uri wrote: Are you linking with libsqlite3.a? For example: $ dmd prog.d -L-lsqlite3 That worked, thanks. I didn't know you had to anything special to link with code in the standard library; is there documentation for this somewhere? Also, is there a way I could make SQLite work with DUB rather than building manually? The command-line help and web page don't seem to mention this anywhere.
Re: Compiling with SQLite
On Tuesday, 18 November 2014 at 01:14:26 UTC, impatient-dev wrote: I'm new to D, and I'm trying to use SQLite, but I can't get this basic program to compile: import etc.c.sqlite3 : sqlite3_open; void main(string[] args){ sqlite3_open("test.sqlite", null); } When compiling with DMD v2.066.1, I get this error: test.o: In function `_Dmain': test.d:(.text._Dmain+0x2f): undefined reference to `sqlite3_open' collect2: ld returned 1 exit status --- errorlevel 1 Any idea what I'm doing wrong? I'm on Ubuntu 12.04 64-bit, but I doubt that matters. I've tried a couple alternatives, but they didn't work either. Are you linking with libsqlite3.a? For example: $ dmd prog.d -L-lsqlite3
Re: Compiling with SQLite
Addendum: I'm using DDT for Eclipse, and the names I'm using come up in its autocomplete. They also appear at http://dlang.org/phobos/etc_c_sqlite3.html, which is why I'm stumped. I get what the error means, but I don't understand why it's occurring.
Compiling with SQLite
I'm new to D, and I'm trying to use SQLite, but I can't get this basic program to compile: import etc.c.sqlite3 : sqlite3_open; void main(string[] args){ sqlite3_open("test.sqlite", null); } When compiling with DMD v2.066.1, I get this error: test.o: In function `_Dmain': test.d:(.text._Dmain+0x2f): undefined reference to `sqlite3_open' collect2: ld returned 1 exit status --- errorlevel 1 Any idea what I'm doing wrong? I'm on Ubuntu 12.04 64-bit, but I doubt that matters. I've tried a couple alternatives, but they didn't work either.
Re: SQLite library on Windows
Man, I wish I'd known about that tool a while ago... It seems to be working, but it looks like I'll need to recompile the DLL myself; DMD is looking for symbols mangled with a leading underscore, but the DLL has unmangled symbols, so optlink still complains. Oh; never mind. I forgot the /system switch. Now I feel like an idiot. :)
Re: SQLite library on Windows
Download their windows binaries and use Digital Mars implib tool with /system switch. Man, I wish I'd known about that tool a while ago... It seems to be working, but it looks like I'll need to recompile the DLL myself; DMD is looking for symbols mangled with a leading underscore, but the DLL has unmangled symbols, so optlink still complains.
Re: SQLite library on Windows
On Thursday, 27 December 2012 at 01:45:26 UTC, BLM768 wrote: I've been trying various methods to get SQLite working in Windows using the etc.c.sqlite3 bindings, but I can't figure out how to get everything in a form that DMD likes. GCC doesn't seem to output anything that OPTLINK can use, and I can't use the standard DLL build without creating a .LIB file from it, which apparently isn't an easy task. I can't remember if I've tried compiling SQLite with DMC, but I'd rather avoid that option because it would require a custom Makefile. Maybe objcopy has an option that would help... Has anyone managed to get the library working on Windows? Download their windows binaries and use Digital Mars implib tool with /system switch.
Re: SQLite library on Windows
On Thursday, 27 December 2012 at 03:03:34 UTC, jose isaias cabrera wrote: I have a huge project with D1 using the old DDBI project in dsource: http://dsource.org/projects/ddbi It would be nice if someone with time will port it to D2. IHTH. jic Actually, my current project is basically along those lines. It currently only has a partial interface and an SQLite driver for now, though, and the interface will probably be quite different from DDBI's (largely for performance reasons).
Re: SQLite library on Windows
"BLM768" ... > Has anyone managed to get the library working on Windows? I have a huge project with D1 using the old DDBI project in dsource: http://dsource.org/projects/ddbi It would be nice if someone with time will port it to D2. IHTH. jic
Re: SQLite library on Windows
On Thursday, 27 December 2012 at 01:45:26 UTC, BLM768 wrote: I've been trying various methods to get SQLite working in Windows using the etc.c.sqlite3 bindings, but I can't figure out how to get everything in a form that DMD likes. GCC doesn't seem to output anything that OPTLINK can use, and I can't use the standard DLL build without creating a .LIB file from it, which apparently isn't an easy task. I can't remember if I've tried compiling SQLite with DMC, but I'd rather avoid that option because it would require a custom Makefile. Maybe objcopy has an option that would help... Has anyone managed to get the library working on Windows? have you tried feed import lib to coffimplib tool to make omf format lib for optlink? ftp://ftp.digitalmars.com/coffimplib.zip
SQLite library on Windows
I've been trying various methods to get SQLite working in Windows using the etc.c.sqlite3 bindings, but I can't figure out how to get everything in a form that DMD likes. GCC doesn't seem to output anything that OPTLINK can use, and I can't use the standard DLL build without creating a .LIB file from it, which apparently isn't an easy task. I can't remember if I've tried compiling SQLite with DMC, but I'd rather avoid that option because it would require a custom Makefile. Maybe objcopy has an option that would help... Has anyone managed to get the library working on Windows?
Re: SQLite with D
reimi gibbons wrote: > downs Wrote: > >> reimi gibbons wrote: >>> im failry new to D, is there any D library project with support for SQLite, >>> if not is there any guide so i can integrate sqlite amalgamated c source >>> (sqlite3.c, sqlite3.h) into my D code. >> tools.sqlite3 might work for you. Ask me if you have any questions about it. >> >> http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d >> >> (Check the very end for an example) > > sorry about earlier reply, mistaken your lib to another lib. btw, how do i > use this file. with precompiled library (dll/so) or .h/.c ? > thanks > Oh, I don't know about that. Sqlite3 is a static library on my Linux. Try to compile the sqlite3.c to .o and just link that in.
Re: SQLite with D
downs Wrote: > reimi gibbons wrote: > > im failry new to D, is there any D library project with support for SQLite, > > if not is there any guide so i can integrate sqlite amalgamated c source > > (sqlite3.c, sqlite3.h) into my D code. > > tools.sqlite3 might work for you. Ask me if you have any questions about it. > > http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d > > (Check the very end for an example) sorry about earlier reply, mistaken your lib to another lib. btw, how do i use this file. with precompiled library (dll/so) or .h/.c ? thanks
Re: SQLite with D
downs Wrote: > reimi gibbons wrote: > > im failry new to D, is there any D library project with support for SQLite, > > if not is there any guide so i can integrate sqlite amalgamated c source > > (sqlite3.c, sqlite3.h) into my D code. > > tools.sqlite3 might work for you. Ask me if you have any questions about it. > > http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d > > (Check the very end for an example) thanks for the link. Is it possible to dynamicly load the precompiled binary and use it wihtout header file? since im hoping to use latest sqlite (3.6)
Re: SQLite with D
reimi gibbons wrote: > im failry new to D, is there any D library project with support for SQLite, > if not is there any guide so i can integrate sqlite amalgamated c source > (sqlite3.c, sqlite3.h) into my D code. tools.sqlite3 might work for you. Ask me if you have any questions about it. http://dsource.org/projects/scrapple/browser/trunk/tools/tools/sqlite3.d (Check the very end for an example)
Re: SQLite with D
On Fri, 24 Apr 2009 06:44:56 +0400, reimi gibbons wrote: im failry new to D, is there any D library project with support for SQLite, if not is there any guide so i can integrate sqlite amalgamated c source (sqlite3.c, sqlite3.h) into my D code. There is a DDBI project that aims to support various databases for D, but its trunk is currently focused on MySQL. OTOH, there is a fork of it that added SQLite support sometime ago. I don't not how stable it is, but you may give it a try: http://github.com/aaronc/ddbi/tree/master
SQLite with D
im failry new to D, is there any D library project with support for SQLite, if not is there any guide so i can integrate sqlite amalgamated c source (sqlite3.c, sqlite3.h) into my D code.