1
0
forked from MTSR/mapserver

postgres return value

This commit is contained in:
NatureFreshMilk 2019-03-21 16:00:48 +01:00
parent e46852d76e
commit 7d5d69684f
2 changed files with 5 additions and 7 deletions

View File

@ -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

View File

@ -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 = `