2012-12-29 84 views
1

我有以下execSQL拋出語法錯誤,並導致我的應用程序崩潰。考慮到我逃脫了單引號和雙引號,我無法弄清楚爲什麼。execSQL導致語法錯誤

下面是代碼:

database.execSQL("insert into " + TABLE_EXERCISES + " (" + COLUMN_NAME + ", " + COLUMN_PRIMARY_MUSCLE + ", " + COLUMN_SECONDARY_MUSCLE + ", " + COLUMN_EQUIPMENT_TYPE + ", " + COLUMN_STEPS + ", " + COLUMN_IMAGES + ") values ('Cable Shrugs', 'Traps', 'None', 'Cable', 'Attach a flat shoulder width bar to the lowest cable pulley. Stand with your feet shoulder width apart. Keep your abs tight and a slight bend in your knees to protect your lower back. Starting with the bar at waist height, raise your shoulders toward your ears as if you\'re saying,\"I don\'t know.\" Hold briefly at the top of the contraction then lower in a slow and controlled manner.', 'cable-shrugs-1.png|cable-shrugs-2.png')"); 

任何人有任何想法?

這裏是日誌:

12-29 23:31:54.174: E/AndroidRuntime(1207): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gauvion.gfit/com.gauvion.gfit.RoutinesActivity}: android.database.sqlite.SQLiteException: near "re": syntax error (code 1): , while compiling: insert into exercises(name, primary_muscle, secondary_muscle, equipment_type, steps, images) VALUES ('Cable Shrugs', 'Traps', 'None', 'Cable', 'Attach a flat shoulder width bar to the lowest cable pulley. Stand with your feet shoulder width apart. Keep your abs tight and a slight bend in your knees to protect your lower back. Starting with the bar at waist height, raise your shoulders toward your ears as if you're saying,"I don't know." Hold briefly at the top of the contraction then lower in a slow and controlled manner.', 'cable-shrugs-1.png|cable-shrugs-2.png') 
+1

你能張貼在崩潰發生敬請logcat中的一部分 – Dan

+2

還要注意,在SQLite中轉義單引號是通過雙引號(''''),而不是反斜線:http://www.sqlite.org/faq.html#q14你真的應該考慮使用位置參數,而不是手工編碼所有逃脫。 – CommonsWare

+0

張貼日誌。也許你是正確的,即時通訊可能不會轉義報價和正確的雙引號 – scarhand

回答

1

有你的錯誤。你不是逃避撇號。據我所知,如果你使用「'這應該工作。

注:「使用 '' 和 」使用 「」

試試這個:

database.execSQL(「 插入 」+ TABLE_EXERCISES +「( 」+ COLUMN_NAME +「, 「電纜聳肩」,「陷阱」,「無」,「電纜」,「電纜」和「電纜聳肩」,「+ COLUMN_PRIMARY_MUSCLE +」,「+ COLUMN_SECONDARY_MUSCLE +」,「+ COLUMN_EQUIPMENT_TYPE +」,「+ COLUMN_STEPS +」,「+ COLUMN_IMAGES +將一個平坦的 肩部寬度杆連接到最低的線纜滑輪。將您的雙腳分開放置肩寬 。保持腹肌緊繃並在您的腰部略微彎曲 膝蓋保護你的腰部。從腰部 高度的酒吧開始,擡起你的肩膀,彷彿你在說,「」我 不知道。「」暫時收縮在收縮頂部,然後緩慢地降低 控制方式「, ‘索聳聳肩-1.png |電纜聳聳肩-2.png’)」);