Quadcap Embeddable Database

com/quadcap/jdbc/PreparedStatement.java

Go to the documentation of this file.
00001 package com.quadcap.jdbc; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.IOException; 00042 import java.io.InputStream; 00043 import java.io.Reader; 00044 00045 import java.util.Calendar; 00046 import java.util.Vector; 00047 00048 import java.math.BigDecimal; 00049 00050 //#ifndef JDK11 00051 import java.sql.Array; 00052 import java.sql.Blob; 00053 import java.sql.Clob; 00054 import java.sql.Ref; 00055 //#endif 00056 00057 import java.sql.Date; 00058 import java.sql.SQLException; 00059 import java.sql.SQLWarning; 00060 import java.sql.Time; 00061 import java.sql.Timestamp; 00062 import java.sql.Types; 00063 00064 import antlr.RecognitionException; 00065 00066 import com.quadcap.sql.InsertBlob; 00067 import com.quadcap.sql.ParameterExpression; 00068 import com.quadcap.sql.SQLParser; 00069 import com.quadcap.sql.Stmt; 00070 00071 import com.quadcap.io.AsciiReader; 00072 import com.quadcap.io.ReaderInputStream; 00073 00074 import com.quadcap.sql.file.BlockFile; 00075 00076 import com.quadcap.sql.types.*; 00077 00078 import com.quadcap.util.Debug; 00079 00080 /** 00081 * This class implements the <code>java.sql.PreparedStatement</code> 00082 * interface, and provides facilities for execution of pre-compiled 00083 * SQL statements. This release of QED performs all of the SQL parsing 00084 * during the prepare phase, so that subsequent execution of the 00085 * compiled statement is considerably faster than directly executing 00086 * the statement using the <code>Statement</code> interface. 00087 * 00088 * @author Stan Bailes 00089 */ 00090 public class PreparedStatement extends Statement 00091 implements java.sql.PreparedStatement 00092 { 00093 Stmt stmt; 00094 Vector params; 00095 //#ifdef DEBUG 00096 String sql; 00097 //#endif 00098 00099 /** 00100 * @deprecated in order to not appear in public javadoc 00101 */ 00102 public PreparedStatement(Connection conn, String sql) 00103 throws SQLException, IOException 00104 { 00105 super(conn); 00106 //#ifdef DEBUG 00107 this.sql = sql; 00108 if (Statement.trace.bit(0)) { 00109 Debug.println("prepare(" + sql + ")"); 00110 } 00111 //#endif 00112 session.makeTransaction(); 00113 SQLParser p = new SQLParser(session, sql, escapeProcessing); 00114 String auth = qConn.getAuth(); 00115 try { 00116 stmt = p.statement(); 00117 params = p.getParameters(); 00118 } catch (RecognitionException e) { 00119 throw new SQLException(e.toString(), "42000"); 00120 } catch (antlr.TokenStreamException e) { 00121 throw new SQLException(e.toString(), "Q0010"); 00122 } finally { 00123 // XXX 00124 // This is a hack. 'create schema' will temporarily set the 00125 // 'auth' to the schema name, and this is the first place where 00126 // we get a chance to restore the correct auth. 00127 // 00128 // This is made worse by the fact that names are resolved during 00129 // the parse phase, and could be made better if antlr parser 00130 // rules allowed you to specify a 'finally' handler. 00131 00132 // Also 'create schema' where the schema name is a parameter is 00133 // going to fail badly. 00134 qConn.setAuth(auth, null); 00135 } 00136 } 00137 00138 /** 00139 * This QED release doesn't support batch statement execution. 00140 * 00141 * @exception SQLException "not implemented" 00142 */ 00143 public void addBatch() throws SQLException { 00144 throw new SQLException("not implemented", "0A000"); 00145 } 00146 00147 ParameterExpression getParam(int i) { 00148 return (ParameterExpression)params.elementAt(i-1); 00149 } 00150 00151 /** 00152 * Clear the values of any parameters to this prepared statement; 00153 * i.e., set them all to <code>NULL</code> 00154 * 00155 * @exception SQLException may be thrown 00156 */ 00157 public void clearParameters() throws SQLException { 00158 for (int i = 1; i <= params.size(); i++) { 00159 ParameterExpression pe = getParam(i); 00160 pe.setValue(ValueNull.valueNull); 00161 } 00162 } 00163 00164 /** 00165 * Execute the current SQL statement, returning <code>true</code> 00166 * if the statement generates a <code>ResultSet</code> object. 00167 * 00168 * @return true if execution of the statement results in the creation 00169 * of a <code>ResultSet</code> 00170 * @see #getResultSet() 00171 * @exception SQLException may be thrown 00172 */ 00173 public boolean execute() throws SQLException { 00174 //#ifdef DEBUG 00175 if (Statement.trace.bit(1)) { 00176 Debug.println("PreparedStatement.execute(" + sql + ")"); 00177 } 00178 //#endif 00179 this.rs = null; 00180 this.updateCount = -1; 00181 00182 if (this.qConn.isClosed()) { 00183 throw new SQLException("Connection closed"); 00184 } 00185 try { 00186 session.doStatement(stmt); 00187 this.rs = (ResultSet)session.getResultSet(this); 00188 if (rs != null) { 00189 return true; 00190 } else { 00191 this.updateCount = session.getUpdateCount(); 00192 return false; 00193 } 00194 } catch (IOException e) { 00195 try { 00196 session.endStatement(true); 00197 } catch (IOException e1) {} 00198 throw new SQLException(e.toString(), "Q0011"); 00199 } catch (SQLException e) { 00200 try { 00201 session.endStatement(true); 00202 } catch (IOException e1) {} 00203 throw e; 00204 } catch (Throwable e) { 00205 Debug.print(e); 00206 try { 00207 session.endStatement(true); 00208 } catch (IOException e1) {} 00209 throw new SQLException(e.toString(), "Q0013"); 00210 } 00211 } 00212 00213 /** 00214 * Execute the prepared SQL query statement, returning the 00215 * <code>ResultSet</code> object containing the results of the 00216 * query. 00217 * 00218 * @return a <code>ResultSet</code> object containing the results of 00219 * the query 00220 * @exception SQLException may be thrown 00221 */ 00222 public java.sql.ResultSet executeQuery() throws SQLException { 00223 if (execute()) { 00224 return this.rs; 00225 } else { 00226 return null; 00227 } 00228 } 00229 00230 /** 00231 * Execute the prepared SQL update statement, returning the update 00232 * count, meaning the number of rows updated or inserted by this 00233 * statement. 00234 * 00235 * @return the update count 00236 * @exception SQLException may be thrown 00237 */ 00238 public int executeUpdate() throws SQLException { 00239 if (!execute()) { 00240 return updateCount; 00241 } else { 00242 return 0; 00243 } 00244 } 00245 00246 /** 00247 * QED doesn't implement this feature, which requires information 00248 * about the <code>ResultSet</code> that will be generated by this 00249 * <code>PreparedStatement</code> object when it is executed. 00250 * Instead, first call <code>execute()</code> or 00251 * <code>executeQuery()</code>, then call 00252 * <code>ResultSet.getMetaData()</code> on the 00253 * <code>ResultSet</code> object that is returned. 00254 * 00255 * @return null 00256 */ 00257 public java.sql.ResultSetMetaData getMetaData() { 00258 return null; 00259 } 00260 00261 /** 00262 * Set the statement parameter to the specified character value using an 00263 * <code>InputStream</code> that contains a stream of ASCII bytes. 00264 * The ASCII bytes are converted to Unicode character values before 00265 * being inserted into the database. 00266 * 00267 * @param col the parameter index 00268 * @param is an input stream containing ASCII bytes. 00269 * @param length the number of bytes to read from the stream 00270 * @return an <code>InputStream</code> 00271 * @exception SQLException may be thrown 00272 */ 00273 public void setAsciiStream(int col, InputStream in, int length) 00274 throws SQLException 00275 { 00276 try { 00277 if (in == null) { 00278 setParamValue(col, ValueNull.valueNull); 00279 } else { 00280 ValueClob clob = new ValueClob(session.getDatabase(), 00281 session.makeTransaction(), 00282 new AsciiReader(in), length); 00283 setParamValue(col, clob); 00284 session.doStep(new InsertBlob(session, clob)); 00285 clob.close(); 00286 } 00287 00288 } catch (IOException e) { 00289 Debug.print(e); 00290 throw new SQLException(e.toString(), "Q001H"); 00291 } 00292 } 00293 00294 final void setParamValue(int col, Value v) throws SQLException { 00295 //#ifdef DEBUG 00296 if (Statement.trace.bit(4)) { 00297 Debug.println("setValue(" + col + ", " + v + ")"); 00298 } 00299 //#endif 00300 getParam(col).setValue(v); 00301 } 00302 00303 /** 00304 * Set the statement parameter to the specified 00305 * <code>BigDecimal</code> value. 00306 * 00307 * @param col the parameter index 00308 * @param val the new value 00309 * @exception SQLException may be thrown 00310 */ 00311 public void setBigDecimal(int col, BigDecimal val) throws SQLException { 00312 if (val == null) { 00313 setParamValue(col, ValueNull.valueNull); 00314 } else { 00315 setParamValue(col, new ValueScaledInteger(val)); 00316 } 00317 } 00318 00319 /** 00320 * Set the statement parameter to the specified binary value using an 00321 * <code>InputStream</code> that contains a stream of bytes. 00322 * 00323 * @param col the parameter index 00324 * @param is an input stream containing ASCII bytes. 00325 * @param length the number of bytes to read from the stream 00326 * <p> 00327 * If 'length &gt; 0', then the blob's length will be set to the value 00328 * of the 'length' parameter. 00329 * <p> 00330 * If 'length &lt; 0', then the blob's length will be set to the number 00331 * of bytes read. 00332 * @return an <code>InputStream</code> 00333 * @exception SQLException may be thrown 00334 */ 00335 public void setBinaryStream(int col, InputStream in, int length) 00336 throws SQLException 00337 { 00338 try { 00339 if (in == null) { 00340 setParamValue(col, ValueNull.valueNull); 00341 } else { 00342 ValueBlob blob = new ValueBlob(session.getDatabase(), 00343 session.makeTransaction(), 00344 in, length); 00345 setParamValue(col, blob); 00346 session.doStep(new InsertBlob(session, blob)); 00347 blob.close(); 00348 } 00349 00350 } catch (IOException e) { 00351 Debug.print(e); 00352 throw new SQLException(e.toString(), "Q001H"); 00353 } 00354 } 00355 00356 /** 00357 * Set the statement parameter to the specified 00358 * <code>boolean</code> value. 00359 * 00360 * @param col the parameter index 00361 * @param val the new value 00362 * @exception SQLException may be thrown 00363 */ 00364 public void setBoolean(int col, boolean val) throws SQLException { 00365 setParamValue(col, new ValueBoolean(val)); 00366 } 00367 00368 /** 00369 * Set the statement parameter to the specified 00370 * <code>byte</code> value. 00371 * 00372 * @param col the parameter index 00373 * @param val the new value 00374 * @exception SQLException may be thrown 00375 */ 00376 public void setByte(int col, byte val) throws SQLException { 00377 setParamValue(col, new ValueShort(val)); 00378 } 00379 00380 /** 00381 * Set the statement parameter to the specified 00382 * <code>byte</code> array value. 00383 * 00384 * @param col the parameter index 00385 * @param val the new value 00386 * @exception SQLException may be thrown 00387 */ 00388 public void setBytes(int col, byte[] val) throws SQLException { 00389 if (val == null) { 00390 setParamValue(col, ValueNull.valueNull); 00391 } else { 00392 setParamValue(col, new ValueOctets(val)); 00393 } 00394 } 00395 00396 /** 00397 * Set the statement parameter to the specified character value using a 00398 * <code>Reader</code> that contains a stream of Unicode characters. 00399 * 00400 * @param col the parameter index 00401 * @param r a reader containing the value's characters. 00402 * @param length the number of bytes to read from the stream 00403 * @return an <code>InputStream</code> 00404 * @exception SQLException may be thrown 00405 */ 00406 public void setCharacterStream(int col, Reader r, int length) 00407 throws SQLException 00408 { 00409 try { 00410 if (r == null) { 00411 setParamValue(col, ValueNull.valueNull); 00412 } else { 00413 ValueClob clob = new ValueClob(session.getDatabase(), 00414 session.makeTransaction(), 00415 r, length); 00416 setParamValue(col, clob); 00417 session.doStep(new InsertBlob(session, clob)); 00418 clob.close(); 00419 } 00420 00421 } catch (IOException e) { 00422 Debug.print(e); 00423 throw new SQLException(e.toString(), "Q001H"); 00424 } 00425 } 00426 00427 /** 00428 * Set the statement parameter to the specified 00429 * <code>Date</code> value. 00430 * 00431 * @param col the parameter index 00432 * @param val the new value 00433 * @exception SQLException may be thrown 00434 */ 00435 public void setDate(int col, Date val) throws SQLException { 00436 if (val == null) { 00437 setParamValue(col, ValueNull.valueNull); 00438 } else { 00439 setParamValue(col, new ValueDate(val.getTime())); 00440 } 00441 } 00442 00443 /** 00444 * Set the statement parameter to the specified 00445 * <code>Date</code> value. 00446 * 00447 * @param col the parameter index 00448 * @param val the new value 00449 * @param cal a <code>Calendar<code> object that is used for converting 00450 * the database date to the local timezone. The database date is 00451 * adjusted based on the <code>Calendar</code> timezone and DST offset. 00452 * @exception SQLException may be thrown 00453 */ 00454 public void setDate(int col, Date val, Calendar cal) throws SQLException { 00455 if (val == null) { 00456 setParamValue(col, ValueNull.valueNull); 00457 } else { 00458 cal.setTime(val); 00459 setParamValue(col, new ValueDate(cal.getTime().getTime())); 00460 } 00461 } 00462 00463 /** 00464 * Set the statement parameter to the specified 00465 * <code>double</code> value. 00466 * 00467 * @param col the parameter index 00468 * @param val the new value 00469 * @exception SQLException may be thrown 00470 */ 00471 public void setDouble(int col, double val) throws SQLException { 00472 setParamValue(col, new ValueDouble(val)); 00473 } 00474 00475 /** 00476 * Set the statement parameter to the specified 00477 * <code>float</code> value. 00478 * 00479 * @param col the parameter index 00480 * @param val the new value 00481 * @exception SQLException may be thrown 00482 */ 00483 public void setFloat(int col, float val) throws SQLException { 00484 setParamValue(col, new ValueDouble(val)); 00485 } 00486 00487 /** 00488 * Set the statement parameter to the specified 00489 * <code>int</code> value. 00490 * 00491 * @param col the parameter index 00492 * @param val the new value 00493 * @exception SQLException may be thrown 00494 */ 00495 public void setInt(int col, int val) throws SQLException { 00496 setParamValue(col, new ValueInteger(val)); 00497 } 00498 00499 /** 00500 * Set the statement parameter to the specified 00501 * <code>long</code> value. 00502 * 00503 * @param col the parameter index 00504 * @param val the new value 00505 * @exception SQLException may be thrown 00506 */ 00507 public void setLong(int col, long val) throws SQLException { 00508 setParamValue(col, new ValueLong(val)); 00509 } 00510 00511 /** 00512 * Set the statement parameter to the specified 00513 * <code>null</code> value. 00514 * 00515 * @param col the parameter index 00516 * @param type the JDBC type of the parameter. This is ignored by QED 00517 * because a null is a null is a null. 00518 * @exception SQLException may be thrown 00519 */ 00520 public void setNull(int col, int type) throws SQLException { 00521 setParamValue(col, ValueNull.valueNull); 00522 } 00523 00524 /** 00525 * Set the statement parameter to the specified 00526 * <code>null</code> value. 00527 * 00528 * @param col the parameter index 00529 * @param type the JDBC type of the parameter. This is ignored by QED 00530 * because a null is a null is a null. 00531 * @param typename the fully qualified type name of the parameter. 00532 * This is ignored by QED 00533 * because a null is a null is a null. 00534 * @exception SQLException may be thrown 00535 */ 00536 public void setNull(int col, int type, String typename) 00537 throws SQLException 00538 { 00539 setParamValue(col, ValueNull.valueNull); 00540 } 00541 00542 /** 00543 * Set the statement parameter to the specified 00544 * <code>Object</code> value. 00545 * 00546 * @param col the parameter index 00547 * @param val the new value 00548 * @exception SQLException may be thrown 00549 */ 00550 public void setObject(int col, Object val) throws SQLException { 00551 if (val instanceof Blob) { 00552 Blob blob = (Blob)val; 00553 setBinaryStream(col, blob.getBinaryStream(), (int)blob.length()); 00554 } else if (val instanceof Clob) { 00555 Clob clob = (Clob)val; 00556 setCharacterStream(col, clob.getCharacterStream(), 00557 (int)clob.length()); 00558 } else { 00559 setParamValue(col, Value.fromObject(val)); 00560 } 00561 } 00562 00563 /** 00564 * Set the statement parameter to the specified 00565 * <code>Object</code> value. 00566 * 00567 * @param col the parameter index 00568 * @param val the new value 00569 * @param type the JDBC type of the parameter. 00570 * @exception SQLException may be thrown 00571 */ 00572 public void setObject(int col, Object val, int type) throws SQLException { 00573 Type t = Value.typeForJdbcType(type); 00574 Value v = Value.fromObject(val); 00575 setParamValue(col, t.convert(v)); 00576 } 00577 00578 /** 00579 * Set the statement parameter to the specified 00580 * <code>Object</code> value. 00581 * 00582 * @param col the parameter index 00583 * @param val the new value 00584 * @param type the JDBC type of the parameter. 00585 * @param scale for numeric types, the precision of the value. 00586 * @exception SQLException may be thrown 00587 */ 00588 public void setObject(int col, Object val, int type, int scale) 00589 throws SQLException 00590 { 00591 Value v = Value.fromObject(val); 00592 Type t = null; 00593 switch (type) { 00594 case Types.NUMERIC: 00595 case Types.DECIMAL: 00596 t = new TypeDecimal(32, scale); 00597 break; 00598 default: 00599 t = Value.typeForJdbcType(type); 00600 } 00601 setParamValue(col, t.convert(v)); 00602 } 00603 00604 /** 00605 * Set the statement parameter to the specified 00606 * <code>short</code> value. 00607 * 00608 * @param col the parameter index 00609 * @param val the new value 00610 * @exception SQLException may be thrown 00611 */ 00612 public void setShort(int col, short val) throws SQLException { 00613 setParamValue(col, new ValueShort(val)); 00614 } 00615 00616 /** 00617 * Set the statement parameter to the specified 00618 * <code>String</code> value. 00619 * 00620 * @param col the parameter index 00621 * @param val the new value 00622 * @exception SQLException may be thrown 00623 */ 00624 public void setString(int col, String val) throws SQLException { 00625 if (val == null) { 00626 setParamValue(col, ValueNull.valueNull); 00627 } else { 00628 setParamValue(col, new ValueString(val)); 00629 } 00630 } 00631 00632 /** 00633 * Set the statement parameter to the specified 00634 * <code>Time</code> value. 00635 * 00636 * @param col the parameter index 00637 * @param val the new value 00638 * @exception SQLException may be thrown 00639 */ 00640 public void setTime(int col, Time val) throws SQLException { 00641 if (val == null) { 00642 setParamValue(col, ValueNull.valueNull); 00643 } else { 00644 setParamValue(col, new ValueTime(val.getTime())); 00645 } 00646 } 00647 00648 /** 00649 * Set the statement parameter to the specified 00650 * <code>Time</code> value. 00651 * 00652 * @param col the parameter index 00653 * @param val the new value 00654 * @param cal a <code>Calendar<code> object that is used for converting 00655 * the database date to the local timezone. The database date is 00656 * adjusted based on the <code>Calendar</code> timezone and DST offset. 00657 * @exception SQLException may be thrown 00658 */ 00659 public void setTime(int col, Time val, Calendar cal) throws SQLException { 00660 if (val == null) { 00661 setParamValue(col, ValueNull.valueNull); 00662 } else { 00663 long t = val.getTime(); 00664 cal.setTime(val); 00665 t -= (cal.get(Calendar.ZONE_OFFSET) + 00666 cal.get(Calendar.DST_OFFSET)); 00667 setParamValue(col, new ValueTime(t)); 00668 } 00669 } 00670 00671 /** 00672 * Set the statement parameter to the specified 00673 * <code>Timestamp</code> value. 00674 * 00675 * @param col the parameter index 00676 * @param val the new value 00677 * @exception SQLException may be thrown 00678 */ 00679 public void setTimestamp(int col, Timestamp val) throws SQLException { 00680 if (val == null) { 00681 setParamValue(col, ValueNull.valueNull); 00682 } else { 00683 setParamValue(col, new ValueTimestamp(val)); 00684 } 00685 } 00686 00687 /** 00688 * Set the statement parameter to the specified 00689 * <code>Timestamp</code> value. 00690 * 00691 * @param col the parameter index 00692 * @param val the new value 00693 * @param cal a <code>Calendar<code> object that is used for converting 00694 * the database date to the local timezone. The database date is 00695 * adjusted based on the <code>Calendar</code> timezone and DST offset. 00696 * @exception SQLException may be thrown 00697 */ 00698 public void setTimestamp(int col, Timestamp val, Calendar cal) 00699 throws SQLException 00700 { 00701 if (val == null) { 00702 setParamValue(col, ValueNull.valueNull); 00703 } else { 00704 long t = val.getTime(); 00705 cal.setTime(val); 00706 t -= (cal.get(Calendar.ZONE_OFFSET) + 00707 cal.get(Calendar.DST_OFFSET)); 00708 Timestamp r = new Timestamp(t); 00709 r.setNanos(val.getNanos()); 00710 setParamValue(col, new ValueTimestamp(r)); 00711 } 00712 } 00713 00714 /** 00715 * @deprecated 00716 */ 00717 public void setUnicodeStream(int col, InputStream in, int length) 00718 throws SQLException 00719 { 00720 setBinaryStream(col, in, length); 00721 } 00722 00723 00724 /** 00725 * @deprecated 00726 */ 00727 public PreparedStatement(Connection conn, String sql, 00728 int resultSetType, 00729 int resultSetConcurrency) 00730 throws SQLException, IOException 00731 { 00732 this(conn, sql); 00733 this.resultSetType = resultSetType; 00734 this.resultSetConcurrency = resultSetConcurrency; 00735 } 00736 00737 //#ifndef JDK11 00738 /** 00739 * Set the statement parameter to the specified 00740 * <code>ARRAY</code> value. 00741 * This QED release doesn't support ARRAY types, so a 00742 * "not implemented" exception is thrown 00743 * 00744 * @param col the parameter index 00745 * @param val the new value 00746 * @exception SQLException "not implemented" 00747 */ 00748 public void setArray(int col, Array val) throws SQLException { 00749 throw new SQLException("not implemented", "0A000"); 00750 } 00751 00752 /** 00753 * Set the statement parameter to the specified 00754 * <code>Blob</code> value. 00755 * 00756 * @param col the parameter index 00757 * @param val the new value 00758 * @exception SQLException may be thrown 00759 */ 00760 public void setBlob(int col, Blob val) throws SQLException { 00761 if (val == null) { 00762 setParamValue(col, ValueNull.valueNull); 00763 } else { 00764 if (val instanceof ValueBlob) { 00765 setParamValue(col, (ValueBlob)val); 00766 } else { 00767 setBinaryStream(col, val.getBinaryStream(), 00768 (int)(val.length())); 00769 } 00770 } 00771 } 00772 00773 /** 00774 * Set the statement parameter to the specified 00775 * <code>Clob</code> value. 00776 * 00777 * @param col the parameter index 00778 * @param val the new value 00779 * @exception SQLException may be thrown 00780 */ 00781 public void setClob(int col, Clob val) throws SQLException { 00782 if (val == null) { 00783 setParamValue(col, ValueNull.valueNull); 00784 } else { 00785 setAsciiStream(col, val.getAsciiStream(), (int)(val.length())); 00786 } 00787 } 00788 00789 /** 00790 * Set the statement parameter to the specified 00791 * <code>REF</code> value. 00792 * This QED release doesn't support ARRAY types, so a 00793 * "not implemented" exception is thrown 00794 * 00795 * @param col the parameter index 00796 * @param val the new value 00797 * @exception SQLException "not implemented" 00798 */ 00799 public void setRef(int col, Ref val) throws SQLException { 00800 throw new SQLException("not implemented", "0A000"); 00801 } 00802 00803 //#endif 00804 00805 //------------------------- JDBC 3.0 ----------------------------------- 00806 //#ifdef JDK14 00807 00808 /** 00809 * Sets the designated parameter to the given <code>java.net.URL</code> 00810 * value. 00811 * The driver converts this to an SQL <code>DATALINK</code> value 00812 * when it sends it to the database. 00813 * 00814 * <p>QED simply converts the URL to a string</p> 00815 * 00816 * @param parameterIndex the first parameter is 1, the second is 2, ... 00817 * @param x the <code>java.net.URL</code> object to be set 00818 * @exception SQLException if a database access error occurs 00819 * @since 1.4 00820 */ 00821 public void setURL(int parameterIndex, java.net.URL x) 00822 throws SQLException 00823 { 00824 setString(parameterIndex, x.toString()); 00825 } 00826 00827 00828 /** 00829 * Retrieves the number, types and properties of this 00830 * <code>PreparedStatement</code> object's parameters. 00831 * 00832 * <p><i>QED: Not implemented</i></p> 00833 * 00834 * @return a <code>ParameterMetaData</code> object that contains information 00835 * about the number, types and properties of this 00836 * <code>PreparedStatement</code> object's parameters 00837 * @exception SQLException if a database access error occurs 00838 * @see ParameterMetaData 00839 * @since 1.4 00840 */ 00841 public java.sql.ParameterMetaData getParameterMetaData() 00842 throws SQLException 00843 { 00844 throw new SQLException("Not implemented"); 00845 } 00846 //#endif 00847 00848 public String toString() { 00849 StringBuffer sb = 00850 new StringBuffer("com.quadcap.jdbc.PreparedStatement("); 00851 if (params != null) for (int i = 1; i <= params.size(); i++) { 00852 if (i > 1) sb.append(","); 00853 ParameterExpression e = getParam(i); 00854 Value v = e.getValue(null, null); 00855 sb.append(String.valueOf(v)); 00856 } 00857 sb.append(")"); 00858 return sb.toString(); 00859 } 00860 00861 }