StungStang Posted February 24, 2011 Posted February 24, 2011 Hi to all, i've made an sql database, but now i've a problem...for example if i would add a value with accent (') it give me of course an error...this is an example code : $Name = "Sant'George" _SQLite_Exec (-1, "INSERT INTO Radio VALUES ("'" & $Name & "'",'try','try','try','try','try');") How i can add a string with accent? There is a metod to compress the database as small as possible? Hi!
Xenobiologist Posted February 24, 2011 Posted February 24, 2011 #include #include Local $hQuery, $aRow _SQLite_Startup() ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open() ; Whithout $sCallback its an Resultless query _SQLite_Exec(-1, "Create table tblTest (a,b int,c single not null);" & _ "Insert into tblTest values ('1',2,3);" & _ "Insert into tblTest values (Null,5,6);") $Name = StringReplace('Sant"George', '"', '""') ;~ $Name = StringReplace("Sant'George", '"', '""') _SQLite_Exec(-1, "INSERT INTO tblTest VALUES (""" & $Name & """,7,8);") $d = _SQLite_Exec(-1, "Select oid,* From tblTest", "_cb") ; _cb Will be called for each row Func _cb($aRow) For $s In $aRow ConsoleWrite($s & @TAB) Next ConsoleWrite(@CRLF) ; Return $SQLITE_ABORT ; Would Abort the process and trigger an @error in _SQLite_Exec() EndFunc ;==>_cb _SQLite_Close() _SQLite_Shutdown() ; Output: ;~ rowid a b c ;~ 1 1 2 3 ;~ 2 5 6 Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
StungStang Posted February 24, 2011 Author Posted February 24, 2011 Why u use stringreplace? ...no way without replace a string with "" ? Hi!
Xenobiologist Posted February 25, 2011 Posted February 25, 2011 (edited) Why u use stringreplace? ...no way without replace a string with "" ?Hi!In Autoit there are two ways of sourrounding a string. " and ' Both of them could be in your string, that is why you need to escape them, otherwise you'll get and error. So, I decided to make ' working all the time and if there is a " in the string you want to store in the DB you need to escape it. Edited February 25, 2011 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
jchd Posted February 25, 2011 Posted February 25, 2011 @Xenobiologist, This isn't the way escaping works for SQL (-lite or not). SQL litterals must be enclosed into single quotes 'like this'. If you have a single quote as part of the string, it needs escaping by doubling it 'O''Connell'. Double quotes in SQL are used for enclosing databases, tables or column names. Some engine need square brackets for that, but SQLite accepts both [Column one] and "Column two". SQlite statement parser also tries to save your ass when you confuse usage of single and double quotes, but there are a number of situations where such silent autocorrection can give wrong results, so SQLite only does auto-corrects when there is no ambiguity. The correct way to escape litterals in SQLite statements is use of eiher _SQLite_Escape() or this faster function: Func X($s) Return ("'" & StringReplace($s, "'", "''", 0, 1) & "'") EndFunc ;==>X 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)
Xenobiologist Posted February 25, 2011 Posted February 25, 2011 @Xenobiologist, This isn't the way escaping works for SQL (-lite or not). SQL litterals must be enclosed into single quotes 'like this'. If you have a single quote as part of the string, it needs escaping by doubling it 'O''Connell'. Double quotes in SQL are used for enclosing databases, tables or column names. Some engine need square brackets for that, but SQLite accepts both [Column one] and "Column two". SQlite statement parser also tries to save your ass when you confuse usage of single and double quotes, but there are a number of situations where such silent autocorrection can give wrong results, so SQLite only does auto-corrects when there is no ambiguity. The correct way to escape litterals in SQLite statements is use of eiher _SQLite_Escape() or this faster function: Func X($s) Return ("'" & StringReplace($s, "'", "''", 0, 1) & "'") EndFunc ;==>X Where is the difference to what I said or did? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
jchd Posted February 25, 2011 Posted February 25, 2011 You never need to escape a double quote included in an SQLite litteral string.In your example,$Name = StringReplace('Sant"George', '"', '""')fed to an SQLite INSERT will incorrectly insert Sant""George while $Name = StringReplace("Sant'George", "'", "''")will correctly insert Sant'GeorgeThis has little relevance to the fact that SQLite accept both single- and double-quotes as string delimiter. Incidently, this fact also eases typing/reading the above StringReplace. 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)
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