KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sqlmagic > tinysql > tinySQLPreparedStatement


1 /*
2  * PreparedStatement object for the tinySQL driver
3  *
4  * A lot of this code is based on or directly taken from
5  * George Reese's (borg@imaginary.com) mSQL driver.
6  *
7  * So, it's probably safe to say:
8  *
9  * Portions of this code Copyright (c) 1996 George Reese
10  *
11  * The rest of it:
12  *
13  * Copyright 1996, Brian C. Jepson
14  * (bjepson@ids.net)
15  *
16  * $Author: davis $
17  * $Date: 2004/12/18 21:31:53 $
18  * $Revision: 1.1 $
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  */

35
36 package com.sqlmagic.tinysql;
37
38
39 import java.sql.SQLException JavaDoc;
40 import java.sql.SQLWarning JavaDoc;
41 import java.sql.ResultSet JavaDoc;
42 import java.sql.Connection JavaDoc;
43 import java.sql.ResultSetMetaData JavaDoc;
44 import java.sql.Date JavaDoc;
45 import java.util.*;
46 import java.math.*;
47
48 /**
49  * @author Thomas Morgner <mgs@sherito.org> statementString contains the last
50  * used SQL-Query. Support for set/getFetchSize, ResultSets are created with a
51  * reference to the creating statement
52  */

