www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - php strings demo

reply Kagamin <spam here.lot> writes:
See attachment. It's just a thought. Anyone want this in the language?
---
string sval="ab128#d";
int ival=274;
static assert("asdf \{sval} astt35 \{ival} zzf \{uuu} g,d" ==
"asdf ab128#d astt35 274 zzf uuu g,d"); //(uuu not found)
---
Nov 20 2010
next sibling parent reply Kagamin <spam here.lot> writes:
Kagamin Wrote:

 See attachment. It's just a thought. Anyone want this in the language?
 ---
 string sval="ab128#d";
 int ival=274;
 static assert("asdf \{sval} astt35 \{ival} zzf \{uuu} g,d" ==
 "asdf ab128#d astt35 274 zzf uuu g,d"); //(uuu not found)
 ---
Wrote some unittests today and thought, this feature is useful when one wants easy sql statements (in, e.g. unittests). string typeName="Employee"; int[] ids=executeVector!int("select ID from Objects where type='\{typeName}'");
Nov 20 2010
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
Kagamin Wrote:
 Wrote some unittests today and thought, this feature is useful when one wants
easy sql statements (in, e.g. unittests). Meh, I find the placeholders to be much better (safer too): db.query("select id from objects where type = ?", typeName); I generally feel the same way about all the interpolated strings. Plain old format("%s", var); works for me.
Nov 20 2010
next sibling parent reply Kagamin <spam here.lot> writes:
Adam D. Ruppe Wrote:

 Meh, I find the placeholders to be much better (safer too):
 
 db.query("select id from objects where type = ?", typeName);
I use it too, but found it hard to maintain/check ordering and meaning of parameters when you edit the query, add or remove parameters.
Nov 20 2010
parent Graham Fawcett <fawcett uwindsor.ca> writes:
On Sat, 20 Nov 2010 18:03:34 -0500, Kagamin wrote:

 Adam D. Ruppe Wrote:
 
 Meh, I find the placeholders to be much better (safer too):
 
 db.query("select id from objects where type = ?", typeName);
I use it too, but found it hard to maintain/check ordering and meaning of parameters when you edit the query, add or remove parameters.
Isn't that a small price to pay to avoid SQL injection attacks? Best, Graham
Nov 23 2010
prev sibling parent Kagamin <spam here.lot> writes:
Adam D. Ruppe Wrote:

 Meh, I find the placeholders to be much better (safer too):
 
 db.query("select id from objects where type = ?", typeName);
It's also non-trivial to implement such functionality, since MS (and Oracle, afaik) require named parameters.
Nov 20 2010
prev sibling next sibling parent "Nick Sabalausky" <a a.a> writes:
"Kagamin" <spam here.lot> wrote in message 
news:ic9fjp$1nok$1 digitalmars.com...
 See attachment. It's just a thought. Anyone want this in the language?
 ---
 string sval="ab128#d";
 int ival=274;
 static assert("asdf \{sval} astt35 \{ival} zzf \{uuu} g,d" ==
 "asdf ab128#d astt35 274 zzf uuu g,d"); //(uuu not found)
 ---
Yes. Ruby has that to: var = 42 Actually, that's pretty common in scripting languages. Although, I'd be happy at least with a a good string templating lib. Something like: auto str1 = "The value of $name$ is $val$".render( ["name":"myVar", "val":"17"] ); auto str2 = "Alternate delimiters are ::what::".render( ["what":"useful"], "::" ); That'd be more general anyway.
Nov 21 2010
prev sibling parent reply =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= <just ask.me> writes:
Dnia 20-11-2010 o 22:46:33 Kagamin <spam here.lot> napisa=B3(a):

 See attachment. It's just a thought. Anyone want this in the language?=
 ---
 string sval=3D"ab128#d";
 int ival=3D274;
 static assert("asdf \{sval} astt35 \{ival} zzf \{uuu} g,d" =3D=3D
 "asdf ab128#d astt35 274 zzf uuu g,d"); //(uuu not found)
 ---
std.conv.text can do this job just fine, bar the "uuu not found" bit. -- = Tomek
Nov 21 2010
parent Kagamin <spam here.lot> writes:
Tomek Sowi�ski Wrote:

 Dnia 20-11-2010 o 22:46:33 Kagamin <spam here.lot> napisa�(a):
 
 See attachment. It's just a thought. Anyone want this in the language?
 ---
 string sval="ab128#d";
 int ival=274;
 static assert("asdf \{sval} astt35 \{ival} zzf \{uuu} g,d" ==
 "asdf ab128#d astt35 274 zzf uuu g,d"); //(uuu not found)
 ---
std.conv.text can do this job just fine, bar the "uuu not found" bit.
Ugh... really... -_-
Nov 21 2010