On Sunday, 27 November 2016 at 16:32:26 UTC, Suliman wrote:
Looks like you forgot a call to format before the opening parenthesis.

should be:
string sqlinsert = format(`INSERT INTO usersshapes (userlogin,
 uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s',
 '%s') `, login, uploading_date, geometry_type, data);

So all string substitute must be called with `format`?

Yes, except when you are passing the strings to a function that does it for you, such as the write family. The language doesn't replace "%s" with strings, the format function does.



because what ends up happening is :
    string sqlinsert = data;
which is almost certainly not what you want.

I thought it's possible to write:

string data = "foo"
string sqlinsert = data

or am I wrong?

No, you are not wrong. That is perfectly valid, but that's not what he meant. Your declaration of sqlinsert was made in such a way that you used several commas to separate different values, the last of which was data. The way the comma operator works, that means sqlinsert would be set to data and all the rest ignored.

Consider this:

void main()
{
        import std.stdio;
        string s = ("foo %s","bar");
        writeln(s);
}

This prints "bar" and "foo %s" is ignored. That's how the comma operator works outside of a function parameter list. It's also why you got the deprecation message, as this usage will eventually become illegal.

Reply via email to