db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rico Setiawan[i-Sprint]" <rico.l...@i-sprint.com>
Subject org.apache.ddlutils.platform.PlatformImplBase Problem! Urgent!
Date Thu, 19 Apr 2007 07:06:20 GMT
Hi, 

I found a bug at org.apache.ddlutils.platform.PlatformImplBase, when you
want to fecth database per-n data then you will use fecth(...,start,end). 
But it seems the method doesn't work properly.

org.apache.ddlutils.platform.PlatformImplBase at line 990 :

    public List fetch(Database model, String sql, Table[] queryHints, int
start, int end) throws DatabaseOperationException
    {
        Connection connection = borrowConnection();
        Statement  statement  = null;
        ResultSet  resultSet  = null;
        List       result     = new ArrayList();

        try
        {
            statement = connection.createStatement();
            resultSet = statement.executeQuery(sql);

            int rowIdx = 0;

            for (Iterator it = createResultSetIterator(model, resultSet,
queryHints); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++)
            {
                if (rowIdx >= start)
                {
                    result.add(it.next());
                }
            }
        }
        catch (SQLException ex)
        {
            throw new DatabaseOperationException("Error while fetching data
from the database", ex);
        } 
        finally 
        {
            // the iterator should return the connection automatically
            // so this is usually not necessary (but just in case)
            closeStatement(statement);
            returnConnection(connection);
        }
        return result;
    }


Take a look line 1008, the pointer (Iterator it) never come forward if
rowIdx >=start..Indeed at the real case its really possible the start point
is not came from 0..

For example start=10 and end=100

In current code, the pointer will always start from 0 since nobody move that
pointer..

My fixed code : 

                if (rowIdx >= start)
                {
                    result.add(it.next());
                }
                else
                	it.next();

In My fixed code, the pointer will start from 10 since I added it.next();

Regards,
Rico Setiawan,
Software Engineer
i-Sprint Innovations Pte Ltd
http://www.i-sprint.com
Identity & Access Management | Single Sign-On | Strong Authentication
Solutions
Tel: +65 62443900 ext 711
HP : +65 98344699
Fax: +65 62448900

Trust without Boundaries (tm)

Red Herring Asia top 100 companies
http://www.redherring.com/rhasia100/Nomination.html

The information transmitted in this e-mail is confidential and may also be 
privileged, if you are not the intended recipient, please notify the sender 
immediately and delete the original. Any other use of the email by you is 
prohibited.
Thank you.


Mime
View raw message