01: /*
02: $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/sql/SybaseDriver.java,v 1.7 2002/12/17 17:51:07 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with XORM; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm.datastore.sql;
21:
22: import java.sql.PreparedStatement;
23: import java.sql.Types;
24:
25: import org.xorm.datastore.Table;
26:
27: /**
28: * Supports the Sybase database's autoincrement for primary keys.
29: * You must set autoincrement="true" in the mapping.
30: */
31: public class SybaseDriver extends BaseSQLDriver {
32:
33: protected void setObject(PreparedStatement ps, int pos,
34: Object value, String type) throws java.sql.SQLException {
35:
36: /*
37: * Sybase doesn't allow you to use setObject with a null, it throws
38: * an exception. However it doesn't seem to really care what
39: * type is used, we use INTEGER here but have verified that it works
40: * with varchar and timestamp (so why don't they just make setObject
41: * work?)
42: */
43: if (value == null) {
44: ps.setNull(pos, Types.INTEGER);
45: return;
46: }
47: /*
48: * Another hack: Sybase sees Strings longer than 255 characters
49: * as TEXT instead of VARCHAR, which can result in an error if
50: * you're trying to store a long String in a VARCHAR field and
51: * expect it to get truncated. Here, we force it to be handled
52: * as a varchar and truncate it to 255 characters max.
53: */
54: if ((value instanceof String)
55: && ((type == null) || ("varchar".equalsIgnoreCase(type)))) {
56: String strValue = (String) value;
57: if (strValue.length() > 255) {
58: value = strValue.substring(0, 255);
59: }
60: ps.setObject(pos, value, Types.VARCHAR);
61: return;
62: }
63: super .setObject(ps, pos, value, type);
64: }
65: } // class SybaseDriver
|