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

Commitfe2dec7

Browse files
author
Barry Lind
committed
Enhancements to how queries with bind values are stored internally and sent to
the server. Previously we allocated a new String object for the entire finalquery we were sending to the database. If you had a big query, or especiallyif you had large bind values you ended up with essentially two copies in memory.This change will reuse the existing objects and therefore should take 1/2 thememory it does today for a given query. This restructuring will also allowin the future the ability to stream bytea data to the server instead of the current approach of pulling it all into memory.I also fixed a test that was failing on a 7.2 database.Also renamed some internal variables and some minor cleanup. Modified Files: jdbc/org/postgresql/core/QueryExecutor.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
1 parenta2a3192 commitfe2dec7

File tree

6 files changed

+162
-147
lines changed

6 files changed

+162
-147
lines changed

‎src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@
1313
* <p>The lifetime of a QueryExecutor object is from sending the query
1414
* until the response has been received from the backend.
1515
*
16-
* $Id: QueryExecutor.java,v 1.13 2002/07/2303:59:55 barry Exp $
16+
* $Id: QueryExecutor.java,v 1.14 2002/08/2320:45:49 barry Exp $
1717
*/
1818

1919
publicclassQueryExecutor
2020
{
2121

22-
privatefinalStringsql;
22+
privatefinalString[]m_sqlFrags;
23+
privatefinalObject[]m_binds;
2324
privatefinaljava.sql.Statementstatement;
2425
privatefinalPG_Streampg_stream;
2526
privatefinalorg.postgresql.jdbc1.AbstractJdbc1Connectionconnection;
2627

27-
publicQueryExecutor(Stringsql,
28+
publicQueryExecutor(String[]p_sqlFrags,Object[]p_binds,
2829
java.sql.Statementstatement,
2930
PG_Streampg_stream,
3031
java.sql.Connectionconnection)
3132
throwsSQLException
3233
{
33-
this.sql =sql;
34+
this.m_sqlFrags =p_sqlFrags;
35+
this.m_binds =p_binds;
3436
this.statement =statement;
3537
this.pg_stream =pg_stream;
3638
this.connection = (org.postgresql.jdbc1.AbstractJdbc1Connection)connection;
@@ -60,7 +62,7 @@ public java.sql.ResultSet execute() throws SQLException
6062
synchronized (pg_stream)
6163
{
6264

63-
sendQuery(sql);
65+
sendQuery();
6466

6567
intc;
6668
booleanl_endQuery =false;
@@ -129,12 +131,18 @@ public java.sql.ResultSet execute() throws SQLException
129131
/*
130132
* Send a query to the backend.
131133
*/
132-
privatevoidsendQuery(Stringquery)throwsSQLException
134+
privatevoidsendQuery()throwsSQLException
133135
{
134136
try
135137
{
136138
pg_stream.SendChar('Q');
137-
pg_stream.Send(connection.getEncoding().encode(query));
139+
for (inti =0 ;i <m_binds.length ; ++i) {
140+
if (m_binds[i] ==null)
141+
thrownewPSQLException("postgresql.prep.param",newInteger(i +1));
142+
pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[i]));
143+
pg_stream.Send(connection.getEncoding().encode(m_binds[i].toString()));
144+
}
145+
pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[m_binds.length]));
138146
pg_stream.SendChar(0);
139147
pg_stream.flush();
140148

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
importorg.postgresql.util.*;
1414

1515

16-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.4 2002/08/16 19:34:57 davec Exp $
16+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.5 2002/08/23 20:45:49 barry Exp $
1717
* This class defines methods of the jdbc1 specification. This class is
1818
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
1919
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -426,7 +426,26 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
426426
*/
427427
publicjava.sql.ResultSetExecSQL(Stringsql,java.sql.Statementstat)throwsSQLException
428428
{
429-
returnnewQueryExecutor(sql,stat,pg_stream, (java.sql.Connection)this).execute();
429+
returnnewQueryExecutor(newString[] {sql},EMPTY_OBJECT_ARRAY,stat,pg_stream, (java.sql.Connection)this).execute();
430+
}
431+
privatestaticfinalObject[]EMPTY_OBJECT_ARRAY =newObject[0];
432+
433+
/*
434+
* Send a query to the backend. Returns one of the ResultSet
435+
* objects.
436+
*
437+
* <B>Note:</B> there does not seem to be any method currently
438+
* in existance to return the update count.
439+
*
440+
* @param p_sqlFragmentss the SQL statement parts to be executed
441+
* @param p_binds the SQL bind values
442+
* @param stat The Statement associated with this query (may be null)
443+
* @return a ResultSet holding the results
444+
* @exception SQLException if a database error occurs
445+
*/
446+
publicjava.sql.ResultSetExecSQL(String[]p_sqlFragments,Object[]p_binds,java.sql.Statementstat)throwsSQLException
447+
{
448+
returnnewQueryExecutor(p_sqlFragments,p_binds,stat,pg_stream, (java.sql.Connection)this).execute();
430449
}
431450

432451
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp