mysql-native Help required

Vino akashvino79 at gmail.com
Thu Oct 22 15:00:54 UTC 2020


On Thursday, 22 October 2020 at 14:08:30 UTC, Steven 
Schveighoffer wrote:
> On 10/22/20 7:04 AM, Vino wrote:
>> Hi All,
>> 
>> 
>>    Request your help on the below code as it is not working as 
>> expected.
>> 
>> GetConnections.d
>> 
>> module common.GetConnections;
>> import mysql;
>> 
>> class Connections
>> {
>>    private Connection conn;
>>    auto constr = 
>> "host=localhost;port=3910;user=user;pwd=password#;db=testdb";
>
> I'd declare this immutable, so it's not stored in the class:
>
> immutable constr = "...";
>
>>    this.conn = new Connection(constr);
>
> You are trying to assign an instance member at compile time, 
> with no actual instance.
>
> You need a constructor
>
>      this() { this.conn = new Connection(constr); }
>> }
>> 
>> GetHost.d
>> 
>> import common.GetConnections;
>> import std.array : array;
>> import std.variant;
>> import mysql;
>> import std.stdio: writeln;
>> 
>> void main()
>> {
>>   auto conn = new Connections();
>>   Row[] data = conn.query("SELECT * FROM hostlog").array;
>>   writeln(data[]);
>> }
>
> The rest should work.
>
> -Steve

Hi Steve,

    Thank you very much, I tried your solution, still not working

File: GetConnections.d
module common.GetConnections;
import mysql;

class Connections
{
   private Connection conn;
   immutable constr = 
"host=localhost;port=3910;user=user;pwd=password#;db=testdb";
   this() { this.conn = new Connection(constr); }
}

Error:
source/common/GetHost.d(11,25): Error: none of the overloads of 
query are callable using argument types (Connections, string), 
candidates are:
/root/.dub/packages/mysql-native-3.0.0/mysql-native/source/mysql/commands.d(321,13):        mysql.commands.query(Connection conn, const(char[]) sql, ColumnSpecialization[] csa = null)
/root/.dub/packages/mysql-native-3.0.0/mysql-native/source/mysql/commands.d(334,13):        mysql.commands.query(Connection conn, const(char[]) sql, VariantN!32LU[] args)
/root/.dub/packages/mysql-native-3.0.0/mysql-native/source/mysql/commands.d(342,13):        mysql.commands.query(Connection conn, ref Prepared prepared)
/root/.dub/packages/mysql-native-3.0.0/mysql-native/source/mysql/commands.d(357,13):        mysql.commands.query(Connection conn, ref Prepared prepared, VariantN!32LU[] args)
/root/.dub/packages/mysql-native-3.0.0/mysql-native/source/mysql/commands.d(364,13):        mysql.commands.query(Connection conn, ref BackwardCompatPrepared prepared)
source/common/GetParams.d(11,25):        ... (2 more, -v to show) 
...

From,
Vino.B


More information about the Digitalmars-d-learn mailing list