TheMathemagicians/sevenkeys/database/remove.go

51 lines
1000 B
Go

package database
import "database/sql"
func RemoveFromBinder(db *sql.DB, location LocateCardResult) error {
query := `UPDATE CardStorageLocation SET CardPrintingId = NULL WHERE Id = ?;`
update, err := db.Prepare(query)
defer update.Close()
if err != nil {
return err
}
_, err = update.Exec(location.CardLocationId)
if err != nil {
return err
}
return nil
}
func RemoveFromBox(db *sql.DB, location LocateCardResult) error {
deleteQuery := `DELETE FROM CardStorageLocation WHERE Id = ?;`
del, err := db.Prepare(deleteQuery)
defer del.Close()
if err != nil {
return err
}
_, err = del.Exec(location.CardLocationId)
if err != nil {
return err
}
updateQuery := `UPDATE CardStorageLocation SET Position = Position - 1 WHERE Position > ? AND StorageAreaId = ?;`
update, err := db.Prepare(updateQuery)
defer update.Close()
if err != nil {
return err
}
_, err = update.Exec(location.Position, location.StorageAreaId)
if err != nil {
return err
}
return nil
}