@@ -45,6 +45,7 @@ import (
45
45
"strings"
46
46
"testing"
47
47
48
+ "github.com/google/uuid"
48
49
. "github.com/oracle-samples/gorm-oracle/tests/utils"
49
50
50
51
"time"
@@ -846,3 +847,77 @@ func TestCreateFromMapWithTable(t *testing.T) {
846
847
t .Errorf ("failed to create data from map with table, @id != id" )
847
848
}
848
849
}
850
+
851
+ // Issue #78: PL/SQL failure when upserting CLOBs
852
+ func TestCreateAndUpdateLargeString (t * testing.T ) {
853
+ DB .Migrator ().DropTable (FolderData {}, FolderProperty {})
854
+
855
+ if err := DB .Exec (`
856
+ CREATE TABLE "folder_data" (
857
+ "folder_id" VARCHAR2(4000),
858
+ "folder_nm" VARCHAR2(4000),
859
+ PRIMARY KEY ("folder_id"))
860
+ ` ).Error ; err != nil {
861
+ t .Errorf ("Failed to create table: %v" , err )
862
+ }
863
+
864
+ if err := DB .Exec (`
865
+ CREATE TABLE "folder_properties" (
866
+ "seq" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,
867
+ "folder_id" VARCHAR2(4000),
868
+ "key" VARCHAR2(4000),
869
+ "value" CLOB,
870
+ PRIMARY KEY ("folder_id","key"),
871
+ CONSTRAINT "fk_folder_data_properties" FOREIGN KEY ("folder_id") REFERENCES "folder_data"("folder_id"),
872
+ CONSTRAINT "uni_folder_properties_key" UNIQUE ("key"))
873
+ ` ).Error ; err != nil {
874
+ t .Errorf ("Failed to create table. Got: %v" , err )
875
+ }
876
+
877
+ id := uuid .New ().String ()
878
+
879
+ folder := & FolderData {
880
+ ID : id ,
881
+ Name : "My Folder" ,
882
+ Properties : []FolderProperty {
883
+ {
884
+ ID : id ,
885
+ Key : "prop1" ,
886
+ Value : strings .Repeat ("A" , 5000 ),
887
+ },
888
+ {
889
+ ID : id ,
890
+ Key : "prop2" ,
891
+ Value : strings .Repeat ("B" , 5000 ),
892
+ },
893
+ },
894
+ }
895
+
896
+ if err := DB .Create (& folder ).Error ; err != nil {
897
+ t .Errorf ("Failed to insert record. Got: %v" , err )
898
+ }
899
+
900
+ createdFolder := & FolderData {}
901
+ if err := DB .Model (& FolderData {}).Preload ("Properties" ).First (& createdFolder ).Error ; err != nil {
902
+ t .Errorf ("Failed to load record. Got: %v" , err )
903
+ }
904
+
905
+ for i , p := range folder .Properties {
906
+ tests .AssertObjEqual (t , p , createdFolder .Properties [i ], "Seq" , "ID" , "Key" , "Value" )
907
+ }
908
+
909
+ clobContent := strings .Repeat ("C" , 4020 )
910
+ folder .Properties [1 ].Value = clobContent
911
+ if err := DB .Save (& folder ).Error ; err != nil {
912
+ t .Errorf ("Failed to update record. Got: %v" , err )
913
+ }
914
+
915
+ updatedFolder := & FolderData {}
916
+ if err := DB .Model (& FolderData {}).Preload ("Properties" ).First (& updatedFolder ).Error ; err != nil {
917
+ t .Errorf ("Failed to load record. Got: %v" , err )
918
+ }
919
+
920
+ for i , p := range folder .Properties {
921
+ tests .AssertObjEqual (t , p , updatedFolder .Properties [i ], "Seq" , "ID" , "Key" , "Value" )
922
+ }
923
+ }
0 commit comments