# I have a ' in my TextField and SQLite complains

**URL:** <https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105>\
**Category:** Databases\
**Created:** [June 22, 2016, 12:32pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105 "2016-06-22T12:32:11Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 22, 2016, 12:32pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/1 "2016-06-22T12:32:11Z")

</div>

Hi,

I recall earlier today that 25 years ago (or so), Excel was complaining when a text file with a single quote code[/code] was loaded. And so, I tested the addition of a ’ in a field and, yes, SQLite complains.

What can I do / must do ?

Use `ReplaceAll(SourceText,"'","") // single quote surrounded with double quotes / replace ' with the curly quote ()` ?

Another solution (like `\\'`) ?

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [June 22, 2016, 12:46pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/2 "2016-06-22T12:46:22Z")

</div>

Use a prepared statement and it will be handled for you.

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [June 22, 2016, 12:49pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/3 "2016-06-22T12:49:38Z")

</div>

Not at my Desk. Taken from my mind. May have spelling issues. 😉

`Dim ps As PreparedStatement
db.Prepare("INSERT INTO myTable (myColumn) VALUES (?)")
ps.Bind(0, myTextToInsert, SQLitePreparedStatement.Text)
ps.SQLExecute`

---

<div class="post-metadata">

**Author:** ![Albin\_Kiland](https://forum.xojo.com/user_avatar/forum.xojo.com/albin_kiland/32/1028_2.png) [@Albin\_Kiland](https://forum.xojo.com/u/Albin_Kiland)\
**Post date:** [June 22, 2016, 1:11pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/4 "2016-06-22T13:11:21Z")

</div>

Get into the habit of using PreparedStatements all the time when you as a developer don’t have control over the input.  
I always use it even if I am controlling the input, just to be safe.

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [June 22, 2016, 1:44pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/5 "2016-06-22T13:44:14Z")

</div>

[quote=273459:@Albin Kiland]Get into the habit of using PreparedStatements all the time when you as a developer don’t have control over the input.  
I always use it even if I am controlling the input, just to be safe.[/quote]

There are only 2 cases in which i avoid them:

1. I work with User/3rd Party Input
2. In a Thread (but only if Number 1 is still true)

\*2: Because i’ve read once, they are slow in a Thread…

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 22, 2016, 2:02pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/6 "2016-06-22T14:02:29Z")

</div>

Tim, Sasha, Albin: thank you.

While this page was opening, I ws thinking: “I really have to start using `PreparedStatements`”.

I think that Now is the time to do that.

> Use a prepared statement and it will be handled for you.  
> I love when it will be handled for you 🙂

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [June 22, 2016, 2:02pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/7 "2016-06-22T14:02:42Z")

</div>

[quote=273463:@Sascha S]There are only 2 cases in which i avoid them:

1. I work with User/3rd Party Input  
[/quote]  
This is exactly when you SHOULD use them

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [June 22, 2016, 2:19pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/8 "2016-06-22T14:19:19Z")

</div>

> [@273467:@Norman Palardy](#):
>
> This is exactly when you SHOULD use them

OMG Norman! I am sorry for the confusion. This is exactly when i use them.  
I was writing this post while i was in a Phone Conference… 😉

There are only 2 cases in which i avoid them:

1. I work with NON User/3rd Party Input
2. In a Thread (but only if Number 1 is still true)

\*2: Because i’ve read once, they are slow in a Thread…

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [June 22, 2016, 2:36pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/9 "2016-06-22T14:36:25Z")

</div>

> [@273470:@Sascha S](#):
>
> \*2: Because i’ve read once, they are slow in a Thread…

Have you tested this?

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [June 22, 2016, 3:27pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/10 "2016-06-22T15:27:04Z")

</div>

> [@273473:@Kem Tekinay](#):
>
> Have you tested this?

Not really (read:no) 🙂

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [June 22, 2016, 4:39pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/11 "2016-06-22T16:39:25Z")

</div>

what I don’t like about prepared statements is that they are different between databases …  
they should really be unified in the syntax…

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [June 22, 2016, 5:15pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/12 "2016-06-22T17:15:48Z")

</div>

Same as if you wrote raw sql  
Different vendors have mostly similar things but lots of proprietary or non-standard bits too (functions etc)

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [June 23, 2016, 8:52am UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/13 "2016-06-23T08:52:39Z")

</div>

Don’t forget that escaping characters works differently in a normal SQL command string such as UPDATE than inside a LIKE string.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:22pm UTC](https://forum.xojo.com/t/i-have-a-in-my-textfield-and-sqlite-complains/32105/14 "2020-10-29T18:22:07Z")

</div>


