execSQL导致语法错误

时间:2012-12-29 23:42:53

标签: android sqlite

我有以下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 个答案:

答案 0 :(得分:1)

  

你的错误。你没有逃避撇号。据我所知,如果你使用''这应该工作。

注意:“使用”和“使用”“

试试这个:

  

database.execSQL(“insert into”+ TABLE_EXERCISES +“(”+ COLUMN_NAME   +“,”+ COLUMN_PRIMARY_MUSCLE +“,”+ COLUMN_SECONDARY_MUSCLE +“,”+ COLUMN_EQUIPMENT_TYPE +“,”+ COLUMN_STEPS +“,”+ COLUMN_IMAGES +“)值('Cable Shrugs','Traps','None','Cable ','附上一个单位   肩宽度杆到最低的缆索滑轮。站起来用脚   肩宽分开。保持你的腹肌紧绷,轻微弯曲   膝盖保护你的下背部。从腰部的酒吧开始   高度,抬起你的肩膀,就像你说的那样,“”我   我不知道。“”紧紧抓住收缩的顶部然后降低   以缓慢和受控的方式。',   '电缆耸肩-1.png |电缆耸肩-2.png')“);