www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Best SQL library to use with local desktop app

reply wakhshti <www.google gmail.com> writes:
what is best (SQLite?)  small  local  offline database library to 
use in D?

and also what about a simple GUI library ? (once there was a 
library named DFL, but i never could get it to run).
Jan 03
next sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 3 January 2018 at 12:14:19 UTC, wakhshti wrote:
 what is best (SQLite?)  small  local  offline database library 
 to use in D?

 and also what about a simple GUI library ? (once there was a 
 library named DFL, but i never could get it to run).
As you proposed SQLite makes sense. My personal preference is the wrapper from Adam you can find here https://github.com/adamdruppe/arsd/blob/master/sqlite.d Do you want to run on a specific OS only or should it run on multiple OS? There is also the Learn forum which fits better for beginner questions. Kind regards Andre
Jan 03
parent reply wakhshti <www.google gmail.com> writes:
On Wednesday, 3 January 2018 at 12:45:51 UTC, Andre Pany wrote:
 As you proposed SQLite makes sense. My personal preference is 
 the wrapper from Adam you can find here 
 https://github.com/adamdruppe/arsd/blob/master/sqlite.d

 Do you want to run on a specific OS only or should it run on 
 multiple OS?

 There is also the Learn forum which fits better for beginner 
 questions.

 Kind regards
 Andre
i downloaded the whole arsd and unzipped to folder that my main.d is. and main.d contents are:
import std.stdio;
import arsd.sqlite;


void main(string[] args) {

    Database db = new Sqlite("test.sqlite.db");

    /+
    db.query("CREATE TABLE users (id integer, name text)");
    db.query("INSERT INTO users values (?, ?)", 1, "hello");
    foreach(line; db.query("SELECT * FROM users")) {
         writefln("%s %s", line[0], line["name"]);
    }
    +/
}
i get this error: D:\ashit\document\DlangIDE\database\database\source>dmd main.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 main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite6__ctorMFAyaiZCQBiQBgQBc main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite7__ClassZ main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite12__ModuleInfoZ Error: linker exited with status 3 ----------------------------------------------------------------- the os i use is Windows7 (dual boot with ubuntu but mainly on windows7) also i tried several libraries. i couldn't run any database or gui libraries correctly so far. dlangui was the only gui library that i was able to run correctly. im interested in DFL and Entice designer (never be able to run them either)
Jan 03
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 3 January 2018 at 20:39:59 UTC, wakhshti wrote:
  Error 42: Symbol Undefined 
 _D4arsd6sqlite6Sqlite6__ctorMFAyaiZCQBiQBgQBc
That means you didn't link in the module. The way I recommend doing it is listing them all on the command line: dmd yourfile.d database.d sqlite.d or if you put them in an arsd folder (optional) dmd yourfile.d arsd\database.d arsd\sqlite.d For sqlite, you also will need a sqlite.lib in the current directory or it will list a lot of Symbol Undefined like _sqlite3_open etc. And at runtime, you will need the sqlite.dll file along with your exe. This is probably your general problem: you need to link in those libs too. Here's the sqlite3.lib and dll too if you don't already have them: http://arsdnet.net/dcode/sqlite3.lib http://arsdnet.net/dcode/sqlite3.dll just download them to the folder with your program.
Jan 03
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 3 January 2018 at 20:52:49 UTC, Adam D. Ruppe wrote:
 Here's the sqlite3.lib and dll too if you don't already have 
 them:
These are just for Windows btw (and for that, only 32 bit. if you are building 64 bit that is different, I have never used sqlite on 64 bit windows. but 32 bit is usually good enough anyway) On Linux, you just need to make sure the sqlite3-devel package is installed. I think that's what it is called too, so apt-get install sqlite3-devel. if not it might suggest the right name
Jan 03
parent wakhshti <www.google gmail.com> writes:
On Wednesday, 3 January 2018 at 20:54:50 UTC, Adam D. Ruppe wrote:
 These are just for Windows btw (and for that, only 32 bit. if 
 you are building 64 bit that is different, I have never used 
 sqlite on 64 bit windows. but 32 bit is usually good enough 
 anyway)

 On Linux, you just need to make sure the sqlite3-devel package 
 is installed. I think that's what it is called too, so apt-get 
 install sqlite3-devel. if not it might suggest the right name
