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

Commitb0146a2

Browse files
author
Barry Lind
committed
Fix in updateable result sets to handle binding null values correctly
Patch submitted by Kris Jurka (applied with some modifications) Modified Files: jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
1 parent3e4978b commitb0146a2

File tree

1 file changed

+42
-151
lines changed

1 file changed

+42
-151
lines changed

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

Lines changed: 42 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
importorg.postgresql.util.PSQLException;
1616

1717

18-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.8 2002/09/11 05:38:45 barry Exp $
18+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.9 2002/10/17 19:17:08 barry Exp $
1919
* This class defines methods of the jdbc2 specification. This class extends
2020
* org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the jdbc1
2121
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2ResultSet
@@ -623,7 +623,11 @@ public synchronized void insertRow()
623623
for (inti =1;keys.hasMoreElements();i++)
624624
{
625625
Stringkey = (String)keys.nextElement();
626-
insertStatement.setObject(i,updateValues.get(key ) );
626+
Objecto =updateValues.get(key);
627+
if (oinstanceofNullObject)
628+
insertStatement.setNull(i,java.sql.Types.NULL);
629+
else
630+
insertStatement.setObject(i,o);
627631
}
628632

629633
insertStatement.executeUpdate();
@@ -735,14 +739,7 @@ public synchronized void updateAsciiStream(int columnIndex,
735739
)
736740
throwsSQLException
737741
{
738-
739-
if ( !isUpdateable() )
740-
{
741-
thrownewPSQLException("postgresql.updateable.notupdateable" );
742-
}
743-
744742
byte[]theData =null;
745-
746743
try
747744
{
748745
x.read(theData,0,length);
@@ -756,9 +753,7 @@ public synchronized void updateAsciiStream(int columnIndex,
756753
thrownewPSQLException("postgresql.updateable.ioerror" +ie);
757754
}
758755

759-
doingUpdates = !onInsertRow;
760-
761-
updateValues.put(fields[columnIndex -1].getName(),theData );
756+
updateValue(columnIndex,theData);
762757

763758
}
764759

@@ -767,15 +762,7 @@ public synchronized void updateBigDecimal(int columnIndex,
767762
java.math.BigDecimalx )
768763
throwsSQLException
769764
{
770-
771-
if ( !isUpdateable() )
772-
{
773-
thrownewPSQLException("postgresql.updateable.notupdateable" );
774-
}
775-
776-
doingUpdates = !onInsertRow;
777-
updateValues.put(fields[columnIndex -1].getName(),x );
778-
765+
updateValue(columnIndex,x);
779766
}
780767

781768

@@ -785,14 +772,7 @@ public synchronized void updateBinaryStream(int columnIndex,
785772
)
786773
throwsSQLException
787774
{
788-
789-
if ( !isUpdateable() )
790-
{
791-
thrownewPSQLException("postgresql.updateable.notupdateable" );
792-
}
793-
794775
byte[]theData =null;
795-
796776
try
797777
{
798778
x.read(theData,0,length);
@@ -806,57 +786,31 @@ public synchronized void updateBinaryStream(int columnIndex,
806786
{
807787
thrownewPSQLException("postgresql.updateable.ioerror" +ie);
808788
}
809-
810-
doingUpdates = !onInsertRow;
811-
812-
updateValues.put(fields[columnIndex -1].getName(),theData );
789+
updateValue(columnIndex,theData);
813790

814791
}
815792

816793

817794
publicsynchronizedvoidupdateBoolean(intcolumnIndex,booleanx)
818795
throwsSQLException
819796
{
820-
821-
if ( !isUpdateable() )
822-
{
823-
thrownewPSQLException("postgresql.updateable.notupdateable" );
824-
}
825-
826797
if (Driver.logDebug )
827798
Driver.debug("updating boolean " +fields[columnIndex -1].getName() +"=" +x);
828-
829-
doingUpdates = !onInsertRow;
830-
updateValues.put(fields[columnIndex -1].getName(),newBoolean(x) );
831-
799+
updateValue(columnIndex,newBoolean(x));
832800
}
833801

834802

835803
publicsynchronizedvoidupdateByte(intcolumnIndex,bytex)
836804
throwsSQLException
837805
{
838-
if ( !isUpdateable() )
839-
{
840-
thrownewPSQLException("postgresql.updateable.notupdateable" );
841-
}
842-
843-
doingUpdates =true;
844-
updateValues.put(fields[columnIndex -1].getName(),String.valueOf(x) );
806+
updateValue(columnIndex,String.valueOf(x));
845807
}
846808

847809

848810
publicsynchronizedvoidupdateBytes(intcolumnIndex,byte[]x)
849811
throwsSQLException
850812
{
851-
852-
if ( !isUpdateable() )
853-
{
854-
thrownewPSQLException("postgresql.updateable.notupdateable" );
855-
}
856-
857-
doingUpdates = !onInsertRow;
858-
updateValues.put(fields[columnIndex -1].getName(),x );
859-
813+
updateValue(columnIndex,x);
860814
}
861815

862816

@@ -866,14 +820,7 @@ public synchronized void updateCharacterStream(int columnIndex,
866820
)
867821
throwsSQLException
868822
{
869-
870-
if ( !isUpdateable() )
871-
{
872-
thrownewPSQLException("postgresql.updateable.notupdateable" );
873-
}
874-
875823
char[]theData =null;
876-
877824
try
878825
{
879826
x.read(theData,0,length);
@@ -887,124 +834,66 @@ public synchronized void updateCharacterStream(int columnIndex,
887834
{
888835
thrownewPSQLException("postgresql.updateable.ioerror" +ie);
889836
}
890-
891-
doingUpdates = !onInsertRow;
892-
updateValues.put(fields[columnIndex -1].getName(),theData);
893-
837+
updateValue(columnIndex,theData);
894838
}
895839

896840

897841
publicsynchronizedvoidupdateDate(intcolumnIndex,java.sql.Datex)
898842
throwsSQLException
899843
{
900-
901-
if ( !isUpdateable() )
902-
{
903-
thrownewPSQLException("postgresql.updateable.notupdateable" );
904-
}
905-
906-
doingUpdates = !onInsertRow;
907-
updateValues.put(fields[columnIndex -1].getName(),x );
844+
updateValue(columnIndex,x);
908845
}
909846

910847

911848
publicsynchronizedvoidupdateDouble(intcolumnIndex,doublex)
912849
throwsSQLException
913850
{
914-
if ( !isUpdateable() )
915-
{
916-
thrownewPSQLException("postgresql.updateable.notupdateable" );
917-
}
918-
919851
if (Driver.logDebug )
920852
Driver.debug("updating double " +fields[columnIndex -1].getName() +"=" +x);
921-
922-
doingUpdates = !onInsertRow;
923-
updateValues.put(fields[columnIndex -1].getName(),newDouble(x) );
924-
853+
updateValue(columnIndex,newDouble(x));
925854
}
926855

927856

928857
publicsynchronizedvoidupdateFloat(intcolumnIndex,floatx)
929858
throwsSQLException
930859
{
931-
if ( !isUpdateable() )
932-
{
933-
thrownewPSQLException("postgresql.updateable.notupdateable" );
934-
}
935-
936860
if (Driver.logDebug )
937861
Driver.debug("updating float " +fields[columnIndex -1].getName() +"=" +x);
938-
939-
doingUpdates = !onInsertRow;
940-
941-
updateValues.put(fields[columnIndex -1].getName(),newFloat(x) );
942-
862+
updateValue(columnIndex,newFloat(x));
943863
}
944864

945865

946866
publicsynchronizedvoidupdateInt(intcolumnIndex,intx)
947867
throwsSQLException
948868
{
949-
if ( !isUpdateable() )
950-
{
951-
thrownewPSQLException("postgresql.updateable.notupdateable" );
952-
}
953-
954869
if (Driver.logDebug )
955870
Driver.debug("updating int " +fields[columnIndex -1].getName() +"=" +x);
956-
957-
doingUpdates = !onInsertRow;
958-
updateValues.put(fields[columnIndex -1].getName(),newInteger(x) );
959-
871+
updateValue(columnIndex,newInteger(x));
960872
}
961873

962874

963875
publicsynchronizedvoidupdateLong(intcolumnIndex,longx)
964876
throwsSQLException
965877
{
966-
if ( !isUpdateable() )
967-
{
968-
thrownewPSQLException("postgresql.updateable.notupdateable" );
969-
}
970-
971878
if (Driver.logDebug )
972879
Driver.debug("updating long " +fields[columnIndex -1].getName() +"=" +x);
973-
974-
doingUpdates = !onInsertRow;
975-
updateValues.put(fields[columnIndex -1].getName(),newLong(x) );
976-
880+
updateValue(columnIndex,newLong(x));
977881
}
978882

979883

980884
publicsynchronizedvoidupdateNull(intcolumnIndex)
981885
throwsSQLException
982886
{
983-
if ( !isUpdateable() )
984-
{
985-
thrownewPSQLException("postgresql.updateable.notupdateable" );
986-
}
987-
988-
doingUpdates = !onInsertRow;
989-
updateValues.put(fields[columnIndex -1].getName(),null);
990-
991-
887+
updateValue(columnIndex,newNullObject());
992888
}
993889

994890

995891
publicsynchronizedvoidupdateObject(intcolumnIndex,Objectx)
996892
throwsSQLException
997893
{
998-
if ( !isUpdateable() )
999-
{
1000-
thrownewPSQLException("postgresql.updateable.notupdateable" );
1001-
}
1002-
1003894
if (Driver.logDebug )
1004895
Driver.debug("updating object " +fields[columnIndex -1].getName() +" = " +x);
1005-
1006-
doingUpdates = !onInsertRow;
1007-
updateValues.put(fields[columnIndex -1].getName(),x );
896+
updateValue(columnIndex,x);
1008897
}
1009898

1010899

@@ -1152,7 +1041,11 @@ public synchronized void updateRow()
11521041
Iteratoriterator =updateValues.values().iterator();
11531042
for (;iterator.hasNext();i++)
11541043
{
1155-
updateStatement.setObject(i +1,iterator.next() );
1044+
Objecto =iterator.next();
1045+
if (oinstanceofNullObject)
1046+
updateStatement.setNull(i+1,java.sql.Types.NULL);
1047+
else
1048+
updateStatement.setObject(i +1,o );
11561049

11571050
}
11581051
for (intj =0;j <numKeys;j++,i++)
@@ -1194,11 +1087,7 @@ public synchronized void updateShort(int columnIndex, short x)
11941087
{
11951088
if (Driver.logDebug )
11961089
Driver.debug("in update Short " +fields[columnIndex -1].getName() +" = " +x);
1197-
1198-
1199-
doingUpdates = !onInsertRow;
1200-
updateValues.put(fields[columnIndex -1].getName(),newShort(x) );
1201-
1090+
updateValue(columnIndex,newShort(x));
12021091
}
12031092

12041093

@@ -1207,10 +1096,7 @@ public synchronized void updateString(int columnIndex, String x)
12071096
{
12081097
if (Driver.logDebug )
12091098
Driver.debug("in update String " +fields[columnIndex -1].getName() +" = " +x);
1210-
1211-
doingUpdates = !onInsertRow;
1212-
updateValues.put(fields[columnIndex -1].getName(),x );
1213-
1099+
updateValue(columnIndex,x);
12141100
}
12151101

12161102

@@ -1219,11 +1105,7 @@ public synchronized void updateTime(int columnIndex, Time x)
12191105
{
12201106
if (Driver.logDebug )
12211107
Driver.debug("in update Time " +fields[columnIndex -1].getName() +" = " +x);
1222-
1223-
1224-
doingUpdates = !onInsertRow;
1225-
updateValues.put(fields[columnIndex -1].getName(),x );
1226-
1108+
updateValue(columnIndex,x);
12271109
}
12281110

12291111

@@ -1232,10 +1114,7 @@ public synchronized void updateTimestamp(int columnIndex, Timestamp x)
12321114
{
12331115
if (Driver.logDebug )
12341116
Driver.debug("updating Timestamp " +fields[columnIndex -1].getName() +" = " +x);
1235-
1236-
doingUpdates = !onInsertRow;
1237-
updateValues.put(fields[columnIndex -1].getName(),x );
1238-
1117+
updateValue(columnIndex,x);
12391118

12401119
}
12411120

@@ -1564,6 +1443,17 @@ public void setStatement(Statement statement)
15641443
this.statement =statement;
15651444
}
15661445

1446+
protectedvoidupdateValue(intcolumnIndex,Objectvalue)throwsSQLException {
1447+
if ( !isUpdateable() )
1448+
{
1449+
thrownewPSQLException("postgresql.updateable.notupdateable" );
1450+
}
1451+
doingUpdates = !onInsertRow;
1452+
if (value ==null)
1453+
updateNull(columnIndex);
1454+
else
1455+
updateValues.put(fields[columnIndex -1].getName(),value);
1456+
}
15671457

15681458
privateclassPrimaryKey
15691459
{
@@ -1581,7 +1471,8 @@ Object getValue() throws SQLException
15811471
}
15821472
};
15831473

1584-
1474+
classNullObject {
1475+
};
15851476

15861477
}
15871478

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp