Textarea and single quote

I’m using a text area to write a sql statement which includes single quotes.

eg: …name=’XYZ’

running this sql on a sqlite database gives me an error : no such column ‘XYZ’

why is a single quote in a textarea not a single quote ???

using an macBook air M4

It’s hard to tell whether or not you’re actually using smart quotes because the forum software will eat plain ones and force-enable smart ones unless you use the preformatted text option (aka “the code tag”).

Check that your System Settings aren’t replacing single quotes with smart quotes. Check that the TextArea settings aren’t also replacing single quotes with smart quotes. Triple check that you’ve really got a plain single-quote in there.

Other than smart quotes, it’s really kind of hard to guess from this distance without seeing the behavior happen and/or being able to reproduce it.

All I’m doing is

selectSql (Textarea.text)

What Tim means is that when you type the quote into the TextArea, macOS might be changing it for a nicer looking one. This causes the SQL to fail because it isn’t the standard quote character anymore.

I don’t need a nicer one, just one that works !

and how can I fix it ?

I tried the sql in text-field and that works !

As Tim mentioned, first check your macOS settings to see if that is the cause.

If it is the problem you will need to perform a ReplaceAll on the string before you pass it to selectSQL.

I changed system settings to single quote and it is working now

many thanks

you have to look very close to see the difference from smart to single quotes !!! only confusing !

Here are the declares for a DesktopTextArea to disable text and character substitutions regardless of your OS settings. It’s really useful for things like SQL queries.

declare function NSClassFromString lib "Cocoa" (aClassName as CFStringRef) as Ptr

declare function documentView lib "Cocoa" selector "documentView" _
(obj_id as Ptr) as Ptr

declare sub setAutomaticQuoteSubstitutionEnabled lib "Cocoa" _
selector "setAutomaticQuoteSubstitutionEnabled:" _
(id as ptr, value as Boolean)

declare sub setAutomaticDashSubstitutionEnabled lib "Cocoa" _
selector "setAutomaticDashSubstitutionEnabled:" _
(id as ptr, value as Boolean)

declare sub setAutomaticTextReplacementEnabled lib "Cocoa" _
selector "setAutomaticTextReplacementEnabled:" _
(id as ptr, value as Boolean)

dim myTextArea as ptr = documentView(me.Handle)

setAutomaticQuoteSubstitutionEnabled(myTextArea, false)
setAutomaticDashSubstitutionEnabled(myTextArea, false)
setAutomaticTextReplacementEnabled(myTextArea, false)
3 Likes

@Johann_Kienbrandt Thank you so much for flagging an answer post. I just wanted to point out that @Jared_Feder 's post above will actually resolve your issue without changing System Settings or modifying the input with String.Replace

You may wish to check it out. :slight_smile: I might also suggest changing the solution post to his, because it actively solves the problem in my opinion!

Update: Corrected the names thanks to @brian_franco :grimacing:

2 Likes

@Tim_Parnell

I’m not seeing a post by Greg_O in this thread?

1 Like

That’s cool, @Jared_Feder .

Thanks for sharing!
Anthony

1 Like