Re: - Mailing list pgsql-jdbc

From vasylenko@uksatse.org.ua
Subject Re:
Date
Msg-id OF4EAC71F4.06A72770-ONC2257261.0030D4E4-C2257261.00316CC6@UKCC.UKSATSE
Whole thread Raw
In response to  (vasylenko@uksatse.org.ua)
Responses Re:
List pgsql-jdbc


Ok, Dave
your question:
>Can you explain this more, or send a small test case. There should be
>no reason to get a primary key simply to move to insert row.
>We do need the primary key in the dataset, but other than that we
>shouldn't fail on move to insert row ?

I have just trased into moveToInsertRow() method step by step.

Firstly, it try to find oid field in result set
Than it looking for Primary Key in result.

That's all what I have done.

there 3 method
moveToInsertRow()
checkUpdateblet()
isUpdateable()

the exception is thrown in the last method.


public synchronized void moveToInsertRow()
    throws SQLException
    {
        checkUpdateable();

        if (insertStatement != null)
        {
            insertStatement = null;
        }


        // make sure the underlying data is null
        clearRowBuffer(false);

        onInsertRow = true;
        doingUpdates = false;

    }



 private void checkUpdateable() throws SQLException
    {
        checkClosed();

        if (!isUpdateable())
            throw new PSQLException(GT.tr("ResultSet is not updateable.
The query that generated this result set must select only one table, and
must select all primary keys from that table. See the JDBC 2.1 API
Specification, section 5.6 for more details."),
                                    PSQLState.INVALID_CURSOR_STATE);

        if (updateValues == null)
        {
            // allow every column to be updated without a rehash.
            updateValues = new HashMap((int)(fields.length / 0.75), 0.75f);
        }
    }






 boolean isUpdateable() throws SQLException
    {
        checkClosed();

        if (resultsetconcurrency == ResultSet.CONCUR_READ_ONLY)
            throw new PSQLException(GT.tr("ResultSets with concurrency
CONCUR_READ_ONLY cannot be updated."),
                                    PSQLState.INVALID_CURSOR_STATE);

        if (updateable)
            return true;

        if ( Driver.logDebug )
            Driver.debug("checking if rs is updateable");

        parseQuery();

        if ( singleTable == false )
        {
            if ( Driver.logDebug )
                Driver.debug("not a single table");
            return false;
        }

        if ( Driver.logDebug )
            Driver.debug("getting primary keys");

        //
        // Contains the primary key?
        //

        primaryKeys = new Vector();

        // this is not stricty jdbc spec, but it will make things much
faster if used
        // the user has to select oid, * from table and then we will just
use oid


        usingOID = false;
        int oidIndex = 0;
        try
        {
            oidIndex = findColumn( "oid" );
        }
        catch (SQLException l_se)
        {
            //Ignore if column oid isn't selected
        }
        int i = 0;


        // if we find the oid then just use it

        //oidIndex will be >0 if the oid was in the select list
        if ( oidIndex > 0 )
        {
            i++;
            primaryKeys.add( new PrimaryKey( oidIndex, "oid" ) );
            usingOID = true;
        }
        else
        {
            // otherwise go and get the primary keys and create a hashtable
of keys
            String[] s = quotelessTableName(tableName);
            String quotelessTableName = s[0];
            String quotelessSchemaName = s[1];
            java.sql.ResultSet rs = ((java.sql.Connection)
connection).getMetaData().getPrimaryKeys("", quotelessSchemaName,
quotelessTableName);
            for (; rs.next(); i++ )
            {
                String columnName = rs.getString(4); // get the columnName
                int index = findColumn( columnName );

                if ( index > 0 )
                {
                    primaryKeys.add( new PrimaryKey(index, columnName ) );
// get the primary key information
                }
            }

            rs.close();
        }

        if ( Driver.logDebug )
            Driver.debug( "no of keys=" + i );

        if ( i < 1 )
        {
            throw new PSQLException(GT.tr("No primary key found for table
{0}.", tableName),
                                    PSQLState.DATA_ERROR);
        }

        updateable = primaryKeys.size() > 0;

        if ( Driver.logDebug )
            Driver.debug( "checking primary key " + updateable );

        return updateable;
    }


pgsql-jdbc by date:

Previous
From: Deval kulshrestha
Date:
Subject: Re: Test db connection to 'jdbc:postgresql://grid-master:5432/arco' ... Failed (1)
Next
From: "Andres Olarte"
Date:
Subject: Re: