Question

I have a strange problem which seems to be device specific: My Android podcast player app fetches data from a server and inserts it into a database. For more than 100 users everything is working fine. But for one user the data insertion fails with an SQLite syntax error, but just on his Galaxy Tab (GT-P7310) with Android 4.0.4. The same user also has two phones (Galaxy Nexus and Nexus 5) where the same data works without problems.

Furth on I can execute the statement without problems in a local SQLite installation.

This is the statement that causes the problem with a few line breaks added to make it more readable:

INSERT OR REPLACE INTO podcast
(uid, uri, url, title, subTitle, link, authorName, authorEmail, categories, keywords, description, imageUrl, modified, subscribed, settings_autoAddEpisodes, settings_autoDownload, settings_maxKeptEpisodes, settings_playbackSpeed, id)
VALUES
(19, 'http://api.sr.se/api/rss/pod/17155', 'http://api.sr.se/api/rss/pod/17155', 'Luuk & Lokko', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4296', 'Luuk & Lokko', 'podd@sverigesradio.se', '[{"name":"Society \u0026 Culture"}]', '[]', 'Luuk & Lokko är ett schemalagt veckosamtal där Kristian Luuk och Andres Lokko pratar med varandra om ämnen som de har bestämt på förhand. Vissa infall kan förekomma men de kommer att vara ytterst tyglade samt relativt få.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4296/2143980_512_512.jpg', 1386174193000, 1, 0, 0, NULL, NULL, NULL),
(580, 'http://sverigesradio.se/api/rss/pod/18535', 'http://sverigesradio.se/api/rss/pod/18535', 'FotbollsArena Radiosporten', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4410', 'FotbollsArena Radiosporten', 'podd@sverigesradio.se', '[{"name":"Sports \u0026 Recreation"}]', '[]', 'Varje vecka diskuterar Radiosportens Richard Henriksson med gäster det senaste och hetaste i fotbollsvärlden. Allt från allsvenskan och landslaget till de stora ligorna i Europa.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4410/2708666_512_512.jpg', 1386173280000, 1, 0, 0, NULL, NULL, NULL),
(581, 'http://sverigesradio.se/api/rss/pod/18656', 'http://sverigesradio.se/api/rss/pod/18656', 'Musikguiden i P3 ', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4067', 'Musikguiden i P3', 'podd@sverigesradio.se', '[{"name":"Music"}]', '[]', ': Jenny Seth presenterar Musikguiden i P3s journalistiska magasin. Vi går på djupet i musik från alla genres genom intervjuer, reportage och gäster i studion.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4067/2472633_512_512.jpg', 1386173083000, 1, 0, 0, NULL, NULL, NULL),
(796, 'http://www.stonesthrow.com/jukebox/podcast.xml', 'http://www.stonesthrow.com/jukebox/podcast.xml', 'Stones Throw Podcast', NULL, 'http://www.stonesthrow.com/podcast', 'Stones Throw Records', 'losangeles@stonesthrow.com', '[{"name":"Music"}]', '[]', 'Music from Stones Throw and the Stones Throw DJs. Archive available at stonesthrow.com', 'http://www.stonesthrow.com/images/stonesthrowpodcast.jpg', 1381769169000, 1, 0, 0, NULL, NULL, NULL),
(1174, 'http://swedroid.libsyn.com/rss', 'http://swedroid.libsyn.com/rss', 'Swedroid Podcast', '', 'http://www.swedroid.se', 'Swedroid', 'podcast@swedroid.se', '[{"name":"Technology","subCategory":"Gadgets"},{"name":"Technology","subCategory":"Podcasting"},{"name":"Technology","subCategory":"Tech News"}]', '["android","podcast","smartphone","swedroid"]', 'Intresserad av Android, Google och smarta telefoner? Missa inte Swedroids podcast! Vi går varje vecka igenom det senaste på Androidfronten.', 'http://assets.libsyn.com/content/6515469.jpg', 1386609291000, 1, 0, 0, NULL, NULL, NULL),
(247, 'http://feeds.feedburner.com/filipochfredrik/podcast', 'http://feeds.feedburner.com/filipochfredrik/podcast', 'Filip och Fredriks podcast', 'Filip & Fredrik och en mikrofon, en gång i veckan. Utnämnd till Sveriges bästa podcast 2011 (Svenska podradiopriset).', 'http://www.filipochfredrik.com', 'Filip och Fredrik', 'podcast@filipochfredrik.com', '[{"name":"Comedy"}]', '[]', 'Filip & Fredrik och en mikrofon, en gång i veckan. Utnämnd till Sveriges bästa podcast 2011 (Svenska podradiopriset).', 'http://www.filipochfredrik.com/wp-content/themes/filipochfredrik/images/ff-podcast-600x600.jpg', 1382878323000, 1, 0, 0, NULL, NULL, NULL),
(6, 'http://alexosigge.libsyn.com/rss', 'http://alexosigge.libsyn.com/rss', 'Alex & Sigges podcast', '', 'http://alexosigge.libsyn.com', 'Alex Schulman & Sigge Eklund', 'alexochsigge@gmail.com', '[{"name":"Comedy"}]', '["schulmans","podcast","eklund","sigge","sigges","schulman","eklunds","alex","radio","podradio"]', 'Alex Schulmans och Sigge Eklunds podcast som publiceras en gång i veckan.', 'http://assets.libsyn.com/content/4601369.jpg', 1386022416000, 1, 0, 0, NULL, NULL, NULL),
(73, 'http://computersweden.libsyn.com/rss', 'http://computersweden.libsyn.com/rss', 'Computer Swedens podcast', 'CS ger dig koll på veckans viktigaste it-händelser', 'http://computersweden.libsyn.com', 'Bjorn Olsberg', 'bjorn.olsberg@idg.se', '[{"name":"Technology","subCategory":"Podcasting"},{"name":"News \u0026 Politics"},{"name":"Technology","subCategory":"Tech News"}]', '["computer","cs","sweden"]', 'Lyssna i stället för att läsa! I Computer Swedens podcast sammanfattar vi it-nyheterna den senaste veckan, med fokus på de tre ämnen som vi tycker är intressantast att diskutera. Nyhetschef Sverker Brundin, debattredaktör Eva Melin och teknikreporter Tomas Zirn blandar hårt med mjukt och högt med lågt varje torsdag kl 17.00.', 'http://assets.libsyn.com/content/6406700.jpg', 1386023131000, 1, 0, 0, NULL, NULL, NULL),
(212, 'http://feeds.feedburner.com/ThisIsMyNextPodcast', 'http://feeds.feedburner.com/ThisIsMyNextPodcast', 'The Vergecast', 'The Vergecast', 'http://www.theverge.com/verge/verge_archives/show?mode=EntryGroup&slug=the-vergecast', 'Joshua Topolsky, Nilay Patel, Paul Miller', 'joshua@theverge.com', '[{"name":"Technology","subCategory":"Tech News"},{"name":"Technology","subCategory":"Gadgets"},{"name":"Technology"}]', '["joshua","gadgets","pcs","this","mac","smartphones","technology","miller","next","apple","pc","gadget","google","laptops","macs","is","paul","tech","ipad","patel","news","nilay","iphone","windows","android","timp","osx","podcast","my","topolsky","microsoft","tablet","tabelts"]', 'The Vergecast is your source for an irreverent and informative look at what''s happening right now (and next) in the world of technology and gadgets. Hosted by Joshua Topolsky, Nilay Patel, and Paul Miller alongside a cavalcade of tech luminaries, The Vergecast is the only podcast you need to make sense of the week in tech news. And your life.', 'http://assets.sbnation.com/assets/770431/vergecast.png', 1382873693000, 1, 0, 0, NULL, NULL, NULL),
(173, 'http://feeds.feedburner.com/Iterate', 'http://feeds.feedburner.com/Iterate', 'Iterate', 'Iterate: Loop until done.', 'http://www.iterate.tv/', 'Edwards, Clifford, Ritchie', 'rene@mobilenations.com', '[{"name":"Arts","subCategory":"Design"},{"name":"Technology","subCategory":"Software How-To"}]', '["icons","windows","interface","design","ipad","x","ux","blackberry","ui","webos","user","phone","iphone","mac","android","experience","os"]', 'Iterate brings together the best designers and app producers in the business to talk user interface and user experience from concept to implementation. Hosted by Marc Edwards, Seth Clifford, and Rene Ritchie. Loop until done.', 'http://www.mobilenations.com/broadcasting/podcast_iterate_1400.jpg', 1382885371000, 1, 0, 0, NULL, NULL, NULL)

And here the original statement on a single line

INSERT OR REPLACE INTO podcast (uid, uri, url, title, subTitle, link, authorName, authorEmail, categories, keywords, description, imageUrl, modified, subscribed, settings_autoAddEpisodes, settings_autoDownload, settings_maxKeptEpisodes, settings_playbackSpeed, id) VALUES (19, 'http://api.sr.se/api/rss/pod/17155', 'http://api.sr.se/api/rss/pod/17155', 'Luuk & Lokko', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4296', 'Luuk & Lokko', 'podd@sverigesradio.se', '[{"name":"Society \u0026 Culture"}]', '[]', 'Luuk & Lokko är ett schemalagt veckosamtal där Kristian Luuk och Andres Lokko pratar med varandra om ämnen som de har bestämt på förhand. Vissa infall kan förekomma men de kommer att vara ytterst tyglade samt relativt få.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4296/2143980_512_512.jpg', 1386174193000, 1, 0, 0, NULL, NULL, NULL), (580, 'http://sverigesradio.se/api/rss/pod/18535', 'http://sverigesradio.se/api/rss/pod/18535', 'FotbollsArena Radiosporten', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4410', 'FotbollsArena Radiosporten', 'podd@sverigesradio.se', '[{"name":"Sports \u0026 Recreation"}]', '[]', 'Varje vecka diskuterar Radiosportens Richard Henriksson med gäster det senaste och hetaste i fotbollsvärlden. Allt från allsvenskan och landslaget till de stora ligorna i Europa.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4410/2708666_512_512.jpg', 1386173280000, 1, 0, 0, NULL, NULL, NULL), (581, 'http://sverigesradio.se/api/rss/pod/18656', 'http://sverigesradio.se/api/rss/pod/18656', 'Musikguiden i P3 ', NULL, 'http://sverigesradio.se/sida/default.aspx?programid=4067', 'Musikguiden i P3', 'podd@sverigesradio.se', '[{"name":"Music"}]', '[]', ': Jenny Seth presenterar Musikguiden i P3s journalistiska magasin. Vi går på djupet i musik från alla genres genom intervjuer, reportage och gäster i studion.', 'http://sverigesradio.se/diverse/appdata/isidor/images/news_images/4067/2472633_512_512.jpg', 1386173083000, 1, 0, 0, NULL, NULL, NULL), (796, 'http://www.stonesthrow.com/jukebox/podcast.xml', 'http://www.stonesthrow.com/jukebox/podcast.xml', 'Stones Throw Podcast', NULL, 'http://www.stonesthrow.com/podcast', 'Stones Throw Records', 'losangeles@stonesthrow.com', '[{"name":"Music"}]', '[]', 'Music from Stones Throw and the Stones Throw DJs. Archive available at stonesthrow.com', 'http://www.stonesthrow.com/images/stonesthrowpodcast.jpg', 1381769169000, 1, 0, 0, NULL, NULL, NULL), (1174, 'http://swedroid.libsyn.com/rss', 'http://swedroid.libsyn.com/rss', 'Swedroid Podcast', '', 'http://www.swedroid.se', 'Swedroid', 'podcast@swedroid.se', '[{"name":"Technology","subCategory":"Gadgets"},{"name":"Technology","subCategory":"Podcasting"},{"name":"Technology","subCategory":"Tech News"}]', '["android","podcast","smartphone","swedroid"]', 'Intresserad av Android, Google och smarta telefoner? Missa inte Swedroids podcast! Vi går varje vecka igenom det senaste på Androidfronten.', 'http://assets.libsyn.com/content/6515469.jpg', 1386609291000, 1, 0, 0, NULL, NULL, NULL), (247, 'http://feeds.feedburner.com/filipochfredrik/podcast', 'http://feeds.feedburner.com/filipochfredrik/podcast', 'Filip och Fredriks podcast', 'Filip & Fredrik och en mikrofon, en gång i veckan. Utnämnd till Sveriges bästa podcast 2011 (Svenska podradiopriset).', 'http://www.filipochfredrik.com', 'Filip och Fredrik', 'podcast@filipochfredrik.com', '[{"name":"Comedy"}]', '[]', 'Filip & Fredrik och en mikrofon, en gång i veckan. Utnämnd till Sveriges bästa podcast 2011 (Svenska podradiopriset).', 'http://www.filipochfredrik.com/wp-content/themes/filipochfredrik/images/ff-podcast-600x600.jpg', 1382878323000, 1, 0, 0, NULL, NULL, NULL), (6, 'http://alexosigge.libsyn.com/rss', 'http://alexosigge.libsyn.com/rss', 'Alex & Sigges podcast', '', 'http://alexosigge.libsyn.com', 'Alex Schulman & Sigge Eklund', 'alexochsigge@gmail.com', '[{"name":"Comedy"}]', '["schulmans","podcast","eklund","sigge","sigges","schulman","eklunds","alex","radio","podradio"]', 'Alex Schulmans och Sigge Eklunds podcast som publiceras en gång i veckan.', 'http://assets.libsyn.com/content/4601369.jpg', 1386022416000, 1, 0, 0, NULL, NULL, NULL), (73, 'http://computersweden.libsyn.com/rss', 'http://computersweden.libsyn.com/rss', 'Computer Swedens podcast', 'CS ger dig koll på veckans viktigaste it-händelser', 'http://computersweden.libsyn.com', 'Bjorn Olsberg', 'bjorn.olsberg@idg.se', '[{"name":"Technology","subCategory":"Podcasting"},{"name":"News \u0026 Politics"},{"name":"Technology","subCategory":"Tech News"}]', '["computer","cs","sweden"]', 'Lyssna i stället för att läsa! I Computer Swedens podcast sammanfattar vi it-nyheterna den senaste veckan, med fokus på de tre ämnen som vi tycker är intressantast att diskutera. Nyhetschef Sverker Brundin, debattredaktör Eva Melin och teknikreporter Tomas Zirn blandar hårt med mjukt och högt med lågt varje torsdag kl 17.00.', 'http://assets.libsyn.com/content/6406700.jpg', 1386023131000, 1, 0, 0, NULL, NULL, NULL), (212, 'http://feeds.feedburner.com/ThisIsMyNextPodcast', 'http://feeds.feedburner.com/ThisIsMyNextPodcast', 'The Vergecast', 'The Vergecast', 'http://www.theverge.com/verge/verge_archives/show?mode=EntryGroup&slug=the-vergecast', 'Joshua Topolsky, Nilay Patel, Paul Miller', 'joshua@theverge.com', '[{"name":"Technology","subCategory":"Tech News"},{"name":"Technology","subCategory":"Gadgets"},{"name":"Technology"}]', '["joshua","gadgets","pcs","this","mac","smartphones","technology","miller","next","apple","pc","gadget","google","laptops","macs","is","paul","tech","ipad","patel","news","nilay","iphone","windows","android","timp","osx","podcast","my","topolsky","microsoft","tablet","tabelts"]', 'The Vergecast is your source for an irreverent and informative look at what''s happening right now (and next) in the world of technology and gadgets. Hosted by Joshua Topolsky, Nilay Patel, and Paul Miller alongside a cavalcade of tech luminaries, The Vergecast is the only podcast you need to make sense of the week in tech news. And your life.', 'http://assets.sbnation.com/assets/770431/vergecast.png', 1382873693000, 1, 0, 0, NULL, NULL, NULL), (173, 'http://feeds.feedburner.com/Iterate', 'http://feeds.feedburner.com/Iterate', 'Iterate', 'Iterate: Loop until done.', 'http://www.iterate.tv/', 'Edwards, Clifford, Ritchie', 'rene@mobilenations.com', '[{"name":"Arts","subCategory":"Design"},{"name":"Technology","subCategory":"Software How-To"}]', '["icons","windows","interface","design","ipad","x","ux","blackberry","ui","webos","user","phone","iphone","mac","android","experience","os"]', 'Iterate brings together the best designers and app producers in the business to talk user interface and user experience from concept to implementation. Hosted by Marc Edwards, Seth Clifford, and Rene Ritchie. Loop until done.', 'http://www.mobilenations.com/broadcasting/podcast_iterate_1400.jpg', 1382885371000, 1, 0, 0, NULL, NULL, NULL)

The statement causes this stack trace:

android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: 
    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) ~[na:0.0]
    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68) ~[na:0.0]
    at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143) ~[na:0.0]
    at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361) ~[na:0.0]
    at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260) ~[na:0.0]
    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84) ~[na:0.0]
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2019) ~[na:0.0]
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1959) ~[na:0.0]

