Skip to content

Commit cf031e5

Browse files
committed
updates th evarrat inserting and updating logic
1 parent a523455 commit cf031e5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

oracle/varray.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (e EmailList) Value() (driver.Value, error) {
6060

6161
ctx := context.Background()
6262

63-
objType, err := godror.GetObjectType(ctx, DB, "EMAIL_LIST_ARR")
63+
objType, err := godror.GetObjectType(ctx, DB, "\"email_list_arr\"")
6464
if err != nil {
6565
return nil, fmt.Errorf("get object type: %w", err)
6666
}

tests/varray_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ package tests
4141
import (
4242
"reflect"
4343
"testing"
44+
45+
"github.com/oracle-samples/gorm-oracle/oracle"
4446
)
4547

4648
// Struct mapping to phone_typ object
@@ -58,12 +60,11 @@ type DeptPhoneList struct {
5860

5961
// Struct for table with email VARRAY
6062
type EmailVarrayTable struct {
61-
ID uint `gorm:"column:ID;primaryKey"`
62-
Emails []string `gorm:"column:EMAILS;type:\"email_list_arr\""`
63+
ID uint `gorm:"column:ID;primaryKey"`
64+
Emails oracle.EmailList `gorm:"column:EMAILS;type:\"email_list_arr\""`
6365
}
6466

6567
func TestStringVarray(t *testing.T) {
66-
t.Skip("Skipping due to issue #87")
6768
dropTable := `
6869
BEGIN
6970
EXECUTE IMMEDIATE 'DROP TABLE "email_varray_tables"';
@@ -90,6 +91,13 @@ func TestStringVarray(t *testing.T) {
9091
t.Fatalf("Failed to create email_varray_tables: %v", err)
9192
}
9293

94+
// expose raw *sql.DB to oracle package for godror.GetObjectType
95+
sqlDB, err := DB.DB()
96+
if err != nil {
97+
t.Fatalf("cannot get *sql.DB from GORM: %v", err)
98+
}
99+
oracle.DB = sqlDB
100+
93101
// Insert initial data via raw SQL
94102
insertRaw := `INSERT INTO "email_varray_tables" VALUES (1, "email_list_arr"('[email protected]','[email protected]','[email protected]'))`
95103
if err := DB.Exec(insertRaw).Error; err != nil {
@@ -102,7 +110,7 @@ func TestStringVarray(t *testing.T) {
102110
t.Fatalf("Failed to fetch varray: %v", err)
103111
}
104112
105-
if !reflect.DeepEqual(expected, got.Emails) {
113+
if !reflect.DeepEqual(expected, []string(got.Emails)) {
106114
t.Errorf("String VARRAY roundtrip failed: got %v, want %v", got.Emails, expected)
107115
}
108116

@@ -115,7 +123,7 @@ func TestStringVarray(t *testing.T) {
115123
if err := DB.First(&updated, 1).Error; err != nil {
116124
t.Fatalf("Failed to reload updated EmailVarrayTable: %v", err)
117125
}
118-
if !reflect.DeepEqual(updated.Emails, newEmails) {
126+
if !reflect.DeepEqual(updated.Emails, oracle.EmailList(newEmails)) {
119127
t.Errorf("String VARRAY update failed: got %v, want %v", updated.Emails, newEmails)
120128
}
121129

@@ -130,7 +138,6 @@ func TestStringVarray(t *testing.T) {
130138
}
131139

132140
func TestVarrayOfObject(t *testing.T) {
133-
t.Skip("Skipping due to issue #87")
134141
dropTable := `
135142
BEGIN
136143
EXECUTE IMMEDIATE 'DROP TABLE "dept_phone_lists"';

0 commit comments

Comments
 (0)