X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fdb%2FRow.java;h=2200aa1def770bde6b4a75fa3039e2ab9cdcc7b1;hb=a1378c84c773511e4ffe99fb419da67af188aff7;hp=f25b0ae0bd93432e4b2378248794ad2545ca5939;hpb=538190e8467a555615fbaf1ada3eed44631e10b4;p=cfb.git diff --git a/prod/net/jaekl/cfb/db/Row.java b/prod/net/jaekl/cfb/db/Row.java index f25b0ae..2200aa1 100644 --- a/prod/net/jaekl/cfb/db/Row.java +++ b/prod/net/jaekl/cfb/db/Row.java @@ -12,6 +12,11 @@ public class Row { } public int getNumColumns() { return m_columns.length; } + public Column getColumn(int idx) { return m_columns[idx]; } + + public Object getValue(int index) { + return m_values[index]; + } public String getString(int index) throws TypeMismatchException { checkType(index, Column.Type.VARCHAR); @@ -25,24 +30,51 @@ public class Row { return num.intValue(); } - public long getLong(int index) throws TypeMismatchException + public Long getLong(int index) throws TypeMismatchException { checkType(index, Column.Type.INTEGER); + if (null == m_values[index]) { + return null; + } + Number num = (Number)m_values[index]; return num.longValue(); } public java.util.Date getDate(int index) throws TypeMismatchException { - checkType(index, Column.Type.INTEGER); - long milliseconds = (Long)m_values[index]; - java.util.Date date = new java.util.Date(milliseconds); - return date; + checkType(index, Column.Type.TIMESTAMPTZ); + return (java.util.Date)m_values[index]; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder("["); + for (int idx = 0; idx < m_columns.length; ++idx) { + if (idx > 0) { + sb.append(", "); + } + sb.append("" + m_columns[idx].getName() + "=" + m_values[idx]); + } + sb.append("]"); + return sb.toString(); } protected void checkType(int index, Column.Type type) throws TypeMismatchException { Column column = m_columns[index]; - if (column.getType().equals(type)) { + Column.Type columnType = column.getType(); + + if (columnType.equals(Column.Type.TIMESTAMPTZ)) { + // Special case: TIMESTAMPTZ is stored as an INTEGER + if ( Column.Type.TIMESTAMPTZ.equals(type) + || Column.Type.INTEGER.equals(type) ) + { + return; + } + } + + if (columnType.equals(type)) { return; }