# SQLite and Quotes

**URL:** <https://forum.xojo.com/t/sqlite-and-quotes/38944>\
**Category:** Databases\
**Created:** [July 29, 2017, 10:07pm UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944 "2017-07-29T22:07:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 29, 2017, 10:07pm UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/1 "2017-07-29T22:07:53Z")

</div>

There has been some discussion about the proper or not so proper use of single and double quotes in SQLite.  
It turns out there is at least one circumstance where it makes a HUGE difference

take for example a situation where you want to read a table, and create a NEW field to use as a LABEL for the data.  
and the label is going to be the name of the field.

```auto
SELECT "myField" as myLabel,myfield
```

DOES NOT WORK… you get two fields, and they both contain the data values for the field ‘myField’  
in this case you MUST use SINGLE quotes  
you would get something like

> [@](#):
>
> 100 | 100

```auto
SELECT 'myField' as myLabel,myfield
```

here you would get

> [@](#):
>
> myField | 100

If you use DOUBLE quotes and the value inside the quotes does NOT resolve to a named field in the table, you get the string you wanted… but if it does, it resolves to the data value

---

<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:** [July 30, 2017, 12:31am UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/2 "2017-07-30T00:31:43Z")

</div>

[http://sqlite.org/faq.html#q24](http://sqlite.org/faq.html#q24)

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 30, 2017, 1:38am UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/3 "2017-07-30T01:38:15Z")

</div>

However… due to the fact that it is not “strict”, it causes people to get in to a habit that is not good…

because

```auto
SELECT "myFieldx" as myLabel,myfield
```

DOES work… leading some people to believe that is “ok” to continue this practice.

---

<div class="post-metadata">

**Author:** ![Joost\_Rongen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/a9a28c/32.png) [@Joost\_Rongen](https://forum.xojo.com/u/Joost_Rongen)\
**Post date:** [July 30, 2017, 3:19pm UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/4 "2017-07-30T15:19:20Z")

</div>

I would suggest working with preparedstatements, even with SQLite… Solves a lot of issues.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 30, 2017, 3:56pm UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/5 "2017-07-30T15:56:27Z")

</div>

Doesn’t solve that one… especially when the SQL statement is entered manually by a user, and not internally generated by the app

---

<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:51pm UTC](https://forum.xojo.com/t/sqlite-and-quotes/38944/6 "2020-10-29T18:51:51Z")

</div>


