Slide 13
Slide 13 text
͘͝γϯϓϧͳྫ
tx, err := db.Begin(
)
if err != nil
{
log.Fatalf("τϥϯβΫγϣϯͷ։࢝ʹࣦഊ͠·ͨ͠: %v", err
)
}
result, err := tx.Exec("INSERT INTO mikan_table (key, value) VALUES ($1, $2)", "ςετ", "ςετͰ͢"
)
if err != nil
{
if err := tx.Rollback(); err != nil
{
log.Fatalf("σʔλͷՃʹࣦഊ͠ɺϩʔϧόοΫࣦഊ͠·ͨ͠: %v", err
)
}
log.Fatalf("σʔλͷՃʹࣦഊͨͨ͠ΊɺϩʔϧόοΫ͠·ͨ͠: %v", err
)
}
n, err := result.RowsAffected(
)
if err != nil
{
if err := tx.Rollback(); err != nil
{
log.Fatalf("σʔλͷՃ݁Ռͷऔಘʹࣦഊ͠ɺϩʔϧόοΫࣦഊ͠·ͨ͠: %v", err
)
}
log.Fatalf("σʔλͷՃ݁Ռͷऔಘʹࣦഊͨͨ͠ΊɺϩʔϧόοΫ͠·ͨ͠: %v", err
)
}
fmt.Printf("Rows affected: %d\n", n
)
if err := tx.Commit(); err != nil
{
log.Fatalf("τϥϯβΫγϣϯͷίϛοτʹࣦഊ͠·ͨ͠: %v", err
)
}
fmt.Println("τϥϯβΫγϣϯྃ")
τϥϯβΫγϣϯͷ։࢝
ࣦഊͨ͠ΒϩʔϧόοΫ
࠷ޙʹίϛοτ