mysql-native ResultRange + map
crimaniak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 5 09:04:42 PDT 2017
Hi all!
After some hard time with debugging, I found ResultRange returned
by query() and Prepared::query() of mysql-native package can't be
combined with map() because after map() it becomes empty
resultset.
Code (conn.queryRows just a wrapper for query(Connections, sql) ):
immutable sql = "SELECT id FROM "~tableName~" ORDER BY id";
conn.queryRows(sql).each!(row => writeln("each:",
row[0].to!string));
string[] applied = conn.queryRows(sql).map!(row =>
row[0].to!string).array;
writeln("applied:", applied);
foreach(row; conn.queryRows(sql))
writeln("foreach: ", row[0].to!string);
conn.queryRows(sql).map!(row => row[0].to!string).each!(row =>
writeln("map-each:", row));
foreach(row; conn.queryRows(sql).map!(row => row[0].to!string))
writeln("foreach-map: ", row);
stdout.flush;
Result:
SELECT id FROM versionupdate ORDER BY id
each:.Script20161013_create_database
each:.Script20161221_sites_table
each:.Script20161227_update_users_devices
each:.Script20170121_ownerid
each:.Script20170124_create_clients
each:.Script20170213_no_unique_site_name
each:.Script20170215_remove_site_sn
each:.Script20170228_remove_site_index
each:.Script20170301_add_linkNo
each:.Script20170301_fix_sites_indexes
each:.Script20170310_demo_client
each:.Script20170513_max_dev_number
SELECT id FROM versionupdate ORDER BY id
applied:[]
SELECT id FROM versionupdate ORDER BY id
foreach: .Script20161013_create_database
foreach: .Script20161221_sites_table
foreach: .Script20161227_update_users_devices
foreach: .Script20170121_ownerid
foreach: .Script20170124_create_clients
foreach: .Script20170213_no_unique_site_name
foreach: .Script20170215_remove_site_sn
foreach: .Script20170228_remove_site_index
foreach: .Script20170301_add_linkNo
foreach: .Script20170301_fix_sites_indexes
foreach: .Script20170310_demo_client
foreach: .Script20170513_max_dev_number
SELECT id FROM versionupdate ORDER BY id
SELECT id FROM versionupdate ORDER BY id
As you see simple each() and foreach() works, but all examples
with map() involved always empty. Can anybody explain such
strange behavior?
More information about the Digitalmars-d-learn
mailing list