This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 193414
Collapse All | Expand All

(-)../../n2/db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java (-32 / +70 lines)
Lines 68-73 Link Here
68
 */
68
 */
69
public class DBReadWriteHelper {
69
public class DBReadWriteHelper {
70
70
71
    private static final long maxUnsignedInt = 4294967295L;
72
    private static final int maxUnsignedShort = 65535;
73
    private static final short maxUnsignedByte = 255;
71
    private static final Logger mLogger = Logger.getLogger(DBReadWriteHelper.class.getName());
74
    private static final Logger mLogger = Logger.getLogger(DBReadWriteHelper.class.getName());
72
75
73
    @SuppressWarnings(value = "fallthrough") // NOI18N
76
    @SuppressWarnings(value = "fallthrough") // NOI18N
Lines 157-186 Link Here
157
                    return bddata;
160
                    return bddata;
158
                }
161
                }
159
            }
162
            }
160
            case Types.INTEGER: {
163
            case Types.INTEGER: 
161
                int idata = rs.getInt(index);
164
            case Types.SMALLINT: 
162
                if (rs.wasNull()) {
163
                    return null;
164
                } else {
165
                    return new Integer(idata);
166
                }
167
            }
168
            case Types.SMALLINT: {
169
                short sidata = rs.getShort(index);
170
                if (rs.wasNull()) {
171
                    return null;
172
                } else {
173
                    return new Short(sidata);
174
                }
175
            }
176
            case Types.TINYINT: {
165
            case Types.TINYINT: {
177
                // byte primitive data type is not enough for UNSIGNED TINYINT
166
		try {
178
                short tidata = rs.getShort(index);
167
			int idata = rs.getInt(index);
179
                if (rs.wasNull()) {
168
			if (rs.wasNull()) {
180
                    return null;
169
			    return null;
181
                } else {
170
			} else {
182
                    return new Short(tidata);
171
			    return new Integer(idata);
183
                }
172
			}
173
		} catch (java.sql.SQLDataException ex) {
174
			long ldata = rs.getLong(index);
175
			if (rs.wasNull()) {
176
			    return null;
177
			} else {
178
			    return new Long(ldata);
179
			}
180
			
181
		}
184
            }
182
            }
185
            // JDBC/ODBC bridge JDK1.4 brings back -9 for nvarchar columns in
183
            // JDBC/ODBC bridge JDK1.4 brings back -9 for nvarchar columns in
186
            // MS SQL Server tables.
184
            // MS SQL Server tables.
Lines 317-330 Link Here
317
                    break;
315
                    break;
318
316
319
                case Types.INTEGER:
317
                case Types.INTEGER:
320
                    numberObj = (valueObj instanceof Number) ? (Number) valueObj : Integer.valueOf(valueObj.toString());
318
                    numberObj = (valueObj instanceof Number) ? (Number) valueObj : Long.valueOf(valueObj.toString());
321
                    ps.setInt(index, numberObj.intValue());
319
                    if(numberObj.longValue() > ((long) Integer.MAX_VALUE)) {
320
                        ps.setLong(index, numberObj.longValue());
321
                    } else {
322
                        ps.setInt(index, numberObj.intValue());
323
                    }
322
                    break;
324
                    break;
323
325
324
                case Types.SMALLINT:
326
                case Types.SMALLINT:
327
                    numberObj = (valueObj instanceof Number) ? (Number) valueObj : Integer.valueOf(valueObj.toString());
328
                    if(numberObj.longValue() > ((long) Short.MAX_VALUE)) {
329
                        ps.setInt(index, numberObj.intValue());
330
                    } else {
331
                        ps.setShort(index, numberObj.shortValue());
332
                    }
333
                    break;
334
325
                case Types.TINYINT:
335
                case Types.TINYINT:
326
                    numberObj = (valueObj instanceof Number) ? (Number) valueObj : Short.valueOf(valueObj.toString());
336
                    numberObj = (valueObj instanceof Number) ? (Number) valueObj : Short.valueOf(valueObj.toString());
327
                    ps.setShort(index, numberObj.shortValue());
337
                    if(numberObj.longValue() > ((long) Byte.MAX_VALUE)) {
338
                        ps.setShort(index, numberObj.shortValue());
339
                    } else {
340
                        ps.setByte(index, numberObj.byteValue());
341
                    }
328
                    break;
342
                    break;
329
343
330
                case Types.TIMESTAMP:
344
                case Types.TIMESTAMP:
Lines 430-443 Link Here
430
                case Types.NUMERIC:
444
                case Types.NUMERIC:
431
                    return valueObj instanceof BigDecimal ? valueObj : new BigDecimal(valueObj.toString());
445
                    return valueObj instanceof BigDecimal ? valueObj : new BigDecimal(valueObj.toString());
432
446
433
                case Types.INTEGER:
447
                case Types.INTEGER: {
434
                    return valueObj instanceof Integer ? valueObj : new Integer(valueObj.toString());
448
                        long ldata = Long.parseLong(valueObj.toString());
449
                        if(ldata >= ((long) Integer.MIN_VALUE) && ldata <= ((long) Integer.MAX_VALUE)) {
450
                            return new Integer((int) ldata);
451
                        } else if ( ldata < maxUnsignedInt ) {
452
                            return new Long(ldata);
453
                        } else {
454
                            throw new NumberFormatException("Illegal value for java.sql.Type.Integer");
455
                        }
456
                }
435
457
436
                case Types.SMALLINT:
458
                case Types.SMALLINT: {
437
                    return valueObj instanceof Short ? valueObj : new Short(valueObj.toString());
459
                        int idata = Integer.parseInt(valueObj.toString());
460
                        if(idata >= ((int) Short.MIN_VALUE) && idata <= ((int) Short.MAX_VALUE)) {
461
                            return new Short((short) idata);
462
                        } else if ( idata < maxUnsignedShort ) {
463
                            return new Integer(idata);
464
                        } else {
465
                            throw new NumberFormatException("Illegal value for java.sql.Type.SMALLINT");
466
                        }
467
                }
438
468
439
                case Types.TINYINT:
469
                case Types.TINYINT: {
440
                    return valueObj instanceof Byte ? valueObj : new Byte(valueObj.toString());
470
                        short sdata = Short.parseShort(valueObj.toString());
471
                        if(sdata >= ((short) Byte.MIN_VALUE) && sdata <= ((short) Byte.MAX_VALUE)) {
472
                            return new Byte((byte) sdata);
473
                        } else if ( sdata < maxUnsignedByte ) {
474
                            return new Short(sdata);
475
                        } else {
476
                            throw new NumberFormatException("Illegal value for java.sql.Type.TINYINT");
477
                        }
478
                }
441
479
442
                case Types.CHAR:
480
                case Types.CHAR:
443
                case Types.VARCHAR:
481
                case Types.VARCHAR:

Return to bug 193414