[Zope-Checkins] CVS: Products/DCOracle2/src - dco2.c:1.103

Matthew T. Kromer matt@zope.com
Thu, 31 Jan 2002 11:52:42 -0500


Update of /cvs-repository/Products/DCOracle2/src
In directory cvs.zope.org:/tmp/cvs-serv21509/src

Modified Files:
	dco2.c 
Log Message:
Apply changes from Marc Wilhelm at Apollis Interactive AG (Mark dot Wilhelm AT 
ai dot AG)


=== Products/DCOracle2/src/dco2.c 1.102 => 1.103 ===
 
 	if (status != OCI_SUCCESS) {
+
+		/* free here the prior allocated statement handle */
+		if (cursor->stmtp != NULL) {
+			TRACE(T_HCALL,("ssA","OCIHandleFree","OCI_HTYPE_STMT",
+				cursor->stmtp));
+			status = OCIHandleFree(cursor->stmtp, OCI_HTYPE_STMT);
+			TRACE(T_HRETURN,("sR","OCIHandleFree",status));
+			if (status != OCI_SUCCESS)
+				fprintf(stderr,"OCI_ERROR %d at %s:%d\n", status,
+					__FILE__, __LINE__ - 3);
+			cursor->stmtp = NULL;
+		}
+		
 		cursor->errhp = NULL;
 		RaiseOCIError(self->envhp, OCI_HTYPE_ENV);
 		Py_DECREF(cursor);
@@ -2830,7 +2843,7 @@
 			self->bind[pos].dty, *indp));
 
 		TRACE((T_CALL | T_INFO),("ssdddd","OCIBindByPos","supplemental",
-			nelem, *nelemp, mode, *alenp));
+			nelem, nelemp, mode, *alenp));
 
 		TRACE((T_CALL | T_INFO),("ssdAAA","OCIBindByPos","arrays",
 			nelem, indp, alenp, rcodep));
@@ -3453,6 +3466,19 @@
 
 	TRACE(T_ENTRY,("sAA", "Cursor_fetch", self, args));
 
+	/* AI-Patch: throw an error if somebody tries to fetch again 
+	** after getting all data out of the cursor without 
+	** reexecuting Cursor_execute. Because this causes remaining 
+	** open cursors in a multithreading environment
+	*/
+	if (self->batchct && self->current==-1)
+	{
+		PyErr_SetString(ProgrammingErrorObject,
+			"Fetch on empty cursor");
+		return NULL;
+	}
+
+
 	/* bindObject may have bound this cursor, in which case we
 	** must refetch the description
 	*/
@@ -3533,7 +3559,7 @@
 		OCIErrorGet(self->errhp, 1, NULL, &errcode, buff,
 			sizeof(buff), OCI_HTYPE_ERROR);
 		/* Oracle errors meaning "end of fetch" 
-		** 1403 is 
+		** 1403 is no data found
 		** 1002 is fetch out of sequence
 		*/
 
@@ -5711,6 +5737,13 @@
 	} else if (precision < 10) {
 		sscanf((char *) data, "%ld", &l);
 		result = PyInt_FromLong(l);
+	} else if (precision == 10 && len<10) {
+		/* AI-Patch: if we have a number(10) db field and
+		** it is possible to store it in an integer variable
+		** then use an PyInt instead of PyLong
+		*/
+		sscanf((char *) data, "%ld", &l);
+		result = PyInt_FromLong(l);
 	} else {
 		result = PyLong_FromString((char *)data, NULL, 10);
 	}
@@ -6398,6 +6431,7 @@
 			TRACE(T_TSWITCH,("sd", "ThreadSwitch", tid));
 		}
 	}
+	
 
 	if (traceNext >= traceCount) traceNext = 0;
 	tr = traceBase + traceNext++;