Giter VIP home page Giter VIP logo

hunt-database's People

Contributors

dangbinghoo avatar gaoxincheng avatar heromyth avatar noclear avatar stevenpan110 avatar viile avatar wangyun0831 avatar ximion avatar zhangyuchun avatar zoujiaqing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hunt-database's Issues

[PostgreSQL] VariantException in count() method

Stack trace:

std.variant.VariantException@std/variant.d(1715): Variant: attempting to use incompatible types long and int
/usr/include/dmd/phobos/std/variant.d:836 inout @property inout(int) std.variant.VariantN!(32uL).VariantN.get!(int).get() [0x55c4f05eea50]
../../.dub/packages/hunt-database-2.0.0-beta.4/hunt-database/source/hunt/database/base/impl/ArrayTuple.d:100 int hunt.database.base.impl.ArrayTuple.ArrayTuple.getInteger(int) [0x55c4f0625601]
../../.dub/packages/hunt-database-2.0.0-beta.4/hunt-database/source/hunt/database/Statement.d:200 int hunt.database.Statement.Statement.count() [0x55c4f05adeaa]
[...]

hunt-database 2.0.0-beta.4, PostgreSQL 11.

Empty query result on SQL errors

When the SQL query is malformed, user doesn't get any feedback - an empty result is returned instead. It makes debugging harder.

I suggest that SQL errors resulted in DatabaseException (or its new subclass - SQLException) thrown on execution of the malformed statement.

Why is RowSet no more a range?

I've just tried 2.0 beta version. However I find it very problematic that RowSet is no more an InputRange. Until now I could freely use all the D's algorithms directly on RowSet (and I used it everywhere). With 2.0 most of my code broke.

Also, sometimes I just need the first row and don't want to use foreach anyway.

Could the RowSet be made an InputRange again?

database 0.0.20 won't build on x64 platform

$ dub run --config=linux --arch=x86 --build=debug --compiler=dmd
Performing "debug" build using dmd for x86.
database 0.0.20: building configuration "sqlite"...
/home/playpeng/.dub/packages/database-0.0.20/database/source/database/url.d(1186,19): Error: cannot implicitly convert expression pos of type ulong to uint
/home/playpeng/.dub/packages/database-0.0.20/database/source/database/url.d(1219,38): Error: template std.array.insertInPlace cannot deduce function from argument types !()(dchar[], ulong, dchar), candidates are:
/usr/include/dlang/dmd/std/array.d(951,6):        std.array.insertInPlace(T, U...)(ref T[] array, size_t pos, U stuff) if (!isSomeString!(T[]) && allSatisfy!(isInputRangeOrConvertible!T, U) && (U.length > 0))
/usr/include/dlang/dmd/std/array.d(1010,6):        std.array.insertInPlace(T, U...)(ref T[] array, size_t pos, U stuff) if (isSomeString!(T[]) && allSatisfy!(isCharOrStringOrDcharRange, U))
dmd failed with exit code 1.

this is the error message, and it has the some err when using ldc2 on windows when trying to build for an x86 target.

Program exited with code -11

Hi All,

We are getting the error message "Program exited with code -11" out of 10 executions we get this error 2 time's not sure what or where is the issue, hence request your help.

setParameter is not implemented but documented in README

I tried out the below and looked the source code it seems that setParameter is not implemented but it's present in the README.md . Is there a way to bind values to prepared statements ?

    string sql = "INSERT INTO testing(data) VALUES (':value');";
    auto stmt = db.prepare(sql);
    stmt.setParameter("value", value);

Empty implementation : https://github.com/huntlabs/database/blob/74ddf46ee42722d2e7967986b0d5fff1f468601c/source/database/statement.d#L42

Thanks

Does not appear to handle boolean for PostgreSQL correctly

When trying to insert a boolean value into a table (created via hunt-entity), this error appears:

2018-09-08T21:16:34.378:statement.d:execute:84  INSERT INTO public.users(name,email,money,status) VALUES('Brian','[email protected]',99.9,0) returning id 
hunt.database.exception.DatabaseException@../source/hunt/database/driver/postgresql/connection.d(83): DB SQL :  INSERT INTO public.users(name,email,money,status) VALUES('Brian','[email protected]',99.9,0) returning id 
DB status : 7 
EXECUTE ERROR : 7
ERROR:  Column »status« has type boolean, but expression has type integer
LINE 1: ...y,status) VALUES('Brian','[email protected]',99.9,0) returni...
                                                             ^

