What characters cannot be used for values ​​in SQLite databases?

I am making an Android application and I used the SQLite database. But I found that if you enter characters as single quotes ('), (also to be used as a primary key), the data will not be saved / retrieved correctly.

Is this a problem with me or is it true? If in his true there are more such characters?

Thank.

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

I've always used direct string concatenation before, but now, since it seems like bad practice, I would like to use prepared statements and / or placeholders.

+5
source share
3 answers

You may have problems with characters such as ASCII STOP and non-printable characters, but if you use prepared instructions and parameter bindings, you will not have problems even with characters such as '.

If you do not want to use parameter bindings and prepared statements, you can replace all of your input 'with \', and everything will be fine.

SQL ' , . , . , . , "" , , SQL ' , '. , .

:

String sql = "INSERT INTO MYTABLE (NAME, EMP_NO, DATE_HIRED) VALUES (?, ?, ?)";
PreparedStatement ps = sqlite.prepareStatement(sql);
ps.setString(1, myString);
ps.setInt(2, myInt);
ps.setDate(3, myDate);
ps.executeUpdate();

, , sqlite Android, .

+4

SQLite - - . ('), , (") :

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

:

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

(, (") Java-.)

SQLiteStatment ( ) bindString()

" ", SQLite ( TEXT) UTF-8 UTF-16. Android build UTF-8. .

+1

SQLite TEXT ( String Java), INTEGER ( long Java) REAL ( double Java). . SQLight , , , , .

0

All Articles