Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0daee96

Browse files
author
Dave Cramer
committed
implemented refresh row
1 parent0dbfea3 commit0daee96

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc2/UpdateableResultSet.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ Object getValue() throws SQLException
7676
protectedjava.sql.PreparedStatementdeleteStatement =null;
7777

7878

79-
privatejava.sql.StatementcurrentStatement =null;
79+
/**
80+
* PreparedStatement used to refresh data
81+
*/
82+
privatejava.sql.PreparedStatementselectStatement =null;
8083

8184

8285
/**
@@ -617,6 +620,78 @@ public synchronized void updateObject(int columnIndex, Object x, int scale) thro
617620

618621
}
619622

623+
624+
publicvoidrefreshRow()throwsSQLException
625+
{
626+
if ( !isUpdateable() )
627+
{
628+
thrownewPSQLException("postgresql.updateable.notupdateable" );
629+
}
630+
631+
try
632+
{
633+
StringBufferselectSQL =newStringBuffer("select ");
634+
635+
finalintnumColumns =java.lang.reflect.Array.getLength(fields);
636+
637+
for (inti=0;i <numColumns ;i++ )
638+
{
639+
640+
selectSQL.append(fields[i].getName() );
641+
642+
if (i <numColumns -1 )
643+
{
644+
645+
selectSQL.append(", ");
646+
}
647+
648+
}
649+
selectSQL.append(" from " ).append(tableName).append(" where ");
650+
651+
intnumKeys =primaryKeys.size();
652+
653+
for (inti =0;i <numKeys;i++ )
654+
{
655+
656+
PrimaryKeyprimaryKey = ((PrimaryKey)primaryKeys.get(i));
657+
selectSQL.append(primaryKey.name).append("= ?");
658+
659+
if (i <numKeys -1 )
660+
{
661+
selectSQL.append(" and ");
662+
}
663+
}
664+
if (Driver.logDebug )Driver.debug("selecting "+selectSQL.toString());
665+
selectStatement = ((java.sql.Connection)connection).prepareStatement(selectSQL.toString());
666+
667+
668+
for(intj=0,i=1;j <numKeys;j++,i++)
669+
{
670+
selectStatement.setObject(i, ((PrimaryKey)primaryKeys.get(j)).getValue() );
671+
}
672+
673+
org.postgresql.jdbc2.ResultSetrs = (org.postgresql.jdbc2.ResultSet)selectStatement.executeQuery();
674+
675+
if(rs.first() )
676+
{
677+
rowBuffer =rs.rowBuffer;
678+
}
679+
680+
rows.setElementAt(rowBuffer,current_row );
681+
if (Driver.logDebug )Driver.debug("done updates");
682+
683+
rs.close();
684+
selectStatement.close();
685+
selectStatement =null;
686+
687+
}
688+
catch (Exceptione)
689+
{
690+
if (Driver.logDebug )Driver.debug(e.getClass().getName()+e);
691+
thrownewSQLException(e.getMessage() );
692+
}
693+
694+
}
620695
/**
621696
*
622697
* @throws SQLException

‎src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testUpdateable()
5757
rs.updateString("name","paul");
5858

5959
rs.insertRow();
60-
60+
rs.refreshRow();
6161
assertTrue(rs.getInt("id") ==3 );
6262
assertTrue(rs.getString("name").equals("paul"));
6363
assertTrue(rs.getString("notselected") ==null );

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp