0

很难将本地文本字段中的数据保存到电晕中的 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
        }

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

4

1 回答 1

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")]])

希望这可以帮助。

于 2012-12-05T02:45:51.617 回答