diff --git a/server/mapobjectdb/postgres/mapobjects.go b/server/mapobjectdb/postgres/mapobjects.go index 12560d9..faa6057 100644 --- a/server/mapobjectdb/postgres/mapobjects.go +++ b/server/mapobjectdb/postgres/mapobjects.go @@ -70,16 +70,13 @@ func (db *PostgresAccessor) RemoveMapData(pos *coords.MapBlockCoords) error { } func (db *PostgresAccessor) AddMapData(data *mapobjectdb.MapObject) error { - res, err := db.db.Exec(addMapDataQuery, + res := db.db.QueryRow(addMapDataQuery, data.X, data.Y, data.Z, data.MBPos.X, data.MBPos.Y, data.MBPos.Z, data.Type, data.Mtime) - if err != nil { - return err - } - - id, err := res.LastInsertId() + lastInsertId := 0 + err := res.Scan(&lastInsertId) if err != nil { return err @@ -87,7 +84,7 @@ func (db *PostgresAccessor) AddMapData(data *mapobjectdb.MapObject) error { for k, v := range data.Attributes { //TODO: batch insert - _, err := db.db.Exec(addMapDataAttributeQuery, id, k, v) + _, err := db.db.Exec(addMapDataAttributeQuery, lastInsertId, k, v) if err != nil { return err diff --git a/server/mapobjectdb/postgres/sql.go b/server/mapobjectdb/postgres/sql.go index aad41fe..8fc6cdd 100644 --- a/server/mapobjectdb/postgres/sql.go +++ b/server/mapobjectdb/postgres/sql.go @@ -21,6 +21,7 @@ const addMapDataQuery = ` insert into objects(x,y,z,posx,posy,posz,type,mtime) values($1, $2, $3, $4, $5, $6, $7, $8) +returning id ` const addMapDataAttributeQuery = `