SQLite
Alfred Newman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 1 10:05:57 PDT 2016
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', 20000.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', 20000.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', 20000.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', 20000.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
More information about the Digitalmars-d-learn
mailing list