Still trying to track down why Entities are returning correctly...
This commit is contained in:
parent
380153ec39
commit
0083f2887e
3 changed files with 26 additions and 13 deletions
37
main.go
37
main.go
|
|
@ -81,7 +81,7 @@ func create_entity(db *sql.DB, user_id int64, spawn_line string) (Entity) {
|
|||
id, _ := res.LastInsertId()
|
||||
ent.id = id
|
||||
ent.user_id = user_id
|
||||
ent.spawn_line = spawn_line
|
||||
ent.spawn_line = spawn_line
|
||||
|
||||
return ent
|
||||
}
|
||||
|
|
@ -92,18 +92,20 @@ func get_entity(db *sql.DB, id int64) (Entity) {
|
|||
|
||||
check(err)
|
||||
|
||||
var e Entity
|
||||
var ent Entity
|
||||
|
||||
res.Next()
|
||||
res.Scan(&e.id, &e.user_id, &e.spawn_line)
|
||||
res.Scan(&ent.id, &ent.user_id, &ent.spawn_line)
|
||||
log.Println("WHY DOESN'T THIS WORK")
|
||||
log.Printf("ID: %d, user_id: %d, spawn_line: %s", ent.id, ent.user_id, ent.spawn_line)
|
||||
res.Close()
|
||||
|
||||
if e.id != 0 {
|
||||
return e
|
||||
} else {
|
||||
|
||||
if ent.id == 0 {
|
||||
log.Printf("Entity id %d doesn't exist!", id)
|
||||
panic("!")
|
||||
}
|
||||
|
||||
return ent
|
||||
}
|
||||
|
||||
func reset_database(db *sql.DB) {
|
||||
|
|
@ -121,16 +123,27 @@ func main() {
|
|||
|
||||
reset_database(db)
|
||||
|
||||
log.Println("Reset db...")
|
||||
log.Println("Reset db...\n")
|
||||
|
||||
// spin up a user...
|
||||
log.Println("Adding users...\n")
|
||||
// spin up a user...
|
||||
u := get_user(db, "Monqui")
|
||||
log.Printf("ID: %d, name: %s", u.id, u.name)
|
||||
u = get_user(db, "Jim")
|
||||
log.Printf("ID: %d, name: %s", u.id, u.name)
|
||||
u = get_user(db, "Monqui")
|
||||
log.Printf("ID: %d, name: %s", u.id, u.name)
|
||||
|
||||
// make an entity for the user...
|
||||
// make some entities...
|
||||
log.Println("Adding entities...\n")
|
||||
e := create_entity(db, u.id, "hello im monqui")
|
||||
log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line)
|
||||
e = create_entity(db, u.id, "here's a whole nother line!")
|
||||
log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line)
|
||||
|
||||
// this should fail...
|
||||
e = create_entity(db, 2, "hello im monqui???")
|
||||
log.Println("Trying to fetch some entities...\n")
|
||||
e = get_entity(db, 1)
|
||||
log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line)
|
||||
e = get_entity(db, 2)
|
||||
log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line)
|
||||
}
|
||||
|
|
|
|||
BIN
rpgqui.db
BIN
rpgqui.db
Binary file not shown.
|
|
@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
|
||||
CREATE TABLE IF NOT EXISTS entities (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER,
|
||||
user_id INTEGER NOT NULL,
|
||||
name VARCHAR(64),
|
||||
spawn_line VARCHAR(64),
|
||||
FOREIGN KEY(user_id) REFERENCES users(id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue