@@ -167,6 +167,49 @@ PyObject *Object_New(
167167}
168168
169169
170+ //-----------------------------------------------------------------------------
171+ // Object_Create()
172+ // Create a new object in the OCI.
173+ //-----------------------------------------------------------------------------
174+ static udt_Object * Object_Create (
175+ udt_ObjectType * self ) // type of object to create
176+ {
177+ dvoid * instance ;
178+ udt_Object * obj ;
179+ sword status ;
180+
181+ // create the object instance
182+ status = OCIObjectNew (self -> connection -> environment -> handle ,
183+ self -> connection -> environment -> errorHandle ,
184+ self -> connection -> handle , self -> typeCode , self -> tdo , NULL ,
185+ OCI_DURATION_SESSION , TRUE, & instance );
186+ if (Environment_CheckForError (self -> connection -> environment , status ,
187+ "Object_Create(): create object instance" ) < 0 )
188+ return NULL ;
189+
190+ // create the object
191+ obj = (udt_Object * ) Object_New (self , instance , NULL , 1 );
192+ if (!obj ) {
193+ OCIObjectFree (self -> connection -> environment -> handle ,
194+ self -> connection -> environment -> errorHandle , instance ,
195+ OCI_DEFAULT );
196+ return NULL ;
197+ }
198+
199+ // get the null indicator structure
200+ status = OCIObjectGetInd (self -> connection -> environment -> handle ,
201+ self -> connection -> environment -> errorHandle , instance ,
202+ & obj -> indicator );
203+ if (Environment_CheckForError (self -> connection -> environment , status ,
204+ "Object_Create(): get indicator structure" ) < 0 ) {
205+ Py_DECREF (obj );
206+ return NULL ;
207+ }
208+
209+ return obj ;
210+ }
211+
212+
170213//-----------------------------------------------------------------------------
171214// Object_Free()
172215// Free an object.
@@ -578,6 +621,36 @@ static int Object_InternalAppend(
578621}
579622
580623
624+ //-----------------------------------------------------------------------------
625+ // Object_InternalExtend()
626+ // Extend the collection by appending each of the items in the sequence.
627+ //-----------------------------------------------------------------------------
628+ static int Object_InternalExtend (
629+ udt_Object * self , // object
630+ PyObject * sequence ) // sequence to extend collection with
631+ {
632+ PyObject * fastSequence , * element ;
633+ Py_ssize_t size , i ;
634+
635+ // make sure we are dealing with a collection
636+ if (Object_CheckIsCollection (self ) < 0 )
637+ return -1 ;
638+
639+ // append each of the items in the sequence to the collection
640+ fastSequence = PySequence_Fast (sequence , "expecting sequence" );
641+ if (!fastSequence )
642+ return -1 ;
643+ size = PySequence_Fast_GET_SIZE (fastSequence );
644+ for (i = 0 ; i < size ; i ++ ) {
645+ element = PySequence_Fast_GET_ITEM (fastSequence , i );
646+ if (Object_InternalAppend (self , element ) < 0 )
647+ return -1 ;
648+ }
649+
650+ return 0 ;
651+ }
652+
653+
581654//-----------------------------------------------------------------------------
582655// Object_Append()
583656// Append an item to the collection.
@@ -651,7 +724,7 @@ static PyObject *Object_Copy(
651724 udt_Object * copiedObject ;
652725 sword status ;
653726
654- copiedObject = ( udt_Object * ) ObjectType_NewObject ( self -> objectType , args );
727+ copiedObject = Object_Create ( self -> objectType );
655728 if (!copiedObject )
656729 return NULL ;
657730 environment = self -> objectType -> connection -> environment ;
@@ -730,28 +803,12 @@ static PyObject *Object_Extend(
730803 udt_Object * self , // object
731804 PyObject * args ) // arguments
732805{
733- PyObject * sequence , * fastSequence , * element ;
734- Py_ssize_t size , i ;
806+ PyObject * sequence ;
735807
736- // make sure we are dealing with a collection
737- if (Object_CheckIsCollection (self ) < 0 )
738- return NULL ;
739-
740- // parse arguments
741808 if (!PyArg_ParseTuple (args , "O" , & sequence ))
742809 return NULL ;
743- fastSequence = PySequence_Fast (sequence , "expecting sequence" );
744- if (!fastSequence )
810+ if (Object_InternalExtend (self , sequence ) < 0 )
745811 return NULL ;
746-
747- // append each of the items in the sequence to the collection
748- size = PySequence_Fast_GET_SIZE (fastSequence );
749- for (i = 0 ; i < size ; i ++ ) {
750- element = PySequence_Fast_GET_ITEM (fastSequence , i );
751- if (Object_InternalAppend (self , element ) < 0 )
752- return NULL ;
753- }
754-
755812 Py_RETURN_NONE ;
756813}
757814
0 commit comments