Skip to content

Commit

Permalink
fix recall stored procedure with same command + add more testing file…
Browse files Browse the repository at this point in the history
…s to recent issues
  • Loading branch information
sijms committed Sep 14, 2024
1 parent 77afbbe commit 7dd03ba
Show file tree
Hide file tree
Showing 54 changed files with 741 additions and 298 deletions.
17 changes: 8 additions & 9 deletions v2/TestIssues/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"context"
"database/sql"
"fmt"
go_ora "github.com/sijms/go-ora/v2"
"strings"
"testing"
"time"

go_ora "github.com/sijms/go-ora/v2"
)

func TestArray(t *testing.T) {
expectedTime := time.Now()
insert := func(db *sql.DB) error {
var expectedTime = time.Now()
var insert = func(db *sql.DB) error {
sqlText := `INSERT INTO TTB_MAIN(ID, NAME, VAL, LDATE, DATA) VALUES(:ID, :NAME, :VAL, :LDATE, :DATA)`
length := 10
type TempStruct struct {
Expand Down Expand Up @@ -44,7 +43,7 @@ func TestArray(t *testing.T) {
return err
}

createPackage := func(db *sql.DB) error {
var createPackage = func(db *sql.DB) error {
sqlText := `create or replace package GOORA_TEMP_PKG as
type t_visit_id is table of TTB_MAIN.id%type index by binary_integer;
type t_visit_name is table of TTB_MAIN.name%type index by binary_integer;
Expand Down Expand Up @@ -96,11 +95,11 @@ func TestArray(t *testing.T) {
return execCmd(db, sqlText)
}

dropPackage := func(db *sql.DB) error {
var dropPackage = func(db *sql.DB) error {
return execCmd(db, "drop package GOORA_TEMP_PKG")
}

query1 := func(db *sql.DB) error {
var query1 = func(db *sql.DB) error {
var cursor go_ora.RefCursor
// sql code take input array of integer and return a cursor that can be queried for result
_, err := db.Exec(`BEGIN GOORA_TEMP_PKG.TEST_GET1(:1, :2); END;`, []int64{1, 3, 5}, sql.Out{Dest: &cursor})
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestArray(t *testing.T) {
return rows.Err()
}

query2 := func(db *sql.DB) error {
var query2 = func(db *sql.DB) error {
var (
nameArray []sql.NullString
valArray []sql.NullFloat64
Expand Down Expand Up @@ -239,7 +238,7 @@ func TestArray(t *testing.T) {
return nil
}

query3 := func(db *sql.DB) error {
var query3 = func(db *sql.DB) error {
var (
nameArray []sql.NullString
valArray []sql.NullFloat64
Expand Down
7 changes: 3 additions & 4 deletions v2/TestIssues/bool_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package TestIssues

import (
"database/sql"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestBoolType(t *testing.T) {
createProc := func(db *sql.DB) error {
var createProc = func(db *sql.DB) error {
return execCmd(db, `CREATE OR REPLACE PROCEDURE GO_ORA_TEMP_PROC(
L_BOOL IN BOOLEAN,
MESSAGE OUT VARCHAR2) AS
Expand All @@ -20,7 +19,7 @@ BEGIN
END IF;
END GO_ORA_TEMP_PROC;`)
}
dropProc := func(db *sql.DB) error {
var dropProc = func(db *sql.DB) error {
return execCmd(db, `drop procedure GO_ORA_TEMP_PROC`)
}

Expand Down
13 changes: 6 additions & 7 deletions v2/TestIssues/bulkinsert_bfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@ package TestIssues

import (
"database/sql"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestBulkinsertBFile(t *testing.T) {
createTable := func(db *sql.DB) error {
var createTable = func(db *sql.DB) error {
return execCmd(db, `create table GOORA_TEST_BFILE (
FILE_ID NUMBER(10) NOT NULL,
FILE_DATA BFILE
)`)
}
dropTable := func(db *sql.DB) error {
var dropTable = func(db *sql.DB) error {
return execCmd(db, "drop table GOORA_TEST_BFILE purge")
}

insertEmpty := func(db *sql.DB) error {
var insertEmpty = func(db *sql.DB) error {
var files []interface{} = make([]interface{}, 2)
files[0] = go_ora.CreateNullBFile()
files[1] = go_ora.CreateNullBFile()
ids := []int{1, 2}
_, err := db.Exec("INSERT INTO GOORA_TEST_BFILE(FILE_ID, FILE_DATA) VALUES(:1, :2)", ids, files)
return err
}
insert := func(db *sql.DB, dirName, fileName string) error {
files := make([]interface{}, 3)
var insert = func(db *sql.DB, dirName, fileName string) error {
var files = make([]interface{}, 3)
var err error
files[0], err = go_ora.CreateBFile(db, dirName, fileName)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions v2/TestIssues/bulkinsert_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package TestIssues

import (
"database/sql"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestBulkinsertBlob(t *testing.T) {
createTable := func(db *sql.DB) error {
var createTable = func(db *sql.DB) error {
return execCmd(db, `CREATE TABLE TTB_465(DATA BLOB)`)
}
dropTable := func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_465 PURGE`) }
insert := func(db *sql.DB, data []byte) error {
var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_465 PURGE`) }
var insert = func(db *sql.DB, data []byte) error {
datas := make([]go_ora.Blob, 3)
datas[0].Data = nil
datas[1].Data = data
Expand Down
9 changes: 4 additions & 5 deletions v2/TestIssues/cascade_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package TestIssues

import (
"database/sql"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestCascadeType(t *testing.T) {
Expand All @@ -21,7 +20,7 @@ func TestCascadeType(t *testing.T) {
Name string `udt:"NAME"`
SubInfo []HkGoraTestSubObj `udt:"SUB_INFO"`
}
createTypes := func(db *sql.DB) error {
var createTypes = func(db *sql.DB) error {
err := execCmd(db,
"create or replace type HK_GORA_ID_OBJ as object(ID number(22,0));",
"create or replace type HK_GORA_ID_COLL as table of HK_GORA_ID_OBJ;",
Expand All @@ -34,7 +33,7 @@ func TestCascadeType(t *testing.T) {
}
return nil
}
dropTypes := func(db *sql.DB) error {
var dropTypes = func(db *sql.DB) error {
return execCmd(db,
"drop type HK_GORA_TEST_COLL",
"drop type HK_GORA_TEST_OBJ",
Expand All @@ -43,7 +42,7 @@ func TestCascadeType(t *testing.T) {
"drop type HK_GORA_ID_COLL",
"drop type HK_GORA_ID_OBJ")
}
registerTypes := func(db *sql.DB) error {
var registerTypes = func(db *sql.DB) error {
err := go_ora.RegisterType(db, "HK_GORA_ID_OBJ", "HK_GORA_ID_COLL", HkGoraIdObj{})
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions v2/TestIssues/client_charset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package TestIssues
import (
"database/sql"
"fmt"
go_ora "github.com/sijms/go-ora/v2"
"strings"
"testing"

go_ora "github.com/sijms/go-ora/v2"
)

func TestClientCharset(t *testing.T) {
createPackage := func(db *sql.DB) error {
var createPackage = func(db *sql.DB) error {
return execCmd(db,
// create package
`CREATE OR REPLACE PACKAGE GOORA_TEMP IS
Expand All @@ -36,11 +35,11 @@ END GOORA_TEMP;`,
)
}

dropPackage := func(db *sql.DB) error {
var dropPackage = func(db *sql.DB) error {
return execCmd(db, "DROP PACKAGE GOORA_TEMP")
}

callProc := func(db *sql.DB, strings_in []string) error {
var callProc = func(db *sql.DB, strings_in []string) error {
var string_out string
_, err := db.Exec(`BEGIN GOORA_TEMP.TEST_PROC(:1, :2); END;`, strings_in,
go_ora.Out{&string_out, 256, false})
Expand Down Expand Up @@ -89,4 +88,5 @@ END GOORA_TEMP;`,
t.Error(err)
return
}

}
9 changes: 4 additions & 5 deletions v2/TestIssues/client_charset_with_string_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package TestIssues

import (
"database/sql"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

func TestClientCharsetWithStringArray(t *testing.T) {
createPackage := func(db *sql.DB) error {
var createPackage = func(db *sql.DB) error {
return execCmd(db,
`CREATE OR REPLACE PACKAGE GOORA_TEMP_PKG IS
TYPE VARCHAR2TABLE_T IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER;
Expand All @@ -32,11 +31,11 @@ END GOORA_TEMP_PKG;`,
)
}

dropPackage := func(db *sql.DB) error {
var dropPackage = func(db *sql.DB) error {
return execCmd(db, "DROP PACKAGE GOORA_TEMP_PKG")
}
var string_out string
callProc := func(db *sql.DB, string_in []string) (string, error) {
var callProc = func(db *sql.DB, string_in []string) (string, error) {
_, err := db.Exec("BEGIN GOORA_TEMP_PKG.TEST_PROC(:1, :2); END;", string_in,
go_ora.Out{Dest: &string_out, Size: 256})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions v2/TestIssues/column_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
)

func TestColumnType(t *testing.T) {
createTable := func(db *sql.DB) error {
var createTable = func(db *sql.DB) error {
return execCmd(db, `CREATE TABLE GOORA_T_CHAR (
col1 char(32),
col2 nchar(32),
col3 varchar2(32),
col4 nvarchar2(32))`)
}

dropTable := func(db *sql.DB) error {
var dropTable = func(db *sql.DB) error {
return execCmd(db, "drop table GOORA_T_CHAR purge")
}

insert := func(db *sql.DB) error {
var insert = func(db *sql.DB) error {
return execCmd(db, `INSERT INTO GOORA_T_CHAR VALUES('char','nchar','varchar2','nvarchar2')`)
}

Expand Down
18 changes: 9 additions & 9 deletions v2/TestIssues/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func TestCrud(t *testing.T) {
Data []byte `db:"DATA"`
}

rowCount := func(db *sql.DB) (count int, err error) {
var rowCount = func(db *sql.DB) (count int, err error) {
err = db.QueryRow("SELECT COUNT(*) FROM TTB_MAIN").Scan(&count)
return
}
insert := func(db Execuer) error {
var insert = func(db Execuer) error {
// insert 10 rows
temp := INPUT{}
var temp = INPUT{}
var err error
for x := 0; x < 10; x++ {
temp.ID = x + 1
Expand All @@ -39,8 +39,8 @@ func TestCrud(t *testing.T) {
}
return nil
}
insertWithPrepare := func(db Execuer) error {
temp := INPUT{}
var insertWithPrepare = func(db Execuer) error {
var temp = INPUT{}
stmt, err := db.Prepare("INSERT INTO TTB_MAIN(ID, NAME, VAL, LDATE, DATA) VALUES(:ID, :NAME, :VAL, :LDATE, :DATA)")
if err != nil {
return err
Expand All @@ -64,10 +64,10 @@ func TestCrud(t *testing.T) {
}
return nil
}
insertBulk := func(db Execuer) error {
var insertBulk = func(db Execuer) error {
data := make([]INPUT, 100)
baseVal := 1.1
for index := range data {
for index, _ := range data {
data[index].ID = index + 1
data[index].Name = strings.Repeat("-", index+1)
data[index].Val = baseVal + float64(index)
Expand All @@ -78,7 +78,7 @@ func TestCrud(t *testing.T) {
data)
return err
}
transaction := func(db *sql.DB, dbFunc func(db Execuer) error, commit bool, rowsIncrement int) error {
var transaction = func(db *sql.DB, dbFunc func(db Execuer) error, commit bool, rowsIncrement int) error {
initialCount, err := rowCount(db)
if err != nil {
return err
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestCrud(t *testing.T) {
}
return nil
}
delRows := func(db *sql.DB) error {
var delRows = func(db *sql.DB) error {
return execCmd(db, "DELETE FROM TTB_MAIN")
}

Expand Down
15 changes: 7 additions & 8 deletions v2/TestIssues/custom_bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"database/sql/driver"
"errors"
"fmt"
"testing"

go_ora "github.com/sijms/go-ora/v2"
"testing"
)

type OracleBool bool
Expand All @@ -27,22 +26,21 @@ func (b *OracleBool) Scan(value interface{}) error {
}
return nil
}

func TestCustomBool(t *testing.T) {
createTable := func(db *sql.DB) error {
var createTable = func(db *sql.DB) error {
return execCmd(db, "CREATE TABLE TB_420(COL1 VARCHAR2(1))")
}

dropTable := func(db *sql.DB) error {
var dropTable = func(db *sql.DB) error {
return execCmd(db, "drop table TB_420 purge")
}
insert := func(db *sql.DB) error {
var insert = func(db *sql.DB) error {
var b OracleBool = true
_, err := db.Exec("INSERT INTO TB_420(col1) VALUES(:myBool)", b)
return err
}

query := func(db *sql.DB) error {
var query = func(db *sql.DB) error {
var result string
var result2 OracleBool
err := db.QueryRow("SELECT col1, col1 FROM TB_420").Scan(&result, &result2)
Expand All @@ -58,7 +56,7 @@ func TestCustomBool(t *testing.T) {
return nil
}

query2 := func(db *sql.DB) error {
var query2 = func(db *sql.DB) error {
var result string
var result2 OracleBool
_, err := db.Exec("BEGIN SELECT col1, col1 into :1, :2 FROM TB_420; END;", go_ora.Out{Dest: &result, Size: 10},
Expand Down Expand Up @@ -112,4 +110,5 @@ func TestCustomBool(t *testing.T) {
t.Error(err)
return
}

}
2 changes: 0 additions & 2 deletions v2/TestIssues/dbms_aq_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package TestIssues

/*
import (
"github.com/sijms/go-ora/dbms"
"testing"
Expand Down Expand Up @@ -56,4 +55,3 @@ func TestDBMSAQ(t *testing.T) {
t.Log("Dequeue message ID: ", messageID)
t.Log("message: ", string(output))
}
*/
Loading

0 comments on commit 7dd03ba

Please sign in to comment.