Request our suggestio: better way to insert data from Array!string[string] into a database table
Vino
akashvino79 at gmail.com
Mon Nov 16 17:44:08 UTC 2020
Hi All,
Request your suggestion, we have a program which call's an api,
the output of the api is parsed using json parser and the result
is stored in an array(Array!string[string] data), then these
stored result are inserted into MySQL table, for inserting the
data into the table we use the below code, this code is a small
code which just contains 2 data items (Type,Hostname) and we have
similar api's which contains 15-20 data items, hence request
your suggestion on is there any better way than the below code,
using the below logic the foreach line is will run into multiple
lines eg:
foreach(i, ref a, ref b,.......ref 20,
lockstep(data["D1"][],data["D2"][],.....data["D20"])
Code:
Statement stmt = con.db.prepare("INSERT INTO test(Type,Hostname)
VALUES(:Type,:Hostname");
foreach(i,ref t,ref h; lockstep(data["Type"][],
data["Hostname"][]) {
stmt.setParameter("Type", data["Type"][i]);
stmt.setParameter("Hostname", data["Hostname"][i]);
result = stmt.execute();
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list