Unrecognized token error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Unrecognized token error

Tito Ciuro
Hello,

I'm trying to store a string and I get the following error:

unrecognized token: \"!\"\"

This happens with SQLite 3.2.7

Any ideas?

Thanks,

-- Tito
Reply | Threaded
Open this post in threaded view
|

Re: Unrecognized token error

John Stanton-3
Tito Ciuro wrote:

> Hello,
>
> I'm trying to store a string and I get the following error:
>
> unrecognized token: \"!\"\"
>
> This happens with SQLite 3.2.7
>
> Any ideas?
>
> Thanks,
>
> -- Tito
What is the string?
Reply | Threaded
Open this post in threaded view
|

[LONG]Re: [sqlite] Unrecognized token error

Tito Ciuro
Hi John,

On 19/03/2006, at 18:23, John Stanton wrote:

> Tito Ciuro wrote:
>> Hello,
>> I'm trying to store a string and I get the following error:
>> unrecognized token: \"!\"\"
>> This happens with SQLite 3.2.7
>> Any ideas?
>> Thanks,
>> -- Tito
> What is the string?

Here's the string (it's a preferences file):

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC  
\"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/ 
PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n
\t<key>ABDirectoryResultColumnTitle</key>\n\t<string>Instant  
Messaging</string>\n\t<key>AccountSortOrder</key>\n\t<array>\n\t
\t<string>3A86A458-555A-4D2C-A710-2D3E40372D7A</string>\n\t</array>\n
\t<key>AutosaveChats</key>\n\t<true/>\n\t<key>BuddyInfoSelectedTab</
key>\n\t<integer>0</integer>\n\t<key>BuddyList.EnableGroups</key>\n
\t<false/>\n\t<key>BuddyList.Visible</key>\n\t<true/>\n
\t<key>CardsBlockingPresentityPictures</key>\n\t<array>\n\t
\t<string>CA3EA6FE-7F19-4419-8AB1-571F8D445738:ABPerson</string>\n\t</
array>\n\t<key>ConfirmSendFiles</key>\n\t<false/>\n
\t<key>CustomAvailableMessages</key>\n\t<array>\n\t\t<string>Fat  
Binaries over coffee</string>\n\t\t<string>Cocoa bindings with a  
bagel</string>\n\t\t<string>Palo Alto Caf\U00e9, California</string>\n
\t\t<string>@Sina's House</string>\n\t\t<string>Web Services +  
Bonjour = Yummy!</string>\n\t\t<string>Sharing data just got  
easier ;-)</string>\n\t\t<string>www.liveplasma.com</string>\n\t
\t<string>In Yuba City, CA!</string>\n\t\t<string>Running around the  
house...</string>\n\t</array>\n\t<key>CustomAwayMessages</key>\n
\t<array>\n\t\t<string>Be right back!</string>\n\t</array>\n
\t<key>CustomInBalloonColor</key>\n\t<false/>\n
\t<key>CustomOutBalloonColor</key>\n\t<false/>\n
\t<key>CustomStatusMessageSheetFrame</key>\n\t<string>46 537 390 286  
0 0 1280 832 </string>\n\t<key>DockDebounceTime</key>\n\t<real>0.5</
real>\n\t<key>GammaFadePauseTime</key>\n\t<real>0.004999999888241291</
real>\n\t<key>JabberViewer.EnableGroups</key>\n\t<false/>\n
\t<key>JabberViewer.Visible</key>\n\t<false/>\n
\t<key>MessageInTextStyle</key>\n\t<dict>\n\t\t<key>bgcolor</key>\n\t
\t<integer>-1</integer>\n\t\t<key>fgcolor</key>\n\t\t<integer>0</
integer>\n\t\t<key>font</key>\n\t\t<string>HelveticaNeue</string>\n\t
\t<key>size</key>\n\t\t<real>13</real>\n\t</dict>\n
\t<key>MessageTextStyle</key>\n\t<dict>\n\t\t<key>bgcolor</key>\n\t
\t<integer>8107502</integer>\n\t\t<key>fgcolor</key>\n\t\t<integer>0</
integer>\n\t\t<key>font</key>\n\t\t<string>HelveticaNeue</string>\n\t
\t<key>size</key>\n\t\t<real>13</real>\n\t</dict>\n
\t<key>NSFontPanelAttributes</key>\n\t<string>1, 1</string>\n
\t<key>NSFontPanelPreviewHeight</key>\n\t<real>0.0</real>\n
\t<key>NSNavBrowserPreferedColumnContentWidth</key>\n\t<real>186</
real>\n\t<key>NSNavLastRootDirectory</key>\n\t<string>~/Desktop</
string>\n\t<key>NSNavPanelExpandedSizeForOpenMode</key>\n\t<string>
{519, 400}</string>\n\t<key>NSPreferencesContentSize</key>\n\t<string>
{517, 389}</string>\n\t<key>NSPreferencesSelectedIndex3</key>\n
\t<integer>1</integer>\n\t<key>NSRecentDocumentRecords</key>\n
\t<array>\n\t\t<dict>\n\t\t\t<key>_NSLocator</key>\n\t\t\t<dict>\n\t\t
\t\t<key>_NSAlias</key>\n\t\t\t\t<data>\n\t\t\t
\tAAAAAAHyAAIAAA1Nb25rZXlTaHV0dGxlAAAAAAAAAAAA\n\t\t\t\tAAAAAAC/
PbTFSCsAAAAEYB4fQmFyYmVyYSBHZW1tYSBv\n\t\t\t
\tbiAyIzFDMTA2OC5pY2hhdAAAAAAAAAAAAAAAAAAAAAAA\n\t\t\t
\tAAAAAAAAAAAAAAAAAAAAABwQaMArChkAAAAAAAAAAP//\n\t\t\t\t//
8AAAkgAAAAAAAAAAAAAAAAAAAABmlDaGF0cwAQAAgA\n\t\t\t\tAL8
+FzUAAAARAAgAAMArepkAAAABABAABGAeAAO4uwAD\n\t\t\t
\tty8AA2dqAAIAS01vbmtleVNodXR0bGU6VXNlcnM6dGNp\n\t\t\t
\tdXJvOkRvY3VtZW50czppQ2hhdHM6QmFyYmVyYSBHZW1t\n\t\t\t
\tYSBvbiAyIzFDMTA2OC5pY2hhdAAADgBWACoAQgBhAHIA\n\t\t\t
\tYgBlAHIAYQAgAEcAZQBtAG0AYQAgAG8AbgAgADIAMAAw\n\t\t\t
\tADYALQAwADMALQAwADEAIABhAHQAIAAwADgALgAyADEA\n\t\t\t
\tLgBpAGMAaABhAHQADwAcAA0ATQBvAG4AawBlAHkAUwBo\n\t\t\t
\tAHUAdAB0AGwAZQASAEhVc2Vycy90Y2l1cm8vRG9jdW1l\n\t\t\t
\tbnRzL2lDaGF0cy9CYXJiZXJhIEdlbW1hIG9uIDIwMDYt\n\t\t\t
\tMDMtMDEgYXQgMDguMjEuaWNoYXQAEwABLwAAFQACAA3/\n\t\t\t\t/wAA\n\t\t\t
\t</data>\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AAAAAAAAA\n\t\t\t
\tAAAAAAAAAAAAAAAAAAAAAARgj76IpH8AAAAAAAAAAP//\n\t\t\t\t//
8AAAkgAAAAAAAAAAAAAAAAAAAABmlDaGF0cwAQAAgA\n\t\t\t\tAL8
+FzUAAAARAAgAAL6JBu8AAAABABAABGAeAAO4uwAD\n\t\t\t
\tty8AA2dqAAIAS01vbmtleVNodXR0bGU6VXNlcnM6dGNp\n\t\t\t
\tdXJvOkRvY3VtZW50czppQ2hhdHM6Q2l1cm8gR3VpbGxl\n\t\t\t
\tcm1vIG9uIDIjNDYwOEYuY2hhdAAADgBYACsAQwBpAHUA\n\t\t\t
\tcgBvACAARwB1AGkAbABsAGUAcgBtAG8AIABvAG4AIAAy\n\t\t\t
\tADAAMAA1AC0AMAA0AC0AMQA4ACAAYQB0ACAAMAAyAC4A\n\t\t\t
\tNAAwAC4AYwBoAGEAdAAPABwADQBNAG8AbgBrAGUAeQBT\n\t\t\t
\tAGgAdQB0AHQAbABlABIASVVzZXJzL3RjaXVyby9Eb2N1\n\t\t\t
\tbWVudHMvaUNoYXRzL0NpdXJvIEd1aWxsZXJtbyBvbiAy\n\t\t\t
\tMDA1LTA0LTE4IGF0IDAyLjQwLmNoYXQAABMAAS8AABUA\n\t\t\t\tAgAN//8AAA==\n
\t\t\t\t</data>\n\t\t\t</dict>\n\t\t</dict>\n\t</array>\n
\t<key>NSTableView Columns NSNavOutlineColumnSettings.v1</key>\n
\t<array>\n\t\t<data>\n\t
\tBAt0eXBlZHN0cmVhbYED6IQBQISEhAhOU1N0cmluZwGEhAhOU09iamVjdACF\n\t
\thAErHE5TTmF2RGlzcGxheU5hbWVGaWxlUHJvcGVydHmG\n\t\t</data>\n\t
\t<string>225</string>\n\t\t<data>\n\t
\tBAt0eXBlZHN0cmVhbYED6IQBQISEhAhOU1N0cmluZwGEhAhOU09iamVjdACF\n\t
\thAErGE5TTmF2TW9kRGF0ZUZpbGVQcm9wZXJ0eYY=\n\t\t</data>\n\t
\t<string>118</string>\n\t</array>\n\t<key>NSTableView Sort Ordering  
NSNavOutlineColumnSettings.v1</key>\n\t<array>\n\t\t<data>\n\t
\tBAt0eXBlZHN0cmVhbYED6IQBQISEhAhOU1N0cmluZwGEhAhOU09iamVjdACF\n\t
\thAErHE5TTmF2RGlzcGxheU5hbWVGaWxlUHJvcGVydHmG\n\t\t</data>\n\t
\t<true/>\n\t</array>\n\t<key>NSWindow Frame BuddyList.Collapsed</key>
\n\t<string>63 760 329 63 0 0 1280 832 </string>\n\t<key>NSWindow  
Frame BuddyList.Uncollapsed</key>\n\t<string>63 13 329 810 0 0 1280  
832 </string>\n\t<key>NSWindow Frame JabberViewer.Collapsed</key>\n
\t<string>820 740 230 63 0 0 1280 832 </string>\n\t<key>NSWindow  
Frame NSFontPanel</key>\n\t<string>1409 77 445 270 0 0 1920 1178 </
string>\n\t<key>NSWindow Frame Preferences</key>\n\t<string>95 113  
593 390 0 0 1280 832 </string>\n\t<key>NSWindow Frame  
SubNetViewer.Collapsed</key>\n\t<string>87 717 305 63 0 0 1280 832 </
string>\n\t<key>NSWindow Frame SubNetViewer.Uncollapsed</key>\n
\t<string>87 40 305 740 0 0 1280 832 </string>\n
\t<key>OverrideIncomingStyle</key>\n\t<true/>\n\t<key>PIPLeft</key>\n
\t<false/>\n\t<key>PIPSize</key>\n\t<real>0.20240136981010437</real>\n
\t<key>PIPTop</key>\n\t<false/>\n\t<key>SendWhileTyping</key>\n
\t<false/>\n\t<key>SubNetViewer.PeopleSortOrder</key>\n\t<dict>\n\t
\t<key>PrimarySort</key>\n\t\t<integer>3</integer>\n\t
\t<key>SecondarySort</key>\n\t\t<integer>2</integer>\n\t</dict>\n
\t<key>SubNetViewer.Visible</key>\n\t<true/>\n
\t<key>TotalGammaFadeTime</key>\n\t<real>0.10000000149011612</real>\n
\t<key>UseAlternateStatusIndicators</key>\n\t<false/>\n
\t<key>VCDefaultCamera</key>\n\t<integer>2857630788650759</integer>\n
\t<key>VCDefaultMic</key>\n\t<string>Source:
1768778083AppleDBDMAAudioDMAEngine:0</string>\n\t<key>VideoChatFrame</
key>\n\t<string>{{482, 480}, {362, 344}}/{{47, 0}, {1233, 832}}/352</
string>\n\t<key>WebIconDatabaseDirectoryDefaultsKey</key>\n
\t<string>~/Library/Icons</string>\n
\t<key>WebKitAllowAnimatedImageLoopingPreferenceKey</key>\n\t<false/>
\n\t<key>WebKitAllowAnimatedImagesPreferenceKey</key>\n\t<false/>\n
\t<key>WebKitDisplayImagesKey</key>\n\t<true/>\n
\t<key>WebKitJavaEnabled</key>\n\t<false/>\n
\t<key>WebKitJavaScriptCanOpenWindowsAutomatically</key>\n\t<false/>\n
\t<key>WebKitJavaScriptEnabled</key>\n\t<false/>\n
\t<key>WebKitMinimumFontSize</key>\n\t<integer>6</integer>\n
\t<key>WebKitPluginsEnabled</key>\n\t<false/>\n
\t<key>WelcomeBackMode</key>\n\t<integer>-1</integer>\n\t<key>bwd</
key>\n\t<dict>\n\t\t<key>ip</key>\n\t\t<string>snatmap.mac.com</
string>\n\t\t<key>portCount</key>\n\t\t<integer>1</integer>\n\t
\t<key>startPort</key>\n\t\t<integer>16384</integer>\n\t</dict>\n
\t<key>bwddown</key>\n\t<integer>327372</integer>\n\t<key>bwdid</key>
\n\t<string>[192.168.0.18:255.255.255.0]</string>\n\t<key>bwdlast</
key>\n\t<real>1142702443.7013011</real>\n\t<key>bwdup</key>\n
\t<integer>328706</integer>\n\t<key>snatmap</key>\n\t<dict>\n\t
\t<key>ip</key>\n\t\t<string>snatmap.mac.com</string>\n\t\t<key>port</
key>\n\t\t<integer>5678</integer>\n\t</dict>\n</dict>\n</plist>\n";
}