53 public class tinySQLPreparedStatement implements java.sql.PreparedStatement JavaDoc {
54
55   /**
56    * Holds the original prepare stement including ? placeholders for
57    * values that will be replaced later.
58    */

59   private String JavaDoc statementString;
60   /**
61    * Holds the list of substitution values to be used in the prepared
62    * statement.
63    */

64   private Vector substitute=(Vector)null;
65   /**
66    * Holds the list of table file objects so that they can be closed
67    * when all the updates have been completed.
68    */

69   private Vector tableList=new Vector();
70   /**
71    * Holds the error message for invalid substitution index.
72    */

73   private String JavaDoc invalidIndex = (String JavaDoc)null;
74   /**
75    * Holds the last used queryString. execute() has to be synchronized,
76    * to guarantee thread-safety
77    */

78   /**
79    *
80    * A connection object to execute queries and... stuff
81    *
82    */

83   private tinySQLConnection connection;
84
85   /**
86    *
87    * A result set returned from this query
88    *
89    */

90   private tinySQLResultSet result;
91   /**
92    *
93    * A set of actions returned by tinySQLParser (see tinySQL.java)
94    *
95    */

96   private Vector actions=(Vector)null;
97
98   /**
99    *
100    * The max field size for tinySQL
101    * This can be pretty big, before things start to break.
102    *
103    */

104   private int max_field_size = 0;
105
106   /**
107    *
108    * The max rows supported by tinySQL
109    * I can't think of any limits, right now, but I'm sure some
110    * will crop up...
111    *
112    */

113   private int max_rows = 65536;
114
115   /**
116    *
117    * The number of seconds the driver will allow for a SQL statement to
118    * execute before giving up. The default is to wait forever (0).
119    *
120    */

121   private int timeout = 0;
122
123   /**
124    * How many rows to fetch in a single run. Default is now 4096 rows.
125    */

126   private int fetchsize = 4096;
127   /**
128    * Debug flag
129    */

130   private static boolean debug=false;
131   /**
132    *
133    * Constructs a new tinySQLStatement object.
134    * @param conn the tinySQLConnection object
135    *
136    */

137   public tinySQLPreparedStatement(tinySQLConnection conn,String JavaDoc inputString) {
138
139     int nextQuestionMark,startAt;
140     connection = conn;
141     startAt = 0;
142     statementString = inputString;
143     while ( (nextQuestionMark=statementString.indexOf("?",startAt)) > -1 )
144     {
145        if ( substitute == (Vector)null ) substitute = new Vector();
146        substitute.addElement(new String JavaDoc(""));
147        startAt = nextQuestionMark + 1;
148     }
149     invalidIndex = " is not in the range 1 to "
150     + Integer.toString(substitute.size());
151     if ( debug ) System.out.println("Prepare statement has " + substitute.size()
152     + " parameters.");
153
154   }
155
156   /**
157    *
158    * Execute an SQL statement and return a result set.
159    * @see java.sql.PreparedStatement#executeQuery
160    * @exception SQLException raised for any errors
161    * @param sql the SQL statement string
162    * @return the result set from the query
163    *
164    */

165   public synchronized ResultSet JavaDoc executeQuery()
166        throws SQLException JavaDoc {
167
168     // tinySQL only supports one result set at a time, so
169
// don't let them get another one, just in case it's
170
// hanging out.
171
//
172
result = null;
173
174     // create a new tinySQLResultSet with the tsResultSet
175
// returned from connection.executetinySQL()
176
//
177
if ( debug) System.out.println("executeQuery conn is " + connection.toString());
178     return new tinySQLResultSet(connection.executetinySQL(this), this);
179
180   }
181   public synchronized ResultSet JavaDoc executeQuery(String JavaDoc sql)
182        throws SQLException JavaDoc {
183
184     // tinySQL only supports one result set at a time, so
185
// don't let them get another one, just in case it's
186
// hanging out.
187
//
188
result = null;
189     statementString = sql;
190
191     // create a new tinySQLResultSet with the tsResultSet
192
// returned from connection.executetinySQL()
193
//
194
if ( debug) System.out.println("executeQuery conn is " + connection.toString());
195     return new tinySQLResultSet(connection.executetinySQL(this), this);
196
197   }
198
199   /**
200    *
201    * Execute an update, insert, delete, create table, etc. This can
202    * be anything that doesn't return rows.
203    * @see java.sql.PreparedStatement#executeUpdate
204    * @exception java.sql.SQLException thrown when an error occurs executing
205    * the SQL
206    * @return either the row count for INSERT, UPDATE or DELETE or 0 for SQL statements that return nothing
207    */

208   public synchronized int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc {
209
210     statementString = sql;
211     return connection.executetinyUpdate(this);
212
213   }
214   public synchronized int executeUpdate() throws SQLException JavaDoc {
215
216     return connection.executetinyUpdate(this);
217
218   }
219
220   /**
221    *
222    * Executes some SQL and returns true or false, depending on
223    * the success. The result set is stored in result, and can
224    * be retrieved with getResultSet();
225    * @see java.sql.PreparedStatement#execute
226    * @exception SQLException raised for any errors
227    * @param sql the SQL to be executed
228    * @return true if there is a result set available
229    */

230   public boolean execute() throws SQLException JavaDoc {
231
232     // a result set object
233
//
234
tsResultSet r;
235
236     // execute the query
237
//
238
r = connection.executetinySQL(this);
239
240     // check for a null result set. If it wasn't null,
241
// use it to create a tinySQLResultSet, and return whether or
242
// not it is null (not null returns true).
243
//
244
if( r == null ) {
245       result = null;
246     } else {
247       result = new tinySQLResultSet(r, this);
248     }
249     return (result != null);
250
251   }
252   public boolean execute(String JavaDoc sql) throws SQLException JavaDoc {
253
254     // a result set object
255
//
256
tsResultSet r;
257     statementString = sql;
258
259     // execute the query
260
//
261
r = connection.executetinySQL(this);
262
263     // check for a null result set. If it wasn't null,
264
// use it to create a tinySQLResultSet, and return whether or
265
// not it is null (not null returns true).
266
//
267
if( r == null ) {
268       result = null;
269     } else {
270       result = new tinySQLResultSet(r, this);
271     }
272     return (result != null);
273
274   }
275
276   /**
277    * Returns the current query-String
278    */

279   public String JavaDoc getSQLString ()
280   {
281     return statementString;
282   }
283
284   /**
285    *
286    * Close any result sets. This is not used by tinySQL.
287    * @see java.sql.PreparedStatement#close
288    *
289    */

290   public void close() throws SQLException JavaDoc
291   {
292      int i;
293      tinySQLTable nextTable;
294      for ( i = 0; i < tableList.size(); i++ )
295      {
296         nextTable = (tinySQLTable)tableList.elementAt(i);
297         if ( debug ) System.out.println("Closing " + nextTable.table);
298         nextTable.close();
299      }
300   }
301
302   /**
303    *
304    * Returns the last result set
305    * @see java.sql.PreparedStatement#getResultSet
306    * @return null if no result set is available, otherwise a result set
307    *
308    */

309   public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc {
310
311     ResultSet JavaDoc r;
312
313     r = result; // save the existing result set
314
result = null; // null out the existing result set
315
return r; // return the previously extant result set
316
}
317
318   /**
319    *
320    * Return the row count of the last operation. tinySQL does not support
321    * this, so it returns -1
322    * @see java.sql.PreparedStatement#getUpdateCount
323    * @return -1
324    */

325   public int getUpdateCount() throws SQLException JavaDoc {
326     return -1;
327   }
328
329   /**
330    *
331    * This returns true if there are any pending result sets. This
332    * should only be true after invoking execute()
333    * @see java.sql.PreparedStatement#getMoreResults
334    * @return true if rows are to be gotten
335    *
336    */

337   public boolean getMoreResults() throws SQLException JavaDoc {
338
339     return (result != null);
340
341   }
342
343   /**
344    *
345    * Get the maximum field size to return in a result set.
346    * @see java.sql.PreparedStatement#getMaxFieldSize
347    * @return the value of max field size
348    *
349    */

350   public int getMaxFieldSize() throws SQLException JavaDoc {
351     return max_field_size;
352   }
353
354   /**
355    *
356    * set the max field size.
357    * @see java.sql.PreparedStatement#setMaxFieldSize
358    * @param max the maximum field size
359    *
360    */

361   public void setMaxFieldSize(int max) throws SQLException JavaDoc {
362     max_field_size = max;
363   }
364
365   /**
366    *
367    * Get the maximum row count that can be returned by a result set.
368    * @see java.sql.PreparedStatement#getMaxRows
369    * @return the maximum rows
370    *
371    */

372   public int getMaxRows() throws SQLException JavaDoc {
373     return max_rows;
374   }
375
376   /**
377    *
378    * Get the maximum row count that can be returned by a result set.
379    * @see java.sql.PreparedStatement.setMaxRows
380    * @param max the max rows
381    *
382    */

383   public void setMaxRows(int max) throws SQLException JavaDoc {
384     max_rows = max;
385   }
386
387   /**
388    *
389    * If escape scanning is on (the default) the driver will do
390    * escape substitution before sending the SQL to the database.
391    * @see java.sql.PreparedStatement#setEscapeProcessing
392    * @param enable this does nothing right now
393    *
394    */

395   public void setEscapeProcessing(boolean enable)
396        throws SQLException JavaDoc {
397     throw new SQLException JavaDoc("The tinySQL Driver doesn't " +
398                            "support escape processing.");
399   }
400
401   /**
402    *
403    * Discover the query timeout.
404    * @see java.sql.PreparedStatement#getQueryTimeout
405    * @see setQueryTimeout
406    * @return the timeout value for this statement
407    *
408    */

409   public int getQueryTimeout() throws SQLException JavaDoc {
410     return timeout;
411   }
412
413   /**
414    *
415    * Set the query timeout.
416    * @see java.sql.PreparedStatement#setQueryTimeout
417    * @see getQueryTimeout
418    * @param x the new query timeout value
419    *
420    */

421   public void setQueryTimeout(int x) throws SQLException JavaDoc {
422     timeout = x;
423   }
424
425   /**
426    *
427    * This can be used by another thread to cancel a statement. This
428    * doesn't matter for tinySQL, as far as I can tell.
429    * @see java.sql.PreparedStatement#cancel
430    *
431    */

432   public void cancel() {
433   }
434
435   /**
436    *
437    * Get the warning chain associated with this Statement
438    * @see java.sql.PreparedStatement#getWarnings
439    * @return the chain of warnings
440    *
441    */

442   public final SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
443     return null;
444   }
445
446   /**
447    *
448    * Clear the warning chain associated with this Statement
449    * @see java.sql.PreparedStatement#clearWarnings
450    *
451    */

