2012-11-22 41 views
0

在corona中將數據從本地文本字段保存到sqlite數據庫非常困難。如何將數據從nativeTextField保存到corona中的sqlite數據庫中

這裏有一些相關的代碼:

function printrecord() 
     for row in db:nrows("SELECT * FROM test") do 
      t = display.newText(row.pname .. " " .. row.age .. " " .. row.desc, 20, 30 * row.id, null, 16) 
      t:setTextColor(255,255,255) 
     end 
    end 

    newData = native.newTextField (20, _H - 90, 280, 30) 
    newData.inputType = "text" 

    saveData = function (event) 
     textString = newData.text 
     db:exec([[ INSERT INTO test VALUES (NULL, textString, 30, "unknown")]]) 
     t:removeSelf() 
     t = nil 
     printrecord() 
    end 

    savebutton = widget.newButton { 
     default = "buttonGreen.png", 
     over = "buttonGreenOver.png", 
     label = "Save", 
     embose = true, 
     onRelease = saveData 
     } 

當我嘗試從db:exec([[ INSERT INTO test VALUES (NULL, textString, 30, "unknown")]])textString改變,如「這是一個字符串」它似乎做工精細字符串,誰能幫助?

回答

0

的Lua不會評價雙括號內textString ...科羅納運行此看出區別:

textString="hello world" 


print([[ INSERT INTO test VALUES (NULL, textString, 30, "unknown")]]) 

print([[ INSERT INTO test VALUES (NULL,"]]..textString..[[",30,"unknown")]]) 

希望這有助於。

+0

很久以前就已經想到了這一點,感謝您的幫助。 – philip

相關問題