Here some more detailed device information:

DEVICE
======
display name: IMM76D.XXLPV
manufacturer: samsung
model:        GT-P7310
product:      GT-P7310
brand:        samsung
tags:         release-keys

And the Android details:

ANDROID
=======
release:  4.0.4
codename: REL
sdk:      15
locale:   sv_SE
Was it helpful?

Solution

The syntax support for inserting multiple rows with a single SQL statement was only added in sqlite 3.7.11. Some manufacturers have older versions of sqlite in their devices. Isn't platform fragmentation fun, eh.

You can fix it by breaking up the inserts to inserting one row at a time.

While there, also consider changing to ? literal placeholders and using bindArgs with execSQL() to supply the values. Or just use ContentValues with insert().

For performance, wrap multiple inserts (say, max 1000) in a single database transaction.

OTHER TIPS

Can you not try inserting half the rows first, then second half and keep halving until you pinpoint the row/rows which are causing the issue. Should make it much easier to spot the issue.

I sugest you to use parameter for inserting values here is a good way to do this

To build on laalto's answer,

Use db.beginTransaction(); then loop and insert your rows with initialValues = new ContentValues(); and initialValues.put(KEY_CATEGORY, category); ect.. then at the end write db.setTransactionSuccessful(); and db.endTransaction();

I use it to insert 9k rows in under 5 seconds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top