/** * Create a parameter object for an update, delete or insert statement. * * @param pos the substitution position of the parameter marker in the SQL * @param info the ColInfo column descriptor * @param value the column data item * @return The new parameter as a <code>ParamInfo</code> object. */ protected ParamInfo buildParameter(int pos, ColInfo info, Object value) throws SQLException { int length = 0; if (value instanceof String) { length = ((String) value).length(); } else if (value instanceof byte[]) { length = ((byte[]) value).length; } else if (value instanceof BlobImpl) { BlobImpl blob = (BlobImpl) value; value = blob.getBinaryStream(); length = (int) blob.length(); } else if (value instanceof ClobImpl) { ClobImpl clob = (ClobImpl) value; value = clob.getCharacterStream(); length = (int) clob.length(); } ParamInfo param = new ParamInfo(info, null, value, length); param.isUnicode = info.sqlType.equals("nvarchar") || info.sqlType.equals("nchar") || info.sqlType.equals("ntext"); param.markerPos = pos; return param; }
/** * Set the specified column's data value. * * @param colIndex The index of the column in the row. * @param value The new column value. */ protected void setColValue(int colIndex, int jdbcType, Object value, int length) throws SQLException { super.setColValue(colIndex, jdbcType, value, length); if (!onInsertRow && currentRow == null) { throw new SQLException(Messages.get("error.resultset.norow"), "24000"); } colIndex--; ParamInfo pi; ColInfo ci = columns[colIndex]; if (onInsertRow) { pi = insertRow[colIndex]; if (pi == null) { pi = new ParamInfo(-1); pi.collation = ci.collation; pi.charsetInfo = ci.charsetInfo; insertRow[colIndex] = pi; } } else { if (updateRow == null) { updateRow = new ParamInfo[columnCount]; } pi = updateRow[colIndex]; if (pi == null) { pi = new ParamInfo(-1); pi.collation = ci.collation; pi.charsetInfo = ci.charsetInfo; updateRow[colIndex] = pi; } } if (value == null) { pi.value = null; pi.length = 0; pi.jdbcType = ci.jdbcType; pi.isSet = true; } else { pi.value = value; pi.length = length; pi.isSet = true; pi.jdbcType = jdbcType; pi.isUnicode = ci.sqlType.equals("ntext") || ci.sqlType.equals("nchar") || ci.sqlType.equals("nvarchar"); } }