Joakim,
This is a SQLite limitation and not a bug in Corona or SQLite. If you search the Internet for “SQLite new line character”, then you’ll find that the rest of the world has this problem too. I agree that it’s really inconvenient because no other database I’ve used (SQL Server, MySQL, Sybase, etc.) has this limitation. I suspect sqlite has this problem because its database file is really a text file, so it has to replace all new line and carriage return characters with “\n” and “\r” string literals before saving to the database file… and it doesn’t bother to convert back that new lines and carriage returns when you query the strings. The nerve, right?!
So, a quick solution would be to do the string replacement yourself when you receive strings from the database. You can do this via the standard Lua fucntion string.gsub(). It would look something like this…
[lua]myString = string.gsub(myString, “\n”, “\n”)
myString = string.gsub(myString, “\r”, “\r”)[/lua]
So, the above will handle the “\n” and the “\r” that SQLite is converting your characters too, but realize that this isn’t a perfect solution. Because what if the end-user of your app types in “\n” somewhere in your text box? Something like “yes\no” for some legitimate reason. In this case, the above solution would wrongly replace the “\n” part of “yes\no” with a new line character. In this case, you would want to replace the new line character with your own “character code”, for example “{0x0A}”, before you INSERT/UPDATE it in SQLite. That is, with a string code that is reasonably unique that you would never expect the end-user to ever type in. It’s not a bullet proof solution because the end-user could type in those exact character code strings to circumvent your control character replacement system, but unless your concerned about system security this solution is probably good enough. You may not like the full bullet proof solution that I’m thinking of.
[import]uid: 32256 topic_id: 22447 reply_id: 111554[/import]