452   public void clearWarnings() throws SQLException JavaDoc {
453   }
454
455   /**
456    *
457    * Sets the cursor name for this connection. Presently unsupported.
458    *
459    */

460   public void setCursorName(String JavaDoc unused) throws SQLException JavaDoc {
461     throw new SQLException JavaDoc("tinySQL does not support cursors.");
462   }
463
464     //--------------------------JDBC 2.0-----------------------------
465

466
467     /**
468      * JDBC 2.0
469      *
470      * Gives the driver a hint as to the direction in which
471          * the rows in a result set
472      * will be processed. The hint applies only to result sets created
473      * using this Statement object. The default value is
474      * ResultSet.FETCH_FORWARD.
475      * <p>Note that this method sets the default fetch direction for
476          * result sets generated by this <code>Statement</code> object.
477          * Each result set has its own methods for getting and setting
478          * its own fetch direction.
479      * @param direction the initial direction for processing rows
480      * @exception SQLException if a database access error occurs
481          * or the given direction
482      * is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or
483      * ResultSet.FETCH_UNKNOWN
484      */

485     public void setFetchDirection(int direction) throws SQLException JavaDoc {
486       throw new SQLException JavaDoc("tinySQL does not support setFetchDirection.");
487     }
488
489     /**
490      * JDBC 2.0
491      *
492      * Retrieves the direction for fetching rows from
493          * database tables that is the default for result sets
494          * generated from this <code>Statement</code> object.
495          * If this <code>Statement</code> object has not set
496          * a fetch direction by calling the method <code>setFetchDirection</code>,
497          * the return value is implementation-specific.
498      *
499      * @return the default fetch direction for result sets generated
500          * from this <code>Statement</code> object
501      * @exception SQLException if a database access error occurs
502      */