This can either be solved by doing a type conversion in the expression (converting 0 into a bool), or by giving the database a boolean t/f value in the first place.

Btw, I think hunt-entity and hunt-database could really benefit from some integration tests with different databases - unfortunately those are a bit annoying to do in D. Maybe I can come up with something in my spare time.

database basic error

I have downloaded this. and run the example mysql. but it throws below error

Dlang\database-0.1.0\examples\mysql>dub run
Performing "debug" build using dmd for x86.
database ~master: building configuration "mysql"...
mysql_demo ~master: building configuration "default"...
Linking...
OPTLINK (R) for Win32 Release 8.00.17
Copyright (C) Digital Mars 1989-2013 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
mysqlclient.lib
Warning 2: File Not Found mysqlclient.lib
libmysql.lib
Warning 2: File Not Found libmysql.lib
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_close@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_set_character_set@8
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_real_connect@32
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_init@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_query@8
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_get_client_info@0
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_error@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_ping@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_thread_id@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_insert_id@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_affected_rows@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_store_result@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(connection)
Error 42: Symbol Undefined _mysql_real_escape_string@16
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_free_result@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_num_rows@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_num_fields@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_fetch_lengths@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_fetch_row@4
.....dub\build\mysql-debug-windows-x86-dmd_2077-E7A5679D03D9D572856F6EF183C4ADBE\database.lib(resultset)
Error 42: Symbol Undefined _mysql_fetch_fields@4
Error: linker exited with status 19
dmd failed with exit code 19.

Dlang\database-0.1.0\examples\mysql>

Warning : [warning] __lambda1 - _tcpConnection is null -

Hi All,

Every time when we execute the code we are getting the below warning, not sure what is this warning menas and how to resolve this issue.

2020-11-09 07:11:16 (3585) [warning] __lambda1 - _tcpConnection is null - /root/.dub/packages/hunt-net-0.5.4/hunt-net/source/hunt/net/NetClientImpl.d:162

Code:
module common.GetApiconf;

import common.GetConnections;
import core.stdc.stdlib: exit;
import hunt.database;

auto getApiconf(string stack)
{
Row[] apiconfig;
auto con = new Connections();
Statement stmt = con.db.prepare("SELECT apiuri FROM apisettings WHERE stack = :stack");
stmt.setParameter("stack", stack);
RowSet apistore = stmt.query();
scope(failure) { con.db.close(); exit(-2); } scope(exit) con.db.close();
foreach(i; apistore) { apiconfig ~= i; }
return apiconfig;
}

From,
Vino.B

Return value of statment.execute is always 2 in mysql.

Hi All,

The below code always returns value 2(result = stmt.execute()) but the data in the tables are getting inserted/ updated perfectly, so shoudnt the below code return the value 0 instead of 2. please correct me if my understanding is wrong.

Code

 auto con = new GetConnections();
