【问题标题】:inserting data using variables in sqlite db在 sqlite db 中使用变量插入数据
【发布时间】:2013-05-04 12:17:40
【问题描述】:

嘿,我正在制作我的第一个 phonegap 应用程序,我在 sqlite db 中遇到了问题 在哪里,我有在数据库中创建表并从中读取的代码,但我需要在数据库中插入一个变量值而不是静态值,这是我要插入的代码:

tx.executeSql('INSERT INTO bus_stations (station_name,station_description,station_lat,station_long) VALUES ("6th October","", + "111" + ,"31.963522")');

这行得通,但这行不通,我该怎么办??!

var x=111;
tx.executeSql('INSERT INTO bus_stations (station_name,station_description,station_lat,station_long) VALUES ("6th October","", x ,"31.963522")');

【问题讨论】:

    标签: eclipse cordova android-sqlite


    【解决方案1】:

    通过将您的 INSERT 放入单个 qoutes ' 中,您实际上是在一个简单的字符串或文本中制作所有内容。你的 x 也变成了字母 x。我建议您拆分 INSERT 字符串并按如下方式添加变量:

    var x = 111;
    tx.executeSql('INSERT INTO bus_stations station_name,station_description,station_lat,station_long) VALUES ("6th October","",' + x + ',"31.963522")');
    

    注意' + x + ',之前你有x

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      相关资源
      最近更新 更多