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

Commitded46bd

Browse files
author
Peter Mount
committed
Implement UpdateCount
1 parent50eb8b7 commitded46bd

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

‎src/interfaces/jdbc/CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Sun Apr 11 17:00:00 BST 1999
2+
- getUpdateCount() now returns the actual update count (before it
3+
simply returned 1 for everything).
4+
- added some updates to example.basic so it would test the new update
5+
count code.
6+
- corrected typo in a comment in Statement.java
7+
18
Mon Jan 25 19:45:00 GMT 1999
29
- created subfolders example/corba and example/corba/idl to hold the
310
new example showing how to hook CORBA and PostgreSQL via JDBC

‎src/interfaces/jdbc/example/basic.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public void doexample() throws SQLException
7777
st.executeUpdate("insert into basic values (2,1)");
7878
st.executeUpdate("insert into basic values (3,1)");
7979

80+
// Now change the value of b from 1 to 8
81+
st.executeUpdate("update basic set b=8");
82+
System.out.println("Updated "+st.getUpdateCount()+" rows");
83+
8084
// For large inserts, a PreparedStatement is more efficient, because it
8185
// supports the idea of precompiling the SQL statement, and to store
8286
// directly, a Java object into any column. PostgreSQL doesnt support

‎src/interfaces/jdbc/postgresql/Connection.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
importpostgresql.util.*;
1111

1212
/**
13-
* $Id: Connection.java,v 1.14 1999/01/17 04:51:50 momjian Exp $
13+
* $Id: Connection.java,v 1.15 1999/04/11 18:03:00 peter Exp $
1414
*
1515
* This abstract class is used by postgresql.Driver to open either the JDBC1 or
1616
* JDBC2 versions of the Connection class.
@@ -321,6 +321,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
321321
intfqp =0;
322322
booleanhfr =false;
323323
Stringrecv_status =null,msg;
324+
intupdate_count =1;
324325
SQLExceptionfinal_error =null;
325326

326327
if (sql.length() >8192)
@@ -358,6 +359,15 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
358359
break;
359360
case'C':// Command Status
360361
recv_status =pg_stream.ReceiveString(8192);
362+
363+
// Now handle the update count correctly.
364+
if(recv_status.startsWith("INSERT") ||recv_status.startsWith("UPDATE")) {
365+
try {
366+
update_count =Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
367+
}catch(NumberFormatExceptionnfe) {
368+
thrownewSQLException("Unable to fathom update count\""+recv_status+"\"");
369+
}
370+
}
361371
if (fields !=null)
362372
hfr =true;
363373
else
@@ -414,8 +424,8 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
414424
}
415425
if (final_error !=null)
416426
throwfinal_error;
417-
returngetResultSet(this,fields,tuples,recv_status,1);
418-
//returnnew ResultSet(this, fields, tuples, recv_status,1);
427+
428+
returngetResultSet(this,fields,tuples,recv_status,update_count);
419429
}
420430
}
421431

‎src/interfaces/jdbc/postgresql/Statement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Statement (Connection c)
3535
}
3636

3737
/**
38-
* Execute a SQL statement thatretruns a single ResultSet
38+
* Execute a SQL statement thatreturns a single ResultSet
3939
*
4040
* @param sql typically a static SQL SELECT statement
4141
* @return a ResulSet that contains the data produced by the query

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp