-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
606 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ _testmain.go | |
*.exe | ||
/example/example | ||
/gofreetds.test | ||
/example/sqlx |
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,70 @@ | ||
package freetds | ||
|
||
import ( | ||
"github.com/stretchrcom/testify/assert" | ||
"testing" | ||
"strings" | ||
) | ||
|
||
func TestExecSp(t *testing.T) { | ||
conn := ConnectToTestDb(t) | ||
results, _, err := conn.execSp("sp_who") | ||
assert.Nil(t, err) | ||
assert.NotNil(t, results) | ||
assert.Equal(t, 1, len(results)) | ||
|
||
|
||
} | ||
|
||
func TestExecSpReturnValue(t *testing.T) { | ||
conn := ConnectToTestDb(t) | ||
err := createProcedure(conn, "test_return_value", " as return 123") | ||
assert.Nil(t, err) | ||
results, status, err := conn.execSp("test_return_value") | ||
assert.Nil(t, err) | ||
assert.Equal(t, 0, len(results)) | ||
assert.Equal(t, 123, status) | ||
} | ||
|
||
|
||
func TestExecSpResults(t *testing.T) { | ||
conn := ConnectToTestDb(t) | ||
err := createProcedure(conn, "test_results", " as select 1 one; select 2 two; return 456") | ||
assert.Nil(t, err) | ||
results, status, err := conn.execSp("test_results") | ||
assert.Nil(t, err) | ||
assert.Equal(t, 2, len(results)) | ||
assert.Equal(t, 456, status) | ||
} | ||
|
||
func TestExecSpInputParams(t *testing.T) { | ||
conn := ConnectToTestDb(t) | ||
err := createProcedure(conn, "test_input_params", "@p1 int = 0 as select @p1 = @p1 + 123; return @p1") | ||
assert.Nil(t, err) | ||
results, status, err := conn.execSp("test_input_params", 123) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 0, len(results)) | ||
assert.Equal(t, 246, status) | ||
} | ||
|
||
|
||
|
||
func createProcedure(conn *Conn, name, body string) error { | ||
drop := ` | ||
if exists(select * from sys.procedures where name = 'sp_name') | ||
drop procedure sp_name | ||
` | ||
create := ` | ||
create procedure sp_name | ||
sp_body | ||
` | ||
drop = strings.Replace(drop, "sp_name", name, -1) | ||
create = strings.Replace(create, "sp_name", name, -1) | ||
create = strings.Replace(create, "sp_body", body, -1) | ||
_, err := conn.Exec(drop) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = conn.Exec(create) | ||
return err | ||
} |
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 |
---|---|---|
|
@@ -286,3 +286,4 @@ func BenchmarkParalelConnectExecute(b *testing.B) { | |
} | ||
} | ||
} | ||
|
Oops, something went wrong.