On Tuesday, 3 November 2020 at 14:05:18 UTC, Vino wrote:
Hi All,

Currently testing Hunt database, and facing an issue as below, hence request your help

File : GetConnections.d
#######################
module common.GetConnections;
import hunt.database;

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

###################################################################################
File: GetConfig.d
#######################
import common.GetConnections;
import hunt.database;

auto getConfig(int Seq)
{
 auto mdb = new Connections();
Statement stmt = mdb.conn.prepare("SELECT * FROM settings WHERE Seq = :Sq");
           stmt.setParameter("Sq", Seq);
           stmt.execute();
 RowSet rs = stmt.query();
 mdb.conn.close();
 return rs;
}
##################################################################################
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:

From,
Vino.B

The hunt database class has a prepare method which expects a SqlConnection as first argument and a string as second argument. You are passing only a string, therefore the first error.

Ad you name your database instance also connection (conn) and your Connections class database (mdb) it makes the source code quite hard to understand :)

Kind regards
Andre

Reply via email to