Thanks,

-- Tito
Reply | Threaded
Open this post in threaded view
|

Re: Unrecognized token error

Tito Ciuro
In reply to this post by John Stanton-3
Hi John,

On 19/03/2006, at 18:23, John Stanton wrote:

> Tito Ciuro wrote:
>> Hello,
>> I'm trying to store a string and I get the following error:
>> unrecognized token: \"!\"\"
>> This happens with SQLite 3.2.7
>> Any ideas?
>> Thanks,
>> -- Tito
> What is the string?

If I escape single quotes (that is, from "'" to "''"), then  
everything is fine. I usually do that when I want to query for a  
value that contains a quote (i.e. O'Rourke).

However, why do I have to manipulate the string value to be stored?  
Shouldn't SQLite allow me to store any string I want?

Thanks,

-- Tito
Reply | Threaded
Open this post in threaded view
|

Re: Unrecognized token error

Nemanja Corlija
On 3/20/06, Tito Ciuro <[hidden email]> wrote:
> If I escape single quotes (that is, from "'" to "''"), then
> everything is fine. I usually do that when I want to query for a
> value that contains a quote (i.e. O'Rourke).
>
> However, why do I have to manipulate the string value to be stored?
> Shouldn't SQLite allow me to store any string I want?
SQLite does allow you to store any string.
There are two ways to do it properly. You can either embed you string
in your SQL statement with all single quotes in string escaped. Which
is what you did here. Though this is not the recommended way.
Recommended way to do it is to use
sqlite3_prepare()/sqlite3_bind_text()/sqlite3_step() instead of
escaping. When you use prepared statements you can bind your string to
a parameter in that prepared statement without escaping it.

Difference is that when you embed your string inside SQL statement you
have to escape string first to enable SQLite parser to understand your
SQL. If you don't escape it, you usually get some "Unrecognized token"
error. Or even worse, you can be vulnerable to SQL injection.
But if you use prepared statements with only a placeholder for your
string then SQLite just leaves that place "empty" and waits for you to
bind some value to it later, after call to sqlite3_prepare(). But if
you do it like this, then you don't have to escape your string because
you're already past the SQLite parser and single quotes in your string
are not important anymore since SQLite parser will never see them.

--
Nemanja Corlija <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Unrecognized token error

Jay Sprenkle
In reply to this post by Tito Ciuro
On 3/19/06, Tito Ciuro <[hidden email]> wrote:

> Hi John,
>
> On 19/03/2006, at 18:23, John Stanton wrote:
>
> > Tito Ciuro wrote:
> >> Hello,
> >> I'm trying to store a string and I get the following error:
> >> unrecognized token: \"!\"\"
> >> This happens with SQLite 3.2.7
> >> Any ideas?
> >> Thanks,
> >> -- Tito
> > What is the string?
>
> If I escape single quotes (that is, from "'" to "''"), then
> everything is fine. I usually do that when I want to query for a
> value that contains a quote (i.e. O'Rourke).
>
> However, why do I have to manipulate the string value to be stored?
> Shouldn't SQLite allow me to store any string I want?

If you use the functions to bind values instead of constructing sql
you don't have to escape the string.

http://sqlite.org/capi3ref.html#sqlite3_bind_text