What characters cannot be used for values in SQLite databases?

10,549

SQLite statements use quotes -- single or double -- for strings. If you need to INSERT a string with (') for example, you can use double quotes (") to wrap the string:

INSERT INTO my_table (some_column) VALUES("'a string'");

Or the other way around:

INSERT INTO my_table (some_column) VALUES('"a string"');

(Of course, you will need to escape any (") in your Java code.)

An alternative is to use a SQLiteStatment (Prepared statement) and bindString()

As for the "characters allowed", SQLite internally stores strings (type TEXT) as UTF-8 or UTF-16. Android's build uses the default of UTF-8. Therefor, you can store any string you like.

Share:
10,549
Roshnal
Author by

Roshnal

I'm a computer geek, a programmer, love travelling and seek perfection. Enjoys good music, avid movie fan & a food and cocktail lover. Proficient in Java, C++, HTML5/CSS, Javascript, Scala, XML, and about 4 more computer languages. Excellent Android & BlackBerry 10 developer, learning iOS development. Speaks 3 human languages (English, Sinhala, Spanish) and learning 5 more (German, Dutch, Italian, Russian & Swedish). 2-time IOI (International Olympiad in Informatics) participant, 2012 Oracle ThinkQuest runner-up, 3-time NSSC (National School Software Competition) medalist and 2013 IT Mastermind runner-up. (TLDR; I know a lot of languages, program a lot, and won a lot of awards and medals). Find me on Twitter: @roshnal15 :-)

Updated on June 15, 2022

Comments

  • Roshnal
    Roshnal almost 2 years

    I'm making an Android app and I have used an SQLite database. But I found out if you type characters like single quotes ('), (also for using as the primary key) the data won't be saved/retrieved correctly.

    Is it a problem with me or is it true? If its true are there any more characters like that?

    Thanks.

    @bdares and @mu Thanks for the tips, but can you please tell me how to use placeholders and/or prepared statements in SQLite?

    I have always used direct String concatenation before but now, as it appears that's a bad practice, I would like to use prepared statements and/or placeholders.

  • Roshnal
    Roshnal over 12 years
    But can I enter any character to a field with the type TEXT?