Skip to content

Commit

Permalink
[test] add unit test of alexbrainman#178
Browse files Browse the repository at this point in the history
  • Loading branch information
tooilxui committed Jun 7, 2022
1 parent 10bbaef commit c6591cd
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,3 +1917,69 @@ IF @@ROWCOUNT = 0
t.Fatal(err)
}
}

// https://github.com/alexbrainman/odbc/issues/178
func TestMSSQLIssue178(t *testing.T) {
db, _, err := mssqlConnect()
if err != nil {
t.Fatal(err)
}
defer func() {
// not checking resources usage here, because these are
// unpredictable due to use of goroutines.
err := db.Close()
if err != nil {
t.Fatalf("error closing DB: %v", err)
}
}()

var langNames = map[string]string{
"zh_tw": "張三",
"zh_cn": "张三",
}

db.Exec("drop table dbo.temp")
exec(t, db, "create table dbo.temp (lang char(5), name varchar(4))")

func() {
// insert people names
s, err := db.Prepare("insert into dbo.temp (lang, name) values (?, ?)")
if err != nil {
t.Fatal(err)
}
defer s.Close()
defer exec(t, db, "drop table dbo.temp")

for lang, name := range langNames {
_, err := s.Exec(lang, name)
if err != nil {
t.Fatal(err)
}
}

// query inserted data and compare with langPeople
rows, err := db.Query("select lang, name from dbo.temp")
if err != nil {
t.Fatalf("Query: %v", err)
}
defer rows.Close()

for rows.Next() {
var rowLang, rowName string
if err = rows.Scan(&rowLang, &rowName); err != nil {
t.Fatalf("Scan: %v", err)
}
name, ok := langNames[rowLang]
if !ok {
t.Fatalf("can't find people name by lang=: %v", rowLang)
}
if name != rowName {
t.Fatalf("people name missmatch, %v != %v", rowName, name)
}
}
err = rows.Err()
if err != nil {
t.Fatal(err)
}
}()
}

0 comments on commit c6591cd

Please sign in to comment.