根据sqlite中的datetime字段更新记录

时间:2014-08-05 11:32:47

标签: sqlite cordova

我正在使用带有phonegap的sqlite,我想更新datetime字段具有相同值的数据。

CREATE TABLE "MyTable" 
(
"VehicleNumber" TEXT, "VehicleImage" TEXT, "LocationId" INTEGER, "LocationName" TEXT, "StartTime" DATETIME, "EndTime" DATETIME, "ComputedCharge" DOUBLE, "InsertedDateTime" DATETIME, "InsertedBy" INTEGER, "UpdatedDateTime" DATETIME, "UpdatedBy" INTEGER, "PaymentIncash" BOOL, "EntryUpdateOnServer" BOOL, "ExitUpdateOnServer" BOOL
)

DATA

INSERT INTO "MyTable" VALUES ("ERA 75TM","Pictures/ERA 75TM.jpeg","1","surat","2014-08-05 13:5:35","2014-08-05 15:40:48","17","2014-08-05 13:5:35","3","2014-08-05 15:40:48","3","false","false","false");

更新查询不起作用

UPDATE MyTable SET 
    VehicleImage='Pictures/ERA 75TM.jpeg',
    ComputedCharge=17,
    EntryUpdateOnServer='true',
    ExitUpdateOnServer='true' 
WHERE VehicleNumber='ERA 75TM' AND StartTime=DATETIME('2014-08-05 13:05:35') AND LocationId=1

2 个答案:

答案 0 :(得分:2)

"2014-08-05 13:5:35"
               ^

具有一位数分钟值的字符串不是supported date formats之一,并且不是您要搜索的字符串。

答案 1 :(得分:-1)

希望以下内容符合您的目的。

使用" true"或"假"对于BOOL不起作用。 BOOL实际上是一个整数,而不是一个字符串。因此,您使用true或false,或简单地使用1或0.

DATETIME(字符串)不起作用。不确定这是否应该像那样工作,因为字符串可以是任意数量的格式。无论如何,我使用了STR_TO_DATE,它按预期工作。

CREATE TABLE `MyTable` (
  `VehicleNumber` TEXT,
  `VehicleImage` TEXT, 
  `LocationId` INTEGER, 
  `LocationName` TEXT, 
  `StartTime` DATETIME, 
  `EndTime` DATETIME, 
  `ComputedCharge` DOUBLE, 
  `InsertedDateTime` DATETIME, 
  `InsertedBy` INTEGER, 
  `UpdatedDateTime` DATETIME, 
  `UpdatedBy` INTEGER, 
  `PaymentIncash` BOOL, 
  `EntryUpdateOnServer` BOOL, 
  `ExitUpdateOnServer` BOOL
);

INSERT INTO `MyTable` VALUES ("ERA 75TM","Pictures/ERA 75TM.jpeg","1","surat","2014-08-05 13:5:35","2014-08-05 15:40:48","17","2014-08-05 13:5:35","3","2014-08-05 15:40:48","3",false,false,false);

UPDATE `MyTable` SET 
    VehicleImage='Pictures/ERA 75TM.jpeg',
    ComputedCharge=17,
    EntryUpdateOnServer=false,
    ExitUpdateOnServer=false 
WHERE VehicleNumber='ERA 75TM' AND StartTime=STR_TO_DATE('2014-08-05 13:05:35','%Y-%m-%d %H:%i:%s') AND LocationId=1;