On Tuesday, 3 November 2020 at 18:14:33 UTC, Andre Pany wrote:
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

Hi Andre,

We have also tried to change the connection (con) as dbconnect (con) as below, as per the example provided in the link https://code.dlang.org/packages/hunt-database, we dont see the prepare method needs SqlConnection as first argument and a string as second where as we can see the need from the source code, so is the example provide in the link is wrong? if yes can you please provide an example nor point me to the correct documentation link

"Statement stmt = db.prepare("SELECT * FROM user where username = :username and age = :age LIMIT 10");"

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;
}
##################################################################################
File : app.d
#######################
import std.stdio;
imoprt common.GetConfig;

void main() {
writeln(getConfig(1));
}

Reply via email to