yes, i agree. 32 bit will work very well. why bother with 64. once i was greedy about using massive and most up to date hardware. you know, it doesn't matter how much resources someone have, if he don't know how to use it, it will never be enough. then i enter the embedded(micro-controller). the world has changed since that. :)
Jan 03
prev sibling parent wakhshti <www.google gmail.com> writes:
On Wednesday, 3 January 2018 at 20:52:49 UTC, Adam D. Ruppe wrote:

 That means you didn't link in the module.

 The way I recommend doing it is listing them all on the command 
 line:

 dmd yourfile.d database.d sqlite.d

 or if you put them in an arsd folder (optional)

 dmd yourfile.d arsd\database.d arsd\sqlite.d



 For sqlite, you also will need a sqlite.lib in the current 
 directory or it will list a lot of Symbol Undefined like 
 _sqlite3_open etc. And at runtime, you will need the sqlite.dll 
 file along with your exe.

 This is probably your general problem: you need to link in 
 those libs too.

 Here's the sqlite3.lib and dll too if you don't already have 
 them:

 http://arsdnet.net/dcode/sqlite3.lib
 http://arsdnet.net/dcode/sqlite3.dll

 just download them to the folder with your program.
thank you. finally i am able to do it in correct way. (i think if there be only one way to do something wrong, it will happen to me :))
Jan 03
prev sibling parent bauss <jj_1337 live.dk> writes:
On Wednesday, 3 January 2018 at 20:39:59 UTC, wakhshti wrote:
 On Wednesday, 3 January 2018 at 12:45:51 UTC, Andre Pany wrote:
 As you proposed SQLite makes sense. My personal preference is 
 the wrapper from Adam you can find here 
 https://github.com/adamdruppe/arsd/blob/master/sqlite.d

 Do you want to run on a specific OS only or should it run on 
 multiple OS?

 There is also the Learn forum which fits better for beginner 
 questions.

 Kind regards
 Andre
i downloaded the whole arsd and unzipped to folder that my main.d is. and main.d contents are:
import std.stdio;
import arsd.sqlite;


void main(string[] args) {

    Database db = new Sqlite("test.sqlite.db");

    /+
    db.query("CREATE TABLE users (id integer, name text)");
    db.query("INSERT INTO users values (?, ?)", 1, "hello");
    foreach(line; db.query("SELECT * FROM users")) {
         writefln("%s %s", line[0], line["name"]);
    }
    +/
}
i get this error: D:\ashit\document\DlangIDE\database\database\source>dmd main.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 main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite6__ctorMFAyaiZCQBiQBgQBc main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite6Sqlite7__ClassZ main.obj(main) Error 42: Symbol Undefined _D4arsd6sqlite12__ModuleInfoZ Error: linker exited with status 3 ----------------------------------------------------------------- the os i use is Windows7 (dual boot with ubuntu but mainly on windows7) also i tried several libraries. i couldn't run any database or gui libraries correctly so far. dlangui was the only gui library that i was able to run correctly. im interested in DFL and Entice designer (never be able to run them either)
You have to pass all source files you wish to compile to dmd.
Jan 03
prev sibling next sibling parent reply Craig Dillabaugh <craig.dillabaugh gmail.com> writes:
On Wednesday, 3 January 2018 at 12:14:19 UTC, wakhshti wrote:
 what is best (SQLite?)  small  local  offline database library 
 to use in D?

 and also what about a simple GUI library ? (once there was a 
 library named DFL, but i never could get it to run).
I've used sqlite3 library: http://code.dlang.org/packages/sqlite3 and it has worked well for me. Documentation is brief, but has a clean API and relatively easy to use. However, there is small bug in the support for floating point values if you need that. I submitted a patch but don't think it has made its way into the main repository.
Jan 03
parent reply wakhshti <www.google gmail.com> writes:
On Wednesday, 3 January 2018 at 16:38:27 UTC, Craig Dillabaugh 
wrote:
 On Wednesday, 3 January 2018 at 12:14:19 UTC, wakhshti wrote:
 what is best (SQLite?)  small  local  offline database library 
 to use in D?

 and also what about a simple GUI library ? (once there was a 
 library named DFL, but i never could get it to run).