503     public int getFetchDirection() throws SQLException JavaDoc {
504       throw new SQLException JavaDoc("tinySQL does not support getFetchDirection.");
505     }
506
507     /**
508      * JDBC 2.0
509      *
510      * Gives the JDBC driver a hint as to the number of rows that should
511      * be fetched from the database when more rows are needed. The number
512      * of rows specified affects only result sets created using this
513      * statement. If the value specified is zero, then the hint is ignored.
514      * The default value is zero.
515      *
516      * @param rows the number of rows to fetch
517      * @exception SQLException if a database access error occurs, or the
518      * condition 0 <= rows <= this.getMaxRows() is not satisfied.
519      */

520     public void setFetchSize(int rows) throws SQLException JavaDoc {
521       if ((rows <= 0) || (rows >= this.getMaxRows ()))
522               throw new SQLException JavaDoc ("Condition 0 <= rows <= this.getMaxRows() is not satisfied");
523     
524       fetchsize = rows;
525     }
526
527     /**
528      * JDBC 2.0
529      *
530      * Retrieves the number of result set rows that is the default
531          * fetch size for result sets
532          * generated from this <code>Statement</code> object.
533          * If this <code>Statement</code> object has not set
534          * a fetch size by calling the method <code>setFetchSize</code>,
535          * the return value is implementation-specific.
536      * @return the default fetch size for result sets generated
537          * from this <code>Statement</code> object
538      * @exception SQLException if a database access error occurs
539      */

540     public int getFetchSize() throws SQLException JavaDoc {
541       return fetchsize;
542     }
543
544     /**
545      * JDBC 2.0
546      *
547      * Retrieves the result set concurrency.
548      */

549     public int getResultSetConcurrency() throws SQLException JavaDoc {
550       throw new SQLException JavaDoc("tinySQL does not support ResultSet concurrency.");
551     }
552
553     /**
554      * JDBC 2.0
555      *
556      * Determine the result set type.
557      */

558     public int getResultSetType() throws SQLException JavaDoc {
559       throw new SQLException JavaDoc("tinySQL does not support getResultSetType.");
560     }
561
562     /**
563      * JDBC 2.0
564      *
565      * Adds a SQL command to the current batch of commmands for the statement.
566      * This method is optional.
567      *
568      * @param sql typically this is a static SQL INSERT or UPDATE statement
569      * @exception SQLException if a database access error occurs, or the
570      * driver does not support batch statements
571      */

572     public void addBatch() throws SQLException JavaDoc {
573       throw new SQLException JavaDoc("tinySQL does not support addBatch.");
574     }
575     public void addBatch( String JavaDoc sql ) throws SQLException JavaDoc {
576       throw new SQLException JavaDoc("tinySQL does not support addBatch.");
577     }
578
579     /**
580      * JDBC 2.0
581      *
582      * Makes the set of commands in the current batch empty.
583      * This method is optional.
584      *
585      * @exception SQLException if a database access error occurs or the
586      * driver does not support batch statements
587      */

588     public void clearBatch() throws SQLException JavaDoc {
589       throw new SQLException JavaDoc("tinySQL does not support clearBatch.");
590     }
591
592     /**
593      * JDBC 2.0
594      *
595      * Submits a batch of commands to the database for execution.
596      * This method is optional.
597      *
598      * @return an array of update counts containing one element for each
599      * command in the batch. The array is ordered according
600      * to the order in which commands were inserted into the batch.
601      * @exception SQLException if a database access error occurs or the
602      * driver does not support batch statements
603      */

604     public int[] executeBatch() throws SQLException JavaDoc {
605       throw new SQLException JavaDoc("tinySQL does not support executeBatch.");
606     }
607
608     /**
609      * JDBC 2.0
610      *
611      * Returns the <code>Connection</code> object
612          * that produced this <code>Statement</code> object.
613          * @return the connection that produced this statement
614      * @exception SQLException if a database access error occurs
615      */

