~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009 Volker Berlin (i-net software)
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
 */
 
24
package sun.jdbc.odbc;
 
25
 
 
26
import java.io.InputStream;
 
27
import java.io.Reader;
 
28
import java.math.BigDecimal;
 
29
import java.net.URL;
 
30
import java.sql.Array;
 
31
import java.sql.Blob;
 
32
import java.sql.Clob;
 
33
import java.sql.Date;
 
34
import java.sql.NClob;
 
35
import java.sql.ParameterMetaData;
 
36
import java.sql.PreparedStatement;
 
37
import java.sql.Ref;
 
38
import java.sql.ResultSet;
 
39
import java.sql.ResultSetMetaData;
 
40
import java.sql.RowId;
 
41
import java.sql.SQLException;
 
42
import java.sql.SQLXML;
 
43
import java.sql.Time;
 
44
import java.sql.Timestamp;
 
45
import java.sql.Types;
 
46
import java.util.Calendar;
 
47
 
 
48
import cli.System.Data.*;
 
49
import cli.System.Data.Common.*;
 
50
import cli.System.Data.Odbc.*;
 
51
 
 
52
/**
 
53
 * @author Volker Berlin
 
54
 */
 
55
public class JdbcOdbcPreparedStatement extends JdbcOdbcStatement implements PreparedStatement{
 
56
 
 
57
    public JdbcOdbcPreparedStatement(JdbcOdbcConnection jdbcConn, OdbcCommand command, String sql, int resultSetType, int resultSetConcurrency){
 
58
        super(jdbcConn, command, resultSetType, resultSetConcurrency);
 
59
        command.set_CommandText(sql);
 
60
        command.Prepare();
 
61
    }
 
62
 
 
63
 
 
64
    public void addBatch() throws SQLException{
 
65
        // TODO Auto-generated method stub
 
66
 
 
67
    }
 
68
 
 
69
 
 
70
    public void clearParameters(){
 
71
        DbParameterCollection params = command.get_Parameters();
 
72
        params.Clear();
 
73
    }
 
74
 
 
75
 
 
76
    public boolean execute() throws SQLException{
 
77
        return super.execute(null);
 
78
    }
 
79
 
 
80
 
 
81
    public ResultSet executeQuery() throws SQLException{
 
82
        return super.executeQuery(null);
 
83
    }
 
84
 
 
85
 
 
86
    public int executeUpdate() throws SQLException{
 
87
        return super.executeUpdate(null);
 
88
    }
 
89
 
 
90
 
 
91
    public ResultSetMetaData getMetaData() throws SQLException{
 
92
        ResultSet rs = getResultSet();
 
93
        if(rs != null){
 
94
            rs.getMetaData();
 
95
        }
 
96
        DbDataReader reader = command.ExecuteReader(CommandBehavior.wrap(CommandBehavior.SchemaOnly));
 
97
        JdbcOdbcResultSetMetaData metadata = new JdbcOdbcResultSetMetaData(reader);
 
98
        reader.Close();
 
99
        return metadata;
 
100
    }
 
101
 
 
102
 
 
103
    public ParameterMetaData getParameterMetaData(){
 
104
        throw new UnsupportedOperationException();
 
105
    }
 
106
 
 
107
 
 
108
    public void setArray(int parameterIndex, Array x) throws SQLException{
 
109
        setObject(parameterIndex, x, Types.ARRAY);
 
110
    }
 
111
 
 
112
 
 
113
    public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException{
 
114
        setObject(parameterIndex, x, Types.LONGVARCHAR);
 
115
    }
 
116
 
 
117
 
 
118
    public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException{
 
119
        setObject(parameterIndex, x, Types.LONGVARCHAR, length);
 
120
    }
 
121
 
 
122
 
 
123
    public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException{
 
124
        setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length);
 
125
    }
 
126
 
 
127
 
 
128
    public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException{
 
129
        setObject(parameterIndex, x, Types.DECIMAL);
 
130
    }
 
131
 
 
132
 
 
133
    public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException{
 
134
        setObject(parameterIndex, x, Types.LONGVARBINARY);
 
135
    }
 
136
 
 
137
 
 
138
    public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException{
 
139
        setObject(parameterIndex, x, Types.LONGVARBINARY, length);
 
140
    }
 
141
 
 
142
 
 
143
    public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException{
 
144
        setObject(parameterIndex, x, Types.LONGVARBINARY, (int)length);
 
145
    }
 
146
 
 
147
 
 
148
    public void setBlob(int parameterIndex, Blob x) throws SQLException{
 
149
        setObject(parameterIndex, x, Types.BLOB);
 
150
    }
 
