我是使用光滑工具的新手,我只是尝试从h2 db插入和提取数据,但是我得到了错误的时间戳格式 这就是我要插入的内容:
FooRecord(1,foo,bar,a,b,c,2016-12-10 23:59:00.0,2016-12-10 23:59:00.0,2016-12-10 23:59:00.0,false)
这是select query
的结果,您可以看到时间为零
FooRecord(1,foo,bar,a,b,c,2016-12-10 00:00:00.0,2016-12-10 00:00:00.0,2016-12-10 00:00:00.0,false)
这是我的表定义的样子
case class FooRecord (id: Long, firstName: String, lastName:String, parameter: String, value: String, unit: String,
validStart: Timestamp, validStop: Timestamp, transactionTime: Timestamp, archive: Boolean = false)
private class FooTable(tag: Tag) extends Table[FooRecord](tag, "myTable") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("first_name")
def lastName = column[String]("last_name")
def parameter = column[String]("parameter")
def value = column[String]("value")
def unit = column[String]("unit")
def validStart = column[Timestamp]("valid_start")
def validStop = column[Timestamp]("valid_stop")
def transactionTime = column[Timestamp]("transaction_time")
def archive = column[Boolean]("archive")
def * =
(id, firstName, lastName, parameter, value, unit, validStart, validStop, transactionTime, archive) <> ((FooRecord.apply _).tupled, FooRecord.unapply)
}
这是插入方法:
def create(firstName: String, lastName:String, parameter: String, value: String, unit: String, validStart: Timestamp,
validStop: Timestamp, transactionTime: Timestamp, archive: Boolean = false): Future[FooRecord] = db.run {
(records.map(p => (p.firstName, p.lastName, p.parameter, p.value, p.unit, p.validStart, p.validStop,p.transactionTime, p.archive))
returning records.map(_.id)
combines our original parameters with the
into ((rec, id) =>
FooRecord(id, rec._1, rec._2, rec._3, rec._4,rec._5, rec._6,rec._7, rec._8, rec._9))
) += (firstName, lastName, parameter, value, unit, validStart, validStop, transactionTime, archive)
}
这是选择查询:
def list(): Future[Seq[FooRecord]] = {
sortedActiveRecords.result
}
如何获取正确的时间戳,包括时间值(小时,分钟,秒)?
-----更新---- 查看日志,似乎插入语句可以: [debug] s.j.J.语句-准备插入语句(返回:id):
insert into "myTable" ("first_name","last_name","parameter","value","unit","valid_start","valid_stop","transaction_time","archive") values (?,?,?,?,?,?,?,?,?)
[debug] s.j.J.parameter - /--------+--------+--------+--------+--------+-----------------------+-----------------------+-----------------------+---------\
[debug] s.j.J.parameter - | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
[debug] s.j.J.parameter - | String | String | String | String | String | Timestamp | Timestamp | Timestamp | Boolean |
[debug] s.j.J.parameter - |--------+--------+--------+--------+--------+-----------------------+-----------------------+-----------------------+---------|
[debug] s.j.J.parameter - | foo | bar | a | b | c | 2016-12-10 23:59:00.0 | 2016-12-10 23:59:00.0 | 2016-12-09 23:59:00.0 | false |
[debug] s.j.J.parameter - \--------+--------+--------+--------+--------+-----------------------+-----------------------+-----------------------+---------/
但是select
查询看起来很奇怪-请注意它们确实没有时间戳值的时间戳值:
[debug] s.b.B.action - #1: result [select "id", "first_name", "last_name", "parameter", "value", "unit", "valid_start", "valid_stop", "transaction_time", "archive" from "myTable"]
[debug] s.j.J.statement - Preparing statement: select "id", "first_name", "last_name", "parameter", "value", "unit", "valid_start", "valid_stop", "transaction_time", "archive" from "myTable"
[debug] s.j.J.benchmark - Execution of prepared statement took 196µs
[debug] s.j.S.result - /----+------------+-----------+-----------+-------+------+-------------+------------+------------------+---------\
[debug] s.j.S.result - | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
[debug] s.j.S.result - | id | first_name | last_name | parameter | value | unit | valid_start | valid_stop | transaction_time | archive |
[debug] s.j.S.result - |----+------------+-----------+-----------+-------+------+-------------+------------+------------------+---------|
[debug] s.j.S.result - | 1 | foo | bar | a | b | c | 2016-12-10 | 2016-12-10 | 2016-12-09 | 0 |
[debug] s.j.S.result - \----+------------+-----------+-----------+-------+------+-------------+------------+------------------+---------/