From torque-user-return-4793-apmail-db-torque-user-archive=db.apache.org@db.apache.org Thu May 06 15:45:11 2004 Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 98043 invoked from network); 6 May 2004 15:45:10 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 6 May 2004 15:45:10 -0000 Received: (qmail 1889 invoked by uid 500); 6 May 2004 15:36:00 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 1825 invoked by uid 500); 6 May 2004 15:36:00 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 1541 invoked from network); 6 May 2004 15:35:59 -0000 Received: from unknown (HELO smtp-gw2.pta.de) (145.253.175.227) by daedalus.apache.org with SMTP; 6 May 2004 15:35:59 -0000 Subject: MSSQL adapter does not handle date values properly To: torque-user@db.apache.org X-Mailer: Lotus Notes Release 5.07a May 14, 2001 Message-ID: From: arne.siegel@pta.de Date: Thu, 6 May 2004 11:22:51 +0200 X-MIMETrack: Serialize by Router on MA_NOTES3/PTA_GL/De(Release 5.0.12 |February 13, 2003) at 05/06/2004 06:05:24 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, this is my first contribution to this list. I'm evaluating Torque 3.1 for use in a small (commercial) project with Microsoft SQL Server 2000 as database. After a few hours I was able to execute the following code fragment: Torque.init("Torque.properties"); Office office = new Office(); office.setOfficeName("Test Office 1"); office.setActive(true); office.setInsDate(new Date()); office.setInsUID("siegel"); office.save(); List offices = OfficePeer.doSelect(new Criteria()); System.out.println("offices = " + offices + "\n"); This worked well. Before going on, I must point out that the INSDATE column is using database type DATETIME, which stores some fractional seconds, too (but not at 1 ms precision, it seems to be around 3 to 4 ms precision). The following code fragment also executed without error, but did not what I expected: for (Iterator i = offices.iterator(); i.hasNext();) { Office o = (Office) i.next(); System.out.println("deleting " + o.getOfficeID() + " ..."); OfficePeer.doDelete(o, conn); System.out.println("... done"); } offices = OfficePeer.doSelect(new Criteria()); System.out.println("offices = " + offices + "\n"); One would expect that all table rows would have been deleted, but they still were all there! After delving into the sources, I found the reason in the DBMSSQL adapter class, which inherits the getDateString implementation from the DBSybase adapter class. That implementation cuts off the fractional part of the Date object. The following modification makes my example code work: public class DBMSSQL extends DBSybase { ... /** date format */ private static final String MSSQL_DATE_FORMAT = "yyyyMMdd HH:mm:ss.SSS" ; public String getDateString(Date date) { char delim = getStringDelimiter(); return (delim + new SimpleDateFormat(MSSQL_DATE_FORMAT).format(date) + delim); } } This leaves one open ISSUE: the failure to delete the object instance on the database should not go unnoticed. A possible solution would be to throw the NoRowsException from the peer doDelete method. To achieve this goal, it seems to be necessary that the BasePeer doDelete method return the number of deleted rows as result value (currently this is a void method, so no problem). The generated Peer doDelete methods which get an object instance or an ObjectKey as its parameter would then have to be extended to evaluate the number of returned rows and throw the proposed exception. Regards, Arne Siegel ********************************************************************** http://www.pta.de Mit 924 Erfahrungsberichten aus 35 Jahren erfolgreicher Projektarbeit! ********************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org