151
 
 
152
 
 
153
    public void setBlob(int parameterIndex, InputStream x) throws SQLException{
 
154
        setObject(parameterIndex, x, Types.BLOB);
 
155
    }
 
156
 
 
157
 
 
158
    public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException{
 
159
        setObject(parameterIndex, x, Types.BLOB, (int)length);
 
160
    }
 
161
 
 
162
 
 
163
    public void setBoolean(int parameterIndex, boolean x) throws SQLException{
 
164
        setObject(parameterIndex, Boolean.valueOf(x), Types.BOOLEAN);
 
165
    }
 
166
 
 
167
 
 
168
    public void setByte(int parameterIndex, byte x) throws SQLException{
 
169
        setObject(parameterIndex, Byte.valueOf(x), Types.TINYINT);
 
170
    }
 
171
 
 
172
 
 
173
    public void setBytes(int parameterIndex, byte[] x) throws SQLException{
 
174
        setObject(parameterIndex, x, Types.BINARY);
 
175
    }
 
176
 
 
177
 
 
178
    public void setCharacterStream(int parameterIndex, Reader x) throws SQLException{
 
179
        setObject(parameterIndex, x, Types.LONGVARCHAR);
 
180
    }
 
181
 
 
182
 
 
183
    public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException{
 
184
        setObject(parameterIndex, x, Types.NCLOB, length);
 
185
    }
 
186
 
 
187
 
 
188
    public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{
 
189
        setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length);
 
190
    }
 
191
 
 
192
 
 
193
    public void setClob(int parameterIndex, Clob x) throws SQLException{
 
194
        setObject(parameterIndex, x, Types.CLOB);
 
195
    }
 
196
 
 
197
 
 
198
    public void setClob(int parameterIndex, Reader x) throws SQLException{
 
199
        setObject(parameterIndex, x, Types.CLOB);
 
200
    }
 
201
 
 
202
 
 
203
    public void setClob(int parameterIndex, Reader x, long length) throws SQLException{
 
204
        setObject(parameterIndex, x, Types.CLOB, (int)length);
 
205
    }
 
206
 
 
207
 
 
208
    public void setDate(int parameterIndex, Date x) throws SQLException{
 
209
        setObject(parameterIndex, x, Types.DATE);
 
210
    }
 
211
 
 
212
 
 
213
    public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException{
 
214
        JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
 
215
        setObject(parameterIndex, x, Types.DATE);
 
216
    }
 
217
 
 
218
 
 
219
    public void setDouble(int parameterIndex, double x) throws SQLException{
 
220
        setObject(parameterIndex, Double.valueOf(x), Types.DOUBLE);
 
221
    }
 
222
 
 
223
 
 
224
    public void setFloat(int parameterIndex, float x) throws SQLException{
 
225
        setObject(parameterIndex, Float.valueOf(x), Types.FLOAT);
 
226
    }
 
227
 
 
228
 
 
229
    public void setInt(int parameterIndex, int x) throws SQLException{
 
230
        setObject(parameterIndex, Integer.valueOf(x), Types.INTEGER);
 
231
    }
 
232
 
 
233
 
 
234
    public void setLong(int parameterIndex, long x) throws SQLException{
 
235
        setObject(parameterIndex, Long.valueOf(x), Types.BIGINT);
 
236
    }
 
237
 
 
238
 
 
239
    public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException{
 
240
        setObject(parameterIndex, x, Types.LONGNVARCHAR);
 
241
    }
 
242
 
 
243
 
 
244
    public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{
 
245
        setObject(parameterIndex, x, Types.LONGNVARCHAR, (int)length);
 
246
    }
 
247
 
 
248
 
 
249
    public void setNClob(int parameterIndex, NClob x) throws SQLException{
 
250
        setObject(parameterIndex, x, Types.NCLOB);
 
251
    }
 
252
 
 
253
 
 
254
    public void setNClob(int parameterIndex, Reader x) throws SQLException{
 
255
        setObject(parameterIndex, x, Types.NCLOB);
 
256
    }
 
257
 
 
258
 
 
259
    public void setNClob(int parameterIndex, Reader x, long length) throws SQLException{
 
260
        setObject(parameterIndex, x, Types.NCLOB, (int)length);
 
261
    }
 
262
 
 
263
 
 
264
    public void setNString(int parameterIndex, String x) throws SQLException{
 
265
        setObject(parameterIndex, x, Types.NVARCHAR);
 
266
    }
 
