|
13 | 13 | * <p>The lifetime of a QueryExecutor object is from sending the query |
14 | 14 | * until the response has been received from the backend. |
15 | 15 | * |
16 | | - * $Id: QueryExecutor.java,v 1.13 2002/07/23 03:59:55 barry Exp $ |
| 16 | + * $Id: QueryExecutor.java,v 1.14 2002/08/23 20:45:49 barry Exp $ |
17 | 17 | */ |
18 | 18 |
|
19 | 19 | public class QueryExecutor |
20 | 20 | { |
21 | 21 |
|
22 | | - private final String sql; |
| 22 | + private final String[] m_sqlFrags; |
| 23 | + private final Object[] m_binds; |
23 | 24 | private final java.sql.Statement statement; |
24 | 25 | private final PG_Stream pg_stream; |
25 | 26 | private final org.postgresql.jdbc1.AbstractJdbc1Connection connection; |
26 | 27 |
|
27 | | - public QueryExecutor(String sql, |
| 28 | + public QueryExecutor(String[] p_sqlFrags, Object[] p_binds, |
28 | 29 | java.sql.Statement statement, |
29 | 30 | PG_Stream pg_stream, |
30 | 31 | java.sql.Connection connection) |
31 | 32 | throws SQLException |
32 | 33 | { |
33 | | - this.sql = sql; |
| 34 | + this.m_sqlFrags = p_sqlFrags; |
| 35 | + this.m_binds = p_binds; |
34 | 36 | this.statement = statement; |
35 | 37 | this.pg_stream = pg_stream; |
36 | 38 | this.connection = (org.postgresql.jdbc1.AbstractJdbc1Connection)connection; |
@@ -60,7 +62,7 @@ public java.sql.ResultSet execute() throws SQLException |
60 | 62 | synchronized (pg_stream) |
61 | 63 | { |
62 | 64 |
|
63 | | - sendQuery(sql); |
| 65 | + sendQuery(); |
64 | 66 |
|
65 | 67 | int c; |
66 | 68 | boolean l_endQuery = false; |
@@ -129,12 +131,18 @@ public java.sql.ResultSet execute() throws SQLException |
129 | 131 | /* |
130 | 132 | * Send a query to the backend. |
131 | 133 | */ |
132 | | - private void sendQuery(String query) throws SQLException |
| 134 | + private void sendQuery() throws SQLException |
133 | 135 | { |
134 | 136 | try |
135 | 137 | { |
136 | 138 | pg_stream.SendChar('Q'); |
137 | | - pg_stream.Send(connection.getEncoding().encode(query)); |
| 139 | + for (int i = 0 ; i < m_binds.length ; ++i) { |
| 140 | + if (m_binds[i] == null) |
| 141 | + throw new PSQLException("postgresql.prep.param", new Integer(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])); |
138 | 146 | pg_stream.SendChar(0); |
139 | 147 | pg_stream.flush(); |
140 | 148 |
|
|
0 commit comments