1
0

Date now stored as Unix time (int64). No NULL is being returned so no such check is needed.

This commit is contained in:
Alexander Andreev 2023-05-09 21:32:01 +04:00
parent 6cfe0a7d8b
commit 761b7626c9
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -128,31 +128,31 @@ func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*guestbook.Ent
for rows.Next() {
var entry guestbook.Entry
var entry_created string
var reply_created sql.NullString
var reply_message sql.NullString
var entry_created int64
var reply_created int64
var reply_message string
if err = rows.Scan(
&entry.ID, &entry_created, &entry.Name,
&entry.Message, &entry.Website,
&entry.Message, &entry.Website, &entry.HideWebsite,
&reply_created, &reply_message); err != nil {
return
}
entry.Created, err = time.Parse(guestbook.DateFormat, entry_created)
entry.Created = time.Unix(entry_created, 0)
if err != nil {
return
}
if reply_message.Valid /* reply_created is also valid if reply is */ {
date, err := time.Parse(guestbook.DateFormat, reply_created.String)
if reply_message != "" {
if err != nil {
return nil, err
}
entry.Reply = &guestbook.Reply{
ID: entry.ID,
Created: date,
Message: reply_message.String}
ID: entry.ID,
// Created: date,
Created: time.Unix(reply_created, 0),
Message: reply_message}
}
entries = append(entries, &entry)
@ -189,7 +189,7 @@ func (d *SQLiteDatabase) NewEntry(entry *guestbook.Entry) error {
}
defer tx.Rollback()
r, err := tx.Stmt(stmtNewEntry).Exec(entry.Created.Format(guestbook.DateFormat), entry.Name, entry.Message,
r, err := tx.Stmt(stmtNewEntry).Exec(entry.Created.UTC().Unix(), entry.Name, entry.Message,
entry.Website, entry.HideWebsite)
if err != nil {
return err
@ -244,7 +244,7 @@ func (d *SQLiteDatabase) NewReply(reply *guestbook.Reply) error {
}
defer tx.Rollback()
_, err = tx.Stmt(stmtNewReply).Exec(reply.ID, reply.Created.Format(guestbook.DateFormat), reply.Message)
_, err = tx.Stmt(stmtNewReply).Exec(reply.ID, reply.Created.UTC().Unix(), reply.Message)
if err != nil {
return err
}