If I have a text variable containing data to put into an SQLite database, then I need to double up any single quotes before offering the data to SQLite. So I might do this:
[code]dim mytext, mynewtext as Text
mynewtext = ReplaceAll(mytext, “’”, “’’”).ToText // Bit hard to read, but I’m replacing one single-quote with two[/code]
and I have to do this because it seems that ReplaceAll expects string arguments and returns a string result.
So the question is, if mytext
contains UTF-8 characters, will mynewtext
still contain the same UTF-8 text, with the only change being just the single-quotes modified as desired?
Yes. You could always check this yourself.
A couple of things. First, you should not be escaping quotes yourself. Use a PreparedStatement, DatabaseRecord, or RecordSet to do the job.
Second (and forgive me for how I’ve phrased this, I mean no offense), you seem to have a fundamental misunderstanding of the differences between String and Text. I say this because there is no such thing as a “UTF-8 character”. There are characters represented by Unicode and there are methods of encoding those characters like UTF-8 so they can be properly represented in memory or in a file.
Please read this as it may help:
https://forum.xojo.com/22534-string-vs-text-an-explanation
You do not need old framework ReplaceAll at all here. If you use the dot-notation form, it will use the new framework and never be converted to a string at all.
mynewtext = mytext.ReplaceAll( "'", "''" )
When you later feed Text to something that expects a String, it will automatically convert to a UTF-8 encoded string.
This is certainly true, and your link has clarified it a lot, thanks. (I think I’d got the impression that strings were just ASCII). I’m still struggling a bit with the documentation at this point.