www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I extract and convert datatypes from ResultRange

reply Anders S <anders xore.se> writes:
Hi guys,

I'm trying to read a post of different datatypes from MariaDB 
table into another message and pass it on into a FIFO pipe to an 
other application.

My code :
    string sql = "SELECT * FROM guirequest WHERE read_request = 
-1;";
     ResultRange range = conn.query(sql);
     Row row = range.front;
     int i, count = (to!int(range.rowCount));
     writeln("rowCount ", range.rowCount, "\n"); // sofar so good

The problem occurs when I wish to extract row data into string, 
int or short datatypes.
It complains on  int i = row[2]; with
Error: cannot implicitly convert expression row.opIndex(2u) of 
type VariantN!24u to int

Same for other datatypes.

Any ideas?
/a
Aug 26 2019
parent reply Olivier Pisano <olivier.pisano laposte.net> writes:
On Monday, 26 August 2019 at 13:49:21 UTC, Anders S wrote:
 Hi guys,

 I'm trying to read a post of different datatypes from MariaDB 
 table into another message and pass it on into a FIFO pipe to 
 an other application.

 My code :
    string sql = "SELECT * FROM guirequest WHERE read_request = 
 -1;";
     ResultRange range = conn.query(sql);
     Row row = range.front;
     int i, count = (to!int(range.rowCount));
     writeln("rowCount ", range.rowCount, "\n"); // sofar so good

 The problem occurs when I wish to extract row data into string, 
 int or short datatypes.
 It complains on  int i = row[2]; with
 Error: cannot implicitly convert expression row.opIndex(2u) of 
 type VariantN!24u to int

 Same for other datatypes.

 Any ideas?
 /a
I don't have a compiler accessible right now, but according to https://dlang.org/phobos/std_variant.html : int i; if (row[2].peek!int !is null) i = row[2].get!int
Aug 26 2019
parent Anders S <anders xore.se> writes:
On Monday, 26 August 2019 at 13:58:34 UTC, Olivier Pisano wrote:
 On Monday, 26 August 2019 at 13:49:21 UTC, Anders S wrote:
 [...]
I don't have a compiler accessible right now, but according to https://dlang.org/phobos/std_variant.html : int i; if (row[2].peek!int !is null) i = row[2].get!int
Hi Olivier, thanks man that did it. /a
Aug 26 2019