2011-07-03 5 views
0

ContentValuesオブジェクトの引用符付き文字列をsqlite挿入に使用するにはどうすればよいですか? SQLiteはのどに詰まらせているようだ。私の価値insertOrThrowのContentValuesを使って引用符で囲まれた文字列を取得する

私は、このエラーが発生します
//inside a for loop of a NodeList 
    ContentValues map = new ContentValues(); 
    Element elm; 
    elm = (Element) nodes.item(i); 
    String elmname = elm.getTagName(); 
    map.put("foto", getValue(elm, "foto")); 
    map.put("fotonormal", getValue(elm, "foto-normal")); 
    map.put("link", getValue(elm, "link")); 

    myDatabase.beginTransaction(); 
    try { 
     myDatabase.insertOrThrow(TABLE_ENDING, null, map); 
     Log.i(TAG, "Added"); 
     myDatabase.setTransactionSuccessful(); 
    } catch (Exception err) { 
     Log.i(TAG, "Transaction failed. Exception: " + err.getMessage()); 
    } finally { 
     myDatabase.endTransaction(); 
    } 

Transaction failed. Exception: unrecognized token: ":": INSERT INTO tbl_ending (fotonormal, foto, link) VALUES (https://example.com/fotonormal.jpg, https://example.com/foto.jpg, https://example.com/); 

の私は、SQL文が

INSERT INTO tbl_ending (fotonormal, foto, link) VALUES ("https://example.com/fotonormal.jpg", "https://example.com/foto.jpg", "https://example.com/"); 

どのように私はこの出力を得ることができなければなりませんと信じて代わりに?

答えて

0

フィリップの答え正しい道に私を入れて、私は文字列としての機能のgetValueの戻り値をキャスト:私は、すなわちは、それが問題を修正する場合は、単に確認するために、明示のgetValueパラメータをキャストするために傾けられます

return (String) getElementValue(n.item(0)); 

これで正常に挿入できます。

1

確かに非常に奇妙な動作です。基本的にmap.putステートメントで弱い型付けが行われていますが、これは役に立ちません。

map.put("foto", (String) getValue(elm, "foto")); 
map.put("fotonormal", (String) getValue(elm, "foto-normal")); 
map.put("link", (String) getValue(elm, "link")); 
+0

エラーが発生しました。トランザクションが失敗しました。例外:エラーコード19:制約に失敗しました。私はこれがあまりにも多くの引用に関連していると思う:http://stackoverflow.com/questions/5364576/android-sqliteconstraintexception-error-code-19-constraint-failed –

関連する問題