icu Posted September 24, 2011 Share Posted September 24, 2011 (edited) Dear AutoIt Community, I'm getting SQLite errors because of the single quote character in a string ('). I figured I could escape it out using a Func based on StringRegExpReplace however it doesn't work and I just don't see why. Here is my code: Func SQLite_Regex (ByRef $string) $value = StringRegExpReplace ($string, ".('+).", "''") Return $value EndFunc $s_Test = "De L'isard's" ConsoleWrite ("Before SQLite_Regex: " & $s_Test & @CRLF) $s_Result = SQLite_Regex ($s_Test) ConsoleWrite ("After SQLite_Regex: " & $s_Result & @CRLF) I was pretty sure I escaped the single quotes with the double quotes enclosure. Any and all help is greatly appreciated. Kind regards, icu Edited September 24, 2011 by icu Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 24, 2011 Moderators Share Posted September 24, 2011 (edited) StringReplace would be faster: StringReplace($string, "'", "''", 0, 1) But... Your question: StringRegExpReplace($string, "'", "''") Edited September 24, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
icu Posted September 24, 2011 Author Share Posted September 24, 2011 @ SmOke_N: Thanks! Link to comment Share on other sites More sharing options...
t0nZ Posted November 16, 2011 Share Posted November 16, 2011 Single quote character (') for Europeans (and not english speaking countries in general ) is a problem. A lot of systems have words with accent (mark) , and with sqlite I have to cope with this situations. For a long time I used this function : Func apostrofo($letto) $letto = StringRegExpReplace($letto, "(w)(')(w)", "1223") ; tra caratteri ;perla ; pearl $letto = StringRegExpReplace($letto, "(w)(')(s)", "1223") ; carattere prima e dopo spazio carattere $letto = StringRegExpReplace($letto, "(s)(')(w)", "1223") ; spazio e poi carattere $letto = StringRegExpReplace($letto, "(s)(')(s)", "1223") ; spazio e poi spazio $letto = StringRegExpReplace($letto, "(w)(')(Z)", "122") ; ultimo carattere è apostrofo $letto = StringRegExpReplace($letto, "(A)(')(w)", "223") ; primo carattere è apostrofo $letto = StringRegExpReplace($letto, "(s)(')(Z)", "122") ; ultimo carattere è apostrofo prima di spazio $letto = StringRegExpReplace($letto, "(A)(')(s)", "223") ; primo carattere è apostrofo e dopo uno spazio $letto = StringRegExpReplace($letto, "(w)(')(,)", "1223") ; carattere e poi virgola ;perla ; pearl , scoperto in tortora.au3 $letto = StringRegExpReplace($letto, "(,)(')(w)", "1223") ; virgola e poi carattere ;perla ; pearl , scoperto in tortora.au3 $letto = StringRegExpReplace($letto, "(w)(')(-)", "1223") ; carattere e poi - ;perla ; pearl , scoperto in tortora.au3 $letto = StringRegExpReplace($letto, "(w)(')(()", "1223") ; carattere e poi ( ;perla ; pearl , scoperto in tortora.au3 Return $letto EndFunc ;==>apostrofo Until now, when I have problems with the last line (w)(')(()", "1223") where the (() don't work at all ... ? But I found this thread and I think I was blind for not seeing a very simple and fast solution like that. thankS ! So I don't use anymore my old function, but for the ()) in regular expression anyone has a solution ? (sorry for the english...) Link to comment Share on other sites More sharing options...
jchd Posted November 17, 2011 Share Posted November 17, 2011 You're making your life more difficult that it should be! Your (() should be (() : remember that ( is an active token in regexps. Now, you should always escape each literal string in SQL statements using StringReplace($s, "'", "''"). The SQLite UDF doesn't offer data binding since it reveals much slower than SQLite_Exec in almost all practical uses. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
t0nZ Posted November 17, 2011 Share Posted November 17, 2011 You are right, now my function is modified in all my recent scripts and looks like: Func apostrofo($letto) $letto = StringReplace($letto, "'", "''", 0, 2) Return $letto EndFunc ;==>apostrofo Shortest and fastest ! Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now