|
|
@@ -22,6 +22,7 @@ var ( |
|
|
|
sqlConnection string |
|
|
|
buildTables bool |
|
|
|
populateTables bool |
|
|
|
autocreate bool |
|
|
|
// internal variables |
|
|
|
db *sql.DB |
|
|
|
queryType int |
|
|
@@ -137,8 +138,17 @@ func newEntrySql(score, player, board int64) error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func newKeySql(player int64) (*Key, error) { |
|
|
|
func newKeySql(player int64, name string) (*Key, error) { |
|
|
|
tx, _ := db.Begin() |
|
|
|
if autocreate { |
|
|
|
sqlPlayer := &Player{ID: player, Name: name} |
|
|
|
if (sqlPlayer.Load() != nil) { |
|
|
|
playerErr := sqlPlayer.Commit() |
|
|
|
if playerErr != nil { |
|
|
|
return nil, playerErr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
newKey := &Key{Token: "new", Player: player, Time: time.Now().Unix()} |
|
|
|
stmt, _ := tx.Prepare(queryStrings[queryType][3]) |
|
|
|
_, err := stmt.Exec(newKey.Token, newKey.Player, newKey.Time) |
|
|
|