616     public Connection JavaDoc getConnection() throws SQLException JavaDoc {
617       throw new SQLException JavaDoc("tinySQL does not support getConnection.");
618     }
619 /*
620  * Set methods for the prepared statement.
621  */

622     public void setBoolean(int parameterIndex,boolean inputValue)
623        throws SQLException JavaDoc
624     {
625        if ( inputValue ) setString(parameterIndex,"TRUE");
626        else setString(parameterIndex,"FALSE");
627     }
628     public void setInt(int parameterIndex,int inputValue)
629        throws SQLException JavaDoc
630     {
631        setString(parameterIndex,Integer.toString(inputValue));
632     }
633     public void setDouble(int parameterIndex,double inputValue)
634        throws SQLException JavaDoc
635     {
636        setString(parameterIndex,Double.toString(inputValue));
637     }
638     public void setBigDecimal(int parameterIndex,BigDecimal inputValue)
639        throws SQLException JavaDoc
640     {
641        setString(parameterIndex,inputValue.toString());
642     }
643     public void setDate(int parameterIndex,java.sql.Date JavaDoc inputValue,
644        java.util.Calendar JavaDoc inputCalendar) throws SQLException JavaDoc
645     {
646        setString(parameterIndex,inputValue.toString());
647     }
648     public void setDate(int parameterIndex,java.sql.Date JavaDoc inputValue)
649        throws SQLException JavaDoc
650     {
651        setString(parameterIndex,inputValue.toString());
652     }
653     public void setTime(int parameterIndex,java.sql.Time JavaDoc inputValue,
654        java.util.Calendar JavaDoc inputCalendar) throws SQLException JavaDoc
655     {
656        setString(parameterIndex,inputValue.toString());
657     }
658     public void setTime(int parameterIndex,java.sql.Time JavaDoc inputValue)
659        throws SQLException JavaDoc
660     {
661        setString(parameterIndex,inputValue.toString());
662     }
663     public void setTimestamp(int parameterIndex,java.sql.Timestamp JavaDoc inputValue,
664        java.util.Calendar JavaDoc inputCalendar ) throws SQLException JavaDoc
665     {
666        setString(parameterIndex,inputValue.toString());
667     }
668     public void setTimestamp(int parameterIndex,java.sql.Timestamp JavaDoc inputValue)
669        throws SQLException JavaDoc
670     {
671        setString(parameterIndex,inputValue.toString());
672     }
673     public void setAsciiStream(int parameterIndex,
674        java.io.InputStream JavaDoc inputValue,int streamLength) throws SQLException JavaDoc
675     {
676        setString(parameterIndex,inputValue.toString());
677     }
678     public void setUnicodeStream(int parameterIndex,
679        java.io.InputStream JavaDoc inputValue,int streamLength) throws SQLException JavaDoc
680     {
681        setString(parameterIndex,inputValue.toString());
682     }
683     public void setBinaryStream(int parameterIndex,
684        java.io.InputStream JavaDoc inputValue,int streamLength) throws SQLException JavaDoc
685     {
686        setString(parameterIndex,inputValue.toString());
687     }
688     public void setCharacterStream(int parameterIndex,
689        java.io.Reader JavaDoc inputValue,int streamLength) throws SQLException JavaDoc
690     {
691        setString(parameterIndex,inputValue.toString());
692     }
693     public void setRef(int parameterIndex,java.sql.Ref JavaDoc inputValue)
694        throws SQLException JavaDoc
695     {
696        setString(parameterIndex,inputValue.toString());
697     }
698     public void setBlob(int parameterIndex,java.sql.Blob JavaDoc inputValue)
699        throws SQLException JavaDoc
700     {
701        setString(parameterIndex,inputValue.toString());
702     }
703     public void setArray(int parameterIndex,java.sql.Array JavaDoc inputValue)
704        throws SQLException JavaDoc
705     {
706        setString(parameterIndex,inputValue.toString());
707     }
708     public void setClob(int parameterIndex,java.sql.Clob JavaDoc inputValue)
709        throws SQLException JavaDoc
710     {
711        setString(parameterIndex,inputValue.toString());
712     }
713     public void setByte(int parameterIndex,byte inputValue)
714        throws SQLException JavaDoc
715     {
716        setString(parameterIndex,Byte.toString(inputValue));
717     }
718     public void setBytes(int parameterIndex,byte[] inputValue)
719        throws SQLException JavaDoc
720     {
721        setString(parameterIndex,Byte.toString(inputValue[0]));
722     }
723     public void setShort(int parameterIndex,short inputValue)
724        throws SQLException JavaDoc
725     {
726        setString(parameterIndex,Short.toString(inputValue));
727     }
728     public void setFloat(int parameterIndex,float inputValue)
729        throws SQLException JavaDoc
730     {
731        setString(parameterIndex,Float.toString(inputValue));
732     }
733     public void setLong(int parameterIndex,long inputValue)
734        throws SQLException JavaDoc
735     {
736        setString(parameterIndex,Long.toString(inputValue));
737     }
738     public void setObject(int parameterIndex,Object JavaDoc inputValue)
739        throws SQLException JavaDoc
740     {
741        setObject(parameterIndex,inputValue,0,0);
742     }
743     public void setObject(int parameterIndex,Object JavaDoc inputValue,
744        int targetSQLType) throws SQLException JavaDoc
745     {
746        setObject(parameterIndex,inputValue,targetSQLType,0);
747     }
748     public void setObject(int parameterIndex,Object JavaDoc inputValue,
749        int targetSQLType, int scale) throws SQLException JavaDoc
750     {
751        setString(parameterIndex,inputValue.toString());
752     }
753     public void setNull(int parameterIndex,int sqlType)
754        throws SQLException JavaDoc
755     {
756        setNull(parameterIndex,sqlType,(String JavaDoc)null);
757     }
758     public void setNull(int parameterIndex,int sqlType,String JavaDoc sqlTypeName)
759        throws SQLException JavaDoc
760     {
761        if ( parameterIndex > substitute.size() )
762           throw new SQLException JavaDoc("Parameter index " + parameterIndex
763           + invalidIndex);
764        substitute.setElementAt((String JavaDoc)null,parameterIndex-1);
765     }
766     public void setString( int parameterIndex, String JavaDoc setString)
767        throws SQLException JavaDoc
768     {
769        if ( parameterIndex > substitute.size() )
770           throw new SQLException JavaDoc("Parameter index " + parameterIndex
771           + invalidIndex);
772        substitute.setElementAt(setString,parameterIndex-1);
773     }
774     public void clearParameters() throws SQLException JavaDoc
775     {
776        substitute.removeAllElements();
777     }
778 /*
779  * Update the actions based upon the contents of the substitute Vector.
780  * Only INSERT and UPDATE commands are supported at this time.
781  */

