-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mssql: support custom SQL to init connection setup
- Loading branch information
Showing
4 changed files
with
118 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// +build go1.10 | ||
|
||
package mssql | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"testing" | ||
) | ||
|
||
func TestResetSQL(t *testing.T) { | ||
checkConnStr(t) | ||
SetLogger(testLogger{t}) | ||
|
||
d := &Driver{} | ||
connector, err := d.OpenConnector(makeConnStr(t).String()) | ||
if err != nil { | ||
t.Fatal("unable to open connector", err) | ||
} | ||
connector.ResetSQL = ` | ||
SET XACT_ABORT ON; -- 16384 | ||
SET ANSI_NULLS ON; -- 32 | ||
SET ARITHIGNORE ON; -- 128 | ||
` | ||
|
||
pool := sql.OpenDB(connector) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
var opt int32 | ||
err = pool.QueryRowContext(ctx, ` | ||
select Options = @@OPTIONS; | ||
`).Scan(&opt) | ||
if err != nil { | ||
t.Fatal("failed to run query", err) | ||
} | ||
mask := int32(16384 | 128 | 32) | ||
|
||
if opt&mask != mask { | ||
t.Fatal("incorrect session settings", opt) | ||
} | ||
} |