digitalmars.D.learn - Using the result of a comma expression is deprecated
- Suliman (7/7) Nov 27 2016 I am getting deprecation message:
- drug007 (3/9) Nov 27 2016 Didn't you miss something like class/structure/function before
- Suliman (13/26) Nov 27 2016 void dbInsert(string login, string uploading_date, string
- Nicholas Wilson (10/36) Nov 27 2016 Looks like you forgot a call to format before the opening
- Erik van Velzen (6/31) Nov 27 2016 As an aside, for security reasons you should use a prepared
- Suliman (5/9) Nov 27 2016 Am I right understand that `scope(exit)` should be always at top,
- Adam D. Ruppe (14/18) Nov 27 2016 No, scope(exit) queues the thing for execution, so it doesn't
- Suliman (5/17) Nov 27 2016 I thought it's possible to write:
- Mike Parker (21/36) Nov 27 2016 Yes, except when you are passing the strings to a function that
I am getting deprecation message: "Using the result of a comma expression is deprecated" on this code: string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); What's wrong with it?
Nov 27 2016
On 27.11.2016 14:07, Suliman wrote:I am getting deprecation message: "Using the result of a comma expression is deprecated" on this code: string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); What's wrong with it?Didn't you miss something like class/structure/function before "(`INSERT..."? What result do you expect?
Nov 27 2016
On Sunday, 27 November 2016 at 11:21:58 UTC, drug007 wrote:On 27.11.2016 14:07, Suliman wrote:void dbInsert(string login, string uploading_date, string geometry_type, string data) { Statement stmt = conn.createStatement(); string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); stmt.executeUpdate(sqlinsert); scope(exit) stmt.close(); // closing } full code.I am getting deprecation message: "Using the result of a comma expression is deprecated" on this code: string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); What's wrong with it?Didn't you miss something like class/structure/function before "(`INSERT..."? What result do you expect?
Nov 27 2016
On Sunday, 27 November 2016 at 11:49:25 UTC, Suliman wrote:On Sunday, 27 November 2016 at 11:21:58 UTC, drug007 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); because what ends up happening is : string sqlinsert = data; which is almost certainly not what you want.On 27.11.2016 14:07, Suliman wrote:void dbInsert(string login, string uploading_date, string geometry_type, string data) { Statement stmt = conn.createStatement(); string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); stmt.executeUpdate(sqlinsert); scope(exit) stmt.close(); // closing } full code.I am getting deprecation message: "Using the result of a comma expression is deprecated" on this code: string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); What's wrong with it?Didn't you miss something like class/structure/function before "(`INSERT..."? What result do you expect?
Nov 27 2016
On Sunday, 27 November 2016 at 12:13:03 UTC, Nicholas Wilson wrote:On Sunday, 27 November 2016 at 11:49:25 UTC, Suliman wrote:As an aside, for security reasons you should use a prepared statement. Also, this is a decent usecase for scope(exit) but it should be put earlier in the function.On Sunday, 27 November 2016 at 11:21:58 UTC, drug007 wrote: void dbInsert(string login, string uploading_date, string geometry_type, string data) { Statement stmt = conn.createStatement(); string sqlinsert = (`INSERT INTO usersshapes (userlogin, uploading_date, geometry_type, data) VALUES ('%s', '%s', '%s', '%s') `, login, uploading_date, geometry_type, data); stmt.executeUpdate(sqlinsert); scope(exit) stmt.close(); // closing } full code.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); because what ends up happening is : string sqlinsert = data; which is almost certainly not what you want.
Nov 27 2016
As an aside, for security reasons you should use a prepared statement.Even if it's server-side code and there is no any iteration with user data (they come as JSON)Also, this is a decent usecase for scope(exit) but it should be put earlier in the function.Am I right understand that `scope(exit)` should be always at top, otherwise it would not work (it's very strange because by the docs it's calling every time when function out of the scopes)?
Nov 27 2016
On Sunday, 27 November 2016 at 16:42:17 UTC, Suliman wrote:Am I right understand that `scope(exit)` should be always at top, otherwise it would not work (it's very strange because by the docs it's calling every time when function out of the scopes)?No, scope(exit) queues the thing for execution, so it doesn't necessarily need to be at the top. void test() { scope(exit) writeln("1"); writeln("2"); scope(exit) writeln("3"); } That would print "2, 3, 1". The first line queues 1. The second line runs immediately and prints 2. The third line queues 3. When the function returns, all queued things are played back in reverse order. Thus, 3 goes first, then 1. If you returned right after the second line, you would only see "2, 1", since the queuing of the 3 would never happen.
Nov 27 2016
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); because what ends up happening is : string sqlinsert = data; which is almost certainly not what you want.So all string substitute must be called with `format`?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?
Nov 27 2016
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.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.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?
Nov 27 2016