I've used sqlite3 library: http://code.dlang.org/packages/sqlite3 and it has worked well for me. Documentation is brief, but has a clean API and relatively easy to use. However, there is small bug in the support for floating point values if you need that. I submitted a patch but don't think it has made its way into the main repository.
yes, it is very good looking API. interesting i downloaded and extracted files into my main.d file directory this is main.d content:
import std.stdio;
import sqlite;

void main(string[] args){

	auto db = new SQLite3("datafile.db");

}
when i run :
dmd main.d
i get this error: D:\ashit\document\DlangIDE\database\db>dmd main.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 main.obj(main) Error 42: Symbol Undefined _D6sqlite7SQLite36__ctorMFAyaZCQBdQz main.obj(main) Error 42: Symbol Undefined _D6sqlite7SQLite37__ClassZ Error: linker exited with status 2 what to do ? i also downloaded new dmd but nothing seems going well.
Jan 03
parent reply Craig Dillabaugh <craig.dillabaugh gmail.com> writes:
On Wednesday, 3 January 2018 at 21:12:54 UTC, wakhshti wrote:
 On Wednesday, 3 January 2018 at 16:38:27 UTC, Craig Dillabaugh 
 wrote:
 On Wednesday, 3 January 2018 at 12:14:19 UTC, wakhshti wrote:

clip
 this is main.d content:

import std.stdio;
import sqlite;

void main(string[] args){

	auto db = new SQLite3("datafile.db");

}
when i run :
dmd main.d
i get this error: D:\ashit\document\DlangIDE\database\db>dmd main.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 main.obj(main) Error 42: Symbol Undefined _D6sqlite7SQLite36__ctorMFAyaZCQBdQz main.obj(main) Error 42: Symbol Undefined _D6sqlite7SQLite37__ClassZ Error: linker exited with status 2 what to do ? i also downloaded new dmd but nothing seems going well.
Looks like you are up and running with Adam's stuff, but if you wanted to use the sqlite3 library I would suggest you use 'dub' to do the build as sqlite3 is in code.dlang.org. An example form my own project: dub.sdl --------------------------------------------------------- name "blah" description "An application that uses sqlite3 library.." authors "Craig Dillabaugh" copyright "Copyright © 2017, Craig Dillabaugh" license "Whatever" dependency "sqlite3" version="~>1.0.0"
Jan 03
parent wakhshti <www.google gmail.com> writes:
On Wednesday, 3 January 2018 at 23:51:23 UTC, Craig Dillabaugh 
wrote:

 Looks like you are up and running with Adam's stuff, but if you 
 wanted to use the sqlite3 library I would suggest you use 'dub' 
 to do the build as sqlite3 is in code.dlang.org.  An example 
 form my own project:

 dub.sdl
 ---------------------------------------------------------
 name "blah"
 description "An application that uses sqlite3 library.."
 authors "Craig Dillabaugh"
 copyright "Copyright © 2017, Craig Dillabaugh"
 license "Whatever"
 dependency "sqlite3" version="~>1.0.0"
now, i can run this too (the same way Adam noted). thank you all ...
Jan 03
prev sibling next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Jan 03, 2018 at 12:14:19PM +0000, wakhshti via Digitalmars-d wrote:
 
 what is best (SQLite?)  small  local  offline database library to use
 in D?
