- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的实体实现 Room 2.2 附带的架构默认值,但它似乎不起作用。
我有一个名为 Place 的实体:
@Entity
public class Place implements Parcelable {
@PrimaryKey(autoGenerate = true)
private Long placeId;
private String name;
private double latitude;
private double longitude;
private int radius;
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
private String createdAt;
@Ignore
public Place() {}
public Place(String name, double latitude, double longitude, int radius) {
this.name = name;
this.latitude = latitude;
this.longitude = longitude;
this.radius = radius;
}
// getters and setters...
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
}
createdAt
字段总是被插入为 NULL。
createdAt
变量为
long
用 0 替换字段。
最佳答案
您可以使用 @查询 具有特定的列名(和值),不包括那些默认为。
按照 :-
Note that the default value you specify here will NOT be used if you simply insert the Entity with @Insert. In that case, any value assigned in Java/Kotlin will be used. Use @Query with an INSERT statement and skip this column there in order to use this default value. defaultValue
@Query("INSERT INTO Place (name,latitude,longitude,radius) VALUES(:name,:latitude,:logitude,:radius)")
DROP TABLE IF EXISTS place;
CREATE TABLE IF NOT EXISTS `Place` (`placeId` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `latitude` REAL NOT NULL, `longitude` REAL NOT NULL, `radius` INTEGER NOT NULL, `createdAt` TEXT DEFAULT CURRENT_TIMESTAMP);
INSERT INTO place VALUES(null,'opt1',0,0,0,null); //<<<< As per @Insert
INSERT INTO place (name,latitude,longitude,radius) VALUES('opt2',1,1,1); //<<<< As per @Query
SELECT * FROM place;
"INSERT OR ABORT INTO `Place` (`placeId`,`name`,`latitude`,`longitude`,`radius`,`createdAt`) VALUES (?,?,?,?,?,?)"
"INSERT INTO place (name,latitude,longitude,radius) VALUES(?, ?, ?, ?)"
关于Android Room defaultValue ="CURRENT_TIMESTAMP"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59340430/
因此,重新格式化了开发机器并盲目地重新安装了 MAMP 堆栈。现在我的 mariadb 与我们的服务器版本不同(10.2.6 vs 10.0.17)。 将服务器数据库转移到开发人员后,新版本似乎已将所
我得到了以下实体: @Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(co
当我创建一个新表时 create table test(rId int auto_increment, createtimestamp timestamp not null, PRIMARY KEY
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this q
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this q
In MariaDB 5.5 and before there could only be one TIMESTAMP column per table that had CURRENT_TIMEST
我写了一个sql来计算现在和上次更新时间之间的时间差异。首先,我只使用 CURRENT_TIMESTAMP - Updated_time 并发现结果在时间单位秒内看起来是正确的。但它并不稳定,有时结果
我刚刚花了几个小时来追踪这个错误。给定以下 SQL: DROP DATABASE IF EXISTS db; CREATE DATABASE db; CREATE TABLE db.tbl (t1 T
我正在尝试将数据库从 mysql 移植到 infinidb。但是在移植时出现上述错误(在标题中描述)。 `CREATE_TIMESTAMP` TIMESTAMP NOT NULL DEFAULT CU
我有一个这样的模型 - { "name": "MakeCallTestConfiguration", "base": "PersistedModel", "idInjection": tr
我们正在使用 Oracle 数据库。 在我们的表中时间戳存储为自 1970 年以来的秒数,如何将通过 current_timestamp() 函数获得的时间戳转换为秒 最佳答案 这样做: select
我正在使用Grails版本2.4.0,Java版本1.7和oracle 12c。 我想将apiEventLogList的记录保留在数据库表中。我不想在Java中设置createdTs字段,而是在GOR
我有一个如下所示的查询: $query = "INSERT INTO `SmsServ`.`SmsReceived` ( `Id` , `Body` , `DateRecei
我试图在将行插入数据库之前将 CURRENT_TIMESTAMP 设置为 UTC。根据我的阅读,这就是针对每个连接执行此操作的方法。 我的服务器时区是 EST (+5:00)。 我在调试时执行以下操作
我有一个数据库,其中有一个名为日期(时间戳)的列,该列设置为默认的 CURRENT_TIMESTAMP。这曾经工作正常,但是将数据库迁移到不同的服务器后,时间戳仅在执行 UPDATE 查询后应用,IN
我们目前在 MySQL 数据库上使用触发器,将“上次修改”时间戳设置为 CURRENT_TIMESTAMP。它在更新时调用。 我们还需要对集群使用基于语句的复制。 有没有办法修改触发器,以便传播的 C
我使用准备好的语句插入数据。如何将变量分配给 CURRENT_TIMESTAMP 并绑定(bind)该值? 我有一个包含列“name、lastfed、lastdoc 和 id”的数据库表。名为 las
我犯了一个出生在新西兰的错误,现在必须弄清楚如何在我的服务器时间上增加 15 小时!将不胜感激任何想法。 目前我正在使用: mysql_query(" INSERT INTO articles (Id
我正在尝试向该表中添加一个时间戳列: CREATE TABLE `task` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(
我在我的数据库中创建了一个表格,其中付款时间为 payment_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP。当我在将 payment_time
我是一名优秀的程序员,十分优秀!