01: /*
02: * Jython Database Specification API 2.0
03: *
04: * $Id: SQLServerDataHandler.java 2414 2005-02-23 04:26:23Z bzimmer $
05: *
06: * Copyright (c) 2001 brian zimmer <bzimmer@ziclix.com>
07: *
08: */
09: package com.ziclix.python.sql.handler;
10:
11: import com.ziclix.python.sql.DataHandler;
12: import com.ziclix.python.sql.FilterDataHandler;
13: import com.ziclix.python.sql.Procedure;
14: import com.ziclix.python.sql.PyCursor;
15: import com.ziclix.python.sql.procedure.SQLServerProcedure;
16: import org.python.core.Py;
17: import org.python.core.PyObject;
18:
19: import java.sql.ResultSet;
20: import java.sql.SQLException;
21: import java.sql.Types;
22:
23: /**
24: * SQLServer specific data handling.
25: *
26: * @author brian zimmer
27: * @author last revised by $Author: bzimmer $
28: * @version $Revision: 2414 $
29: */
30: public class SQLServerDataHandler extends FilterDataHandler {
31:
32: /**
33: * Field UNICODE_VARCHAR
34: */
35: public static final int UNICODE_VARCHAR = -9;
36:
37: /**
38: * Decorator for handling SQLServer specific issues.
39: *
40: * @param datahandler the delegate DataHandler
41: */
42: public SQLServerDataHandler(DataHandler datahandler) {
43: super (datahandler);
44: }
45:
46: public Procedure getProcedure(PyCursor cursor, PyObject name)
47: throws SQLException {
48: return new SQLServerProcedure(cursor, name);
49: }
50:
51: /**
52: * Given a ResultSet, column and type, return the appropriate
53: * Jython object.
54: * <p/>
55: * <p>Note: DO NOT iterate the ResultSet.
56: *
57: * @param set the current ResultSet set to the current row
58: * @param col the column number (adjusted properly for JDBC)
59: * @param type the column type
60: * @throws SQLException if the type is unmappable
61: */
62: public PyObject getPyObject(ResultSet set, int col, int type)
63: throws SQLException {
64:
65: PyObject obj = Py.None;
66:
67: switch (type) {
68:
69: case UNICODE_VARCHAR:
70: obj = super.getPyObject(set, col, Types.VARCHAR);
71: break;
72:
73: default:
74: obj = super.getPyObject(set, col, type);
75: }
76:
77: return (set.wasNull() || (obj == null)) ? Py.None : obj;
78: }
79: }
|