Jens-Joris Decorte
Jens-Joris Decorte

Reputation: 56

Insert a String containing an apostrophe (sqlite)

Is there a way to save strings that contain an apostrophe into an sqlite database?

(I have an app that saves the names of all installed apps on your device and ran into an error while saving "Dood's Music Streamer")

Upvotes: 1

Views: 1464

Answers (2)

Elliott Frisch
Elliott Frisch

Reputation: 201429

You could use a compiled statement and bind the String parameter.

SQLiteDatabase db = dbHelper.getWritableDatabase();
SQLiteStatement stmt = db.compileStatement("INSERT INTO FOO (NAME) VALUES (?)");
stmt.bindString(1, "Dood's Music Streamer");
stmt.execute();

Upvotes: 1

Casey Ferguson
Casey Ferguson

Reputation: 101

I'm not familiar with sqlite, but it might need an escape character similar to Java and C++, for example Dood\'s Music Streamer

Upvotes: 0

Related Questions