782     public void updateActions(Vector inputActions) throws SQLException JavaDoc
783     {
784        Vector values,originalValues;
785        Hashtable action;
786        String JavaDoc actionType,valueString;
787        int i,j,subCount;
788        if ( actions == (Vector)null )
789           actions = inputActions;
790        if ( actions == (Vector)null ) return;
791        for ( i = 0; i < actions.size(); i++ )
792        {
793           action = (Hashtable)actions.elementAt(i);
794           actionType = (String JavaDoc)action.get("TYPE");
795           if ( actionType.equals("INSERT") | actionType.equals("UPDATE") )
796           {
797 /*
798  * Look for the original values (with the ? for parameters).
799  */

800              originalValues = (Vector)action.get("ORIGINAL_VALUES");
801              values = (Vector)action.get("VALUES");
802              if ( originalValues == (Vector)null )
803              {
804                 originalValues = (Vector)values.clone();
805                 action.put("ORIGINAL_VALUES",originalValues);
806              }
807              subCount = 0;
808              for ( j = 0; j < originalValues.size(); j++ )
809              {
810                 valueString = (String JavaDoc)originalValues.elementAt(j);
811                 if ( valueString.equals("?") )
812                 {
813                    if ( subCount > substitute.size() - 1 )
814                       throw new SQLException JavaDoc("Substitution index " + subCount
815                       + " not between 0 and "
816                       + Integer.toString(substitute.size() - 1));
817                    values.setElementAt(substitute.elementAt(subCount),j);
818                    subCount++;
819                 }
820              }
821           }
822        }
823     }
824     public void addTable(tinySQLTable inputTable)
825     {
826        int i;
827        tinySQLTable nextTable;
828        for ( i = 0; i < tableList.size(); i++ )
829        {
830           nextTable = (tinySQLTable)tableList.elementAt(i);
831           if ( nextTable.table.equals(inputTable.table) ) return;
832        }
833        tableList.addElement(inputTable);
834     }
835       
836      
837     public Vector getActions()
838     {
839        return actions;
840     }
841     public ResultSetMetaData JavaDoc getMetaData()
842     {
843        return (ResultSetMetaData JavaDoc)null;
844     }
845        
846 }
847
Popular Tags