267
 
 
268
 
 
269
    public void setNull(int parameterIndex, int sqlType) throws SQLException{
 
270
        setObject(parameterIndex, null, sqlType);
 
271
    }
 
272
 
 
273
 
 
274
    public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException{
 
275
        setObject(parameterIndex, null, sqlType);
 
276
    }
 
277
 
 
278
 
 
279
    public void setObject(int parameterIndex, Object x) throws SQLException{
 
280
        setObject(parameterIndex, x, Types.OTHER, -1);
 
281
    }
 
282
 
 
283
 
 
284
    public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException{
 
285
        setObject(parameterIndex, x, targetSqlType, -1);
 
286
    }
 
287
 
 
288
 
 
289
    public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException{
 
290
        DbParameter para = getPara(parameterIndex);
 
291
        para.set_Value(JdbcOdbcUtils.convertJava2Net(x, scaleOrLength));
 
292
        if(para.get_Direction().Value == ParameterDirection.Output){
 
293
            para.set_Direction(ParameterDirection.wrap(ParameterDirection.InputOutput));
 
294
        }
 
295
        
 
296
        if(targetSqlType != Types.OTHER){
 
297
            para.set_DbType(DbType.wrap(JdbcOdbcUtils.convertJdbc2AdoNetType(targetSqlType)));
 
298
        }
 
299
        
 
300
        if(scaleOrLength >= 0){
 
301
            switch(targetSqlType){
 
302
                case Types.DECIMAL:
 
303
                case Types.NUMERIC:
 
304
                    para.set_Scale((byte)scaleOrLength);
 
305
            }
 
306
        }
 
307
    }
 
308
 
 
309
 
 
310
    public void setRef(int parameterIndex, Ref x) throws SQLException{
 
311
        setObject(parameterIndex, x, Types.REF);
 
312
    }
 
313
 
 
314
 
 
315
    public void setRowId(int parameterIndex, RowId x) throws SQLException{
 
316
        setObject(parameterIndex, x, Types.ROWID);
 
317
    }
 
318
 
 
319
 
 
320
    public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException{
 
321
        setObject(parameterIndex, x, Types.SQLXML);
 
322
    }
 
323
 
 
324
 
 
325
    public void setShort(int parameterIndex, short x) throws SQLException{
 
326
        setObject(parameterIndex, Short.valueOf(x), Types.SMALLINT);
 
327
    }
 
328
 
 
329
 
 
330
    public void setString(int parameterIndex, String x) throws SQLException{
 
331
        setObject(parameterIndex, x, Types.VARCHAR);
 
332
    }
 
333
 
 
334
 
 
335
    public void setTime(int parameterIndex, Time x) throws SQLException{
 
336
        setObject(parameterIndex, x, Types.TIME);
 
337
    }
 
338
 
 
339
 
 
340
    public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException{
 
341
        JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
 
342
        setObject(parameterIndex, x, Types.TIME);
 
343
    }
 
344
 
 
345
 
 
346
    public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException{
 
347
        setObject(parameterIndex, x, Types.TIMESTAMP);
 
348
    }
 
349
 
 
350
 
 
351
    public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException{
 
352
        JdbcOdbcUtils.convertCalendarToLocalDate(x, cal);
 
353
        setObject(parameterIndex, x, Types.TIMESTAMP);
 
354
    }
 
355
 
 
356
 
 
357
    public void setURL(int parameterIndex, URL x) throws SQLException{
 
358
        setObject(parameterIndex, x, Types.DATALINK);
 
359
    }
 
360
 
 
361
 
 
362
    public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException{
 
363
        setObject(parameterIndex, x, Types.LONGNVARCHAR, length);
 
364
    }
 
365
 
 
366
 
 
367
    /**
 
368
     * Get the DbParameter from the current command. If the parameter does not exits in the collection then add it.
 
369
     * 
 
370
     * @param parameterIndex
 
371
     *            The JDBC parameter index starting with 1
 
372
     * @return the DbParameter for the index.
 
373
     * @throws SQLException
 
374
     *             If any error occur.
 
375
     */
 
376
    protected DbParameter getPara(int parameterIndex) throws SQLException{
 
377
        try{
 
378
            DbParameterCollection params = command.get_Parameters();
 
379
            while(params.get_Count() < parameterIndex){
 
380
                params.Add(command.CreateParameter());
 
381
            }
 
382
            return params.get_Item(parameterIndex - 1);
 
383
        }catch(Throwable th){
 
384
            throw JdbcOdbcUtils.createSQLException(th);
 
385
        }
 
386
    }
 
387
}