xsharp.eu • Escaping quotes like in C#?
Page 1 of 1

Escaping quotes like in C#?

Posted: Tue May 26, 2020 4:11 pm
by pemo18
Hello,

Does X# supports the quoting mechanismn of C# like

string sqlCommand = @"Select Nachname ""Nachnahme"" From Adressen";

which results to Select Nachname "Nachnahme" From Adressen

this would bei helpful for building SQL commands with aliases that works with Postgre for example.

Right now we would use something like Nachname 'Nachname' and StrTran() for replacing ' with Chr(34) which works well

Kind regards,
Peter

Escaping quotes like in C#?

Posted: Tue May 26, 2020 5:22 pm
by lumberjack
Hi Peter,
pemo18 wrote: Does X# supports the quoting mechanismn of C# like
Yes

Code: Select all

string sqlCommand = @"Select Nachname ""Nachnahme"" From Adressen";
LOCAL sqlCommand := "Select Nachname ""Nachnahme"" from Adressend" // Double quote notation AS STRING
or
LOCAL sqlCommand := e"Select Nachname "Nachnahme" from Adressend" // Escaped string nrt etc...

Escaping quotes like in C#?

Posted: Tue May 26, 2020 6:55 pm
by pemo18
Oh, thats good (so I did no try hard enough to make it work;)

Regards,
Peter

Escaping quotes like in C#?

Posted: Tue May 26, 2020 7:45 pm
by pemo18
Hi Johan,

Are you sure about the first option?

I could only make it work with the second option (e and ) which I like better because its more readable.

Regards,
Peter

Escaping quotes like in C#?

Posted: Tue May 26, 2020 8:10 pm
by FFF
I think, Johan mixed the " and ' ...
And don't forget, there are differences in behaviour between core and the dialects!

@Chris, now you have the reason, why 'Chris is "great" ' should work, too, as does "Chris is 'great' "
Some time ago we discussed why that's not handled equal ;)

Escaping quotes like in C#?

Posted: Tue May 26, 2020 9:12 pm
by Chris
Never said that they should not both be supported! (the features I mean, not the content :))
This is why they are both allowed now in X# for VO and other dialects (while single quotes were not supported in vulcan). In Core, this is not supported, in order to make the syntax more .Net-friendly, because .Net languages use single quotes for the Char type.

About the "abc""def""ghi" syntax, this is indeed not supported, I remember we had discussed about it, but can't remember what was decided :). Will open a feature request for it.

Escaping quotes like in C#?

Posted: Wed May 27, 2020 6:22 am
by robert
Guys,
Do you really want another string format ?
We already have
- double quoted strings ("abc'[]")
- single quoted strings ('abc"[]')
- bracketed strings ([abc'"])
- interpolated strings (i"abc{i}")
- extended strings ( e"trn")
- extended interpolated strings (ei"r{i}" and ie"r{i}")
- character literals ('a' or c'a')

We are planning to add binary literals like in FoxPro (0h202020), but I personally think that is enough.

Robert

Escaping quotes like in C#?

Posted: Wed May 27, 2020 7:44 am
by FFF
Robert,
i'd say, if ' "abc" ' works, like " 'abc' " does, it would be enough - but this variant indeed would come handy for the SQL writers...

Escaping quotes like in C#?

Posted: Wed May 27, 2020 9:20 am
by Chris
Robert,

The problem is that single quoted strings do not work in Core dialect. Only way to workaround this is with escaped strings, but this syntax is difficult to read. So since c# supports the syntax "abc""def", I think it would be nice to support it in X# as well. Of course it's not high priority...