Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractMemoryResultSet对SQL的wasNull实现有问题 #176

Closed
beefluga opened this issue Nov 16, 2016 · 0 comments
Closed

AbstractMemoryResultSet对SQL的wasNull实现有问题 #176

beefluga opened this issue Nov 16, 2016 · 0 comments

Comments

@beefluga
Copy link

beefluga commented Nov 16, 2016

标志位wasNull是在结果集中某个字段的值是SQLNULL的时候会被设置为true,用来表示从ResultSet中获取的值是null。但是当某个字段的值不是null的时候应该及时修改此标志位。

但是AbstractMemoryResultSet的实现中没有及时修正此flag,导致查询的数据会出现一连串的null。

比如,getObject方法应该这样处理wasNull。

    @Override
    public Object getObject(final int columnIndex) throws SQLException {
        Preconditions.checkState(!isClosed(), "Result set is closed");
        Preconditions.checkState(!beforeFirst, "Before start of result set");
        Preconditions.checkState(null != currentRow, "After end of result set");
        Preconditions.checkArgument(currentRow.inRange(columnIndex), String.format("Column Index %d out of range", columnIndex));
        Object result = currentRow.getCell(columnIndex);
        wasNull = null == result;
        return result;
    }

当然还有其他的几个方法同样存在这样的问题。

Java中对此接口的定义如下:

    /**
     * Reports whether
     * the last column read had a value of SQL <code>NULL</code>.
     * Note that you must first call one of the getter methods
     * on a column to try to read its value and then call
     * the method <code>wasNull</code> to see if the value read was
     * SQL <code>NULL</code>.
     *
     * @return <code>true</code> if the last column value read was SQL
     *         <code>NULL</code> and <code>false</code> otherwise
     * @exception SQLException if a database access error occurs or this method is
     *            called on a closed result set
     */
    boolean wasNull() throws SQLException;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants