From 7dd03ba09e9e4e182d492b48bb01d64f1e8593b7 Mon Sep 17 00:00:00 2001 From: Samy Sultan Date: Sun, 15 Sep 2024 00:28:39 +0300 Subject: [PATCH] fix recall stored procedure with same command + add more testing files to recent issues --- v2/TestIssues/array_test.go | 17 +-- v2/TestIssues/bool_type_test.go | 7 +- v2/TestIssues/bulkinsert_bfile_test.go | 13 +- v2/TestIssues/bulkinsert_blob_test.go | 9 +- v2/TestIssues/cascade_type_test.go | 9 +- v2/TestIssues/client_charset_test.go | 10 +- .../client_charset_with_string_array_test.go | 9 +- v2/TestIssues/column_type_test.go | 6 +- v2/TestIssues/crud_test.go | 18 +-- v2/TestIssues/custom_bool_test.go | 15 +- v2/TestIssues/dbms_aq_test.go | 2 - v2/TestIssues/dbms_output_test.go | 2 - v2/TestIssues/emoji_test.go | 7 +- v2/TestIssues/global_vars.go | 24 ++- v2/TestIssues/gorm_test.go | 10 +- v2/TestIssues/issue_173_test.go | 10 +- v2/TestIssues/issue_205_test.go | 12 +- v2/TestIssues/issue_264_test.go | 11 +- v2/TestIssues/issue_274_test.go | 12 +- v2/TestIssues/issue_287_test.go | 8 +- v2/TestIssues/issue_307_test.go | 3 +- v2/TestIssues/issue_320_test.go | 11 +- v2/TestIssues/issue_335_test.go | 6 +- v2/TestIssues/issue_343_test.go | 8 +- v2/TestIssues/issue_355_test.go | 17 +-- v2/TestIssues/issue_356_test.go | 1 + v2/TestIssues/issue_363_test.go | 4 +- v2/TestIssues/issue_408_test.go | 15 +- v2/TestIssues/issue_422_test.go | 8 +- v2/TestIssues/issue_429_test.go | 6 +- v2/TestIssues/issue_430_test.go | 7 +- v2/TestIssues/issue_466_test.go | 8 +- v2/TestIssues/issue_468_test.go | 10 +- v2/TestIssues/issue_482_test.go | 15 +- v2/TestIssues/issue_532_test.go | 8 +- v2/TestIssues/issue_543_test.go | 2 +- v2/TestIssues/issue_544_test.go | 61 ++++++++ v2/TestIssues/issue_556_test.go | 69 +++++++++ v2/TestIssues/large_udt_array_test.go | 13 +- v2/TestIssues/lob_test.go | 15 +- v2/TestIssues/long_input_test.go | 13 +- v2/TestIssues/multiple_returning_test.go | 6 +- v2/TestIssues/neg_binary_float_test.go | 85 +++++++++++ v2/TestIssues/nested_udt_array_test.go | 35 +++-- v2/TestIssues/nested_udt_test.go | 25 ++- v2/TestIssues/prefetch_large_blob_test.go | 10 +- v2/TestIssues/raw_test.go | 2 +- v2/TestIssues/recall_stored_proc_test.go | 118 ++++++++++++++ v2/TestIssues/regular_type_array_test.go | 31 ++-- v2/TestIssues/session_pars_test.go | 9 +- v2/TestIssues/time_test.go | 10 +- v2/TestIssues/udt_string_test.go | 144 ++++++++++++++++++ v2/TestIssues/varray_test.go | 7 +- v2/command.go | 46 +++--- 54 files changed, 741 insertions(+), 298 deletions(-) create mode 100644 v2/TestIssues/issue_544_test.go create mode 100644 v2/TestIssues/issue_556_test.go create mode 100644 v2/TestIssues/neg_binary_float_test.go create mode 100644 v2/TestIssues/recall_stored_proc_test.go create mode 100644 v2/TestIssues/udt_string_test.go diff --git a/v2/TestIssues/array_test.go b/v2/TestIssues/array_test.go index 0481d2f2..e656dfc7 100644 --- a/v2/TestIssues/array_test.go +++ b/v2/TestIssues/array_test.go @@ -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 { @@ -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; @@ -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}) @@ -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 @@ -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 diff --git a/v2/TestIssues/bool_type_test.go b/v2/TestIssues/bool_type_test.go index a7aab496..3585f5f5 100644 --- a/v2/TestIssues/bool_type_test.go +++ b/v2/TestIssues/bool_type_test.go @@ -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 @@ -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`) } diff --git a/v2/TestIssues/bulkinsert_bfile_test.go b/v2/TestIssues/bulkinsert_bfile_test.go index 32c05637..108524b2 100644 --- a/v2/TestIssues/bulkinsert_bfile_test.go +++ b/v2/TestIssues/bulkinsert_bfile_test.go @@ -2,23 +2,22 @@ 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() @@ -26,8 +25,8 @@ func TestBulkinsertBFile(t *testing.T) { _, 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 { diff --git a/v2/TestIssues/bulkinsert_blob_test.go b/v2/TestIssues/bulkinsert_blob_test.go index a5db6f6f..bf8c92a3 100644 --- a/v2/TestIssues/bulkinsert_blob_test.go +++ b/v2/TestIssues/bulkinsert_blob_test.go @@ -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 diff --git a/v2/TestIssues/cascade_type_test.go b/v2/TestIssues/cascade_type_test.go index acfd893e..f4703557 100644 --- a/v2/TestIssues/cascade_type_test.go +++ b/v2/TestIssues/cascade_type_test.go @@ -2,9 +2,8 @@ package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestCascadeType(t *testing.T) { @@ -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;", @@ -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", @@ -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 diff --git a/v2/TestIssues/client_charset_test.go b/v2/TestIssues/client_charset_test.go index fea8e46f..da79b719 100644 --- a/v2/TestIssues/client_charset_test.go +++ b/v2/TestIssues/client_charset_test.go @@ -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 @@ -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}) @@ -89,4 +88,5 @@ END GOORA_TEMP;`, t.Error(err) return } + } diff --git a/v2/TestIssues/client_charset_with_string_array_test.go b/v2/TestIssues/client_charset_with_string_array_test.go index 46163d82..51f33f6a 100644 --- a/v2/TestIssues/client_charset_with_string_array_test.go +++ b/v2/TestIssues/client_charset_with_string_array_test.go @@ -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; @@ -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 { diff --git a/v2/TestIssues/column_type_test.go b/v2/TestIssues/column_type_test.go index 1d679f6f..58c6e353 100644 --- a/v2/TestIssues/column_type_test.go +++ b/v2/TestIssues/column_type_test.go @@ -6,7 +6,7 @@ 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), @@ -14,11 +14,11 @@ func TestColumnType(t *testing.T) { 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')`) } diff --git a/v2/TestIssues/crud_test.go b/v2/TestIssues/crud_test.go index c3681673..037c6fb9 100644 --- a/v2/TestIssues/crud_test.go +++ b/v2/TestIssues/crud_test.go @@ -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 @@ -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 @@ -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) @@ -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 @@ -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") } diff --git a/v2/TestIssues/custom_bool_test.go b/v2/TestIssues/custom_bool_test.go index 60fd0817..192ff5ce 100644 --- a/v2/TestIssues/custom_bool_test.go +++ b/v2/TestIssues/custom_bool_test.go @@ -5,9 +5,8 @@ import ( "database/sql/driver" "errors" "fmt" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) type OracleBool bool @@ -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) @@ -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}, @@ -112,4 +110,5 @@ func TestCustomBool(t *testing.T) { t.Error(err) return } + } diff --git a/v2/TestIssues/dbms_aq_test.go b/v2/TestIssues/dbms_aq_test.go index 25ca224a..0642cd83 100644 --- a/v2/TestIssues/dbms_aq_test.go +++ b/v2/TestIssues/dbms_aq_test.go @@ -1,6 +1,5 @@ package TestIssues -/* import ( "github.com/sijms/go-ora/dbms" "testing" @@ -56,4 +55,3 @@ func TestDBMSAQ(t *testing.T) { t.Log("Dequeue message ID: ", messageID) t.Log("message: ", string(output)) } -*/ diff --git a/v2/TestIssues/dbms_output_test.go b/v2/TestIssues/dbms_output_test.go index 840f281d..6440f65f 100644 --- a/v2/TestIssues/dbms_output_test.go +++ b/v2/TestIssues/dbms_output_test.go @@ -1,6 +1,5 @@ package TestIssues -/* import ( "github.com/sijms/go-ora/dbms" "testing" @@ -62,4 +61,3 @@ END;`) t.Errorf("expected: %s and got: %s", "this is a test2", line) } } -*/ diff --git a/v2/TestIssues/emoji_test.go b/v2/TestIssues/emoji_test.go index 86ad2633..c3a84e02 100644 --- a/v2/TestIssues/emoji_test.go +++ b/v2/TestIssues/emoji_test.go @@ -2,19 +2,18 @@ package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestEmoji(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TEST_EMOJI( ID number(10) NOT NULL, CONTENT NCLOB )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TEST_EMOJI PURGE`) } diff --git a/v2/TestIssues/global_vars.go b/v2/TestIssues/global_vars.go index 5461a231..b91fdb58 100644 --- a/v2/TestIssues/global_vars.go +++ b/v2/TestIssues/global_vars.go @@ -4,25 +4,23 @@ import ( "database/sql" "errors" "fmt" + go_ora "github.com/sijms/go-ora/v2" "os" "reflect" "strconv" "time" - - go_ora "github.com/sijms/go-ora/v2" ) -var ( - server = os.Getenv("SERVER") - port int - service = os.Getenv("SERVICE") - username = os.Getenv("USER") - password = os.Getenv("PASSWORD") - urlOptions = map[string]string{ - "TRACE FILE": "trace.log", - "lob fetch": "pre", - } -) +// var db *sql.DB +var server = os.Getenv("SERVER") +var port int +var service = os.Getenv("SERVICE") +var username = os.Getenv("USER") +var password = os.Getenv("PASSWORD") +var urlOptions = map[string]string{ + "TRACE FILE": "trace.log", + "lob fetch": "pre", +} type Execuer interface { Exec(query string, args ...any) (sql.Result, error) diff --git a/v2/TestIssues/gorm_test.go b/v2/TestIssues/gorm_test.go index 1f105e3a..54dfe393 100644 --- a/v2/TestIssues/gorm_test.go +++ b/v2/TestIssues/gorm_test.go @@ -1,12 +1,11 @@ package TestIssues import ( - "testing" - "time" - oracle "github.com/godoes/gorm-oracle" go_ora "github.com/sijms/go-ora/v2" "gorm.io/gorm" + "testing" + "time" ) func TestGorm(t *testing.T) { @@ -26,17 +25,18 @@ func TestGorm(t *testing.T) { t.Error(err) return } - // Create + //Create db.Create(&Product{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Code: "D42", Price: 100}) // drop defer func() { db.Exec("drop table products purge") }() - // Read + //Read var product Product db.First(&product, 1) // find product with primary key = 1 t.Log(product) db.First(&product, "code = ?", "D42") // find product with code = D42 t.Log(product) + } diff --git a/v2/TestIssues/issue_173_test.go b/v2/TestIssues/issue_173_test.go index ecb78d3d..9b59e6bb 100644 --- a/v2/TestIssues/issue_173_test.go +++ b/v2/TestIssues/issue_173_test.go @@ -3,14 +3,13 @@ package TestIssues import ( "database/sql" "errors" + go_ora "github.com/sijms/go-ora/v2" "strings" "testing" - - go_ora "github.com/sijms/go-ora/v2" ) func TestIssue173(t *testing.T) { - createFunction := func(db *sql.DB) error { + var createFunction = func(db *sql.DB) error { return execCmd(db, `CREATE OR REPLACE FUNCTION go_ora$text(p_param VARCHAR2) RETURN CLOB AS v_txt CLOB; BEGIN @@ -21,8 +20,8 @@ func TestIssue173(t *testing.T) { RETURN v_txt || '\n' || p_param; END;`) } - dropFunction := func(db *sql.DB) error { return execCmd(db, "DROP FUNCTION go_ora$text") } - run := func(db *sql.DB) error { + var dropFunction = func(db *sql.DB) error { return execCmd(db, "DROP FUNCTION go_ora$text") } + var run = func(db *sql.DB) error { var str go_ora.Clob _, err := db.Exec("BEGIN :1 := go_ora$text(:2);end;", go_ora.Out{Dest: &str, Size: 100000}, "ss") if err != nil { @@ -63,4 +62,5 @@ func TestIssue173(t *testing.T) { return } } + } diff --git a/v2/TestIssues/issue_205_test.go b/v2/TestIssues/issue_205_test.go index 905b0149..62eafacc 100644 --- a/v2/TestIssues/issue_205_test.go +++ b/v2/TestIssues/issue_205_test.go @@ -8,23 +8,23 @@ import ( ) func TestIssue205(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_205( ID NUMBER(10) NOT NULL, BIG_TEXT LONG, PRIMARY KEY (ID) ) NOCOMPRESS`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_205 PURGE`) } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { type ttb_205 struct { Id int `db:"ID"` Name sql.NullString `db:"NAME"` } data := make([]ttb_205, 100) - for index := range data { + for index, _ := range data { data[index].Id = index + 1 if (index+1)%2 == 0 { data[index].Name.Valid = false @@ -39,7 +39,7 @@ func TestIssue205(t *testing.T) { } return nil } - sqlQuery := func(db *sql.DB) error { + var sqlQuery = func(db *sql.DB) error { rows, err := db.Query("SELECT BIG_TEXT, ID FROM TTB_205 WHERE ID < 3") if err != nil { return err @@ -70,7 +70,7 @@ func TestIssue205(t *testing.T) { } return rows.Err() } - outputQuery := func(db *sql.DB, id int) error { + var outputQuery = func(db *sql.DB, id int) error { temp := struct { ID int `db:"ID,,,output"` Name sql.NullString `db:"NAME,,100000,output"` diff --git a/v2/TestIssues/issue_264_test.go b/v2/TestIssues/issue_264_test.go index 17904bc7..78326d65 100644 --- a/v2/TestIssues/issue_264_test.go +++ b/v2/TestIssues/issue_264_test.go @@ -2,29 +2,28 @@ package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestIssue264(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_264( ID number(10) NOT NULL, SVGTEMPLATE BLOB )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_264 PURGE`) } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { _, err := db.Exec("INSERT INTO TTB_264(ID, SVGTEMPLATE) VALUES(:1, :2)", 1, []byte("123456789012345678901234567890")) if err != nil { return err } return nil } - update := func(db *sql.DB) error { + var update = func(db *sql.DB) error { blob := go_ora.Blob{Data: []byte("123456789012345678901234567890 123456789012345678901234567890")} stmt, err := db.Prepare("UPDATE TTB_264 SET SVGTEMPLATE=:1 WHERE ID=1") if err != nil { diff --git a/v2/TestIssues/issue_274_test.go b/v2/TestIssues/issue_274_test.go index 1798e529..0667e05c 100644 --- a/v2/TestIssues/issue_274_test.go +++ b/v2/TestIssues/issue_274_test.go @@ -8,7 +8,7 @@ import ( ) func TestIssue274(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_274( ID NUMBER(10) NOT NULL, NAME VARCHAR(200), @@ -17,16 +17,16 @@ func TestIssue274(t *testing.T) { PRIMARY KEY (ID) )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "DROP TABLE TTB_274 PURGE") } - dbLock := func(db *sql.DB) error { + var dbLock = func(db *sql.DB) error { execCtx, execCancel := context.WithTimeout(context.Background(), 3*time.Second) defer execCancel() _, err := db.ExecContext(execCtx, "begin DBMS_LOCK.sleep(5); end;") return err } - insert := func(db *sql.DB, rowNum int) error { + var insert = func(db *sql.DB, rowNum int) error { type TTB_274 struct { ID int `db:"ID"` Name string `db:"NAME"` @@ -35,7 +35,7 @@ func TestIssue274(t *testing.T) { } interval := 1.1 data := make([]TTB_274, rowNum) - for index := range data { + for index, _ := range data { data[index].ID = index + 1 data[index].Name = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" data[index].Val = float64(index) + interval @@ -47,7 +47,7 @@ func TestIssue274(t *testing.T) { } return nil } - query := func(db *sql.DB, rowNum int) error { + var query = func(db *sql.DB, rowNum int) error { execCtx, execCancel := context.WithTimeout(context.Background(), 4*time.Second) defer execCancel() rows, err := db.QueryContext(execCtx, `SELECT ID, NAME, VAL, LDATE FROM TTB_274 WHERE ID < :1 ORDER BY ID`, rowNum) diff --git a/v2/TestIssues/issue_287_test.go b/v2/TestIssues/issue_287_test.go index 54029c11..05fd92e3 100644 --- a/v2/TestIssues/issue_287_test.go +++ b/v2/TestIssues/issue_287_test.go @@ -7,19 +7,19 @@ import ( ) func TestIssue287(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_287( TS TIMESTAMP DEFAULT CURRENT_TIMESTAMP )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "DROP TABLE TTB_287 PURGE") } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { _, err := db.Exec("INSERT INTO TTB_287 VALUES(DEFAULT)") return err } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { rows, err := db.Query("SELECT * FROM TTB_287") if err != nil { return err diff --git a/v2/TestIssues/issue_307_test.go b/v2/TestIssues/issue_307_test.go index a34cb64b..31b57db7 100644 --- a/v2/TestIssues/issue_307_test.go +++ b/v2/TestIssues/issue_307_test.go @@ -1,10 +1,9 @@ package TestIssues import ( + go_ora "github.com/sijms/go-ora/v2" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestIssue307(t *testing.T) { diff --git a/v2/TestIssues/issue_320_test.go b/v2/TestIssues/issue_320_test.go index 612ed35c..ad282d95 100644 --- a/v2/TestIssues/issue_320_test.go +++ b/v2/TestIssues/issue_320_test.go @@ -3,9 +3,8 @@ package TestIssues import ( "context" "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestIssue320(t *testing.T) { @@ -13,7 +12,7 @@ func TestIssue320(t *testing.T) { Id sql.NullString Response go_ora.Clob } - MatCol := func(colname string, mat *Mat) interface{} { + var MatCol = func(colname string, mat *Mat) interface{} { switch colname { case "ID": return &mat.Id @@ -23,7 +22,7 @@ func TestIssue320(t *testing.T) { return new(string) } } - create := func(db *sql.DB) error { + var create = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_320( ID varchar2(100), RESPONSE CLOB @@ -37,13 +36,13 @@ END TP_320;`, `INSERT INTO TTB_320(ID, RESPONSE) VALUES('1', 'THIS IS A TEST')`, ) } - drop := func(db *sql.DB) error { + var drop = func(db *sql.DB) error { return execCmd(db, "DROP FUNCTION TP_320", "DROP TABLE TTB_320 PURGE", ) } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { var cursor go_ora.RefCursor _, err := db.Exec(`BEGIN :1 := TP_320(); END;`, sql.Out{Dest: &cursor}) if err != nil { diff --git a/v2/TestIssues/issue_335_test.go b/v2/TestIssues/issue_335_test.go index 3cabb377..ba607d12 100644 --- a/v2/TestIssues/issue_335_test.go +++ b/v2/TestIssues/issue_335_test.go @@ -6,7 +6,7 @@ import ( ) func TestIssue335(t *testing.T) { - create := func(db *sql.DB) error { + var create = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_335 ( varchar2_col VARCHAR2(10), char_col CHAR(10), @@ -66,10 +66,10 @@ func TestIssue335(t *testing.T) { ) } - drop := func(db *sql.DB) error { + var drop = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_335 PURGE`) } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { rows, err := db.Query("SELECT * FROM TTB_335") if err != nil { return err diff --git a/v2/TestIssues/issue_343_test.go b/v2/TestIssues/issue_343_test.go index fc5a3baa..6d0e4fc6 100644 --- a/v2/TestIssues/issue_343_test.go +++ b/v2/TestIssues/issue_343_test.go @@ -7,7 +7,7 @@ import ( ) func TestIssue343(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_343 ( "ID" NUMBER(20,0) NOT NULL ENABLE, "TM" VARCHAR2(30), @@ -22,10 +22,10 @@ func TestIssue343(t *testing.T) { PRIMARY KEY ("ID") )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "DROP TABLE TTB_343 PURGE") } - merge := func(db *sql.DB) error { + var merge = func(db *sql.DB) error { sqlText := `MERGE INTO TTB_343 t1 USING(select :ID ID from dual) tmp ON (tmp.ID=t1.ID) WHEN MATCHED THEN UPDATE SET TM=:TM,SN=:SN,CUS=:CUS, AID=:AID,TR=:TR,PID=:PID,CODE=:CODE,TTNO=:TTNO,UPDATETIME=:UPDATETIME WHERE t1.ID=:ID AND t1.UPDATETIME<=:UPDATETIME WHEN NOT MATCHED THEN INSERT (ID,TM,SN,CUS,AID,TR,PID,CODE,TTNO,UPDATETIME) VALUES (:ID,:TM,:SN,:CUS,:AID,:TR,:PID,:CODE,:TTNO,:UPDATETIME)` @@ -43,7 +43,7 @@ func TestIssue343(t *testing.T) { UpdateTime time.Time `db:"UPDATETIME,timestamp"` } data := make([]TestShort, length) - for index := range data { + for index, _ := range data { data[index].Id = index + 1 if index > 0 && index%10 == 0 { data[index].Tm = sql.NullString{Valid: false} diff --git a/v2/TestIssues/issue_355_test.go b/v2/TestIssues/issue_355_test.go index 9ead324c..93995947 100644 --- a/v2/TestIssues/issue_355_test.go +++ b/v2/TestIssues/issue_355_test.go @@ -2,13 +2,12 @@ package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestIssue355(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 IS TYPE VARCHAR2TABLE_T IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER; PROCEDURE TEST_PROC_STRING( @@ -54,27 +53,27 @@ END GOORA_TEMP;`, END; END GOORA_TEMP;`) } - dropPackage := func(db *sql.DB) error { + var dropPackage = func(db *sql.DB) error { return execCmd(db, "DROP PACKAGE GOORA_TEMP") } - call_string := func(db *sql.DB, input string) error { + var call_string = func(db *sql.DB, input string) error { _, err := db.Exec("BEGIN GOORA_TEMP.TEST_PROC_STRING(:1); END;", input) return err } - call_StringArray := func(db *sql.DB, input []string) error { + var call_StringArray = func(db *sql.DB, input []string) error { var output sql.NullInt64 _, err := db.Exec("BEGIN GOORA_TEMP.TEST_PROC_STRINGARRAY2(:1, :2); END;", input, go_ora.Out{Dest: &output}) return err } - call_StringPointerArray := func(db *sql.DB, input []*string) error { + var call_StringPointerArray = func(db *sql.DB, input []*string) error { _, err := db.Exec("BEGIN GOORA_TEMP.TEST_PROC_STRINGARRAY(:1); END;", input) return err } - call_SqlNullStringArray := func(db *sql.DB, input []sql.NullString) error { + var call_SqlNullStringArray = func(db *sql.DB, input []sql.NullString) error { _, err := db.Exec(`BEGIN GOORA_TEMP.TEST_PROC_STRINGARRAY(:1); END;`, input) return err } - call_ByteArray := func(db *sql.DB, input []byte) error { + var call_ByteArray = func(db *sql.DB, input []byte) error { _, err := db.Exec(`BEGIN GOORA_TEMP.TEST_PROC_BYTEARRAY(:1); END;`, input) return err } diff --git a/v2/TestIssues/issue_356_test.go b/v2/TestIssues/issue_356_test.go index 4558b730..4aefadd3 100644 --- a/v2/TestIssues/issue_356_test.go +++ b/v2/TestIssues/issue_356_test.go @@ -3,4 +3,5 @@ package TestIssues import "testing" func TestIssue356(t *testing.T) { + } diff --git a/v2/TestIssues/issue_363_test.go b/v2/TestIssues/issue_363_test.go index bedc87d8..d34084d6 100644 --- a/v2/TestIssues/issue_363_test.go +++ b/v2/TestIssues/issue_363_test.go @@ -1,10 +1,8 @@ package TestIssues import ( - "testing" - go_ora "github.com/sijms/go-ora/v2" - + "testing" "xorm.io/xorm" ) diff --git a/v2/TestIssues/issue_408_test.go b/v2/TestIssues/issue_408_test.go index 2a2d2d7c..40f5fb6d 100644 --- a/v2/TestIssues/issue_408_test.go +++ b/v2/TestIssues/issue_408_test.go @@ -2,9 +2,8 @@ package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestIssue408(t *testing.T) { @@ -17,19 +16,19 @@ func TestIssue408(t *testing.T) { Name string `udt:"NAME"` } - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return 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;", "create or replace type HK_GORA_TEST_OBJ as object(ID number(22,0), NAME varchar2(2000));", "create or replace type HK_GORA_TEST_COLL as table of HK_GORA_TEST_OBJ;") } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, "drop type HK_GORA_ID_COLL", "drop type HK_GORA_ID_OBJ", "drop type HK_GORA_TEST_COLL", "drop type HK_GORA_TEST_OBJ") } - createPackage := func(db *sql.DB) error { + var createPackage = func(db *sql.DB) error { return execCmd(db, ` create or replace package HK_GORA_TEST_PCK as function F_GetData(P_Ids HK_GORA_ID_COLL, P_AnzChars number) return HK_GORA_TEST_COLL; @@ -53,11 +52,11 @@ create or replace package body HK_GORA_TEST_PCK as end; end;`) } - dropPackage := func(db *sql.DB) error { + var dropPackage = func(db *sql.DB) error { return execCmd(db, "DROP PACKAGE HK_GORA_TEST_PCK") } - 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 @@ -68,7 +67,7 @@ end;`) } return nil } - executeTest := func(db *sql.DB, anzChars int) error { + var executeTest = func(db *sql.DB, anzChars int) error { var res []HkGoraTestObj _, err := db.Exec(`BEGIN :1 := HK_GORA_TEST_PCK.F_GetData(:2, :3); END;`, go_ora.Out{Dest: &res, Size: 2}, diff --git a/v2/TestIssues/issue_422_test.go b/v2/TestIssues/issue_422_test.go index 752357e3..d17bbd9d 100644 --- a/v2/TestIssues/issue_422_test.go +++ b/v2/TestIssues/issue_422_test.go @@ -18,18 +18,18 @@ func TestIssue422(t *testing.T) { TimeSysdate time.Time `db:"T_SYSDATE"` TimeSystimestamp time.Time `db:"T_SYSTIMESTAMP"` } - dumpJson := func(d any) { + var dumpJson = func(d any) { b, _ := json.MarshalIndent(d, "", " ") t.Logf("%s\n", string(b)) } - dumpTime := func(r TimeDebug) { + var dumpTime = func(r TimeDebug) { t.Logf("%16s: %s\n", "Sysdate", r.TimeSysdate.Format(time.UnixDate)) t.Logf("%16s: %s\n", "Systimestamp", r.TimeSystimestamp.Format(time.UnixDate)) t.Logf("%16s: %s\n", "Real Time", time.Now().Format(time.UnixDate)) } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { sqlText := ` SELECT to_char(CURRENT_DATE, 'YYYY-MM-DD HH24:MI:SS') "CURRENT_DATE", @@ -41,7 +41,7 @@ func TestIssue422(t *testing.T) { SYSDATE as T_SYSDATE, SYSTIMESTAMP as T_SYSTIMESTAMP FROM DUAL` - r := TimeDebug{} + var r = TimeDebug{} err := queryStruct(db.QueryRow(sqlText), &r) if err != nil { return err diff --git a/v2/TestIssues/issue_429_test.go b/v2/TestIssues/issue_429_test.go index cf8d2b5f..03c90a93 100644 --- a/v2/TestIssues/issue_429_test.go +++ b/v2/TestIssues/issue_429_test.go @@ -15,9 +15,9 @@ func TestIssue429(t *testing.T) { Val float64 `db:"VAL"` Date time.Time `db:"LDATE"` } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { data := make([]TTB_DATA, 100) - for x := range data { + for x, _ := range data { data[x].Id = int64(1000000000 + x) data[x].Name = "test_" + strconv.Itoa(x) data[x].Val = 100.23 + 1 @@ -29,7 +29,7 @@ func TestIssue429(t *testing.T) { } return nil } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { var id int err := db.QueryRow("SELECT ID FROM TTB_MAIN WHERE NAME = :1", "test_0").Scan(&id) if err != nil { diff --git a/v2/TestIssues/issue_430_test.go b/v2/TestIssues/issue_430_test.go index c1c7f14f..e70919f6 100644 --- a/v2/TestIssues/issue_430_test.go +++ b/v2/TestIssues/issue_430_test.go @@ -9,7 +9,7 @@ import ( ) func TestIssue430(t *testing.T) { - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { type TTB_DATA struct { Id int64 `db:"ID"` Name string `db:"NAME"` @@ -17,7 +17,7 @@ func TestIssue430(t *testing.T) { Date time.Time `db:"LDATE"` } data := make([]TTB_DATA, 100) - for x := range data { + for x, _ := range data { data[x].Id = int64(1 + x) data[x].Name = "test_" + strconv.Itoa(x) data[x].Val = 100.23 + 1 @@ -29,7 +29,7 @@ func TestIssue430(t *testing.T) { } return nil } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { result := struct { Id int64 `db:"ID,number,,output"` Name string `db:"NAME,,200,output"` @@ -79,4 +79,5 @@ END;`, &result) t.Error(err) return } + } diff --git a/v2/TestIssues/issue_466_test.go b/v2/TestIssues/issue_466_test.go index d1eab20a..edd3c8eb 100644 --- a/v2/TestIssues/issue_466_test.go +++ b/v2/TestIssues/issue_466_test.go @@ -7,20 +7,20 @@ import ( ) func TestIssue466(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_466(ID varchar2(100))`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_466 purge`) } - generateRows := func(startIndex, count int) []string { + var generateRows = func(startIndex, count int) []string { rows := make([]string, count) for i := 0; i < count; i++ { rows[i] = fmt.Sprintf("ID%02d", i+startIndex) } return rows } - insert := func(stmt *sql.Stmt, rows []string) error { + var insert = func(stmt *sql.Stmt, rows []string) error { result, err := stmt.Exec(rows) if err != nil { return err diff --git a/v2/TestIssues/issue_468_test.go b/v2/TestIssues/issue_468_test.go index 83a78a9a..d0428708 100644 --- a/v2/TestIssues/issue_468_test.go +++ b/v2/TestIssues/issue_468_test.go @@ -7,21 +7,21 @@ import ( ) func TestIssue468(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_468(N NUMBER)`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "DROP TABLE TTB_468 PURGE") } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { data := make([]int, 100) - for index := range data { + for index, _ := range data { data[index] = index + 1 } _, err := db.Exec("INSERT INTO TTB_468(N) VALUES (:1)", data) return err } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { var ( n1, n2 int32 cursor sql.Rows diff --git a/v2/TestIssues/issue_482_test.go b/v2/TestIssues/issue_482_test.go index 28b05d5a..3a973908 100644 --- a/v2/TestIssues/issue_482_test.go +++ b/v2/TestIssues/issue_482_test.go @@ -3,36 +3,35 @@ package TestIssues import ( "database/sql" "fmt" + go_ora "github.com/sijms/go-ora/v2" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestIssue482(t *testing.T) { type test1 struct { Name string `udt:"name"` } - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return execCmd(db, `CREATE TYPE test1 AS OBJECT ( name varchar2(256) )`, `CREATE OR REPLACE TYPE test1collection AS TABLE OF test1`) } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, `DROP TYPE test1collection`, `DROP TYPE test1`) } - setupQueue := func(db *sql.DB) error { + var setupQueue = func(db *sql.DB) error { return execCmd(db, `BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'test1table', queue_payload_type => 'test1' ); END;`, `BEGIN DBMS_AQADM.CREATE_QUEUE ( queue_name => 'test1queue', queue_table => 'test1table' ); END;`, `BEGIN DBMS_AQADM.START_QUEUE ( queue_name => 'test1queue', enqueue => TRUE ); END;`) } - stopQueue := func(db *sql.DB) error { + var stopQueue = func(db *sql.DB) error { return execCmd(db, `BEGIN DBMS_AQADM.STOP_QUEUE(queue_name => 'test1queue'); END;`, `BEGIN DBMS_AQADM.DROP_QUEUE(queue_name => 'test1queue'); END;`, `BEGIN DBMS_AQADM.DROP_QUEUE_TABLE(queue_table => 'test1table'); END;`) } - enqueue := func(db *sql.DB, message test1) error { + var enqueue = func(db *sql.DB, message test1) error { _, err := db.Exec(` DECLARE enqueueOptions DBMS_AQ.enqueue_options_t; @@ -50,7 +49,7 @@ END;`, message) return err } - dequeueArray := func(db *sql.DB, arraySize int, waitTime time.Duration) ([]test1, error) { + var dequeueArray = func(db *sql.DB, arraySize int, waitTime time.Duration) ([]test1, error) { sqlText := fmt.Sprintf(` DECLARE dequeueOptions DBMS_AQ.dequeue_options_t; diff --git a/v2/TestIssues/issue_532_test.go b/v2/TestIssues/issue_532_test.go index a88194e7..61cee015 100644 --- a/v2/TestIssues/issue_532_test.go +++ b/v2/TestIssues/issue_532_test.go @@ -11,7 +11,7 @@ func TestIssue532(t *testing.T) { ID int `db:"ID"` Name string `db:"NAME"` } - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_532( EMP_ID NUMBER, EMP_NAME VARCHAR2(255), @@ -19,11 +19,11 @@ func TestIssue532(t *testing.T) { )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "drop table TTB_532 purge") } - insert := func(db *sql.DB, rowNum int) error { + var insert = func(db *sql.DB, rowNum int) error { data := make([]TTB_DATA, rowNum) for index := range data { data[index].ID = index + 1 @@ -33,7 +33,7 @@ func TestIssue532(t *testing.T) { return err } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { rows, err := db.Query("SELECT * FROM TTB_532 FOR UPDATE") if err != nil { return err diff --git a/v2/TestIssues/issue_543_test.go b/v2/TestIssues/issue_543_test.go index 9aeb6a95..c60047eb 100644 --- a/v2/TestIssues/issue_543_test.go +++ b/v2/TestIssues/issue_543_test.go @@ -18,7 +18,7 @@ func TestIssue543(t *testing.T) { } }() var result string - err = db.QueryRow("select column_expression from dba_ind_expressions where index_name = 'members_last_name_fi' and column_position = 1").Scan(&result) + err = db.QueryRow("select column_expression from dba_ind_expressions where index_owner = 'APEX_230200' and index_name = 'WWV_FLOW_WORKSHEET_RPTS_UK' and column_position = 1").Scan(&result) if err != nil { t.Error(err) return diff --git a/v2/TestIssues/issue_544_test.go b/v2/TestIssues/issue_544_test.go new file mode 100644 index 00000000..1370aade --- /dev/null +++ b/v2/TestIssues/issue_544_test.go @@ -0,0 +1,61 @@ +// insert and query json data +// require oracle 21c +package TestIssues + +// +//import ( +// "database/sql" +// "testing" +//) +// +//func TestIssue544(t *testing.T) { +// var createInsert = func(db *sql.DB) error { +// return execCmd(db, `CREATE TABLE TTB_544( +// id NUMBER PRIMARY KEY, +// data JSON +// )`, `INSERT INTO TTB_544(ID, DATA) VALUES (1, '{"name": "John", "age": 30}')`) +// } +// var dropTable = func(db *sql.DB) error { +// return execCmd(db, `DROP TABLE TTB_544 PURGE`) +// } +// +// db, err := getDB() +// if err != nil { +// t.Error(err) +// return +// } +// defer func() { +// err := db.Close() +// if err != nil { +// t.Error(err) +// } +// }() +// err = createInsert(db) +// if err != nil { +// t.Error(err) +// return +// } +// defer func() { +// err := dropTable(db) +// if err != nil { +// t.Error(err) +// } +// }() +// var ( +// id int +// data []byte +// ) +// err = db.QueryRow("SELECT ID, DATA FROM TTB_544").Scan(&id, &data) +// if err != nil { +// t.Error(err) +// return +// } +// if id != 1 { +// t.Errorf("want 1, got %d", id) +// return +// } +// if string(data) != `{"name":"John","age":30}` { +// t.Errorf("want %s, got %s", `{"name":"John","age":30}`, string(data)) +// return +// } +//} diff --git a/v2/TestIssues/issue_556_test.go b/v2/TestIssues/issue_556_test.go new file mode 100644 index 00000000..7e156fbf --- /dev/null +++ b/v2/TestIssues/issue_556_test.go @@ -0,0 +1,69 @@ +// call prepare stmt which contain lob after call query double time will get error +// fetch out of sequence. +// the issue occur because queryLobPrefetch should be called one time (at first) only +package TestIssues + +import ( + "database/sql" + "testing" +) + +func TestIssue556(t *testing.T) { + db, err := getDB() + if err != nil { + t.Error(err) + return + } + defer func() { + err = db.Close() + if err != nil { + t.Error(err) + } + }() + var stmt *sql.Stmt + stmt, err = db.Prepare("SELECT TO_CLOB('this is a test') FROM DUAL") + if err != nil { + t.Error(err) + return + } + defer func() { + err = stmt.Close() + if err != nil { + t.Error(err) + } + }() + var rows *sql.Rows + rows, err = stmt.Query() + if err != nil { + t.Error(err) + return + } + var data string + for rows.Next() { + err = rows.Scan(&data) + if err != nil { + t.Error(err) + return + } + if data != "this is a test" { + t.Errorf("expected %s and got %s", "this is a test", data) + return + } + } + rows, err = stmt.Query() + if err != nil { + t.Error(err) + return + } + for rows.Next() { + err = rows.Scan(&data) + if err != nil { + t.Error(err) + return + } + if data != "this is a test" { + t.Errorf("expected %s and got %s", "this is a test", data) + return + } + } +} diff --git a/v2/TestIssues/large_udt_array_test.go b/v2/TestIssues/large_udt_array_test.go index 32292630..67d69cb9 100644 --- a/v2/TestIssues/large_udt_array_test.go +++ b/v2/TestIssues/large_udt_array_test.go @@ -1,28 +1,28 @@ +// issue 554 package TestIssues import ( "database/sql" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestLargeUDTArray(t *testing.T) { - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return execCmd(db, ` create or replace type stringsType as object( STRING1 varchar2(60), STRING2 varchar2(300) )`, `create or replace type stringsTypeCol as table of stringsType`) } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, "DROP TYPE stringsTypeCol", "DROP TYPE stringsType") } type StringsType struct { String1 string `udt:"STRING1"` String2 string `udt:"STRING2"` } - inputPars := func(db *sql.DB, input []StringsType) (int, error) { + var inputPars = func(db *sql.DB, input []StringsType) (int, error) { var length int _, err := db.Exec(` DECLARE @@ -33,7 +33,7 @@ func TestLargeUDTArray(t *testing.T) { END;`, input, go_ora.Out{Dest: &length}) return length, err } - outputPars := func(db *sql.DB, length int) ([]StringsType, error) { + var outputPars = func(db *sql.DB, length int) ([]StringsType, error) { var output []StringsType _, err := db.Exec(` declare @@ -98,4 +98,5 @@ func TestLargeUDTArray(t *testing.T) { if len(outputArray) != size { t.Errorf("expected size: %d and got: %d", size, len(outputArray)) } + } diff --git a/v2/TestIssues/lob_test.go b/v2/TestIssues/lob_test.go index 5a129f4c..9e5fcd31 100644 --- a/v2/TestIssues/lob_test.go +++ b/v2/TestIssues/lob_test.go @@ -5,11 +5,10 @@ import ( "database/sql" "errors" "fmt" + go_ora "github.com/sijms/go-ora/v2" "os" "strings" "testing" - - go_ora "github.com/sijms/go-ora/v2" ) func TestLob(t *testing.T) { @@ -20,7 +19,7 @@ func TestLob(t *testing.T) { } clob := strings.Repeat(string(fileData), 10) blob := bytes.Repeat(fileData, 10) - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE GOORA_TEMP_LOB( ID number(10) NOT NULL, DATA1 CLOB, @@ -31,11 +30,11 @@ func TestLob(t *testing.T) { )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "drop table GOORA_TEMP_LOB purge") } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { type TempStruct struct { ID int `db:"ID"` Data1 sql.NullString `db:"DATA1"` @@ -66,7 +65,7 @@ func TestLob(t *testing.T) { return err } - sqlQuery := func(db *sql.DB) error { + var sqlQuery = func(db *sql.DB) error { sqlText := "SELECT ID, DATA1, DATA2, DATA3, DATA4 FROM GOORA_TEMP_LOB WHERE ID < 3" rows, err := db.Query(sqlText) if err != nil { @@ -111,11 +110,11 @@ func TestLob(t *testing.T) { } return nil } - parameterQuery := func(db *sql.DB, id int) error { + var parameterQuery = func(db *sql.DB, id int) error { sqlText := `BEGIN SELECT ID, DATA1, DATA2, DATA3, DATA4 INTO :ID, :DATA1, :DATA2, :DATA3, :DATA4 FROM GOORA_TEMP_LOB WHERE ID = :iid; END;` - temp := struct { + var temp = struct { ID int `db:"ID,,,output"` Data1 sql.NullString `db:"DATA1,,500,output"` Data2 go_ora.Clob `db:"DATA2,clob,100000000,output"` diff --git a/v2/TestIssues/long_input_test.go b/v2/TestIssues/long_input_test.go index 88f22e0b..4a1e9449 100644 --- a/v2/TestIssues/long_input_test.go +++ b/v2/TestIssues/long_input_test.go @@ -4,15 +4,14 @@ import ( "bytes" "database/sql" "fmt" + go_ora "github.com/sijms/go-ora/v2" "strings" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestLongInput(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_557 ( ID NUMBER(10), DATA_BLOB BLOB, @@ -21,11 +20,11 @@ func TestLongInput(t *testing.T) { LDATE DATE ) NOCOMPRESS`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "drop table TTB_557 purge") } - raw := func(db *sql.DB, data []byte) error { + var raw = func(db *sql.DB, data []byte) error { _, err := db.Exec(`INSERT INTO TTB_557(DATA_BLOB, ID, LDATE) VALUES(:1, :2, :3)`, data, 1, time.Now()) if err != nil { return err @@ -69,7 +68,7 @@ func TestLongInput(t *testing.T) { return nil } - varchar := func(db *sql.DB, data string) error { + var varchar = func(db *sql.DB, data string) error { _, err := db.Exec(`INSERT INTO TTB_557(DATA_CLOB, ID, LDATE) VALUES(:1, :2, :3)`, data, 1, time.Now()) if err != nil { return err @@ -113,7 +112,7 @@ func TestLongInput(t *testing.T) { return nil } - nvarchar := func(db *sql.DB, data string) error { + var nvarchar = func(db *sql.DB, data string) error { _, err := db.Exec(`INSERT INTO TTB_557(DATA_NCLOB, ID, LDATE) VALUES(:1, :2, :3)`, go_ora.NVarChar(data), 1, time.Now()) if err != nil { return err diff --git a/v2/TestIssues/multiple_returning_test.go b/v2/TestIssues/multiple_returning_test.go index 446fbdd1..658b49c5 100644 --- a/v2/TestIssues/multiple_returning_test.go +++ b/v2/TestIssues/multiple_returning_test.go @@ -8,7 +8,7 @@ import ( ) func TestMultipleReturning(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_329( ID NUMBER(10), NAME VARCHAR2(100), @@ -16,10 +16,10 @@ func TestMultipleReturning(t *testing.T) { ONBOARD_DATE DATE )`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "DROP TABLE TTB_329 PURGE") } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { temp := struct { Id int `db:"ID"` Name string `db:"NAME"` diff --git a/v2/TestIssues/neg_binary_float_test.go b/v2/TestIssues/neg_binary_float_test.go new file mode 100644 index 00000000..08f0ff24 --- /dev/null +++ b/v2/TestIssues/neg_binary_float_test.go @@ -0,0 +1,85 @@ +// issue 580 +package TestIssues + +import ( + "database/sql" + "errors" + "fmt" + "testing" +) + +func TestNegBinaryFloat(t *testing.T) { + var create = func(db *sql.DB) error { + return execCmd(db, `CREATE TABLE TTB_580( + ID number(10) NOT NULL, + COL1 BINARY_FLOAT, + COL2 BINARY_DOUBLE + )`, + `INSERT INTO TTB_580 (ID, COL1, COL2) VALUES (1, 1.1, 1.1)`, + `INSERT INTO TTB_580 (ID, COL1, COL2) VALUES (2, -1.1, -1.1)`) + } + var drop = func(db *sql.DB) error { + return execCmd(db, `DROP TABLE TTB_580 PURGE`) + } + var query = func(db *sql.DB) error { + var ( + id int + col1, col2 float64 + ) + rows, err := db.Query("SELECT ID, COL1, COL2 FROM TTB_580") + if err != nil { + return err + } + defer func() { + err = rows.Close() + if err != nil { + t.Error(err) + } + }() + for rows.Next() { + if err := rows.Scan(&id, &col1, &col2); err != nil { + return err + } + switch id { + case 1: + if col1 != 1.1 && col2 != 1.1 { + return fmt.Errorf("expected 1.1, 1.1 got %v, %v", col1, col2) + } + case 2: + if col1 != -1.1 && col2 != -1.1 { + return fmt.Errorf("expected -1.1, -1.1 got %v, %v", col1, col2) + } + default: + return errors.New("invalid id") + } + } + return rows.Err() + } + db, err := getDB() + if err != nil { + t.Error(err) + return + } + defer func() { + err = db.Close() + if err != nil { + t.Error(err) + } + }() + err = create(db) + if err != nil { + t.Error(err) + return + } + defer func() { + err = drop(db) + if err != nil { + t.Error(err) + } + }() + err = query(db) + if err != nil { + t.Error(err) + return + } +} diff --git a/v2/TestIssues/nested_udt_array_test.go b/v2/TestIssues/nested_udt_array_test.go index 1fbd1a01..f81e9464 100644 --- a/v2/TestIssues/nested_udt_array_test.go +++ b/v2/TestIssues/nested_udt_array_test.go @@ -14,10 +14,9 @@ package TestIssues import ( "database/sql" "fmt" + go_ora "github.com/sijms/go-ora/v2" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestNestedUDTArray(t *testing.T) { @@ -39,8 +38,8 @@ func TestNestedUDTArray(t *testing.T) { Data []typeChild `udt:"DATA"` Child typeChild `udt:"CHILD"` } - refDate := time.Date(2024, 1, 11, 19, 19, 19, 0, time.UTC) - createParent := func(index int, date time.Time) typeParent { + var refDate = time.Date(2024, 1, 11, 19, 19, 19, 0, time.UTC) + var createParent = func(index int, date time.Time) typeParent { var parent typeParent parent.Id = index + 1 parent.Value = fmt.Sprintf("parent_%d", index+1) @@ -61,7 +60,7 @@ func TestNestedUDTArray(t *testing.T) { parent.Child.Child = typeChild2{6, "child2_6", date} return parent } - checkChildType2 := func(input *typeChild2, index, idShift int, extraText string) error { + var checkChildType2 = func(input *typeChild2, index, idShift int, extraText string) error { if input.Id != index+1+idShift { return fmt.Errorf("expected child2.Id: %d and got: %d at index: %d", index+1+idShift, input.Id, index) @@ -76,7 +75,7 @@ func TestNestedUDTArray(t *testing.T) { } return nil } - checkChildType := func(input *typeChild, index, idShift int, extraText string) error { + var checkChildType = func(input *typeChild, index, idShift int, extraText string) error { for index2, temp := range input.Data { err := checkChildType2(&temp, index2, idShift, extraText) if err != nil { @@ -93,7 +92,7 @@ func TestNestedUDTArray(t *testing.T) { } return checkChildType2(&input.Child, 5, idShift, extraText) } - checkParentType := func(input *typeParent, index, idShift int, extraText string) error { + var checkParentType = func(input *typeParent, index, idShift int, extraText string) error { for index2, temp := range input.Data { err := checkChildType(&temp, index2, idShift, extraText) if err != nil { @@ -109,7 +108,7 @@ func TestNestedUDTArray(t *testing.T) { } return checkChildType(&input.Child, 3, idShift, extraText) } - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return execCmd(db, ` create or replace type childType2 as object( ID number, @@ -129,7 +128,7 @@ create or replace type parentType as object( child childType )`, `create or replace type parentTypeCol as table of parentType`) } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, "DROP TYPE parentTypeCol", "DROP TYPE parentType", @@ -138,8 +137,8 @@ create or replace type parentType as object( "DROP TYPE childType2Col", "DROP TYPE childType2") } - outputPar := func(db *sql.DB) error { - parent := typeParent{} + var outputPar = func(db *sql.DB) error { + var parent = typeParent{} _, err := db.Exec(` DECLARE v_child2 childType2; @@ -176,12 +175,12 @@ END;`, sql.Named("ldate", refDate), sql.Named("output", go_ora.Out{Dest: &parent return checkParentType(&parent, 0, 0, "") } - inputPar := func(db *sql.DB) error { - input := time.Date(2024, 1, 11, 19, 19, 19, 0, time.UTC) - parent := createParent(0, time.Now()) + var inputPar = func(db *sql.DB) error { + var input = time.Date(2024, 1, 11, 19, 19, 19, 0, time.UTC) + var parent = createParent(0, time.Now()) var output typeParent - id := 5 - name := "_verified" + var id = 5 + var name = "_verified" _, err := db.Exec(` DECLARE parent parentType; @@ -234,7 +233,7 @@ end;`, sql.Named("parent", parent), sql.Named("id", id), sql.Named("name", name) return checkParentType(&output, 0, id, name) } - inputParArray := func(db *sql.DB) error { + var inputParArray = func(db *sql.DB) error { var parents []typeParent parents = append(parents, createParent(0, refDate), createParent(1, refDate), @@ -296,7 +295,7 @@ end;`, sql.Named("parent", parent), sql.Named("id", id), sql.Named("name", name) return checkParentType(&output, 0, id, name) } - outputParArray := func(db *sql.DB) error { + var outputParArray = func(db *sql.DB) error { var parents []typeParent _, err := db.Exec(` DECLARE diff --git a/v2/TestIssues/nested_udt_test.go b/v2/TestIssues/nested_udt_test.go index d0cde933..acd9bd64 100644 --- a/v2/TestIssues/nested_udt_test.go +++ b/v2/TestIssues/nested_udt_test.go @@ -3,15 +3,14 @@ package TestIssues import ( "database/sql" "fmt" + go_ora "github.com/sijms/go-ora/v2" "strings" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestNestedUDT(t *testing.T) { - create := func(db *sql.DB) error { + var create = func(db *sql.DB) error { return execCmd(db, ` create or replace type subType2 as object( num number(10), @@ -49,7 +48,7 @@ BEGIN end loop; END TP_NESTED_UDT;`) } - drop := func(db *sql.DB) error { + var drop = func(db *sql.DB) error { return execCmd(db, "DROP PROCEDURE TP_NESTED_UDT", "DROP TABLE TTB_NESTED_UDT", @@ -74,7 +73,7 @@ END TP_NESTED_UDT;`) } now := time.Now() expectedTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local) - isEqual := func(s1, s2 mainS) bool { + var isEqual = func(s1, s2 mainS) bool { time1 := s1.Sub1.Sub2.LDate time2 := s2.Sub1.Sub2.LDate if time1.Year() == time2.Year() && @@ -92,7 +91,7 @@ END TP_NESTED_UDT;`) } return false } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { length := 100 type insertData struct { Id int `db:"ID"` @@ -103,7 +102,7 @@ END TP_NESTED_UDT;`) } baseValue := 1.1 data := make([]insertData, length) - for index := range data { + for index, _ := range data { data[index].Id = index + 1 data[index].Sep1 = strings.Repeat("-", 100) data[index].Sep2 = strings.Repeat("-", 100) @@ -126,7 +125,7 @@ END TP_NESTED_UDT;`) VALUES(:ID, :DATA1, :SEP1, :DATA2, :SEP2)`, data) return err } - queryTable := func(db *sql.DB) error { + var queryTable = func(db *sql.DB) error { rows, err := db.Query("SELECT ID, DATA1, SEP1, DATA2, SEP2 FROM TTB_NESTED_UDT") if err != nil { return err @@ -154,7 +153,7 @@ END TP_NESTED_UDT;`) } return rows.Err() } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { got := mainS{} err := db.QueryRow("SELECT mainType(5, subType1(1, 'test', subType2(33, :1)), 'NAME') from dual", expectedTime).Scan(&got) if err != nil { @@ -177,8 +176,8 @@ END TP_NESTED_UDT;`) } return nil } - inputPar := func(db *sql.DB) error { - input := mainS{ + var inputPar = func(db *sql.DB) error { + var input = mainS{ Num: 7, Sub1: sub1{ Num: 8, @@ -190,7 +189,7 @@ END TP_NESTED_UDT;`) }, S1: sql.NullString{"test", true}, } - output := mainS{} + var output = mainS{} _, err := db.Exec(` DECLARE v_main mainType; @@ -219,7 +218,7 @@ END TP_NESTED_UDT;`) } return nil } - callProc := func(db *sql.DB) error { + var callProc = func(db *sql.DB) error { var output []mainS _, err := db.Exec(`BEGIN TP_NESTED_UDT(10, :1); END;`, go_ora.Out{Dest: &output, Size: 100}) if err != nil { diff --git a/v2/TestIssues/prefetch_large_blob_test.go b/v2/TestIssues/prefetch_large_blob_test.go index 1cbb2143..c9f3b439 100644 --- a/v2/TestIssues/prefetch_large_blob_test.go +++ b/v2/TestIssues/prefetch_large_blob_test.go @@ -11,8 +11,8 @@ import ( ) func TestPrefetchLargeBlob(t *testing.T) { - refDate := time.Now() - createTable := func(db *sql.DB) error { + var refDate = time.Now() + var createTable = func(db *sql.DB) error { return execCmd(db, `CREATE TABLE TTB_PREFETCH_LARGE_BLOB ( ID number(10) NOT NULL, DATA1 BLOB, @@ -26,10 +26,10 @@ func TestPrefetchLargeBlob(t *testing.T) { PRIMARY KEY(ID) ) NOCOMPRESS`) } - dropTable := func(db *sql.DB) error { + var dropTable = func(db *sql.DB) error { return execCmd(db, "drop table TTB_PREFETCH_LARGE_BLOB purge") } - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { type Table struct { Id int `db:"ID"` Data1 []byte `db:"DATA1,blob"` @@ -62,7 +62,7 @@ func TestPrefetchLargeBlob(t *testing.T) { VALUES(:ID, :DATA1, :SEP1, :DATA2, :SEP2, :DATA3, :SEP3, :DATA4, :SEP4)`, input) return err } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { var ( id int data1 []byte diff --git a/v2/TestIssues/raw_test.go b/v2/TestIssues/raw_test.go index 92baf666..f065da1a 100644 --- a/v2/TestIssues/raw_test.go +++ b/v2/TestIssues/raw_test.go @@ -9,7 +9,7 @@ import ( ) func TestRaw(t *testing.T) { - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { sqlText := `INSERT INTO TTB_MAIN(ID, NAME, VAL, LDATE, DATA) VALUES(:ID, :NAME, :VAL, :LDATE, :DATA)` length := 500 type TempStruct struct { diff --git a/v2/TestIssues/recall_stored_proc_test.go b/v2/TestIssues/recall_stored_proc_test.go new file mode 100644 index 00000000..d39568c7 --- /dev/null +++ b/v2/TestIssues/recall_stored_proc_test.go @@ -0,0 +1,118 @@ +// issue 589 +package TestIssues + +import ( + "database/sql" + "fmt" + go_ora "github.com/sijms/go-ora/v2" + "testing" +) + +func TestRecallStoredProc(t *testing.T) { + var create = func(db *sql.DB) error { + return execCmd(db, `create or replace procedure SIMPLE_ADD_NUM( + N1 in NUMBER, + N2 in NUMBER, + N3 out NUMBER) AS +BEGIN + N3 := N1 + N2; +END;`, `create or replace procedure SIMPLE_ADD_STR( + N1 in VARCHAR2, + N2 in VARCHAR2, + N3 out VARCHAR2) AS +BEGIN + N3 := N1 || N2; +END;`) + } + var drop = func(db *sql.DB) error { + return execCmd(db, `drop procedure SIMPLE_ADD_NUM`, `drop procedure SIMPLE_ADD_STR`) + } + var callAddInt = func(db *sql.DB) error { + var result int + s, err := db.Prepare(`BEGIN SIMPLE_ADD_NUM(:1, :2, :3); END;`) + if err != nil { + return err + } + defer func() { + err = s.Close() + if err != nil { + t.Error(err) + } + }() + _, err = s.Exec(1, 2, go_ora.Out{Dest: &result}) + if err != nil { + return err + } + if result != 3 { + return fmt.Errorf("expected 3 but got %d", result) + } + _, err = s.Exec(4, 5, go_ora.Out{Dest: &result}) + if err != nil { + return err + } + if result != 9 { + return fmt.Errorf("expected 9 but got %d", result) + } + return nil + } + var callAddString = func(db *sql.DB) error { + var result string + s, err := db.Prepare("BEGIN SIMPLE_ADD_STR(:1, :2, :3); END;") + if err != nil { + return err + } + defer func() { + err = s.Close() + if err != nil { + t.Error(err) + } + }() + _, err = s.Exec("hello ", "world", go_ora.Out{Dest: &result, Size: 500}) + if err != nil { + return err + } + if result != "hello world" { + return fmt.Errorf(`expected "hello world" but got "%s"`, result) + } + _, err = s.Exec("helloHELLO ", "worldWORLD", go_ora.Out{Dest: &result, Size: 500}) + if err != nil { + return err + } + if result != "helloHELLO worldWORLD" { + return fmt.Errorf(`expected "helloHELLO worldWORLD" but got "%s"`, result) + } + return nil + } + db, err := getDB() + if err != nil { + t.Error(err) + return + } + defer func() { + err = db.Close() + if err != nil { + t.Error(err) + } + }() + err = create(db) + if err != nil { + t.Error(err) + return + } + defer func() { + err = drop(db) + if err != nil { + t.Error(err) + } + }() + err = callAddInt(db) + if err != nil { + t.Error(err) + return + } + err = callAddString(db) + if err != nil { + t.Error(err) + return + } +} diff --git a/v2/TestIssues/regular_type_array_test.go b/v2/TestIssues/regular_type_array_test.go index dda20fc9..cee0c93f 100644 --- a/v2/TestIssues/regular_type_array_test.go +++ b/v2/TestIssues/regular_type_array_test.go @@ -4,11 +4,10 @@ import ( "bytes" "database/sql" "fmt" + go_ora "github.com/sijms/go-ora/v2" "strings" "testing" "time" - - go_ora "github.com/sijms/go-ora/v2" ) func TestRegularTypeArray(t *testing.T) { @@ -19,7 +18,7 @@ func TestRegularTypeArray(t *testing.T) { PRICES []float64 `udt:"PRICES"` BirthDate time.Time `udt:"BIRTH_DATE"` } - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return execCmd(db, "create or replace TYPE SLICE AS TABLE OF varchar2(500)", "create or replace type IntArray as table of number(10, 2)", "create or replace type DateArray as table of DATE", @@ -38,7 +37,7 @@ BIRTH_DATE DATE )`, ) } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, "DROP TYPE Customer", "drop type SLICE", "drop type IntArray", "drop type DateArray", "drop type ZoneArray", "drop type SLICE2", "DROP TYPE ByteArray", @@ -46,12 +45,12 @@ BIRTH_DATE DATE ) } - outputParString := func(db *sql.DB) error { + var outputParString = func(db *sql.DB) error { var output []sql.NullString var output2 []sql.NullString var output3 []sql.NullInt64 var output4 []sql.NullTime - // var output5 []sql.NullTime + //var output5 []sql.NullTime var output6 [][]byte _, err := db.Exec(` DECLARE @@ -147,14 +146,14 @@ end;`, go_ora.Out{Dest: go_ora.Object{Name: "SLICE", Value: &output}}, return nil } - basicPars := func(db *sql.DB) error { + var basicPars = func(db *sql.DB) error { var ( length = 10 input1, output1 []sql.NullString input2, output2 []sql.NullString input3, output3 []sql.NullInt64 input4, output4 []sql.NullTime - // input5, output5 []sql.NullTime + //input5, output5 []sql.NullTime input6, output6 [][]byte input7, output7 []go_ora.Blob input8, output8 []go_ora.Clob @@ -165,7 +164,7 @@ end;`, go_ora.Out{Dest: go_ora.Object{Name: "SLICE", Value: &output}}, input2 = make([]sql.NullString, length) input3 = make([]sql.NullInt64, length) input4 = make([]sql.NullTime, length) - // input5 = make([]sql.NullTime, length) + //input5 = make([]sql.NullTime, length) input6 = make([][]byte, length) input7 = make([]go_ora.Blob, length) input8 = make([]go_ora.Clob, length) @@ -176,7 +175,7 @@ end;`, go_ora.Out{Dest: go_ora.Object{Name: "SLICE", Value: &output}}, input2[x] = sql.NullString{"", false} input3[x] = sql.NullInt64{0, false} input4[x] = sql.NullTime{Valid: false} - // input5[x] = sql.NullTime{Valid: false} + //input5[x] = sql.NullTime{Valid: false} input6[x] = nil input7[x] = go_ora.Blob{Data: nil} input8[x] = go_ora.Clob{Valid: false} @@ -186,7 +185,7 @@ end;`, go_ora.Out{Dest: go_ora.Object{Name: "SLICE", Value: &output}}, input2[x] = sql.NullString{"안녕하세요AAA_", true} input3[x] = sql.NullInt64{int64(x), true} input4[x] = sql.NullTime{time.Now(), true} - // input5[x] = sql.NullTime{Time: time.Now(), Valid: true} + //input5[x] = sql.NullTime{Time: time.Now(), Valid: true} input6[x] = []byte("test_") input7[x] = go_ora.Blob{Data: []byte("BLOB")} input8[x] = go_ora.Clob{String: "CLOB_", Valid: true} @@ -248,7 +247,7 @@ END;`, length, go_ora.Object{Name: "SLICE2", Value: input2}, go_ora.Object{Name: "IntArray", Value: input3}, go_ora.Object{Name: "DateArray", Value: input4}, - // go_ora.Object{Name: "ZoneArray", Value: input5}, + //go_ora.Object{Name: "ZoneArray", Value: input5}, go_ora.Object{Name: "ByteArray", Value: input6}, go_ora.Object{Name: "BlobArray", Value: input7}, go_ora.Object{Name: "ClobArray", Value: input8}, @@ -258,7 +257,7 @@ END;`, length, go_ora.Object{Name: "SLICE2", Value: &output2}, go_ora.Object{Name: "IntArray", Value: &output3}, go_ora.Object{Name: "DateArray", Value: &output4}, - // go_ora.Object{Name: "ZoneArray", Value: &output5}, + //go_ora.Object{Name: "ZoneArray", Value: &output5}, go_ora.Object{Name: "ByteArray", Value: &output6}, go_ora.Object{Name: "BlobArray", Value: &output7}, go_ora.Object{Name: "ClobArray", Value: &output8}, @@ -325,15 +324,15 @@ END;`, length, return nil } - getTempLobs := func(db *sql.DB) (int, error) { + var getTempLobs = func(db *sql.DB) (int, error) { var r int err := db.QueryRow(`SELECT SUM(cache_lobs) + SUM(nocache_lobs) + SUM(abstract_lobs) FROM v$temporary_lobs l, v$session s WHERE s.SID = l.SID AND s.sid = userenv('SID')`).Scan(&r) return r, err } - nestedRegularArray := func(db *sql.DB) error { + var nestedRegularArray = func(db *sql.DB) error { refDate := time.Now() - customer := Customer{ + var customer = Customer{ Id: 10, Name: "Name1", BirthDate: refDate, } var output Customer diff --git a/v2/TestIssues/session_pars_test.go b/v2/TestIssues/session_pars_test.go index 41b9c15c..db2db5fb 100644 --- a/v2/TestIssues/session_pars_test.go +++ b/v2/TestIssues/session_pars_test.go @@ -2,9 +2,8 @@ package TestIssues import ( "bytes" - "testing" - go_ora "github.com/sijms/go-ora/v2" + "testing" ) func TestSessionPars(t *testing.T) { @@ -33,14 +32,12 @@ func TestSessionPars(t *testing.T) { defer go_ora.DelSessionParam(db, "nls_language") _, err = db.Exec("INSERT INTO TEST_S(ID, name) VALUES(1, 's')") if err != nil { - expected := []byte{ - 79, 82, 65, 45, 48, 48, 57, 52, 50, 58, 32, 216, 167, 217, + expected := []byte{79, 82, 65, 45, 48, 48, 57, 52, 50, 58, 32, 216, 167, 217, 132, 216, 172, 216, 175, 217, 136, 217, 132, 32, 216, 163, 217, 136, 32, 216, 167, 217, 132, 216, 172, 216, 175, 217, 136, 217, 132, 32, 216, 167, 217, 132, 216, 167, 216, 185, 216, 170, 216, 168, 216, 167, 216, 177, 217, 138, 32, 216, 186, 217, 138, 216, 177, 32, 217, 133, 217, 136, 216, 172, 217, - 136, 216, 175, - } + 136, 216, 175} got := []byte(err.Error()) if bytes.Equal(got, expected) { t.Errorf("expected: %v and got: %v", string(expected), err.Error()) diff --git a/v2/TestIssues/time_test.go b/v2/TestIssues/time_test.go index c62e75bf..25330211 100644 --- a/v2/TestIssues/time_test.go +++ b/v2/TestIssues/time_test.go @@ -8,7 +8,7 @@ import ( ) func TestTime(t *testing.T) { - createTable := func(db *sql.DB) error { + var createTable = func(db *sql.DB) error { return execCmd(db, ` CREATE TABLE TTB_TIME( ID NUMBER, @@ -19,15 +19,15 @@ CREATE TABLE TTB_TIME( )`) } - dropTable := func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_TIME PURGE`) } - date := time.Now() + var dropTable = func(db *sql.DB) error { return execCmd(db, `DROP TABLE TTB_TIME PURGE`) } + var date = time.Now() loc, _ := time.LoadLocation("Asia/Shanghai") - insert := func(db *sql.DB) error { + var insert = func(db *sql.DB) error { _, err := db.Exec("INSERT INTO TTB_TIME(ID, DATE1, DATE2, DATE3, DATE4) VALUES(:1, :2, :3, :4, :5)", 1, date, date, date.In(loc), date) return err } - query := func(db *sql.DB) error { + var query = func(db *sql.DB) error { var ( id int date1, date2, date3, date4 time.Time diff --git a/v2/TestIssues/udt_string_test.go b/v2/TestIssues/udt_string_test.go new file mode 100644 index 00000000..b8f99901 --- /dev/null +++ b/v2/TestIssues/udt_string_test.go @@ -0,0 +1,144 @@ +// issue 578 +// can't read or write UDT when contain string > 251 +package TestIssues + +import ( + "database/sql" + "errors" + "fmt" + go_ora "github.com/sijms/go-ora/v2" + "strings" + "testing" + "time" +) + +func TestUDTString(t *testing.T) { + type Data struct { + DateCreated time.Time `udt:"DATE_CREATED" json:"dateCreated"` + Qty int `udt:"QTY" json:"qty"` + FirstName string `udt:"FIRST_NAME" json:"firstName"` + } + var create = func(db *sql.DB) error { + return execCmd(db, ` + create table TAB_EMPLOYEE_K( + firstname varchar2(4000), + DATE_CREATED DATE, + qty NUMBER + )`, `create or replace type OBJ_TYPE_DATA as object( + DATE_CREATED DATE, + QTY NUMBER, + FIRST_NAME varchar2(4000) + )`, `create or replace PROCEDURE USP_SAVE_TEST( + P_DATE IN OBJ_TYPE_DATA, + p_code out number, + p_msg out varchar2 + ) AS + BEGIN + INSERT INTO TAB_EMPLOYEE_K(firstname, DATE_CREATED, qty) + VALUES (p_date.FIRST_NAME, sysdate, length(p_date.FIRST_NAME)); + p_code := 200; + p_msg := 'Success'; + exception when others then + p_code := 500; + p_msg := 'Error'; + END;`, `CREATE OR REPLACE PROCEDURE USP_LOAD_TEST + ( + L_DATA OUT OBJ_TYPE_DATA, + L_QTY NUMBER + ) AS + P_DATA OBJ_TYPE_DATA; + BEGIN + P_DATA := OBJ_TYPE_DATA(NULL, NULL, NULL); + SELECT FIRSTNAME, DATE_CREATED, QTY + INTO P_DATA.FIRST_NAME, P_DATA.DATE_CREATED, P_DATA.QTY + FROM TAB_EMPLOYEE_K + WHERE QTY = L_QTY; + L_DATA := P_DATA; + END USP_LOAD_TEST;`) + } + var drop = func(db *sql.DB) error { + return execCmd(db, `DROP TYPE OBJ_TYPE_DATA`, + `DROP PROCEDURE USP_LOAD_TEST`, + `DROP PROCEDURE USP_SAVE_TEST`, + `drop table TAB_EMPLOYEE_K`) + } + + var callSave = func(db *sql.DB, data Data) error { + var code int + var message string + _, err := db.Exec(`BEGIN USP_SAVE_TEST(:1, :2, :3); END;`, data, + go_ora.Out{Dest: &code}, go_ora.Out{Dest: &message, Size: 2000}) + if err != nil { + return err + } + if code != 200 || message != "Success" { + return errors.New("Error occur inside function save") + } + return nil + } + var callLoad = func(db *sql.DB, qty int) error { + var obj Data + _, err := db.Exec(`BEGIN USP_LOAD_TEST(:1, :2); END;`, go_ora.Object{ + Owner: "LAB", + Name: "OBJ_TYPE_DATA", + Value: &obj, + }, qty) + if err != nil { + return err + } + if len(obj.FirstName) != qty { + return fmt.Errorf("expected string length: %d and got %d", qty, len(obj.FirstName)) + } + return nil + } + db, err := getDB() + if err != nil { + t.Error(err) + return + } + defer func() { + err = db.Close() + if err != nil { + t.Error(err) + } + }() + err = create(db) + if err != nil { + t.Error(err) + return + } + defer func() { + err = drop(db) + if err != nil { + t.Error(err) + } + }() + err = go_ora.RegisterType(db, "OBJ_TYPE_DATA", "", Data{}) + if err != nil { + t.Error(err) + return + } + // call save with string < 251 + err = callSave(db, Data{time.Now(), 241, strings.Repeat("a", 241)}) + if err != nil { + t.Error(err) + return + } + // call save with string > 251 + err = callSave(db, Data{time.Now(), 261, strings.Repeat("a", 261)}) + if err != nil { + t.Error(err) + return + } + // call load for string < 251 + err = callLoad(db, 241) + if err != nil { + t.Error(err) + return + } + err = callLoad(db, 261) + if err != nil { + t.Error(err) + return + } +} diff --git a/v2/TestIssues/varray_test.go b/v2/TestIssues/varray_test.go index b61e07db..4b02a056 100644 --- a/v2/TestIssues/varray_test.go +++ b/v2/TestIssues/varray_test.go @@ -3,17 +3,16 @@ 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 TestVarray(t *testing.T) { - createTypes := func(db *sql.DB) error { + var createTypes = func(db *sql.DB) error { return execCmd(db, `create type StringArray as VARRAY(10) of varchar2(20) not null`) } - dropTypes := func(db *sql.DB) error { + var dropTypes = func(db *sql.DB) error { return execCmd(db, `drop type StringArray`) } db, err := getDB() diff --git a/v2/command.go b/v2/command.go index 99dc6beb..9f4d8862 100644 --- a/v2/command.go +++ b/v2/command.go @@ -359,7 +359,7 @@ func (stmt *Stmt) writePars() error { if par.Flag == 0x80 { continue } - if !stmt.parse && par.Direction == Output { + if !stmt.parse && !stmt.reSendParDef && par.Direction == Output { continue } if !par.isLongType() { @@ -469,10 +469,8 @@ func (stmt *Stmt) write() error { //for valueIndex, values := range arrayValue { // stmt.Pars[parIndex].BValue = values[valueIndex] //} - // valueIndex := 0; valueIndex < stmt.arrayBindCount; valueIndex++ { // each value represented an array of []byte - //} //for valueIndex := 0; valueIndex < stmt.arrayBindCount; valueIndex++ { // for parIndex, arrayValue := range arrayValues { @@ -553,9 +551,6 @@ func (stmt *Stmt) write() error { return err } } - stmt.parse = false - stmt.define = false - stmt.reSendParDef = false } return session.Write() } @@ -1817,6 +1812,9 @@ func (stmt *Stmt) _exec(args []driver.NamedValue) (*QueryResult, error) { return nil, err } } + stmt.parse = false + stmt.define = false + stmt.reSendParDef = false return result, nil } @@ -2021,29 +2019,22 @@ func (stmt *Stmt) QueryContext(ctx context.Context, namedArgs []driver.NamedValu return stmt.Query_(namedArgs) } -func (stmt *Stmt) reset() { - stmt.reSendParDef = false - stmt.parse = true - stmt.execute = true - stmt.define = false - stmt._hasBLOB = false - stmt._hasLONG = false - stmt.bulkExec = false - // stmt.disableCompression = false - stmt.arrayBindCount = 0 - stmt.columns = nil -} +//func (stmt *Stmt) reset() { +// stmt.reSendParDef = false +// stmt.parse = true +// stmt.execute = true +// stmt.define = false +// stmt._hasBLOB = false +// stmt._hasLONG = false +// stmt.bulkExec = false +// // stmt.disableCompression = false +// stmt.arrayBindCount = 0 +// stmt.columns = nil +//} func (stmt *Stmt) _query() (*DataSet, error) { var err error var dataSet *DataSet - //defer func() { - // err = stmt.freeTemporaryLobs() - // if err != nil { - // stmt.connection.tracer.Printf("Error free temporary lobs: %v", err) - // } - //}() - stmt.connection.session.ResetBuffer() err = stmt.write() if err != nil { @@ -2055,7 +2046,7 @@ func (stmt *Stmt) _query() (*DataSet, error) { return nil, err } // deal with lobs - if (stmt._hasBLOB || stmt._hasLONG) && stmt.connection.connOption.Lob == configurations.INLINE { + if stmt.parse && (stmt._hasBLOB || stmt._hasLONG) && stmt.connection.connOption.Lob == configurations.INLINE { stmt.define = true stmt.execute = false stmt.parse = false @@ -2069,6 +2060,9 @@ func (stmt *Stmt) _query() (*DataSet, error) { if err != nil { return nil, err } + stmt.parse = false + stmt.define = false + stmt.reSendParDef = false return dataSet, err }