ini result;
 Statement stmt = con.db.prepare("INSERT INTO test (Hostname,Location,Rack,Updated)
                                  VALUES(:Hostname,:Location,:Location,:Updated)
                                  ON DUPLICATE KEY UPDATE
                                  Location = IF(Location != VALUES(Location), VALUES(Location), :Location),
                                  Rack = IF(Rack != VALUES(Rack), VALUES(Rack), :Rack),
                                  Updated = :Updated");
 foreach(i,ref h,ref l,ref r; lockstep(data["Hostname"][], data["Location"][], data["Rack"][])) {
    stmt.setParameter("Hostname", data["Hostname"][i]);
    stmt.setParameter("Location", data["Location"][i]);
    stmt.setParameter("Rack", data["Rack"][i]);
    stmt.setParameter("Updated", Clock.currTime().toISOExtString()[0..19]);
    result =  stmt.execute();
 }
 con.db.close();

warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info

bubnenkov@DESKTOP-A1C4H1H D:\code\2018\ftp_walker
$ dub --arch=x86_64
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86_64.
hunt 1.0.0-rc.6: building configuration "library"...
hunt-sql 1.0.1: building configuration "library"...
hunt-database 1.0.3: building configuration "default"...
cachetools 0.0.7: building configuration "library"...
requests 1.0.4: building configuration "std"...
ftp_walker ~master: building configuration "application"...
Linking...
hunt-database.lib(Connection.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(ResultSet.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(Dialect.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(Connection.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(ResultSet.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(Dialect.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
hunt-database.lib(Dialect.obj) : warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info
sqlite3.lib : warning LNK4003: invalid library format; library ignored
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_open referenced in function _D4arsd6sqlite6Sqlite6__ctorMFAyaiZCQBiQBgQBc
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_close referenced in function _D4arsd6sqlite6Sqlite6__dtorMFZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_mprintf referenced in function _D4arsd6sqlite6Sqlite6escapeMFAyaZQe
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_free referenced in function _D4arsd6sqlite6Sqlite6escapeMFAyaZQe
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_errmsg referenced in function _D4arsd6sqlite6Sqlite5errorMFZAyaftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_changes referenced in function _D4arsd6sqlite6Sqlite12affectedRowsMFZi
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_last_insert_rowid referenced in function _D4arsd6sqlite6Sqlite12lastInsertIdMFZi
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_exec referenced in function _D4arsd6sqlite6Sqlite4execMFAyaDFHAxaAaZvZi
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_prepare_v2 referenced in function _D4arsd6sqlite9Statement6__ctorMFNcCQBiQBg6SqliteAyaZSQCaQByQBu
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_step referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_count referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_name referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_type referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_int64 referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_double referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_text referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_blob referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_column_bytes referenced in function _D4arsd6sqlite9Statement7executeMFbZCQBj8database9ResultSet
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_reset referenced in function _D4arsd6sqlite9Statement5resetMFZvftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_clear_bindings referenced in function _D4arsd6sqlite9Statement13resetBindingsMFZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_parameter_index referenced in function _D4arsd6sqlite9Statement14bindNameLookUpMFxAaZi
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_null referenced in function _D4arsd6sqlite9Statement4bindMFixAaZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_text referenced in function _D4arsd6sqlite9Statement4bindMFixAaZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_double referenced in function _D4arsd6sqlite9Statement4bindMFifZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_int referenced in function _D4arsd6sqlite9Statement4bindMFiiZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_int64 referenced in function _D4arsd6sqlite9Statement4bindMFilZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_bind_blob referenced in function _D4arsd6sqlite9Statement4bindMFixAgZv
ftp_walker.obj : error LNK2019: unresolved external symbol sqlite3_finalize referenced in function _D4arsd6sqlite9Statement8finalizeMFZv
.dub\build\application-debug-windows-x86_64-dmd_2083-CBDF9E55C89E612C8728A3C32B910230\ftp_walker.exe : fatal error LNK1120: 28 unresolved externals
Error: linker exited with status 1120
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

bubnenkov@DESKTOP-A1C4H1H D:\code\2018\ftp_walker
$ dmd
DMD32 D Compiler v2.083.1

assertion fails on setParameter for prepared INSERT statement

I am trying to insert some data into a table.

Statement statement = db.prepare(`INSERT INTO users (email, first_name, last_name) VALUES (:email, :firstName, :lastName`);
statement.setParameter(`:email`, "[email protected]");
statement.setParameter(`:firstName`, "John");
statement.setParameter(`:lastName`, "Doe");
statement.execute();

However, an assertion fails.

core.exception.AssertError@/home/mitu/.dub/packages/hunt-database-0.2.2/hunt-database/source/hunt/database/statement.d(62): Assertion failure

I noticed that for SELECT queries (with params in WHERE clause) it works properly, but for INSERTs it does not.

hunt.database.Statement存在识别参数错误和SQL注入风险

问题方法:private string sql(SqlConnection conn)

重现代码:
auto db = new Database("mysql://root:root@localhost:3306/asp?charset=utf8mb4");
auto conn = db.getConnection();
Statement stmt = db.prepare(conn, "SELECT * FROM sys_user where Name = :username ");
//下面一行会发生错误:username后缺少空格会导致参数无法被替换导致SQL错误
//Statement stmt = db.prepare(conn, "SELECT * FROM sys_user where Name = :username");
// 这里可以直接注入成功,说明字符串是直接拼接的
stmt.setParameter("username", "' OR ''='");
RowSet rs = stmt.query();
foreach (row; rs)
{
writeln(row["Name"]);
}
conn.close();
db.close();
readln();

结果:输出了所有数据

SQLite

Has SQLite support been dropped from 2.0 entirely or it will be restored at some point?
I actually planned to use both connectors from the same code, so the library supporting both PostgreSQL and SQLite would help me a lot.

`exsit` method in class Row - isn't it a typo?

As in title. Unless I just misunderstand this method's name, it seems to be a typo.

I'd suggest renaming it to exist or better: exists or hasCol/hasColumn. The last one is in my opinion the most informative.

sqlite connection

Hi when i try to connect with sqlite database i got this error
`database.exception.DatabaseException@../../../.dub/packages/database-0.0.13/database/source/database/pool.d(62): Don't support database driver: sqlite

??:? database.driver.connection.Connection database.pool.Pool.initConnection() [0x86a7c1cd]
??:? database.pool.Pool database.pool.Pool.__ctor(database.option.DatabaseOption) [0x86a7c0bf]
??:? void database.database.Database.initPool() [0x86a76483]
??:? database.database.Database database.database.Database.__ctor(immutable(char)[]) [0x86a76423]
??:? _Dmain [0x86a7551b]
Program exited with code 1`

OS: Deepin 15.4.1 64bit
DMD64 D Compiler v2.076.1

postgresql connection without password crashes with Range Violation

When connecting to a postgresql database using no password the correct URL format is

postgresql://user@host:post/database

However if a Database is constructed using a URL in that format with database you get an error similar to the following

core.exception.RangeError@/home/cody/.dub/packages/database-0.1.7/database/source/database/url.d(422): Range violation
----------------
??:? _d_arrayboundsp [0xbdeadc72]
/home/cody/.dub/packages/database-0.1.7/database/source/database/url.d:422 @safe bool database.url.tryParseURL(immutable(char)[], out database.url.URL) [0xbde7011e]
/home/cody/.dub/packages/database-0.1.7/database/source/database/url.d:756 @safe database.url.URL database.url.parseURL(immutable(char)[]) [0xbde6347c]
/home/cody/.dub/packages/database-0.1.7/database/source/database/option.d:34 database.option.DatabaseOption database.option.DatabaseOption.__ctor(immutable(char)[]) [0xbde4fce0]
/home/cody/.dub/packages/database-0.1.7/database/source/database/database.d:23 database.database.Database database.database.Database.__ctor(immutable(char)[]) [0xbde45de3]
source/app.d:8 _Dmain [0xbde38527]

this can be worked around by including a colon but no password (postgresql will still loging without using the empty password) like the following

postgresql://user:@localhost:port/database

Its not clear if this is intentionally designed this way, or if it is a but in database's URL parsing.

SQLite - string parameters are not escaped

I tried to append a record with a string containing apostrophe.

Code:

auto statement = CascataskDatabase.prepare(`UPDATE tasks SET title = :title WHERE task_id = :taskID ;`);
statement.setParameter("title", title);
statement.setParameter("taskID", taskID.to!string);
statement.execute();

Parameters: test = "Test'test", taskID is any UUID.

Result:

hunt.database.DatabaseException.DatabaseException@../../../.dub/packages/hunt-database-1.1.3/hunt-database/source/hunt/database/driver/sqlite/Connection.d(122): SQL : UPDATE tasks
		SET title = 'Test'test' WHERE task_id = '*****' ;

Does not build for SQLite on Linux

Hello, I'm trying to build with SQLite support for Linux. An error appears:

../../../../../../home/mitu/.dub/packages/database-0.0.9/database/source/database/driver/sqlite/connection.d(120,52): Error: cannot implicitly convert 
expression `sqlite3_last_insert_rowid(this.conn)` of type `long` to `int`
../../../../../../home/mitu/.dub/packages/database-0.0.9/database/source/database/url.d(306,20): 
Deprecation: variable database.url.URL.query is deprecated - use queryParams
../../../../../../home/mitu/.dub/packages/database-0.0.9/database/source/database/url.d(309,28): 
Deprecation: variable database.url.URL.query is deprecated - use queryParams
../../../../../../home/mitu/.dub/packages/database-0.0.9/database/source/database/url.d(493,13): 
Deprecation: variable database.url.URL.query is deprecated - use queryParams

The compiler is DMD 2.076.

SQL query in parallel.

Hi All,

Request your help as the below code is failing when executed in parallel

Program Code

@trusted public auto getconf(immutable string account) 
{
 string result;
 auto account = Array!string("A1","A2",'A3",'A4");
 foreach(i; parallel(account[], 1)) 
      result  = getconf(i);
 }
 return result;

SQL Code

@trusted public auto getconf(immutable string account)
{
 auto con = new GetConnections();
 Statement stmt = con.db.prepare("SELECT username,passwd FROM config WHERE account = :account");
 stmt.setParameter("account", account);
 RowSet awsaccount = stmt.query();
 scope(exit) con.db.close();
 return account;
}

Error

2020-Nov-19 19:23:36.4671909 | 25056 | warning | FuturePromise.get | Timeout for a promise in 10 secs... | /root/.dub/packages/hunt-extra-1.0.6/hunt-extra/source/hunt/concurrency/FuturePromise.d:170
2020-Nov-19 19:23:36.4673074 | 25060 | warning | FuturePromise.get | Timeout for a promise in 10 secs... | /root/.dub/packages/hunt-extra-1.0.6/hunt-extra/source/hunt/concurrency/FuturePromise.d:170
2020-Nov-19 19:23:36.4672478 | 25061 | warning | FuturePromise.get | Timeout for a promise in 10 secs... | /root/.dub/packages/hunt-extra-1.0.6/hunt-extra/source/hunt/concurrency/FuturePromise.d:170
2020-Nov-19 19:23:36.4675667 | 25061 | warning | PoolBase.getConnection | Timeout in 10 secs | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:149
2020-Nov-19 19:23:36.4676192 | 25061 | info | ConnectionPool.logStatus | pool status, size: 1/5, available: 0, waiters: 0, threads: 9 | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/ConnectionPool.d:284
2020-Nov-19 19:23:36.4675651 | 25056 | warning | PoolBase.getConnection | Timeout in 10 secs | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:149
2020-Nov-19 19:23:36.467762 | 25056 | info | ConnectionPool.logStatus | pool status, size: 1/5, available: 0, waiters: 0, threads: 9 | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/ConnectionPool.d:284
2020-Nov-19 19:23:36.4684355 | 25067 | warning | getConnectionAsync.__lambda1 | The promise 1 has been done. So the connection 3 will be returned to the pool. | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:109
2020-Nov-19 19:23:36.4675788 | 25060 | warning | PoolBase.getConnection | Timeout in 10 secs | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:149
2020-Nov-19 19:23:36.4684981 | 25060 | info | ConnectionPool.logStatus | pool status, size: 1/5, available: 1, waiters: 0, threads: 9 | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/ConnectionPool.d:284
2020-Nov-19 19:23:36.4686326 | 25065 | warning | getConnectionAsync.__lambda1 | The promise 1 has been done. So the connection 2 will be returned to the pool. | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:109
2020-Nov-19 19:23:36.4689074 | 25066 | warning | getConnectionAsync.__lambda1 | The promise 1 has been done. So the connection 4 will be returned to the pool. | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/PoolBase.d:109
hunt.Exceptions.TimeoutException@/root/.dub/packages/hunt-extra-1.0.6/hunt-extra/source/hunt/concurrency/FuturePromise.d(171): Timeout in 10 secs

Schema support for row

It can be very covenient to have schema for binding to row fetched from DB like:

// structured row annotations
	struct PlaceFull {
		uint id;
		string name;
		@optional string thumbnail;	// ok to be null or missing
		@optional GeoRef location;	// nested fields ok to be null or missing
		@optional @as("contact_person") string contact; // optional, and sourced from field contact_person instead

		@ignore File tumbnail;	// completely ignored
	}

And used as:

// after fetchning
auto place = row.toStruct!PlaceFull;

furthure

// automated struct member uncamelcase
	@uncamel struct PlaceOwner {
		uint placeID;			// matches placeID and place_id
		uint locationId;		// matches locationId and location_id
		string ownerFirstName;	// matches ownerFirstName and owner_first_name
		string ownerLastName;	// matches ownerLastName and owner_last_name
		string feedURL;			// matches feedURL and feed_url
	}

This resulting schema (strict) can easily be used to generate a json output for rest api. Private columns can be marked with @ignore

Example provided for the prepare method doesn't seem to be working

Hi All,

The below code is not working and throwing the below error after analyzing we found the the prepare method expects a SqlConnection as first argument and a string as second argument where in the example provide in the link does not state the same, so would request you to update the document with correct procedure.

Eg from the example document https://code.dlang.org/packages/hunt-database
"Statement stmt = db.prepare("SELECT * FROM user where username = :username and age = :age LIMIT 10");"

Code
File : GetConnections.d

`module common.GetConnections;
import hunt.database;

class dbconnect
{
public Database con;
this() { con = new Database("mysql://username:password@localhost:3910/testdb"); }
}`

File: GetConfig.d

`import common.GetConnections;
import hunt.database;

auto getConfig(int Seq)
{
auto mdb = new dbconnect();
Statement stmt = mdb.con.prepare("SELECT * FROM settings WHERE Seq = :Sq");
stmt.setParameter("Sq", Seq);
stmt.execute();
RowSet rs = stmt.query();
mdb.conn.close();
return rs;
}`

Note: Seq is of type int
File : app.d
`import std.stdio;
imoprt common.GetConfig;

void main() {
writeln(getConfig(1));
}`
##################################################################################
Error:
GetConfig.d
Error: function hunt.database.Database.Database.prepare(SqlConnection conn, string sql) is not callable using argument types (string)
cannot pass argument "SELECT * FROM settings WHERE Seq = :Sq" of type string to parameter SqlConnection conn
Error: template hunt.database.Statement.Statement.setParameter cannot deduce function from argument types !()(int, int), candidates are:

Compilation fails on version 1.1.4

Warning message:

../../../.dub/packages/hunt-database-1.1.4/hunt-database/source/hunt/database/Statement.d(100,9): Warning: statement is not reachable

Configuration: sqlite

Don't support database driver: mysql

Hi.

hunt.database.DatabaseException.DatabaseException@C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Pool.d(66): Don't support database driver: mysql

import std.stdio;
import hunt.database;

void main(string[] args)
{
    auto db = new Database("mysql://aaa:aaa@localhost:3306/aaa");
    auto query = "SELECT * FROM aaa";
    foreach (row; db.query(query))
    {
        writeln(row["aaa"]);
    }

    db.close();
}

Windows 10

hunt.database.DatabaseException.DatabaseException@C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Pool.d(66): Don't support database driver: mysql
----------------
0x00007FF699F5E01B in hunt.database.Pool.Pool.initConnection at C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Pool.d(66)
0x00007FF699F5DEBE in hunt.database.Pool.Pool.this at C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Pool.d(34)
0x00007FF699F56309 in hunt.database.Database.Database.initPool at C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Database.d(57)
0x00007FF699F56175 in hunt.database.Database.Database.this at C:\Users\dmitr\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Database.d(26)
0x00007FF699F51530 in D main at d:\.JOB\RPBox\utils\parsers\db_to_sqlupdate-not_work\source\app.d(6)
0x00007FF69A666632 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().__lambda1()
0x00007FF69A66644F in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())
0x00007FF69A66655B in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
0x00007FF69A66644F in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())
0x00007FF69A666201 in d_run_main
0x00007FF699F560F2 in __entrypoint.main
0x00007FF69A74C84C in __scrt_common_main_seh at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288)
0x00007FFC365C7E94 in BaseThreadInitThunk
0x00007FFC3779A251 in RtlUserThreadStart
Program exited with code 1

Several adjustments need to be made

  1. db.query(string sql) return ResultSet, like:
foreach(row; db.query(sql))
{
    writeln(row);
}
  1. add Statement.query() and Statement.execute() for prepared statement object
  2. Statement.fetchAll() return rows array
  3. Question: Statement.execute() return rows affected or Statement object? How to get lastInsertId()?

Don't support database driver: sqlite

Example from https://github.com/huntlabs/hunt-database/blob/master/examples/sqlite/source/app.d
Error:

>  dub -b=release
Performing "release" build using C:\D\dmd2\windows\bin\dmd.exe for x86.
hunt 1.0.0-rc.6: building configuration "library"...
hunt-sql 1.0.1: building configuration "library"...
hunt-database 1.0.2: building configuration "default"...
test ~master: building configuration "application"...
Linking...
Running .\test.exe
---GlobalInit OK---

hunt.database.DatabaseException.DatabaseException@C:\Users\Dima\AppData\Local\dub\packages\hunt-database-1.0.2\hunt-database\source\hunt\database\Pool.d(66): Don't support database driver: sqlite
----------------
0x004049D8
0x00423249
0x004230E3
0x004038CC
0x74A18654 in BaseThreadInitThunk
0x77E04A47 in RtlGetAppContainerNamedObjectPath
0x77E04A17 in RtlGetAppContainerNamedObjectPath
Program exited with code 1

Prepared Insert Fails

HI All,

The below prepred insert fails with the below MySQL error, hence request your help.

auto con = new Connections();
Statement stmt = con.db.prepare("INSERT INTO test (Type) VALUES(:Typ)");
stmt.setParameter(":Typ", "DEV");
stmt.execute();

MySQL Error:
2020-Nov-09 17:21:09.0039376 | 16107 | warning | SqlClientBase.query | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':Typ)' at line 1 | /root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/SqlClientBase.d:94
hunt.database.base.Exceptions.DatabaseException@/root/.dub/packages/hunt-database-2.1.11/hunt-database/source/hunt/database/base/impl/SqlClientBase.d(96): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':Typ)' at line 1

Deprecation: module hunt.util.Serialize is deprecated - It's buggy. Use hunt.serialization.JsonSerializer instead

Hi All,

Would it be possible to clear all such deprecation in next release as we tried to adopt to the change as specified, few programs worked and few other's started to throw different error.

/root/.dub/packages/hunt-sql-1.4.5/hunt-sql/source/hunt/sql/stat/TableStat.d(21,8): Deprecation: module hunt.util.Serialize is deprecated - It's buggy. Use hunt.serialization.JsonSerializer instead.

Cannot connect to SQLite - URLException

I've recently updated the library to the latest version. Now I am unable to connect to SQLite database, an URLExcepiton is thrown.

It seems like now the username/password part of the URL is required. However, sqlite desn't use it at all, so it can't meet the requirement. I guess that problem has been introduced here:

469dfe4

Install instructions

Since D may be new for people (at least to me it is) and that D will be available in gcc-9, i think it would be great to get a hint on how to setup the D ecosystem properly.
The hunt-database stuff looks pretty professional and i would love to include it into a small (and first) D-project.

I tried following:

$ tar -xf hunt-database-1.2.0-rc.1.tar.gz
$ cd cd hunt-database-1.2.0-rc.1
$ mkdir build
$ cd build
$ meson --prefix=/tmp/test ..
The Meson build system
Version: 0.49.2
Source dir: /home/lfs/belfspm/trunk/belfs_d/hunt-database-1.2.0-rc.1
Build dir: /home/lfs/belfspm/trunk/belfs_d/hunt-database-1.2.0-rc.1/build
Build type: native build
Project name: hunt-database
Project version: 1.1.1
Native D compiler: gdc (gcc 9.0.1 "gdc (GCC) 9.0.1 20190331 (experimental)")
Build machine cpu family: x86_64
Build machine cpu: x86_64

meson.build:61:0: ERROR: Failed to initialize 'subprojects/hunt-sql':
Subproject directory not found and hunt-sql.wrap file not found

A full log can be found at /home/lfs/belfspm/trunk/belfs_d/hunt-database-1.2.0-rc.1/build/meson-logs/meson-log.txt


What am i doing wrong?

Cannot build with SQLite

Errors:

../../../.dub/packages/hunt-database-1.1.1/hunt-database/source/hunt/database/driver/sqlite/Connection.d(71,25): Error: undefined identifier `buildPath`
../../../.dub/packages/hunt-database-1.1.1/hunt-database/source/hunt/database/driver/sqlite/Connection.d(76,9): Error: undefined identifier `trace`

Random empty results from PostgreSQL

Sometimes it seems like the DB returned the empty result set (PostgreSQL). No error or log seems to be yielded, so I don't have any more information to supply.

It always looks like when user refreshes the app's page, the first query an application tries returns an empty result - and the subsequent ones return properly. If user refreshes page a few times more, eventually the first query returns proper result as well, but some time later the error will appear again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.