Subject | Re: Data Type Mappings |
---|---|
Author | rrokytskyy |
Post date | 2002-06-06T22:44:54Z |
Hi,
I will try to answer your questions. In general we perform type
maping according to table defined in JDBC specifications. In
particular this means:
1) one of numeric types (INTEGER, NUMERIC, DOUBLE PRECISION, etc),
value of 1 means true, any other value means false;
2) CHAR or VARCHAR, value of 'Y' or 'TRUE' (ignoring the case) means
true, value of 'N' or 'FALSE' means false, otherwise you get
SQLException;
3) any other type throws SQLException.
otherwise you get SQLException; we support conversion in numeric
types and string types;
INTEGER - java.lang.Integer
NUMERIC(18,0) - java.lang.Long
DOUBLE PRECISION - java.lang.Double
CHAR or VARCHAR - java.lang.String
BLOB with custom type - java.sql.Blob
BLOB SUB_TYPE 0 or 1 - byte[]
TIME - java.sql.Time
DATE - java.sql.Date
TIMESTAMP - java.sql.Timestamp
string fields - convert to string and store as string;
time fields - SQLException
rs.getObject(...) method.
accessing. If no conversion is possible, we throw SQLException. We
try to be intelligent here.
that performs setObject(...):
if (value == null) {
setNull(true);
return;
}
if (value instanceof BigDecimal) {
setBigDecimal((BigDecimal) value);
} else
if (value instanceof Blob) {
if (value instanceof FBBlob)
setBlob((FBBlob)value);
else
setBinaryStream(((Blob) value).getBinaryStream(),
(int)((Blob)value).length());
} else
if (value instanceof Boolean) {
setBoolean(((Boolean) value).booleanValue());
} else
if (value instanceof Byte) {
setByte(((Byte) value).byteValue());
} else
if (value instanceof byte[]) {
setBytes((byte[]) value);
} else
if (value instanceof Date) {
setDate((Date) value);
} else
if (value instanceof Double) {
setDouble(((Double) value).doubleValue());
} else
if (value instanceof Float) {
setFloat(((Float) value).floatValue());
} else
if (value instanceof Integer) {
setInteger(((Integer) value).intValue());
} else
if (value instanceof Long) {
setLong(((Long) value).longValue());
} else
if (value instanceof Short) {
setShort(((Short) value).shortValue());
} else
if (value instanceof String) {
setString((String) value);
} else
if (value instanceof Time) {
setTime((Time) value);
} else
if (value instanceof Timestamp) {
setTimestamp((Timestamp) value);
} else {
throw (SQLException) createException(
OBJECT_CONVERSION_ERROR).fillInStackTrace();
}
You have to pass byte[] with serialized data. That's what persistence
manager usually does. We might add some code to accept
java.io.InputStream, but AFAIK, we are not planning to add generic
serialization mechanism.
Hope this helps.
Best regards,
Roman Rokytskyy
I will try to answer your questions. In general we perform type
maping according to table defined in JDBC specifications. In
particular this means:
> java.sql.ResultSet (or interbase.interclient.ResultSet) :if field is of:
> getBoolean(String columnName)
1) one of numeric types (INTEGER, NUMERIC, DOUBLE PRECISION, etc),
value of 1 means true, any other value means false;
2) CHAR or VARCHAR, value of 'Y' or 'TRUE' (ignoring the case) means
true, value of 'N' or 'FALSE' means false, otherwise you get
SQLException;
3) any other type throws SQLException.
> getByte(String columnName)We try to convert value to byte, if we're successful - we return it,
otherwise you get SQLException; we support conversion in numeric
types and string types;
> getObject(int columnIndex)depends on the type of the field:
INTEGER - java.lang.Integer
NUMERIC(18,0) - java.lang.Long
DOUBLE PRECISION - java.lang.Double
CHAR or VARCHAR - java.lang.String
BLOB with custom type - java.sql.Blob
BLOB SUB_TYPE 0 or 1 - byte[]
TIME - java.sql.Time
DATE - java.sql.Date
TIMESTAMP - java.sql.Timestamp
> andsame as in rs.getBoolean(...) but reversed;
>
> java.sql.PreparedStatement (or
> interbase.interclient.PreparedStatement)
> setBoolean(int parameterIndex,boolean x)
> setByte(int parameterIndex,byte x)numeric fields - store byte value;
string fields - convert to string and store as string;
time fields - SQLException
> setObject(int parameterIndex, Object x)depends on the type of x, in general procedure reversed to one in
rs.getObject(...) method.
> In the InterClient javadocs of PreparedStatement interface I readWe try to convert data from the type of the column to the type you're
> that the boolean is converted to SQL BIT the byte is converted to
> SQL TINYINT, however in the Interbase docs I don't see either of
> these data types. What am I missing?
accessing. If no conversion is possible, we throw SQLException. We
try to be intelligent here.
> If I pass a Serialized object (implementing Serialized interface) toIn general, BLOB. But we do not serialize objects. Here's the code
> setObject(int parameterIndex, Object x) function what should be the
> corresponding data type in the Firebird Sql table?
that performs setObject(...):
if (value == null) {
setNull(true);
return;
}
if (value instanceof BigDecimal) {
setBigDecimal((BigDecimal) value);
} else
if (value instanceof Blob) {
if (value instanceof FBBlob)
setBlob((FBBlob)value);
else
setBinaryStream(((Blob) value).getBinaryStream(),
(int)((Blob)value).length());
} else
if (value instanceof Boolean) {
setBoolean(((Boolean) value).booleanValue());
} else
if (value instanceof Byte) {
setByte(((Byte) value).byteValue());
} else
if (value instanceof byte[]) {
setBytes((byte[]) value);
} else
if (value instanceof Date) {
setDate((Date) value);
} else
if (value instanceof Double) {
setDouble(((Double) value).doubleValue());
} else
if (value instanceof Float) {
setFloat(((Float) value).floatValue());
} else
if (value instanceof Integer) {
setInteger(((Integer) value).intValue());
} else
if (value instanceof Long) {
setLong(((Long) value).longValue());
} else
if (value instanceof Short) {
setShort(((Short) value).shortValue());
} else
if (value instanceof String) {
setString((String) value);
} else
if (value instanceof Time) {
setTime((Time) value);
} else
if (value instanceof Timestamp) {
setTimestamp((Timestamp) value);
} else {
throw (SQLException) createException(
OBJECT_CONVERSION_ERROR).fillInStackTrace();
}
You have to pass byte[] with serialized data. That's what persistence
manager usually does. We might add some code to accept
java.io.InputStream, but AFAIK, we are not planning to add generic
serialization mechanism.
Hope this helps.
Best regards,
Roman Rokytskyy