[...] I've been using SQLite for this type of usage, and it's served me pretty well. I've been using Adam Ruppe's SQLite bindings: https://github.com/adamdruppe/arsd/blob/master/sqlite.d which is very nice, lightweight, and doesn't have heavy dependencies (all you need is database.d and sqlite.d, plop them into a subdirectory called arsd, and then just `import arsd.sqlite` and you're all set to go). Recently, though, I decided to write my own bindings due to certain design decisions in Adam's sqlite.d that made it a little awkward to use for my particular application. My bindings are now usable for basic database operation and have a rather nice API, if I do say so myself (well, it is modelled after Adam's sqlite.d which already has a nice and simple API), but feature-wise it's still quite bare (doesn't support precompiled SQL statements yet). The current main features are: - Basic database operation: open a database file, execute SQL statements (on par with Adam's sqlite.d). - Automatic binding (on par with Adam's sqlite.d), e.g.: long id = 123; string name = "abc"; auto rs = db.query("SELECT * FROM product WHERE id=? AND name=?", id, name); - Supports binding floating-point values. - Supports binary blobs in the form of ubyte[]. - Supports integers up to signed 64-bit (long). - Supports nested transactions (via SAVEPOINT and RELEASE). - Range-based API for iterating over result sets. - Convenient automatic conversions to/from SQLite data types, e.g.: float maxPrice = 100.00; auto rs = db.query("SELECT count, price FROM product WHERE price < ?", maxPrice); foreach (row; rs) { int count = row[0].to!int; float price = row[1].to!float; } - Fully-automated transcription of result sets to array of structs, or individual rows to structs, and convenience functions for extracting single-column result sets into an array of scalar values, or individual single-column rows into scalar values. Example: struct S { int name; float price; ubyte[] image; // BLOB } // Transcribe individual rows to struct foreach (row; db.query("SELECT name,price,image FROM product")) { S s = row.to!S; } // Transcribe entire result set to array of structs S[] results = db.query("SELECT name,price,image FROM product") .to!(S[]); If you wish, I can give you a copy of the code -- it's just a single file that you can import directly, no other dependencies besides the SQLite library itself. It's not quite in the shape to be posted to a public repository like github just yet, but depending on what you need, it might be good enough. T -- An elephant: A mouse built to government specifications. -- Robert Heinlein
Jan 03
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 3 January 2018 at 19:08:44 UTC, H. S. Teoh wrote:
 Recently, though, I decided to write my own bindings due to 
 certain design decisions in Adam's sqlite.d that made it a 
 little awkward to use for my particular application.
I'm open to extensions and PRs... I don't remember if we have already talked about this but if not email me destructionator gmail.com and we'll see if we can't merge again. I know you have had some trouble with the classes before, maybe we can work out a more deterministic design there.
Jan 03
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2018-01-03 13:14, wakhshti wrote:

 and also what about a simple GUI library ? (once there was a library 
 named DFL, but i never could get it to run).
For a GUI library you can give DWT [1] a try. Works on Linux and Windows and is using native drawing operations. [1] https://github.com/d-widget-toolkit/dwt -- /Jacob Carlborg
Jan 04
parent reply wakhshti <www.google gmail.com> writes:
On Thursday, 4 January 2018 at 09:59:08 UTC, Jacob Carlborg wrote:
 On 2018-01-03 13:14, wakhshti wrote:

 and also what about a simple GUI library ? (once there was a 
 library named DFL, but i never could get it to run).
For a GUI library you can give DWT [1] a try. Works on Linux and Windows and is using native drawing operations. [1] https://github.com/d-widget-toolkit/dwt
it is not compiling:
C:\Users\wakhshti\Downloads\dwt-master>rdmd base swt -m32mscoff
Error: module base is in file 'base.d' which cannot be read
import path[0] = .
import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
Failed: ["dmd", "-v", "-o-", "base.d", "-I."]
Jan 04
parent reply Jacob Carlborg <doob me.com> writes:
On 2018-01-04 13:48, wakhshti wrote:

 it is not compiling:
 
 C:\Users\wakhshti\Downloads\dwt-master>rdmd base swt -m32mscoff
 Error: module base is in file 'base.d' which cannot be read
 import path[0] = .
 import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
 import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
 Failed: ["dmd", "-v", "-o-", "base.d", "-I."]
Looks like the readme is wrong. It should be: rdmd build base swt -m32mscoff -- /Jacob Carlborg
Jan 04
parent Jacob Carlborg <doob me.com> writes:
On 2018-01-04 15:39, Jacob Carlborg wrote:

 Looks like the readme is wrong. It should be:
 
 rdmd build base swt -m32mscoff
I've corrected the readme now. -- /Jacob Carlborg
Jan 04