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

Matthew T. Kromer matt@zope.com
Thu, 24 Oct 2002 11:16:45 -0400


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

Modified Files:
	dco2.c 
Log Message:
Make an Oracle date creation routine which will accept input dates that don't
have to be in timestamp form, so that dates don't have to be entered in
string notation (Collector #74).


=== Products/DCOracle2/src/dco2.c 1.122 => 1.123 ===
--- Products/DCOracle2/src/dco2.c:1.122	Mon Oct  7 16:58:17 2002
+++ Products/DCOracle2/src/dco2.c	Thu Oct 24 11:16:44 2002
@@ -609,6 +609,7 @@
 		PyObject *args);
 static void TransactionContext_dealloc(TransactionContext *self);
 static PyObject *OracleDate_alloc(PyObject *self, PyObject *args);
+static PyObject *OracleDate2_alloc(PyObject *self, PyObject *args);
 static void OracleDate_dealloc(OracleDate *self);
 static PyObject *OracleDate_getattr(OracleDate *self, char *name);
 static PyObject *OracleDate_str(OracleDate *self);
@@ -5698,7 +5699,9 @@
 
 	TRACE(T_ENTRY,("sA", "OracleDate_alloc", args));
 
-	if (!PyArg_ParseTuple(args, "i", &ticks)) return NULL;
+	if (!PyArg_ParseTuple(args, "i", &ticks))
+		/* Try the other input routine */
+		return OracleDate2_alloc(self, args);
 
 	TRACE(T_ARGS,("sd","OracleDate_alloc", ticks));
 
@@ -5755,6 +5758,70 @@
 	TRACE(T_EXIT,("sA", "OracleDate_alloc", dateobject));
 
 	return OBJECT(dateobject);
+}
+
+
+/*
+** OracleDate_alloc
+**
+*/
+
+PyObject *OracleDate2_alloc(PyObject *self, PyObject *args) {
+
+	int year = 0;
+	int month = 0;
+	int day = 0;
+	int hour = 0;
+	int minute = 0;
+	int second = 0;
+	unsigned char ocidate[7];
+
+	PyObject *result = NULL;
+
+	PyErr_Clear();
+
+	TRACE(T_ENTRY,("sA", "OracleDate2_alloc", args));
+
+	if (!PyArg_ParseTuple(args, "iii|iii", &year, &month, &day,
+				&hour, &minute, &second)) return NULL;
+
+	TRACE(T_ARGS,("sdddddd","OracleDate2_alloc", year, month, day,
+				hour, minute, second));
+
+
+	if (  year < 0
+	   || year > 9999 
+	   || month < 0
+	   || month > 12
+	   || day < 0
+	   || day > 31
+	   || hour < 0
+	   || hour > 23
+	   || minute < 0
+	   || minute > 59
+	   || second < 0
+	   || second > 59
+	   || (month < 1 && year > 0)
+	   || (day < 1 && year > 0)
+	   ) {
+		PyErr_SetString(PyExc_ValueError,"Invalid date or time");
+		return NULL;
+	}
+
+	ocidate[0] = year / 100 + 100;		/* Century	*/
+	ocidate[1] = year % 100 + 100;		/* Year 	*/
+	ocidate[2] = month;			/* Month	*/
+	ocidate[3] = day;			/* Day		*/
+	ocidate[4] = hour + 1;			/* Hour	 	*/
+	ocidate[5] = minute + 1;		/* Minute	*/
+	ocidate[6] = second + 1;		/* Second	*/
+
+	result = convertOut_SQLT_DAT(SQLT_DAT, 7, 0, 0, &ocidate, NULL);
+
+	TRACE(T_EXIT,("sA", "OracleDate2_alloc", result));
+
+	return result;
+
 }
 
 /*