如何将数据从nativeTextField保存到corona中的sqlite数据库

时间:2012-11-22 05:17:59

标签: 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
        }

当我尝试将textStringdb:exec( [[ INSERT INTO test VALUES (NULL, textString, 30, "unknown")]] )更改为“这是一个字符串”之类的字符串时,似乎工作正常,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

Lua不会在双括号内评估textString ...在Corona中运行它以查看差异:

textString="hello world"


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

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

希望这有帮助。