|
From: Michael K. <ko...@us...> - 2006-05-24 09:03:09
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8047 Modified Files: DBAccessImpl.java Log Message: Corrected problems with PorstgreSQL database server (which does not automatically convert String to column types) Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- DBAccessImpl.java 3 Jan 2006 09:35:20 -0000 1.25 +++ DBAccessImpl.java 24 May 2006 09:02:55 -0000 1.26 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -23,6 +23,7 @@ import org.cobricks.core.CobricksException; import org.cobricks.core.CoreManager; +import org.cobricks.core.util.DateUtil; import org.cobricks.core.util.LogUtil; import org.cobricks.core.util.ResourceUtil; @@ -393,16 +394,26 @@ String aname = (String)i.next(); String type = td.getColumnType(aname); Object o = attrs.get(aname); - if (o == null) - logger.debug("setPrepared "+aname+": NULL"); - else - logger.debug("setPrepared "+aname+": "+o.getClass().getName()); + if (o == null) { + logger.debug("setPrepared "+count+" "+aname+": NULL"); + } else { + if (type.equals("timestamp") && (o instanceof String)) { + // some converting is needed ... + o = DateUtil.string2Date((String)o); + } else + if (type.equals("int") && (o instanceof String)) { + // some converting is needed ... + o = new Integer((String)o); + } + logger.debug("setPrepared "+count+" "+type+" "+aname+": " + +o.getClass().getName()); + } // is the parameter a Set? - then convert it to a String - // tbd ... not perfect yes + // tbd ... not perfect yet if (o instanceof Set) { o = setToString((Set)o); } - count += setPreparedObject(pstmt, o, count); + count = count + setPreparedObject(pstmt, o, count); } } @@ -482,6 +493,15 @@ else if (o instanceof java.sql.Time) { pstmt.setTime(position, (java.sql.Time)o); } + else if (o instanceof java.lang.Integer) { + pstmt.setInt(position, ((java.lang.Integer)o).intValue()); + } + else if (o instanceof java.lang.Float) { + pstmt.setFloat(position, ((java.lang.Float)o).floatValue()); + } + else if (o instanceof java.lang.Long) { + pstmt.setLong(position, ((java.lang.Long)o).longValue()); + } else if (o instanceof byte[]) { pstmt.setBytes(position, (byte[])o); } |