KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > SQLParser


1 /* Generated By:JavaCC: Do not edit this line. SQLParser.java */
2 /*
3
4    Derby - File org.apache.derby.impl.sql.compile.sqlgrammar.jj
5
6    Licensed to the Apache Software Foundation (ASF) under one or more
7    contributor license agreements. See the NOTICE file distributed with
8    this work for additional information regarding copyright ownership.
9    The ASF licenses this file to you under the Apache License, Version 2.0
10    (the "License"); you may not use this file except in compliance with
11    the License. You may obtain a copy of the License at
12
13       http://www.apache.org/licenses/LICENSE-2.0
14
15    Unless required by applicable law or agreed to in writing, software
16    distributed under the License is distributed on an "AS IS" BASIS,
17    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18    See the License for the specific language governing permissions and
19    limitations under the License.
20
21 */

22
23 package org.apache.derby.impl.sql.compile;
24
25 import org.apache.derby.iapi.sql.Statement;
26 import org.apache.derby.iapi.sql.StatementType;
27
28 /* aggregates */
29 import org.apache.derby.impl.sql.compile.CountAggregateDefinition;
30 import org.apache.derby.impl.sql.compile.MaxMinAggregateDefinition;
31 import org.apache.derby.impl.sql.compile.SumAvgAggregateDefinition;
32
33 import org.apache.derby.impl.sql.compile.AggregateNode;
34 import org.apache.derby.impl.sql.compile.BinaryOperatorNode;
35 import org.apache.derby.impl.sql.compile.CallStatementNode;
36 import org.apache.derby.impl.sql.compile.CharConstantNode;
37 import org.apache.derby.impl.sql.compile.CastNode;
38 import org.apache.derby.impl.sql.compile.ColumnDefinitionNode;
39 import org.apache.derby.impl.sql.compile.ColumnReference;
40 import org.apache.derby.impl.sql.compile.CursorNode;
41 import org.apache.derby.impl.sql.compile.FromBaseTable;
42 import org.apache.derby.impl.sql.compile.FromList;
43 import org.apache.derby.impl.sql.compile.FromSubquery;
44 import org.apache.derby.impl.sql.compile.FromTable;
45 import org.apache.derby.impl.sql.compile.GroupByList;
46 import org.apache.derby.impl.sql.compile.HasNodeVisitor;
47 import org.apache.derby.impl.sql.compile.JavaToSQLValueNode;
48 import org.apache.derby.impl.sql.compile.JoinNode;
49 import org.apache.derby.impl.sql.compile.MethodCallNode;
50 import org.apache.derby.impl.sql.compile.QueryTreeNode;
51 import org.apache.derby.impl.sql.compile.ReplaceAggregatesWithCRVisitor;
52 import org.apache.derby.impl.sql.compile.ResultColumnList;
53 import org.apache.derby.impl.sql.compile.ResultColumn;
54 import org.apache.derby.impl.sql.compile.OrderByList;
55 import org.apache.derby.impl.sql.compile.OrderByColumn;
56 import org.apache.derby.impl.sql.compile.ResultSetNode;
57 import org.apache.derby.impl.sql.compile.SelectNode;
58 import org.apache.derby.impl.sql.compile.SubqueryNode;
59 import org.apache.derby.impl.sql.compile.TableName;
60 import org.apache.derby.impl.sql.compile.TernaryOperatorNode;
61 import org.apache.derby.impl.sql.compile.ParameterNode;
62 import org.apache.derby.impl.sql.compile.PrivilegeNode;
63 import org.apache.derby.impl.sql.compile.ConstraintDefinitionNode;
64 import org.apache.derby.impl.sql.compile.DMLModStatementNode;
65 import org.apache.derby.impl.sql.compile.RoutineDesignator;
66 import org.apache.derby.impl.sql.compile.StatementNode;
67 import org.apache.derby.impl.sql.compile.TableElementList;
68 import org.apache.derby.impl.sql.compile.TableElementNode;
69 import org.apache.derby.impl.sql.compile.TableOperatorNode;
70 import org.apache.derby.impl.sql.compile.TablePrivilegesNode;
71 import org.apache.derby.impl.sql.compile.TransactionStatementNode;
72 import org.apache.derby.impl.sql.compile.TriggerReferencingStruct;
73 import org.apache.derby.impl.sql.compile.UnionNode;
74 import org.apache.derby.impl.sql.compile.IntersectOrExceptNode;
75 import org.apache.derby.impl.sql.compile.UnaryOperatorNode;
76 import org.apache.derby.impl.sql.compile.UntypedNullConstantNode;
77 import org.apache.derby.impl.sql.compile.UpdateNode;
78 import org.apache.derby.impl.sql.compile.UserTypeConstantNode;
79 import org.apache.derby.impl.sql.compile.ValueNode;
80 import org.apache.derby.impl.sql.compile.ValueNodeList;
81 import org.apache.derby.impl.sql.compile.GroupByColumn;
82 import org.apache.derby.impl.sql.compile.CurrentDatetimeOperatorNode;
83 import org.apache.derby.impl.sql.compile.DDLStatementNode;
84 import org.apache.derby.impl.sql.compile.AlterTableNode;
85
86 import org.apache.derby.impl.sql.compile.ParseException;
87 import org.apache.derby.impl.sql.compile.Token;
88 import org.apache.derby.impl.sql.compile.TokenMgrError;
89 import org.apache.derby.impl.sql.compile.SQLParserConstants;
90 import org.apache.derby.impl.sql.compile.CharStream;
91 import org.apache.derby.impl.sql.execute.TablePrivilegeInfo;
92 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
93 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
94 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;
95 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;
96 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
97
98 import org.apache.derby.iapi.sql.conn.Authorizer;
99 import org.apache.derby.iapi.sql.execute.ConstantAction;
100 import org.apache.derby.iapi.sql.execute.ExecutionContext;
101
102 import org.apache.derby.iapi.types.DataTypeDescriptor;
103 import org.apache.derby.iapi.types.TypeId;
104 import org.apache.derby.iapi.sql.compile.TypeCompiler;
105 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
106
107 import org.apache.derby.iapi.types.DateTimeDataValue;
108 import org.apache.derby.iapi.types.DataTypeDescriptor;
109 import org.apache.derby.iapi.types.DataTypeUtilities;
110 import org.apache.derby.iapi.types.StringDataValue;
111 import org.apache.derby.iapi.types.DataValueDescriptor;
112
113 import org.apache.derby.iapi.error.StandardException;
114
115 import org.apache.derby.iapi.reference.Property;
116 import org.apache.derby.iapi.reference.SQLState;
117 import org.apache.derby.iapi.reference.JDBC30Translation;
118 import org.apache.derby.iapi.reference.Limits;
119
120 import org.apache.derby.iapi.sql.compile.CompilerContext;
121 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
122
123 import org.apache.derby.iapi.services.context.ContextManager;
124
125 import org.apache.derby.iapi.sql.compile.NodeFactory;
126
127 import org.apache.derby.iapi.services.sanity.SanityManager;
128
129 import org.apache.derby.catalog.AliasInfo;
130 import org.apache.derby.catalog.TypeDescriptor;
131 import org.apache.derby.catalog.types.RoutineAliasInfo;
132
133 import org.apache.derby.iapi.services.io.FormatableProperties;
134 import org.apache.derby.iapi.services.io.StoredFormatIds;
135 import org.apache.derby.iapi.util.ReuseFactory;
136 import org.apache.derby.iapi.services.io.FormatableBitSet;
137 import org.apache.derby.iapi.util.StringUtil;
138
139 import java.sql.Types JavaDoc;
140 import java.util.List JavaDoc;
141 import java.util.ArrayList JavaDoc;
142 import java.util.Hashtable JavaDoc;
143 import java.util.Properties JavaDoc;
144 import java.util.StringTokenizer JavaDoc;
145 import java.util.Vector JavaDoc;
146 import java.lang.Character JavaDoc;
147
148 public class SQLParser implements SQLParserConstants {
149         private static final String JavaDoc[] SAVEPOINT_CLAUSE_NAMES = {"UNIQUE", "ON ROLLBACK RETAIN LOCKS", "ON ROLLBACK RETAIN CURSORS"};
150         private static final String JavaDoc[] ROUTINE_CLAUSE_NAMES =
151                 {null, "SPECIFIC", "RESULT SET", "LANGUAGE", "EXTERNAL NAME", "PARAMETER STYLE", "SQL", "ON NULL INPUT"};
152         /**
153        Clauses required for Java routines. Numbers correspond
154        to offsets in ROUTINE_CLAUSE_NAMES.
155        3 - "LANGUAGE"
156        4 - "EXTERNAL NAME"
157        5 - "PARAMETER STYLE"
158     */

159         private static final int[] JAVA_ROUTINE_CLAUSES = {3,4,5};
160         private static final String JavaDoc[] TEMPORARY_TABLE_CLAUSE_NAMES = {"NOT LOGGED", "ON COMMIT", "ON ROLLBACK"};
161         /* The default length of a char or bit if the length is omitted */
162         private static final int DEFAULT_STRING_COLUMN_LENGTH = 1;
163
164         // Defines for ON or USING clauses
165
private static final int ON_OR_USING_CLAUSE_SIZE = 2;
166         private static final int ON_CLAUSE = 0;
167         private static final int USING_CLAUSE = 1;
168
169         // Defines for optional table clauses
170
private static final int OPTIONAL_TABLE_CLAUSES_SIZE = 3;
171         private static final int OPTIONAL_TABLE_CLAUSES_TABLE_PROPERTIES = 0;
172         private static final int OPTIONAL_TABLE_CLAUSES_DERIVED_RCL = 1;
173         private static final int OPTIONAL_TABLE_CLAUSES_CORRELATION_NAME = 2;
174
175         // Define for UTF8 max
176
private static final int MAX_UTF8_LENGTH = 65535;
177
178     // Constants for set operator types
179
private static final int NO_SET_OP = 0;
180     private static final int UNION_OP = 1;
181     private static final int UNION_ALL_OP = 2;
182     private static final int EXCEPT_OP = 3;
183     private static final int EXCEPT_ALL_OP = 4;
184     private static final int INTERSECT_OP = 5;
185     private static final int INTERSECT_ALL_OP = 6;
186
187         private Object JavaDoc[] paramDefaults;
188         private String JavaDoc statementSQLText;
189         private NodeFactory nodeFactory;
190         private ContextManager cm;
191         private CompilerContext compilerContext;
192
193         /* The number of the next ? parameter */
194         private int parameterNumber;
195
196         /* The list of ? parameters */
197         private Vector JavaDoc parameterList;
198
199         /* Remember if the last identifier or keyword was a
200      * delimited identifier. This is used for remembering
201      * if the xxx in SERIALIZE(xxx) was a delimited identifier
202      * because we need to know whether or not we can convert
203      * xxx to upper case if we try to resolve it as a class
204      * alias at bind time.
205      */

206         private Boolean JavaDoc lastTokenDelimitedIdentifier = Boolean.FALSE;
207         private Boolean JavaDoc nextToLastTokenDelimitedIdentifier = Boolean.FALSE;
208
209
210         /*
211     ** Remember the last token we got that was an identifier
212     */

213         private Token lastIdentifierToken;
214         private Token nextToLastIdentifierToken;
215
216         static final String JavaDoc SINGLEQUOTES = "\'\'";
217         static final String JavaDoc DOUBLEQUOTES = "\"\"";
218
219         static final String JavaDoc DEFAULT_INDEX_TYPE = "BTREE";
220
221         //the following 2 booleans are used to make sure only null or not null is
222
//defined for a column while creating a table or altering a table. Defining
223
//both at the same time will be an error case.
224
boolean explicitNotNull = false;
225         boolean explicitNull = false;
226
227         //this vector keeps a list of explicitly nullable columns, so that if they
228
//get used in the table level primary key constraint, it will result in an
229
//exception.
230
Vector JavaDoc explicitlyNullableColumnsList = new Vector JavaDoc();
231
232
233         final void setCompilerContext(CompilerContext cc) {
234                 this.compilerContext = cc;
235                 this.cm = cc.getContextManager();
236         }
237
238         /**
239       * Get the NodeFactory for this database.
240       *
241       * @return The NodeFactory for this database.
242       * @exception StandardException Thrown on error
243       */

244         private final NodeFactory getNodeFactory() throws StandardException
245         {
246                 if ( nodeFactory == null )
247                 {
248                         nodeFactory = getCompilerContext().getNodeFactory();
249                 }
250
251                 return nodeFactory;
252         }
253
254         private final CompilerContext getCompilerContext()
255         {
256                 return compilerContext;
257         }
258
259         private DataTypeDescriptor getDataTypeServices(int type, int precision, int scale,
260                         int length)
261         {
262                 return new DataTypeDescriptor(
263                                         TypeId.getBuiltInTypeId(type),
264                                         precision,
265                                         scale,
266                                         true, /* assume nullable for now, change it if not nullable */
267                                         length
268                                 );
269         }
270
271         private DataTypeDescriptor getJavaClassDataTypeDescriptor(String JavaDoc javaClassName)
272         {
273                 return new DataTypeDescriptor(
274                                         TypeId.getUserDefinedTypeId(
275                                                                 javaClassName,
276                                                                 lastTokenDelimitedIdentifier.booleanValue()),
277                                         true);
278         }
279         private LanguageConnectionContext getLanguageConnectionContext()
280         {
281                 return (LanguageConnectionContext) getContextManager().getContext(
282                                                                                 LanguageConnectionContext.CONTEXT_ID);
283         }
284
285         /**
286         Utility method for checking that the underlying database has been
287         upgraded to the required level to use this functionality. Used to
288         disallow SQL statements that would leave on-disk formats that would
289         not be understood by a engine that matches the current upgrade level
290         of the database. Throws an exception if the database is not a the required level.
291         <P>
292         Typically used for CREATE statements at the parser level. Called usually just
293         before the node is created, or can be called in just a partial syntax fragment
294         
295         @param version Data Dictionary major version (DataDictionary.DD_ constant)
296         @param feature SQL Feature name, for error text.
297     */

298         private void checkVersion(int version, String JavaDoc feature) throws StandardException
299         {
300                 getLanguageConnectionContext().getDataDictionary().checkVersion(
301                                 version, feature);
302         }
303
304     /**
305         Utility method for checking that the underlying database uses SQL standard
306         permission checking (GRANT/REVOKE).
307
308         @param command "GRANT" or "REVOKE"
309     */

310         private void checkSqlStandardAccess( String JavaDoc command) throws StandardException
311         {
312                 if( getLanguageConnectionContext().usesSqlAuthorization())
313                         return;
314
315                 throw StandardException.newException(SQLState.LANG_GRANT_REVOKE_WITH_LEGACY_ACCESS,
316                                                                                         command,
317                                                                                         Property.SQL_AUTHORIZATION_PROPERTY,
318                                                                                         "TRUE");
319         }
320
321         /*
322     ** Make sure that a select list in a parser-rewritten tree does
323     ** not contain two columns by the same name. This is the patch
324     ** to bug 280. In this case, the bind phase cannot tell the
325     ** difference between the two columns and so the query may
326     ** return wrong results.
327     **
328     ** This issue is caused by parser rewriting of group by/having clauses
329     ** into table expressions. (See function tableExpression() in this file)
330     ** There is an improvement request filed under DERBY-681 to eliminate this
331     ** rewrite, after which it should be possible to allow multiple columns to
332     ** have same name in the select list.
333     */

334         private void vetSelectList280( ResultColumnList selectList )
335                 throws StandardException
336         {
337                 Hashtable JavaDoc allNames = new Hashtable JavaDoc();
338                 int count = selectList.size();
339
340                 for ( int i = 0; i < count; i++ )
341                 {
342                         ResultColumn rc = (ResultColumn) selectList.elementAt( i );
343                         String JavaDoc duplicateName = ambiguousDuplicateName( allNames, rc );
344
345                         if ( duplicateName != null )
346                         {
347                                 throw StandardException.newException
348                                 ( SQLState.LANG_UNBINDABLE_REWRITE, duplicateName );
349                         }
350
351                 }
352         }
353
354         // allow two references to the same column. disallow aliasing
355
// two different expressions to the same name. returns the
356
// ambiguous column name if two result columns cannot be distinguished.
357
private String JavaDoc ambiguousDuplicateName( Hashtable JavaDoc allNames, ResultColumn rc )
358                 throws StandardException
359         {
360                 String JavaDoc columnName = rc.getName();
361                 ValueNode newExpression = rc.getExpression();
362
363                 // no column name means that the compiler will generate a
364
// unique name. that's ok and avoids bug 280
365
if ( columnName == null ) { return null; }
366
367                 ValueNode oldExpression = (ValueNode) allNames.get( columnName );
368
369                 // no problem yet if we haven't seen this column
370
if ( oldExpression == null )
371                 {
372                         allNames.put( columnName, newExpression );
373                         return null;
374                 }
375
376                 // if the two identically named references aren't both the
377
// same table column, then the bug occurs
378
if (
379                                 !(newExpression instanceof ColumnReference) ||
380                                 !(oldExpression instanceof ColumnReference)
381                    )
382                 { return columnName; }
383
384                 ColumnReference newCR = (ColumnReference) newExpression;
385                 ColumnReference oldCR = (ColumnReference) oldExpression;
386                 TableName newTableName = newCR.getTableNameNode();
387                 TableName oldTableName = oldCR.getTableNameNode();
388
389                 if (
390                                 ( (newTableName == null) && (oldTableName == null) ) ||
391                                 ( (newTableName != null) && (newTableName.equals( oldTableName )) )
392                    )
393                 {
394                         // same table but different column aliased to same column name
395
if ( !newCR.getColumnName().equals( oldCR.getColumnName() ) )
396                         { return columnName; }
397                         else { return null; }
398                 }
399
400                 // different tables
401
return null;
402         }
403
404         /**
405         Check that the current mode supports internal extensions.
406
407         @param feature Description of feature for exception.
408
409         @exception StandardException current mode does not support statement
410     */

411         private void checkInternalFeature(String JavaDoc feature) throws StandardException
412         {
413                 CompilerContext cc = getCompilerContext();
414                 if ((cc.getReliability() & CompilerContext.INTERNAL_SQL_ILLEGAL) != 0)
415                         throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, feature);
416         }
417
418         /**
419      * check if the type length is ok for the given type.
420      */

421         private void checkTypeLimits(int type, int length)
422                 throws StandardException
423         {
424         boolean valid = true;
425
426
427         switch (type) {
428                 case Types.BINARY:
429                 case Types.CHAR:
430                         if (length > Limits.DB2_CHAR_MAXWIDTH)
431                                 valid = false;
432                         break;
433
434                 case Types.VARBINARY:
435                 case Types.VARCHAR:
436                         if (length > Limits.DB2_VARCHAR_MAXWIDTH)
437                                 valid = false;
438
439                         break;
440                 default:
441                         break;
442         }
443         if (!valid) // If these limits are too big
444
{
445                         DataTypeDescriptor charDTD =
446                                 DataTypeDescriptor.getBuiltInDataTypeDescriptor(type, length);
447
448                         throw StandardException.newException(SQLState.LANG_DB2_LENGTH_PRECISION_SCALE_VIOLATION, charDTD.getSQLstring());
449                 }
450         }
451
452
453
454         // Get the current ContextManager
455
private final ContextManager getContextManager()
456         {
457                 return cm;
458         }
459
460         /*
461     ** Compress 2 adjacent (single or double) quotes into a single (s or d) quote when
462     ** found in the middle of a String.
463     ** NOTE: """" or '''' will be compressed into "" or ''.
464     ** This function assumes that the leading and trailing quote from a
465     ** string or delimited identifier have already been removed.
466     */

467         private static String JavaDoc compressQuotes(String JavaDoc source, String JavaDoc quotes)
468         {
469                 String JavaDoc result = source;
470                 int index;
471
472                 /* Find the first occurrence of adjacent quotes. */
473                 index = result.indexOf(quotes);
474
475                 /* Replace each occurrence with a single quote and begin the
476          * search for the next occurrence from where we left off.
477          */

478                 while (index != -1)
479                 {
480                         result = result.substring(0, index + 1) + result.substring(index + 2);
481
482                         index = result.indexOf(quotes, index + 1);
483                 }
484
485                 return result;
486         }
487
488         private static void verifyImageLength(String JavaDoc image) throws StandardException
489                 {
490                 // beetle 2758. For right now throw an error for literals > 64K
491
if (image.length() > MAX_UTF8_LENGTH)
492                         {
493                 throw StandardException.newException(SQLState.LANG_INVALID_LITERAL_LENGTH);
494                         }
495                 }
496
497         /*
498     ** Converts a delimited id to a canonical form.
499     ** Post process delimited identifiers to eliminate leading and
500     ** trailing " and convert all occurrences of "" to ".
501     */

502         private static String JavaDoc normalizeDelimitedID(String JavaDoc str)
503         {
504                 str = compressQuotes(str, DOUBLEQUOTES);
505                 return str;
506         }
507         private static boolean isDATETIME(int val)
508         {
509                 if (val == DATE || val == TIME || val == TIMESTAMP)
510                         return true;
511                 else
512                         return false;
513         }
514
515         /*
516      * Generate a multiplicative operator node, if necessary.
517      *
518      * If there are two operands, generate the multiplicative operator
519      * that corresponds to the multiplicativeOperator parameter. If there
520      * is no left operand, just return the right operand.
521      *
522      * @param leftOperand The left operand, null if no operator
523      * @param rightOperand The right operand
524      * @param multiplicativeOperator An identifier from BinaryOperatorNode
525      * telling what operator to generate.
526      *
527      * @return The multiplicative operator, or the right operand if there is
528      * no operator.
529      *
530      * @exception StandardException Thrown on error
531      */

532
533         ValueNode multOp(ValueNode leftOperand,
534                                                         ValueNode rightOperand,
535                                                         int multiplicativeOperator)
536                                         throws StandardException
537         {
538                 if (leftOperand == null)
539                 {
540                         return rightOperand;
541                 }
542
543                 switch (multiplicativeOperator)
544                 {
545                   case BinaryOperatorNode.TIMES:
546                         return (ValueNode) nodeFactory.getNode(
547                                                                         C_NodeTypes.BINARY_TIMES_OPERATOR_NODE,
548                                                                         leftOperand,
549                                                                         rightOperand,
550                                                                         getContextManager());
551
552                   case BinaryOperatorNode.DIVIDE:
553                         return (ValueNode) nodeFactory.getNode(
554                                                                         C_NodeTypes.BINARY_DIVIDE_OPERATOR_NODE,
555                                                                         leftOperand,
556                                                                         rightOperand,
557                                                                         getContextManager());
558                   case BinaryOperatorNode.CONCATENATE:
559                         return (ValueNode) nodeFactory.getNode(
560                                                                         C_NodeTypes.CONCATENATION_OPERATOR_NODE,
561                                                                         leftOperand,
562                                                                         rightOperand,
563                                                                         getContextManager());
564
565                   default:
566                         if (SanityManager.DEBUG)
567                         SanityManager.THROWASSERT("Unexpected multiplicative operator " +
568                                                                                 multiplicativeOperator);
569                         return null;
570                 }
571         }
572
573         /**
574      * Set up and like the parameters to the descriptors.
575      * Set all the ParameterNodes to point to the array of
576      * parameter descriptors.
577      *
578      * @exception StandardException
579      */

580          private void setUpAndLinkParameters()
581                         throws StandardException
582          {
583                 CompilerContext cc = getCompilerContext();
584                 cc.setParameterList(parameterList);
585                 /* Link the untyped parameters to the array of parameter descriptors */
586
587                 DataTypeDescriptor[] descriptors = cc.getParameterTypes();
588
589                 ParameterNode newNode;
590                 ParameterNode oldNode;
591                 int paramCount;
592
593                 /*
594         ** Iterate through the list of untyped parameter nodes, set each one
595         ** to point to the array of parameter descriptors.
596         */

597                 paramCount = -1;
598                 int plSize = parameterList.size();
599                 for (int index = 0; index < plSize; index++)
600                 {
601                         paramCount++;
602
603                         newNode = (ParameterNode) parameterList.elementAt(index);
604                         newNode.setDescriptors(descriptors );
605                 }
606         }
607
608         /**
609      * Initializes the list of unnamed parameters, i.e., "?" parameters
610      *
611      * Usually, this routine just gets an empty list for the unnamed parameters.
612      *
613      *
614      */

615         void initUnnamedParameterList()
616         {
617                 parameterList = new Vector JavaDoc();
618         }
619
620         /**
621      * Makes a new unnamed ParameterNode and chains it onto parameterList.
622      *
623      * @return new unnamed parameter.
624      *
625      * @exception StandardException
626      */

627         ParameterNode makeParameterNode( )
628                                         throws StandardException
629         {
630                 ParameterNode parm;
631                 DataValueDescriptor sdv = null;
632
633                 if ((paramDefaults != null) && (parameterNumber < paramDefaults.length))
634                 {
635                         sdv = (DataValueDescriptor) paramDefaults[parameterNumber];
636                 }
637
638                 parm = (ParameterNode) nodeFactory.getNode(
639                                                                 C_NodeTypes.PARAMETER_NODE,
640                                                                 ReuseFactory.getInteger(parameterNumber),
641                                                                 sdv,
642                                                                 getContextManager());
643
644                 parameterNumber++;
645                 parameterList.addElement(parm);
646
647                 return parm;
648         }
649
650         /**
651      * Looks up an unnamed parameter given its parameter number.
652      *
653      * @param paramNumber Number of parameter in unnamed
654      * parameter list.
655      *
656      * @return corresponding unnamed parameter.
657      *
658      */

659         ParameterNode lookupUnnamedParameter( int paramNumber )
660         {
661                 ParameterNode unnamedParameter;
662
663                 unnamedParameter = (ParameterNode) parameterList.elementAt( paramNumber );
664                 return unnamedParameter;
665         }
666
667         /**
668      * Translate a String containing a number into the appropriate type
669      * of Numeric node.
670      *
671      * @exception StandardException Thrown on error
672      */

673         ValueNode getNumericNode(String JavaDoc num) throws StandardException
674         {
675                 ContextManager cm = getContextManager();
676
677                 // first, see if it might be an integer
678
try
679                 {
680                         return (ValueNode) nodeFactory.getNode(
681                                                                                 C_NodeTypes.INT_CONSTANT_NODE,
682                                                                                 new Integer JavaDoc(num),
683                                                                                 cm);
684                 }
685                 catch (NumberFormatException JavaDoc nfe)
686                 {
687                         // we catch because we want to continue on below
688
}
689
690                 // next, see if it might be a long
691
try
692                 {
693                         return (ValueNode) nodeFactory.getNode(
694                                                                                 C_NodeTypes.LONGINT_CONSTANT_NODE,
695                                                                                 new Long JavaDoc(num),
696                                                                                 cm);
697                 }
698                 catch (NumberFormatException JavaDoc nfe)
699                 {
700                         // we catch because we want to continue on below
701
}
702
703                 return (ValueNode) nodeFactory.getNode(
704                                                                         C_NodeTypes.DECIMAL_CONSTANT_NODE,
705                                                                         num,
706                                                                         cm);
707         }
708         /**
709      * Determine whether the current token represents one of
710      * the built-in aliases.
711      *
712      * @return TRUE iff the current token names a built-in alias
713      */

714         private boolean isBuiltInAlias()
715         {
716                 boolean retval = false;
717
718                 switch (token.kind)
719                 {
720                   case UCASE:
721                   case LCASE:
722                   case SQRT:
723                   case LOCATE:
724                   case ABS:
725                   case ABSVAL:
726                   case SUBSTR:
727                   case MOD:
728                         retval = true;
729                         break;
730
731                   default:
732                         retval = false;
733                         break;
734                 }
735
736
737                 return retval;
738         }
739
740
741         /**
742      * Determine whether the next sequence of tokens represents one of
743      * the common (built-in) datatypes.
744      *
745      * @return TRUE iff the next set of tokens names a common datatype
746      */

747         boolean commonDatatypeName(boolean checkFollowingToken)
748         {
749                 boolean retval = false;
750
751                 switch (getToken(1).kind)
752                 {
753                   case CHARACTER:
754                   case CHAR:
755                   case VARCHAR:
756                   case NVARCHAR:
757                   case NCHAR:
758                   case BIT:
759                   case NUMERIC:
760                   case DECIMAL:
761                   case DEC:
762                   case INTEGER:
763                   case INT:
764                   case SMALLINT:
765                   case LONGINT:
766                   case FLOAT:
767                   case REAL:
768                   case DATE:
769                   case TIME:
770                   case TIMESTAMP:
771                   case BOOLEAN:
772                   case DOUBLE:
773                   case BLOB:
774                   case CLOB:
775                   case NCLOB:
776                   case BINARY: // LARGE OBJECT
777
case XML:
778                         retval = true;
779                         break;
780
781                   case LONG:
782                         if (checkFollowingToken == true)
783                         {
784                                 switch (getToken(2).kind)
785                                 {
786                                   case VARCHAR:
787                                   case NVARCHAR:
788                                   case BINARY:
789                                   case VARBINARY:
790                                   case BIT:
791                                         retval = true;
792                                         break;
793                                 }
794                                 break;
795                         }
796                         else
797                         {
798                                 retval = true;
799                                 break;
800                         }
801
802                   case NATIONAL:
803                         if (checkFollowingToken == true)
804                         {
805                                 switch (getToken(2).kind)
806                                 {
807                                   case CHAR:
808                                   case CHARACTER:
809                                         retval = true;
810                                         break;
811                                 }
812                                 break;
813                         }
814                         else
815                         {
816                                 retval = true;
817                                 break;
818                         }
819                 }
820
821                 return retval;
822         }
823
824         /**
825      * Get a DELETE node given the pieces.
826      *
827      *
828      * @exception StandardException
829      */

830          private QueryTreeNode getDeleteNode(FromTable fromTable,
831                                                                                  TableName tableName,
832                                                                                  ValueNode whereClause)
833                 throws StandardException
834         {
835                 FromList fromList = (FromList) nodeFactory.getNode(
836                                                                 C_NodeTypes.FROM_LIST,
837                                                                 getContextManager());
838                 QueryTreeNode retval;
839                 SelectNode resultSet;
840
841                 fromList.addFromTable(fromTable);
842
843                 resultSet = (SelectNode) nodeFactory.getNode(
844                                                                                 C_NodeTypes.SELECT_NODE,
845                                                                                 null,
846                                                                                 null, /* AGGREGATE list */
847                                                                                 fromList, /* FROM list */
848                                                                                 whereClause, /* WHERE clause */
849                                                                                 null, /* GROUP BY list */
850                                                                                 getContextManager());
851
852                 retval =
853                         (QueryTreeNode) nodeFactory.getNode(
854                                                         C_NodeTypes.DELETE_NODE,
855                                                         tableName,
856                                                         resultSet,
857                                                         getContextManager());
858
859                 setUpAndLinkParameters();
860
861                 return retval;
862         }
863
864         /**
865      * Get an UPDATE node given the pieces.
866      *
867      *
868      * @exception StandardException
869      */

870          private QueryTreeNode getUpdateNode(FromTable fromTable,
871                                                                                  TableName tableName,
872                                                                                  ResultColumnList setClause,
873                                                                                  ValueNode whereClause)
874                 throws StandardException
875         {
876                 FromList fromList = (FromList) nodeFactory.getNode(
877                                                                 C_NodeTypes.FROM_LIST,
878                                                                 getContextManager());
879                 QueryTreeNode retval;
880                 SelectNode resultSet;
881
882                 fromList.addFromTable(fromTable);
883
884                 resultSet = (SelectNode) nodeFactory.getNode(
885                                                                                 C_NodeTypes.SELECT_NODE,
886                                                                                 setClause,
887                                                                                 null, /* AGGREGATE list */
888                                                                                 fromList, /* FROM list */
889                                                                                 whereClause, /* WHERE clause */
890                                                                                 null, /* GROUP BY list */
891                                                                                 getContextManager());
892
893                 retval =
894                         (QueryTreeNode) nodeFactory.getNode(
895                                                         C_NodeTypes.UPDATE_NODE,
896                                                         tableName,
897                                                         resultSet,
898                                                         getContextManager());
899
900                 setUpAndLinkParameters();
901
902                 return retval;
903         }
904
905         /**
906      * Determine whether the next sequence of tokens can be the beginning
907      * of a remainingPredicate() rule.
908      *
909      * @return TRUE iff the next set of tokens is the beginning of a
910      * remainingPredicate()
911      */

912         private boolean remainingPredicateFollows()
913         {
914                 boolean retval = false;
915
916                 switch (getToken(1).kind)
917                 {
918                   case EQUALS_OPERATOR:
919                   case NOT_EQUALS_OPERATOR:
920                   case NOT_EQUALS_OPERATOR2: // !=
921
case LESS_THAN_OPERATOR:
922                   case GREATER_THAN_OPERATOR:
923                   case LESS_THAN_OR_EQUALS_OPERATOR:
924                   case GREATER_THAN_OR_EQUALS_OPERATOR:
925                   case IN:
926                   case LIKE:
927                   case BETWEEN:
928                         retval = true;
929                         break;
930
931                   case NOT:
932                         switch (getToken(2).kind)
933                         {
934                           case IN:
935                           case LIKE:
936                           case BETWEEN:
937                                 retval = true;
938                         }
939                         break;
940                 }
941
942                 return retval;
943         }
944
945
946         /**
947      * Determine whether the next token is a DROP
948      *
949      * @return TRUE iff the next token is DROP
950      */

951         private boolean dropFollows()
952         {
953                 if (getToken(1).kind == DROP)
954                 { return true; }
955                 else { return false; }
956         }
957
958         /**
959      * Determine whether the next sequence of tokens can be the beginning
960      * of a escapedValueFunction().
961      *
962      * We check only for the punctuation here, because identifiers are
963      * very hard to check for in semantic lookahead.
964      *
965      * @return TRUE iff the next set of tokens is the beginning of a
966      * escapedValueFunction()
967      */

968         private boolean escapedValueFunctionFollows()
969         {
970                 if (getToken(1).kind != LEFT_BRACE)
971                 {
972                         return false;
973                 }
974
975                 return getToken(2).kind == FN;
976         }
977
978
979     /**
980        List of JDBC escape functions that map directly onto
981        a function in the SYSFUN schema.
982     */

983         private static final String JavaDoc[] ESCAPED_SYSFUN_FUNCTIONS =
984         {"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN", "PI",
985          "DEGREES", "RADIANS", "EXP", "LOG", "LOG10", "CEILING", "FLOOR" };
986
987     /**
988        Convert a JDBC escaped function name to a function
989        name in the SYSFUC schema. Returns null if no such
990        function exists.
991     */

992         private String JavaDoc getEscapedSYSFUN(String JavaDoc name)
993         {
994             name = StringUtil.SQLToUpperCase(name);
995
996             for (int i = 0; i < ESCAPED_SYSFUN_FUNCTIONS.length; i++)
997             {
998                 if (ESCAPED_SYSFUN_FUNCTIONS[i].equals(name))
999                     return name;
1000            }
1001            return null;
1002        }
1003
1004        /**
1005     * Determine whether the next sequence of tokens can be the beginning
1006     * of a columnInvocation() rule. columnInvocations start with
1007     * [ [ id . ] id . ] id . id (
1008     *
1009     * We check only for the punctuation here, because identifiers are
1010     * very hard to check for in semantic lookahead.
1011     *
1012     * @return TRUE iff the next set of tokens is the beginning of a
1013     * columnInvocation()
1014     */

1015        private boolean columnMethodInvocationFollows()
1016        {
1017                int tokKind;
1018
1019                // First token must not be a built-in function name that can be
1020
// followed immediately by a PERIOD. There are only a few of
1021
// these - most built-in functions have a LEFT_PAREN following
1022
// the function name.
1023

1024                // if we run out of token, it's probably a syntax error,
1025
// in fact
1026
tokKind = getToken(1).kind;
1027                if ( tokKind == EOF ) { return false; }
1028
1029                // disambiguate from named parameter reference
1030
if ( getToken(1).image.charAt(0) == '?' ) { return false; }
1031
1032                if (tokKind == CURRENT_DATE ||
1033                        tokKind == CURRENT_TIME ||
1034                        tokKind == CURRENT_TIMESTAMP ||
1035                        tokKind == CURRENT && (isDATETIME(getToken(2).kind)) )
1036                {
1037                        return false;
1038                }
1039
1040                // Second token must be a PERIOD
1041
if (getToken(2).kind != PERIOD)
1042                {
1043                        return false;
1044                }
1045
1046                // We have established that we start with " id . "
1047
tokKind = getToken(4).kind;
1048                if (tokKind == LEFT_PAREN)
1049                {
1050                        // id.id(
1051
return true;
1052                }
1053
1054                // Not id.id(, so 4th token must be PERIOD
1055
if (tokKind != PERIOD)
1056                {
1057                        return false;
1058                }
1059
1060                tokKind = getToken(6).kind;
1061                if (tokKind == LEFT_PAREN)
1062                {
1063                        // id.id.id(
1064
return true;
1065                }
1066
1067                // Not id.id.id(, so 6th token must be PERIOD
1068
if (tokKind != PERIOD)
1069                {
1070                        return false;
1071                }
1072
1073                tokKind = getToken(8).kind;
1074                if (tokKind == LEFT_PAREN)
1075                {
1076                        // id.id.id.id(
1077
return true;
1078                }
1079
1080                return false;
1081        }
1082
1083        /**
1084     * Determine whether the next sequence of tokens can be the beginning
1085     * of an aggregateNode()() rule. aggregateNodes() start with one
1086     * of the built-in aggregate names, or with an identifier followed
1087     * by "( DISTINCT". A non-distinct user-defined aggregate invocation
1088     * is treated as a staticMethodInvocationAlias() by the parser,
1089     * and the binding phase figures out what it really is by looking
1090     * at the data dictionary.
1091     *
1092     * We check only for the punctuation here, because identifiers are
1093     * very hard to check for in semantic lookahead.
1094     *
1095     * @return TRUE iff the next set of tokens is the beginning of a
1096     * aggregateNode()
1097     */

1098        private boolean aggregateFollows()
1099        {
1100                boolean retval = false;
1101
1102                switch (getToken(1).kind)
1103                {
1104                  case MAX:
1105                  case AVG:
1106                  case MIN:
1107                  case SUM:
1108                        // This is a built-in aggregate
1109
retval = true;
1110                        break;
1111
1112                  case COUNT:
1113                        // COUNT is not a reserved word
1114
// This may eclipse use of COUNT as a function or a procedure that is probably what we want
1115
if (getToken(2).kind == LEFT_PAREN)
1116                                retval = true;
1117                  default:
1118                        // Not a built-in aggregate - assume the first token is an
1119
// identifier, and see whether it is followed by " ( DISTINCT "
1120
if (getToken(2).kind == LEFT_PAREN && getToken(3).kind == DISTINCT)
1121                                retval = true;
1122                        break;
1123                }
1124
1125                return retval;
1126        }
1127
1128        /**
1129     * Determine whether the next sequence of tokens can be the beginning
1130     * of a miscBuiltins().
1131     *
1132     * We check only for the punctuation here, because identifiers are
1133     * very hard to check for in semantic lookahead.
1134     *
1135     * @return TRUE iff the next set of tokens is the beginning of a
1136     * aggregateNode()
1137     */

1138        private boolean miscBuiltinFollows()
1139        {
1140                boolean retval = false;
1141                int tokKind = getToken(1).kind;
1142
1143                if (getToken(0).kind == CALL)
1144                        retval = true;
1145
1146                switch (tokKind)
1147                {
1148                  case GET_CURRENT_CONNECTION:
1149                  case CURRENT_DATE:
1150                  case CURRENT_TIME:
1151                  case CURRENT_TIMESTAMP:
1152                        retval = true;
1153                        break;
1154
1155                  case CURRENT:
1156                        if (isDATETIME(getToken(2).kind))
1157                                retval = true;
1158                        break;
1159
1160                  case CAST:
1161                  case LEFT_PAREN:
1162                        retval = false;
1163                        break;
1164
1165                  default:
1166                    if (getToken(2).kind == LEFT_PAREN)
1167                                retval = true;
1168                        break;
1169                }
1170
1171                return retval;
1172        }
1173
1174        /**
1175     * Determine whether the next sequence of tokens can be the beginning
1176     * of a subquery. A subquery can begin with an arbitrary number of
1177     * left parentheses, followed by either SELECT or VALUES.
1178     *
1179     * @return TRUE iff the next set of tokens is the beginning of a
1180     * subquery.
1181     */

1182        private boolean subqueryFollows()
1183        {
1184                int tokKind;
1185                boolean retval = false;
1186
1187                for (int i = 1; true; i++)
1188                {
1189                        tokKind = getToken(i).kind;
1190                        if (tokKind == LEFT_PAREN)
1191                        {
1192                                // A subquery can start with an arbitrary number of left
1193
// parentheses.
1194
continue;
1195                        }
1196                        else if (tokKind == SELECT || tokKind == VALUES)
1197                        {
1198                                // If the first token we find after all the left parentheses
1199
// is SELECT or VALUES, it's a subquery.
1200
retval = true;
1201                                break;
1202                        }
1203                        else
1204                        {
1205                                // If the first token we find after all the left parentheses
1206
// is neither SELECT nor VALUES, it's not a subquery.
1207
break;
1208                        }
1209                }
1210
1211                return retval;
1212        }
1213
1214
1215        /**
1216     * Determine whether the next sequence of tokens can be the beginning
1217     * of a rowValueConstructorList. A rowValueConstructorList is a comma-
1218     * separated list of expressions enclosed in parentheses. This presents
1219     * special problems, because an expression be nested within an
1220     * arbitrary number of parentheses. To determine whether a left
1221     * parenthesis introduces a rowValueConstructorList or an expression,
1222     * we need to find the closing parenthesis, and determine whether
1223     * the next token is a comma.
1224     *
1225     * For example, the following is a rowValueConstructorList:
1226     *
1227     * (((1)), 2)
1228     *
1229     * and the following is just an expression:
1230     *
1231     * (((1)))
1232     *
1233     * @return TRUE iff the next set of tokens is the beginning of a
1234     * subquery.
1235     */

1236        private boolean rowValueConstructorListFollows()
1237        {
1238                int nesting;
1239                boolean retval = false;
1240
1241                // A rowValueConstructorList starts with a left parenthesis
1242
if (getToken(1).kind == LEFT_PAREN)
1243                {
1244                        // Keep track of the nesting of parens while looking ahead
1245
nesting = 1;
1246                        for (int i = 2; true; i++)
1247                        {
1248                                int tokKind = getToken(i).kind;
1249
1250                                // Special case for NULL/DEFAULT because they are not allowed in
1251
// a parenthesized expression, so (null)/(default) must be seen
1252
// as a rowValueConstructorList with one element.
1253
if (i == 2 && (tokKind == NULL || tokKind == _DEFAULT))
1254                                {
1255                                        retval = true;
1256                                        break;
1257                                }
1258
1259                                // There must be a COMMA at nesting level 1 (i.e. outside of
1260
// the first expression) for it to be a rowValueConstructorList
1261
if (nesting == 1 && tokKind == COMMA)
1262                                {
1263                                        retval = true;
1264                                        break;
1265                                }
1266
1267                                // If we run out of tokens before finding the last closing
1268
// parenthesis, it's not a rowValueConstructorList (it's
1269
// probably a syntax error, in fact)
1270
if (tokKind == EOF)
1271                                {
1272                                        break;
1273                                }
1274
1275                                // Increase the nesting for each (, and decrease it for each )
1276
if (tokKind == LEFT_PAREN)
1277                                {
1278                                        nesting++;
1279                                }
1280                                else if (tokKind == RIGHT_PAREN)
1281                                {
1282                                        nesting--;
1283                                }
1284
1285                                // Don't look any farther than the last closing parenthesis
1286
if (nesting == 0)
1287                                {
1288                                        break;
1289                                }
1290                        }
1291                }
1292
1293                return retval;
1294        }
1295
1296        /**
1297     * Determine whether the next token is the beginning of a propertyList().
1298     * A properties list is the comment "--derby-properties" followed by a
1299     * dot-separated list, followed by an =, followed by a value all on that
1300     * comment line. This means that the comment should start with the word
1301     * "derby-properties".
1302     *
1303     * @return TRUE iff the next token is derby-properties
1304     */

1305        private boolean derbyPropertiesListFollows()
1306        {
1307                return
1308                        getToken(1).kind == DERBYDASHPROPERTIES;
1309        }
1310
1311        /**
1312     * Determine whether the next sequence of tokens can be the beginning
1313     * of a newInvocation(). A newInvocation() begins with the word "new"
1314     * followed by a dot-separated list of identifiers, followed
1315     * by a left parenthesis.
1316     *
1317     * @param startToken Token to look for new at
1318     *
1319     * @return TRUE iff the next set of tokens is the beginning of a
1320     * newInvocation().
1321     */

1322        private boolean newInvocationFollows(int startToken)
1323        {
1324                boolean retval = false;
1325
1326                // newInvocation() starts with the word "new"
1327
if (getToken(startToken).kind == NEW)
1328                {
1329                        // Look at every other token. Ignore the identifiers, because
1330
// they are hard to test for.
1331
for (int i = 2 + startToken; true; i += 2)
1332                        {
1333                                int tokKind = getToken(i).kind;
1334
1335                                // If we find a left parenthesis without any intervening
1336
// cruft, we have found a newInvocation()
1337
if (tokKind == LEFT_PAREN)
1338                                {
1339                                        retval = true;
1340                                        break;
1341                                }
1342                                else if (tokKind != PERIOD)
1343                                {
1344                                        // Anything other than a PERIOD is "cruft"
1345
break;
1346                                }
1347                        }
1348                }
1349
1350                return retval;
1351        }
1352        /**
1353     * Determine whether the next sequence of tokens is a class name
1354     *
1355     * @return TRUE iff the next set of tokens is the java class name
1356     */

1357        boolean javaClassFollows()
1358        {
1359                boolean retval = false;
1360
1361                // Look at every other token. Ignore the identifiers, because
1362
// they are hard to test for.
1363
for (int i = 2; true; i += 2)
1364                {
1365                        int tokKind = getToken(i).kind;
1366
1367                        // If we find a '::' without any intervening
1368
// cruft, we have found a javaClass
1369
if (tokKind == DOUBLE_COLON)
1370                        {
1371                                retval = true;
1372                                break;
1373                        }
1374                        else if (tokKind != PERIOD)
1375                        {
1376                                // Anything other than a PERIOD is "cruft"
1377
break;
1378                        }
1379                }
1380
1381                return retval;
1382        }
1383
1384        /**
1385     * Determine whether the next sequence of tokens can be the beginning
1386     * of a FROM newInvocation(). A FROM newInvocation() begins with the words "from new"
1387     * followed by a dot-separated list of identifiers, followed
1388     * by a left parenthesis.
1389     *
1390     * @return TRUE iff the next set of tokens is the beginning of a
1391     * FROM newInvocation().
1392     */

1393        private boolean fromNewInvocationFollows()
1394        {
1395                boolean retval = false;
1396
1397                // FROM newInvocation() starts with the words "from new"
1398
return (getToken(1).kind == FROM && newInvocationFollows(2));
1399        }
1400
1401        /**
1402     * Determine whether the next sequence of tokens can be the beginning
1403     * of a joinedTableExpression(). A joinedTableExpression() begins
1404     * with one of:
1405     *
1406     * JOIN
1407     * INNER JOIN
1408     * LEFT OUTER JOIN
1409     * RIGHT OUTER JOIN
1410     *
1411     * @return TRUE iff the next set of tokens is the beginning of a
1412     * joinedTableExpression().
1413     */

1414        private boolean joinedTableExpressionFollows()
1415        {
1416                boolean retval = false;
1417
1418                int tokKind1 = getToken(1).kind;
1419                int tokKind2 = getToken(2).kind;
1420
1421                if (tokKind1 == JOIN)
1422                {
1423                        retval = true;
1424                }
1425                else if (tokKind1 == INNER && tokKind2 == JOIN)
1426                {
1427                        retval = true;
1428                }
1429                else if ((tokKind1 == LEFT || tokKind1 == RIGHT) && tokKind2 == OUTER)
1430                {
1431                        if (getToken(3).kind == JOIN)
1432                        {
1433                                retval = true;
1434                        }
1435                }
1436                else if ((tokKind1 == LEFT || tokKind1 == RIGHT) && tokKind2 == JOIN)
1437                {
1438                        retval = true;
1439                }
1440
1441                return retval;
1442        }
1443
1444        /**
1445     * Translate a token for the name of a built-in aggregate to a String
1446     * containing an aggregate name.
1447     */

1448        private static String JavaDoc aggName(Token token)
1449        {
1450                String JavaDoc retval = null;
1451
1452                switch (token.kind)
1453                {
1454                  case MAX:
1455                        retval = "MAX";
1456                        break;
1457
1458                  case AVG:
1459                    retval = "AVG";
1460                        break;
1461
1462                  case MIN:
1463                    retval = "MIN";
1464                        break;
1465
1466                  case SUM:
1467                    retval = "SUM";
1468                        break;
1469
1470                  case COUNT:
1471                    retval = "COUNT";
1472                        break;
1473
1474                  default:
1475                        if (SanityManager.DEBUG)
1476                        {
1477                                SanityManager.THROWASSERT("Unexpected token type in aggName: " +
1478                                                                                        token.kind);
1479                        }
1480                        break;
1481                }
1482
1483                return retval;
1484        }
1485
1486        /**
1487     * Translate a token for the name of a built-in aggregate to an
1488     * aggregate definition class.
1489     */

1490        private static Class JavaDoc aggClass(Token token)
1491        {
1492                Class JavaDoc retval = null;
1493
1494                switch (token.kind)
1495                {
1496                  case MAX:
1497                  case MIN:
1498                        retval = MaxMinAggregateDefinition.class;
1499                        break;
1500
1501                  case AVG:
1502                  case SUM:
1503                        retval = SumAvgAggregateDefinition.class;
1504                        break;
1505
1506                  case COUNT:
1507                    retval = CountAggregateDefinition.class;
1508                        break;
1509
1510                  default:
1511                        if (SanityManager.DEBUG)
1512                        {
1513                                SanityManager.THROWASSERT("Unexpected token type in aggClass: "
1514                                                                                        + token.kind);
1515                        }
1516                        break;
1517                }
1518
1519                return retval;
1520        }
1521
1522        /**
1523     * Determine whether the next sequence of tokens can be the beginning
1524     * of another element in a PROPERTY list. These elements are of the
1525     * form:
1526     *
1527     * COMMA dot.separated.list = ...
1528     *
1529     * Look for the COMMA, the dots in the dot-separated list, and the =
1530     *
1531     * @return TRUE iff the next set of tokens is the beginning of a
1532     * another element in a PROPERTY list.
1533     */

1534        private boolean anotherPropertyFollows()
1535        {
1536                boolean retval = false;
1537
1538                // Element must start with COMMA
1539
if (getToken(1).kind == COMMA)
1540                {
1541                        // Rest of element is dot-separated list with = at end
1542
int i = 3;
1543                        int tokKind;
1544                        do
1545                        {
1546                                tokKind = getToken(i).kind;
1547
1548                                // If we've found nothing but PERIODs until the EQUALS_OPERATOR
1549
// it is the beginning of another property list element.
1550
if (tokKind == EQUALS_OPERATOR)
1551                                {
1552                                        retval = true;
1553                                        break;
1554                                }
1555
1556                                i += 2;
1557                        } while (tokKind == PERIOD);
1558                }
1559
1560                return retval;
1561        }
1562
1563        /**
1564     * Get one of the several types of create alias nodes.
1565     *
1566     * @param aliasName The name of the alias
1567     * @param fullStaticMethodName The full path/method name
1568     * @param aliasSpecificInfo Information specific to the type of alias being created.
1569     * @param aliasType The type of alias to create
1570     * @param delimitedIdentifier Whether or not to treat the class name
1571     * as a delimited identifier if trying to
1572     * resolve it as a class alias.
1573     *
1574     * @return A CreateAliasNode matching the given parameters
1575     *
1576     * @exception StandardException Thrown on error
1577     */

1578        QueryTreeNode
1579        getCreateAliasNode(
1580                Object JavaDoc aliasName,
1581                String JavaDoc fullStaticMethodName,
1582                Object JavaDoc aliasSpecificInfo,
1583                char aliasType,
1584                Boolean JavaDoc delimitedIdentifier)
1585                throws StandardException
1586        {
1587
1588                StatementNode aliasNode = (StatementNode) getNodeFactory().getCreateAliasNode
1589                        (
1590                                aliasName,
1591                                fullStaticMethodName,
1592                                aliasSpecificInfo,
1593                                aliasType,
1594                                delimitedIdentifier,
1595                                getContextManager()
1596                        );
1597
1598                return aliasNode;
1599        }
1600
1601        /**
1602        Create a node for the drop alias/procedure call.
1603    */

1604        QueryTreeNode
1605        dropAliasNode(Object JavaDoc aliasName, char type) throws StandardException
1606        {
1607
1608                StatementNode stmt = (StatementNode) nodeFactory.getNode(
1609                                                                C_NodeTypes.DROP_ALIAS_NODE,
1610                                                                aliasName,
1611                                                                new Character JavaDoc(type),
1612                                                                getContextManager());
1613
1614                return stmt;
1615        }
1616
1617    /**
1618     * Get a substring node from
1619     * - the string
1620     * - the start position
1621     * - the length
1622     * - a boolean values for specifying the kind of substring function
1623     * @exception StandardException Thrown on error
1624     */

1625    ValueNode getSubstringNode( ValueNode stringValue, ValueNode startPosition,
1626                         ValueNode length, Boolean JavaDoc boolVal ) throws StandardException
1627    {
1628        return (ValueNode) nodeFactory.getNode(
1629                                                C_NodeTypes.SUBSTRING_OPERATOR_NODE,
1630                                                stringValue,
1631                                                startPosition,
1632                                                length,
1633                                                ReuseFactory.getInteger(TernaryOperatorNode.SUBSTRING),
1634                                                null,
1635                                                    getContextManager());
1636    }
1637
1638    final public TableName
1639    qualifiedName(int id_length_limit) throws ParseException, StandardException
1640    {
1641        return qualifiedName( C_NodeTypes.TABLE_NAME, id_length_limit);
1642    }
1643
1644    private void initStatement( String JavaDoc statementSQLText, Object JavaDoc[] paramDefaults)
1645        throws StandardException
1646    {
1647        /* Do per-statement initialization here */
1648        parameterNumber = 0;
1649       this.statementSQLText = statementSQLText;
1650        this.paramDefaults = paramDefaults;
1651        nodeFactory = getNodeFactory();
1652        initUnnamedParameterList();
1653    } // End of initStatement
1654

1655    private void checkIdentifierLengthLimit( String JavaDoc identifier, int identifier_length_limit)
1656        throws StandardException
1657    {
1658        if (identifier.length() > identifier_length_limit)
1659                throw StandardException.newException(SQLState.LANG_IDENTIFIER_TOO_LONG, identifier, String.valueOf(identifier_length_limit));
1660    }
1661
1662    private ValueNode getJdbcIntervalNode( int intervalType) throws StandardException
1663    {
1664        return (ValueNode) nodeFactory.getNode( C_NodeTypes.INT_CONSTANT_NODE,
1665                                                ReuseFactory.getInteger( intervalType),
1666                                                getContextManager());
1667    }
1668
1669        private void checkAuthorizationLength( String JavaDoc authorization)
1670                throws StandardException
1671        {
1672                checkIdentifierLengthLimit( authorization, Limits.DB2_MAX_USERID_LENGTH);
1673        }
1674
1675    /**
1676        Check to see if the required claues have been added
1677        to a procedure or function defintion.
1678        
1679        @param required int array of require clauses
1680        @param clauses the array of declared clauses.
1681    */

1682    void checkRequiredRoutineClause(int[] required, Object JavaDoc[] clauses)
1683        throws StandardException
1684    {
1685        for (int i = 0; i < required.length; i++)
1686        {
1687            int re = required[i];
1688            if (clauses[re] == null)
1689            {
1690                throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR,
1691                                 ROUTINE_CLAUSE_NAMES[re]);
1692                    }
1693                }
1694    }
1695
1696/*
1697 * <A NAME="Statement">Statement</A>
1698 */

1699  final public QueryTreeNode Statement(String JavaDoc statementSQLText, Object JavaDoc[] paramDefaults) throws ParseException, StandardException {
1700        QueryTreeNode statementNode;
1701
1702        initStatement(statementSQLText, paramDefaults);
1703    statementNode = StatementPart(null);
1704    jj_consume_token(0);
1705                {if (true) return statementNode;}
1706    throw new Error JavaDoc("Missing return statement in function");
1707  }
1708
1709  final public QueryTreeNode proceduralStatement(Token[] tokenHolder) throws ParseException, StandardException {
1710        QueryTreeNode statementNode;
1711        tokenHolder[0] = getToken(1);
1712    switch (jj_nt.kind) {
1713    case INSERT:
1714      statementNode = insertStatement();
1715      break;
1716    case UPDATE:
1717      statementNode = preparableUpdateStatement();
1718      break;
1719    case DELETE:
1720      statementNode = preparableDeleteStatement();
1721      break;
1722    case SELECT:
1723    case VALUES:
1724    case LEFT_PAREN:
1725      statementNode = preparableSelectStatement(true);
1726      break;
1727    case CALL:
1728    case LEFT_BRACE:
1729    case QUESTION_MARK:
1730      statementNode = callStatement();
1731      break;
1732    default:
1733      jj_la1[0] = jj_gen;
1734      jj_consume_token(-1);
1735      throw new ParseException();
1736    }
1737                {if (true) return statementNode;}
1738    throw new Error JavaDoc("Missing return statement in function");
1739  }
1740
1741/*
1742 * <A NAME="StatementPart">StatementPart</A>
1743 *
1744 * @param tokenHolder returns the token that starts
1745 * the statement. If null, ignored.
1746 */

1747  final public QueryTreeNode StatementPart(Token[] tokenHolder) throws ParseException, StandardException {
1748        QueryTreeNode statementNode;
1749        //before starting new statements, initialize this variables. Otherwise, the left
1750
//over values from previously failed sql will affect the next sql.
1751
explicitNotNull = false;
1752        explicitNull = false;
1753        explicitlyNullableColumnsList = new Vector JavaDoc();
1754
1755        /*
1756    ** Grab the token preceding this production
1757    */

1758        if (tokenHolder != null)
1759        {
1760                tokenHolder[0] = getToken(1);
1761        }
1762    switch (jj_nt.kind) {
1763    case LOCK:
1764    case RENAME:
1765      switch (jj_nt.kind) {
1766      case RENAME:
1767        statementNode = spsRenameStatement();
1768        break;
1769      case LOCK:
1770        // statementNode = SQLTransactionStatement() |
1771
statementNode = lockStatement();
1772        break;
1773      default:
1774        jj_la1[1] = jj_gen;
1775        jj_consume_token(-1);
1776        throw new ParseException();
1777      }
1778        {if (true) return statementNode;}
1779      break;
1780    default:
1781      jj_la1[4] = jj_gen;
1782      if (jj_2_2(1)) {
1783        switch (jj_nt.kind) {
1784        case CREATE:
1785          statementNode = createStatements();
1786          break;
1787        case DROP:
1788          statementNode = dropStatements();
1789          break;
1790        case ALTER:
1791          statementNode = spsAlterStatement();
1792          break;
1793        case DECLARE:
1794          statementNode = globalTemporaryTableDeclaration();
1795          break;
1796        case DELETE:
1797        case INSERT:
1798        case ROLLBACK:
1799        case SELECT:
1800        case UPDATE:
1801        case VALUES:
1802        case RELEASE:
1803        case SAVEPOINT:
1804        case CALL:
1805        case LEFT_BRACE:
1806        case LEFT_PAREN:
1807        case QUESTION_MARK:
1808          statementNode = preparableSQLDataStatement();
1809          break;
1810        default:
1811          jj_la1[2] = jj_gen;
1812          if (jj_2_1(1)) {
1813            statementNode = spsSetStatement();
1814          } else {
1815            switch (jj_nt.kind) {
1816            case TRUNCATE:
1817              statementNode = truncateTableStatement();
1818              break;
1819            case GRANT:
1820              statementNode = grantStatement();
1821              break;
1822            case REVOKE:
1823              statementNode = revokeStatement();
1824              break;
1825            case EXECUTE:
1826              statementNode = execStatement();
1827              break;
1828            default:
1829              jj_la1[3] = jj_gen;
1830              jj_consume_token(-1);
1831              throw new ParseException();
1832            }
1833          }
1834        }
1835        {if (true) return statementNode;}
1836      } else {
1837        jj_consume_token(-1);
1838        throw new ParseException();
1839      }
1840    }
1841    throw new Error JavaDoc("Missing return statement in function");
1842  }
1843
1844/*
1845 * <A NAME="createStatements">spsCreateStatement</A>
1846 */

1847  final public QueryTreeNode createStatements() throws ParseException, StandardException {
1848        QueryTreeNode statementNode;
1849        Token beginToken;
1850        int tokKind;
1851    beginToken = jj_consume_token(CREATE);
1852    switch (jj_nt.kind) {
1853    case SCHEMA:
1854    case VIEW:
1855    case SYNONYM:
1856    case TRIGGER:
1857      switch (jj_nt.kind) {
1858      case SCHEMA:
1859        statementNode = schemaDefinition();
1860        break;
1861      case VIEW:
1862        statementNode = viewDefinition(beginToken);
1863        break;
1864      case TRIGGER:
1865        statementNode = triggerDefinition();
1866        break;
1867      case SYNONYM:
1868        statementNode = synonymDefinition();
1869        break;
1870      default:
1871        jj_la1[5] = jj_gen;
1872        jj_consume_token(-1);
1873        throw new ParseException();
1874      }
1875
1876      break;
1877    case TABLE:
1878      statementNode = tableDefinition();
1879
1880      break;
1881    case PROCEDURE:
1882      statementNode = procedureDefinition();
1883      break;
1884    case FUNCTION:
1885      statementNode = functionDefinition();
1886      break;
1887    case UNIQUE:
1888    case INDEX:
1889      statementNode = indexDefinition();
1890
1891      break;
1892    default:
1893      jj_la1[6] = jj_gen;
1894      jj_consume_token(-1);
1895      throw new ParseException();
1896    }
1897                {if (true) return statementNode;}
1898    throw new Error JavaDoc("Missing return statement in function");
1899  }
1900
1901/*
1902 * <A NAME="dropStatements">spsDropStatement</A>
1903 */

1904  final public QueryTreeNode dropStatements() throws ParseException, StandardException {
1905        QueryTreeNode statementNode;
1906    jj_consume_token(DROP);
1907    switch (jj_nt.kind) {
1908    case SCHEMA:
1909      statementNode = dropSchemaStatement();
1910      break;
1911    case TABLE:
1912      statementNode = dropTableStatement();
1913      break;
1914    case INDEX:
1915      statementNode = dropIndexStatement();
1916      break;
1917    case FUNCTION:
1918    case PROCEDURE:
1919    case SYNONYM:
1920      statementNode = dropAliasStatement();
1921      break;
1922    case VIEW:
1923      statementNode = dropViewStatement();
1924      break;
1925    case TRIGGER:
1926      statementNode = dropTriggerStatement();
1927      break;
1928    default:
1929      jj_la1[7] = jj_gen;
1930      jj_consume_token(-1);
1931      throw new ParseException();
1932    }
1933                {if (true) return statementNode;}
1934    throw new Error JavaDoc("Missing return statement in function");
1935  }
1936
1937/*
1938 * <A NAME="spsAlterStatement">spsAlterStatement</A>
1939 */

1940  final public QueryTreeNode spsAlterStatement() throws ParseException, StandardException {
1941        QueryTreeNode statementNode;
1942    jj_consume_token(ALTER);
1943    statementNode = alterTableStatement();
1944                {if (true) return statementNode;}
1945    throw new Error JavaDoc("Missing return statement in function");
1946  }
1947
1948/*
1949 * <A NAME="spsSetStatement">spsSetStatement</A>
1950 */

1951  final public QueryTreeNode spsSetStatement() throws ParseException, StandardException {
1952        QueryTreeNode statementNode;
1953    if (getToken(1).kind == SET && getToken(2).kind != CURRENT) {
1954      jj_consume_token(SET);
1955      if (jj_2_3(1)) {
1956        statementNode = setIsolationStatement();
1957      } else if (jj_2_4(1)) {
1958        statementNode = setSchemaStatement();
1959      } else {
1960        switch (jj_nt.kind) {
1961        case MESSAGE_LOCALE:
1962          statementNode = setMessageLocaleStatement();
1963          break;
1964        default:
1965          jj_la1[8] = jj_gen;
1966          jj_consume_token(-1);
1967          throw new ParseException();
1968        }
1969      }
1970                {if (true) return statementNode;}
1971    } else if (getToken(1).kind == SET && getToken(2).kind == CURRENT) {
1972      jj_consume_token(SET);
1973      if (jj_2_5(1)) {
1974        statementNode = setSchemaStatement();
1975      } else if (jj_2_6(1)) {
1976        statementNode = setIsolationStatement();
1977      } else {
1978        jj_consume_token(-1);
1979        throw new ParseException();
1980      }
1981                {if (true) return statementNode;}
1982    } else {
1983      jj_consume_token(-1);
1984      throw new ParseException();
1985    }
1986    throw new Error JavaDoc("Missing return statement in function");
1987  }
1988
1989/*
1990 * <A NAME="preparableSQLDataStatement">preparableSQLDataStatement</A>
1991 *
1992 * preparableSQLDataStatement differs from
1993 * directSQLDataStatement in that it
1994 * supports positioned update and delete
1995 * and a preparable select (with FOR UPDATE)
1996 * instead of a direct select (without FOR UPDATE)
1997 */

1998  final public QueryTreeNode preparableSQLDataStatement() throws ParseException, StandardException {
1999        QueryTreeNode dmlStatement;
2000    switch (jj_nt.kind) {
2001    case DELETE:
2002      /*
2003        ** RESOLVE: Ignoring temporary table declarations for now.
2004        */

2005              dmlStatement = preparableDeleteStatement();
2006                {if (true) return dmlStatement;}
2007      break;
2008    case SELECT:
2009    case VALUES:
2010    case LEFT_PAREN:
2011      dmlStatement = preparableSelectStatement(true);
2012                {if (true) return dmlStatement;}
2013      break;
2014    case INSERT:
2015      dmlStatement = insertStatement();
2016                {if (true) return dmlStatement;}
2017      break;
2018    case UPDATE:
2019      dmlStatement = preparableUpdateStatement();
2020                {if (true) return dmlStatement;}
2021      break;
2022    case CALL:
2023    case LEFT_BRACE:
2024    case QUESTION_MARK:
2025      dmlStatement = callStatement();
2026                {if (true) return dmlStatement;}
2027      break;
2028    case ROLLBACK:
2029    case RELEASE:
2030    case SAVEPOINT:
2031      dmlStatement = savepointStatement();
2032                {if (true) return dmlStatement;}
2033      break;
2034    default:
2035      jj_la1[9] = jj_gen;
2036      jj_consume_token(-1);
2037      throw new ParseException();
2038    }
2039    throw new Error JavaDoc("Missing return statement in function");
2040  }
2041
2042/*
2043 * <A NAME="preparableDeleteStatement">preparableDeleteStatement</A>
2044 *
2045 * This may be a search or positioned delete statement.
2046 */

2047  final public QueryTreeNode preparableDeleteStatement() throws ParseException, StandardException {
2048        QueryTreeNode qtn;
2049    jj_consume_token(DELETE);
2050    qtn = deleteBody();
2051                {if (true) return qtn;}
2052    throw new Error JavaDoc("Missing return statement in function");
2053  }
2054
2055  final public QueryTreeNode deleteBody() throws ParseException, StandardException {
2056        JavaToSQLValueNode javaToSQLNode = null;
2057        String JavaDoc correlationName = null;
2058        TableName tableName = null;
2059        ValueNode whereClause = null;
2060        FromTable fromTable = null;
2061        QueryTreeNode retval;
2062        Properties targetProperties = null;
2063        Token whereToken = null;
2064    if (fromNewInvocationFollows()) {
2065      jj_consume_token(FROM);
2066      javaToSQLNode = newInvocation();
2067      switch (jj_nt.kind) {
2068      case WHERE:
2069        whereToken = jj_consume_token(WHERE);
2070        whereClause = whereClause(whereToken);
2071        break;
2072      default:
2073        jj_la1[10] = jj_gen;
2074        ;
2075      }
2076                fromTable = (FromTable) nodeFactory.getNode(
2077                                                                        C_NodeTypes.FROM_VTI,
2078                                                                        javaToSQLNode.getJavaValueNode(),
2079                                                                        (String JavaDoc) null,
2080                                                                        null,
2081                                                                        (Properties) null,
2082                                                                        getContextManager());
2083
2084                {if (true) return getDeleteNode(fromTable, tableName, whereClause);}
2085    } else {
2086      switch (jj_nt.kind) {
2087      case FROM:
2088        jj_consume_token(FROM);
2089        tableName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH);
2090        if ((getToken(1).kind != EOF) && (getToken(1).kind != WHERE) && !derbyPropertiesListFollows()) {
2091          switch (jj_nt.kind) {
2092          case AS:
2093            jj_consume_token(AS);
2094            break;
2095          default:
2096            jj_la1[11] = jj_gen;
2097            ;
2098          }
2099          correlationName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
2100        } else {
2101          ;
2102        }
2103        switch (jj_nt.kind) {
2104        case DERBYDASHPROPERTIES:
2105          targetProperties = propertyList(false);
2106          jj_consume_token(CHECK_PROPERTIES);
2107          break;
2108        default:
2109          jj_la1[12] = jj_gen;
2110          ;
2111        }
2112        switch (jj_nt.kind) {
2113        case WHERE:
2114          whereToken = jj_consume_token(WHERE);
2115          if ((getToken(1).kind == CURRENT) &&
2116                                                   (getToken(2).kind == OF)) {
2117            fromTable = currentOfClause(correlationName);
2118          } else if (jj_2_7(1)) {
2119            whereClause = whereClause(whereToken);
2120          } else {
2121            jj_consume_token(-1);
2122            throw new ParseException();
2123          }
2124          break;
2125        default:
2126          jj_la1[13] = jj_gen;
2127          ;
2128        }
2129                /* Fabricate a ResultSetNode (SelectNode) under the DeleteNode.
2130         * For a searched delete,
2131         * The FromList is simply the table that we are deleting from.
2132         * (NOTE - we mark the table as the one that we are deleting from.)
2133         * For a positioned delete,
2134         * the FromList is a CurrentOfNode holding the cursor name.
2135         * The select list will be null for now. We will generate it at
2136         * bind time, in keeping with the design decision that the parser's
2137         * output should look like the language.
2138         */

2139                if (fromTable == null)
2140                        fromTable = (FromTable) nodeFactory.getNode(
2141                                                                                C_NodeTypes.FROM_BASE_TABLE,
2142                                                                                tableName,
2143                                                                                correlationName,
2144                                                                                ReuseFactory.getInteger(
2145                                                                                                FromBaseTable.DELETE),
2146                                                                                null,
2147                                                                                getContextManager());
2148
2149                /* Update the FromTable with any properties, if non-null */
2150                if (targetProperties != null)
2151                {
2152                        if (SanityManager.DEBUG)
2153                        {
2154                                if (((FromBaseTable) fromTable).getProperties() != null)
2155                                {
2156                                        SanityManager.THROWASSERT(
2157                                                "Overwriting existing properties");
2158                                }
2159                        }
2160                        ((FromBaseTable) fromTable).setTableProperties(targetProperties);
2161                }
2162
2163                {if (true) return getDeleteNode(fromTable, tableName, whereClause);}
2164        break;
2165      default:
2166        jj_la1[14] = jj_gen;
2167        jj_consume_token(-1);
2168        throw new ParseException();
2169      }
2170    }
2171    throw new Error JavaDoc("Missing return statement in function");
2172  }
2173
2174/*
2175 * <A NAME="currentOfClause">currentOfClause</A>
2176 */

2177  final public FromTable currentOfClause(String JavaDoc correlationName) throws ParseException, StandardException {
2178        String JavaDoc cursorName = null;
2179    jj_consume_token(CURRENT);
2180    jj_consume_token(OF);
2181    cursorName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
2182                {if (true) return (FromTable) nodeFactory.getNode(
2183                                                                C_NodeTypes.CURRENT_OF_NODE,
2184                                                                correlationName,
2185                                                                cursorName,
2186                                                                null,
2187                                                                getContextManager());}
2188    throw new Error JavaDoc("Missing return statement in function");
2189  }
2190
2191/*
2192 * <A NAME="preparableSelectStatement">preparableSelectStatement</A>
2193 *
2194 *
2195 * The preparable select statement is a superset of
2196 * the directSelectStatementMultipleRows in that it
2197 * allows both the preparable single row select statement
2198 * (a query expression that returns one row, although it
2199 * is also handled like a cursor) and the preparable
2200 * multiple row select statement, which allows not only
2201 * an order by clause but also a for update clause.
2202 */

2203  final public CursorNode preparableSelectStatement(boolean checkParams) throws ParseException, StandardException {
2204        ResultSetNode queryExpression;
2205        Vector JavaDoc updateColumns = new Vector JavaDoc();
2206        int forUpdateState = CursorNode.UNSPECIFIED;
2207        int isolationLevel = ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL;
2208        CursorNode retval;
2209        OrderByList orderCols = null;
2210    queryExpression = queryExpression(null, NO_SET_OP);
2211    switch (jj_nt.kind) {
2212    case ORDER:
2213      orderCols = orderByClause();
2214      break;
2215    default:
2216      jj_la1[15] = jj_gen;
2217      ;
2218    }
2219    switch (jj_nt.kind) {
2220    case FOR:
2221      jj_consume_token(FOR);
2222      forUpdateState = forUpdateClause(updateColumns);
2223      break;
2224    default:
2225      jj_la1[16] = jj_gen;
2226      ;
2227    }
2228    switch (jj_nt.kind) {
2229    case WITH:
2230      isolationLevel = atIsolationLevel();
2231      break;
2232    default:
2233      jj_la1[17] = jj_gen;
2234      ;
2235    }
2236                // Note: if order by is specified, the for update clause
2237
// must be READ ONLY or empty, and the cursor
2238
// is implicitly READ_ONLY.
2239

2240                retval = (CursorNode) nodeFactory.getNode(
2241                                C_NodeTypes.CURSOR_NODE,
2242                                "SELECT",
2243                                queryExpression,
2244                                null,
2245                                orderCols,
2246                                ReuseFactory.getInteger(forUpdateState),
2247                                (forUpdateState == CursorNode.READ_ONLY ? null : updateColumns ),
2248                                getContextManager());
2249
2250                if (checkParams)
2251                {
2252                        setUpAndLinkParameters();
2253                }
2254
2255                /* Set the isolation levels for the scans if specified */
2256                if (isolationLevel != ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL)
2257                {
2258                        getCompilerContext().setScanIsolationLevel(isolationLevel);
2259                }
2260
2261                {if (true) return retval;}
2262    throw new Error JavaDoc("Missing return statement in function");
2263  }
2264
2265/*
2266 * <A NAME="insertStatement">insertStatement</A>
2267 */

2268  final public QueryTreeNode insertStatement() throws ParseException, StandardException {
2269        QueryTreeNode insertNode;
2270        QueryTreeNode targetTable;
2271    jj_consume_token(INSERT);
2272    jj_consume_token(INTO);
2273    targetTable = targetTable();
2274    insertNode = insertColumnsAndSource(targetTable);
2275                setUpAndLinkParameters();
2276
2277                {if (true) return insertNode;}
2278    throw new Error JavaDoc("Missing return statement in function");
2279  }
2280
2281  final public QueryTreeNode targetTable() throws ParseException, StandardException {
2282        JavaToSQLValueNode javaToSQLNode = null;
2283        String JavaDoc correlationName = null;
2284        TableName tableName;
2285    if (newInvocationFollows(1)) {
2286      javaToSQLNode = newInvocation();
2287                {if (true) return (QueryTreeNode) nodeFactory.getNode(
2288                                                                C_NodeTypes.FROM_VTI,
2289                                                                javaToSQLNode.getJavaValueNode(),
2290                                                                correlationName,
2291                                                                null,
2292                                                                (Properties) null,
2293                                                                getContextManager());}
2294    } else {
2295      switch (jj_nt.kind) {
2296      case BINARY:
2297      case COALESCE:
2298      case COUNT:
2299      case D:
2300      case MODULE:
2301      case T:
2302      case TS:
2303      case VALUE:
2304      case VARBINARY:
2305      case ABS:
2306      case ABSVAL:
2307      case ACTION:
2308      case ALWAYS:
2309      case BLOB:
2310      case C:
2311      case CALLED:
2312      case CLOB:
2313      case COBOL:
2314      case COMMITTED:
2315      case CONCAT:
2316      case CONTAINS:
2317      case DATA:
2318      case DATE:
2319      case DAY:
2320      case DYNAMIC:
2321      case FORTRAN:
2322      case GENERATED:
2323      case IDENTITY_VAL_LOCAL:
2324      case INCREMENT:
2325      case INITIAL:
2326      case INTERVAL:
2327      case LANGUAGE:
2328      case LARGE:
2329      case LENGTH:
2330      case LEVEL:
2331      case LOCKS:
2332      case LOCKSIZE:
2333      case LOGGED:
2334      case MOD:
2335      case MODIFIES:
2336      case MODIFY:
2337      case MONTH:
2338      case _MORE:
2339      case MUMPS:
2340      case NAME:
2341      case NCLOB:
2342      case NULLABLE:
2343      case NUMBER:
2344      case OBJECT:
2345      case PASCAL:
2346      case PLI:
2347      case PRECISION:
2348      case RELEASE:
2349      case REPEATABLE:
2350      case RESTART:
2351      case RETURNS:
2352      case ROW:
2353      case SAVEPOINT:
2354      case SCALE:
2355      case SERIALIZABLE:
2356      case SQL_TSI_FRAC_SECOND:
2357      case SQL_TSI_SECOND:
2358      case SQL_TSI_MINUTE:
2359      case SQL_TSI_HOUR:
2360      case SQL_TSI_DAY:
2361      case SQL_TSI_WEEK:
2362      case SQL_TSI_MONTH:
2363      case SQL_TSI_QUARTER:
2364      case SQL_TSI_YEAR:
2365      case START:
2366      case STATEMENT:
2367      case SYNONYM:
2368      case THEN:
2369      case TIME:
2370      case TIMESTAMP:
2371      case TIMESTAMPADD:
2372      case TIMESTAMPDIFF:
2373      case TRUNCATE:
2374      case TYPE:
2375      case UNCOMMITTED:
2376      case USAGE:
2377      case WHEN:
2378      case CURDATE:
2379      case CURTIME:
2380      case DATABASE:
2381      case LONG:
2382      case AFTER:
2383      case BEFORE:
2384      case CLASS:
2385      case COMPRESS:
2386      case CONTENT:
2387      case CS:
2388      case DB2SQL:
2389      case DIRTY:
2390      case DOCUMENT:
2391      case EACH:
2392      case EMPTY:
2393      case EXCLUSIVE:
2394      case FN:
2395      case INDEX:
2396      case JAVA:
2397      case LCASE:
2398      case LOCATE:
2399      case LOCK:
2400      case MESSAGE_LOCALE:
2401      case METHOD:
2402      case MODE:
2403      case NEW:
2404      case NEW_TABLE:
2405      case OJ:
2406      case OFF:
2407      case OLD:
2408      case OLD_TABLE:
2409      case PARAMETER:
2410      case PASSING:
2411      case PROPERTIES:
2412      case READS:
2413      case REF:
2414      case REFERENCING:
2415      case RENAME:
2416      case RESET:
2417      case RESULT:
2418      case RETAIN:
2419      case RETURNING:
2420      case RR:
2421      case RS:
2422      case SEQUENCE:
2423      case SEQUENTIAL:
2424      case SETS:
2425      case SHARE:
2426      case SQLID:
2427      case SPECIFIC:
2428      case SQRT:
2429      case STABILITY:
2430      case STRIP:
2431      case STYLE:
2432      case TRIGGER:
2433      case UCASE:
2434      case UR:
2435      case WHITESPACE:
2436      case IDENTIFIER:
2437      case DELIMITED_IDENTIFIER:
2438        tableName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH);
2439                {if (true) return (QueryTreeNode) tableName;}
2440        break;
2441      default:
2442        jj_la1[18] = jj_gen;
2443        jj_consume_token(-1);
2444        throw new ParseException();
2445      }
2446    }
2447    throw new Error JavaDoc("Missing return statement in function");
2448  }
2449
2450/*
2451 * <A NAME="preparableUpdateStatement">preparableUpdateStatement</A>
2452 */

2453  final public QueryTreeNode preparableUpdateStatement() throws ParseException, StandardException {
2454        QueryTreeNode qtn;
2455    jj_consume_token(UPDATE);
2456    qtn = updateBody();
2457                {if (true) return qtn;}
2458    throw new Error JavaDoc("Missing return statement in function");
2459  }
2460
2461  final public boolean tableOrIndex() throws ParseException {
2462    switch (jj_nt.kind) {
2463    case TABLE:
2464      jj_consume_token(TABLE);
2465                {if (true) return true;}
2466      break;
2467    case INDEX:
2468      jj_consume_token(INDEX);
2469                {if (true) return false;}
2470      break;
2471    default:
2472      jj_la1[19] = jj_gen;
2473      jj_consume_token(-1);
2474      throw new ParseException();
2475    }
2476    throw new Error JavaDoc("Missing return statement in function");
2477  }
2478
2479  final public QueryTreeNode updateBody() throws ParseException, StandardException {
2480        ResultColumnList columnList;
2481        String JavaDoc correlationName = null;
2482        JavaToSQLValueNode javaToSQLNode = null;
2483        TableName tableName = null;
2484        ValueNode whereClause = null;
2485        FromTable fromTable = null;
2486        Properties targetProperties = null;
2487        Token whereToken = null;
2488    if (newInvocationFollows(1)) {
2489      javaToSQLNode = newInvocation();
2490      jj_consume_token(SET);
2491      columnList = setClauseList();
2492      switch (jj_nt.kind) {
2493      case WHERE:
2494        whereToken = jj_consume_token(WHERE);
2495        whereClause = whereClause(whereToken);
2496        break;
2497      default:
2498        jj_la1[20] = jj_gen;
2499        ;
2500      }
2501                fromTable = (FromTable) nodeFactory.getNode(
2502                                                                        C_NodeTypes.FROM_VTI,
2503                                                                        javaToSQLNode.getJavaValueNode(),
2504                                                                        (String JavaDoc) null,
2505                                                                        null,
2506                                                                        (Properties) null,
2507                                                                        getContextManager());
2508
2509                {if (true) return getUpdateNode(fromTable, tableName, columnList, whereClause);}
2510    } else {
2511      switch (jj_nt.kind) {
2512      case BINARY:
2513      case COALESCE:
2514      case COUNT:
2515      case D:
2516      case MODULE:
2517      case T:
2518      case TS:
2519      case VALUE:
2520      case VARBINARY:
2521      case ABS:
2522      case ABSVAL:
2523      case ACTION:
2524      case ALWAYS:
2525      case BLOB:
2526      case C:
2527      case CALLED:
2528      case CLOB:
2529      case COBOL:
2530      case COMMITTED:
2531      case CONCAT:
2532      case CONTAINS:
2533      case DATA:
2534      case DATE:
2535      case DAY:
2536      case DYNAMIC:
2537      case FORTRAN:
2538      case GENERATED:
2539      case IDENTITY_VAL_LOCAL:
2540      case INCREMENT:
2541      case INITIAL:
2542      case INTERVAL:
2543      case LANGUAGE:
2544      case LARGE:
2545      case LENGTH:
2546      case LEVEL:
2547      case LOCKS:
2548      case LOCKSIZE:
2549      case LOGGED:
2550      case MOD:
2551      case MODIFIES:
2552      case MODIFY:
2553      case MONTH:
2554      case _MORE:
2555      case MUMPS:
2556      case NAME:
2557      case NCLOB:
2558      case NULLABLE:
2559      case NUMBER:
2560      case OBJECT:
2561      case PASCAL:
2562      case PLI:
2563      case PRECISION:
2564      case RELEASE:
2565      case REPEATABLE:
2566      case RESTART:
2567      case RETURNS:
2568      case ROW:
2569      case SAVEPOINT:
2570      case SCALE:
2571      case SERIALIZABLE:
2572      case SQL_TSI_FRAC_SECOND:
2573      case SQL_TSI_SECOND:
2574      case SQL_TSI_MINUTE:
2575      case SQL_TSI_HOUR:
2576      case SQL_TSI_DAY:
2577      case SQL_TSI_WEEK:
2578      case SQL_TSI_MONTH:
2579      case SQL_TSI_QUARTER:
2580      case SQL_TSI_YEAR:
2581      case START:
2582      case STATEMENT:
2583      case SYNONYM:
2584      case THEN:
2585      case TIME:
2586      case TIMESTAMP:
2587      case TIMESTAMPADD:
2588      case TIMESTAMPDIFF:
2589      case TRUNCATE:
2590      case TYPE:
2591      case UNCOMMITTED:
2592      case USAGE:
2593      case WHEN:
2594      case CURDATE:
2595      case CURTIME:
2596      case DATABASE:
2597      case LONG:
2598      case AFTER:
2599      case BEFORE:
2600      case CLASS:
2601      case COMPRESS:
2602      case CONTENT:
2603      case CS:
2604      case DB2SQL:
2605      case DIRTY:
2606      case DOCUMENT:
2607      case EACH:
2608      case EMPTY:
2609      case EXCLUSIVE:
2610      case FN:
2611      case INDEX:
2612      case JAVA:
2613      case LCASE:
2614      case LOCATE:
2615      case LOCK:
2616      case MESSAGE_LOCALE:
2617      case METHOD:
2618      case MODE:
2619      case NEW:
2620      case NEW_TABLE:
2621      case OJ:
2622      case OFF:
2623      case OLD:
2624      case OLD_TABLE:
2625      case PARAMETER:
2626      case PASSING:
2627      case PROPERTIES:
2628      case READS:
2629      case REF:
2630      case REFERENCING:
2631      case RENAME:
2632      case RESET:
2633      case RESULT:
2634      case RETAIN:
2635      case RETURNING:
2636      case RR:
2637      case RS:
2638      case SEQUENCE:
2639      case SEQUENTIAL:
2640      case SETS:
2641      case SHARE:
2642      case SQLID:
2643      case SPECIFIC:
2644      case SQRT:
2645      case STABILITY:
2646      case STRIP:
2647      case STYLE:
2648      case TRIGGER:
2649      case UCASE:
2650      case UR:
2651      case WHITESPACE:
2652      case IDENTIFIER:
2653      case DELIMITED_IDENTIFIER:
2654        tableName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH);
2655        if ((getToken(1).kind != SET) && !derbyPropertiesListFollows()) {
2656          switch (jj_nt.kind) {
2657          case AS:
2658            jj_consume_token(AS);
2659            break;
2660          default:
2661            jj_la1[21] = jj_gen;
2662            ;
2663          }
2664          correlationName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
2665        } else {
2666          ;
2667        }
2668        switch (jj_nt.kind) {
2669        case DERBYDASHPROPERTIES:
2670          targetProperties = propertyList(false);
2671          jj_consume_token(CHECK_PROPERTIES);
2672          break;
2673        default:
2674          jj_la1[22] = jj_gen;
2675          ;
2676        }
2677        jj_consume_token(SET);
2678        columnList = setClauseList();
2679        switch (jj_nt.kind) {
2680        case WHERE:
2681          whereToken = jj_consume_token(WHERE);
2682          if (jj_2_8(1)) {
2683            whereClause = whereClause(whereToken);
2684          } else {
2685            switch (jj_nt.kind) {
2686            case CURRENT:
2687              fromTable = currentOfClause(correlationName);
2688              break;
2689            default:
2690              jj_la1[23] = jj_gen;
2691              jj_consume_token(-1);
2692              throw new ParseException();
2693            }
2694          }
2695          break;
2696        default:
2697          jj_la1[24] = jj_gen;
2698          ;
2699        }
2700                /* Fabricate a ResultSetNode (SelectNode) under the UpdateNode.
2701         * For a searched update,
2702         * The FromList is simply the table that we are updating.
2703         * For a positioned update,
2704         * the FromList is a CurrentOfNode holding the cursor name.
2705         * (NOTE - we mark the table as the one that we are updating.)
2706         * The select list is the columns in the SET clause. At bind time,
2707         * we will prepend the CurrentRowLocation() in keeping with the design
2708         * decision that the parser's output should look like the language.
2709         */

2710                if (fromTable == null)
2711                        fromTable = (FromTable) nodeFactory.getNode(
2712                                                                                C_NodeTypes.FROM_BASE_TABLE,
2713                                                                                tableName,
2714                                                                                correlationName,
2715                                                                                ReuseFactory.getInteger(
2716                                                                                                                FromBaseTable.UPDATE),
2717                                                                                null,
2718                                                                                getContextManager());
2719
2720                /* Update the FromTable with any properties, if non-null */
2721                if (targetProperties != null)
2722                {
2723                        if (SanityManager.DEBUG)
2724                        {
2725                                if (((FromBaseTable) fromTable).getProperties() != null)
2726                                {
2727                                        SanityManager.THROWASSERT(
2728                                                "Overwriting existing properties");
2729                                }
2730                        }
2731                        ((FromBaseTable) fromTable).setTableProperties(targetProperties);
2732                }
2733                {if (true) return getUpdateNode(fromTable, tableName, columnList, whereClause);}
2734        break;
2735      default:
2736        jj_la1[25] = jj_gen;
2737        jj_consume_token(-1);
2738        throw new ParseException();
2739      }
2740    }
2741    throw new Error JavaDoc("Missing return statement in function");
2742  }
2743
2744/*
2745 * <A NAME="callStatement">callStatement</A>
2746 */

2747  final public QueryTreeNode callStatement() throws ParseException, StandardException {
2748        QueryTreeNode retval;
2749    switch (jj_nt.kind) {
2750    case CALL:
2751    case QUESTION_MARK:
2752      retval = bareCallStatement();
2753      break;
2754    case LEFT_BRACE:
2755      jj_consume_token(LEFT_BRACE);
2756      retval = bareCallStatement();
2757      jj_consume_token(RIGHT_BRACE);
2758      break;
2759    default:
2760      jj_la1[26] = jj_gen;
2761      jj_consume_token(-1);
2762      throw new ParseException();
2763    }
2764                {if (true) return retval;}
2765    throw new Error JavaDoc("Missing return statement in function");
2766  }
2767
2768/*
2769 * <A NAME="bareCallStatement">baseCallStatement</A>
2770 */

2771  final public QueryTreeNode bareCallStatement() throws ParseException, StandardException {
2772        ParameterNode returnParam = null;
2773
2774        ValueNode value = null;
2775
2776        ResultSetNode resultSetNode = null;
2777    switch (jj_nt.kind) {
2778    case CALL:
2779      jj_consume_token(CALL);
2780      value = primaryExpression(true);
2781                if (! (value instanceof JavaToSQLValueNode) ||
2782                        ! (((JavaToSQLValueNode) value).getJavaValueNode() instanceof MethodCallNode))
2783                {
2784                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_CALL_STATEMENT);}
2785                }
2786
2787                QueryTreeNode callStatement =
2788                                                                        (QueryTreeNode) nodeFactory.getNode(
2789                                                                                                C_NodeTypes.CALL_STATEMENT_NODE,
2790                                                                                                value,
2791                                                                                                getContextManager());
2792
2793                setUpAndLinkParameters();
2794
2795                {if (true) return callStatement;}
2796      break;
2797    case QUESTION_MARK:
2798      returnParam = dynamicParameterSpecification();
2799                getCompilerContext().setReturnParameterFlag(); //bug4450
2800

2801      jj_consume_token(EQUALS_OPERATOR);
2802      jj_consume_token(CALL);
2803      resultSetNode = rowValueConstructor(null);
2804                // validate that we have something that is an appropriate call statement
2805
ResultColumnList rcl = resultSetNode.getResultColumns();
2806
2807                // we can have only 1 return value/column
2808
if (rcl == null || rcl.size() > 1)
2809                {
2810                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_CALL_STATEMENT);}
2811                }
2812
2813                // we must have a method call node
2814
value = ((ResultColumn) rcl.elementAt(0)).getExpression();
2815                if (! (value instanceof JavaToSQLValueNode) ||
2816                        ! (((JavaToSQLValueNode) value).getJavaValueNode() instanceof MethodCallNode))
2817                {
2818                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_CALL_STATEMENT);}
2819                }
2820
2821                // wrap the row result set in a cursor node
2822
QueryTreeNode cursorNode =
2823                                        (QueryTreeNode) nodeFactory.getNode(
2824                                                C_NodeTypes.CURSOR_NODE,
2825                                                "SELECT",
2826                                                resultSetNode,
2827                                                null,
2828                                                null,
2829                                                ReuseFactory.getInteger(CursorNode.READ_ONLY),
2830                                                null,
2831                                                getContextManager());
2832
2833                // set the 0th param to be a RETURN param
2834
returnParam.setReturnOutputParam(value);
2835
2836                setUpAndLinkParameters();
2837
2838                {if (true) return cursorNode;}
2839      break;
2840    default:
2841      jj_la1[27] = jj_gen;
2842      jj_consume_token(-1);
2843      throw new ParseException();
2844    }
2845    throw new Error JavaDoc("Missing return statement in function");
2846  }
2847
2848/*
2849 * <A NAME="primaryExpression">primaryExpression</A>
2850 *
2851 * @param inSelectClause will be true if this method got called while parsing the select or values clause
2852 * If in select or values clause, we do not want to allow boolean values.
2853 */

2854  final public ValueNode primaryExpression(boolean inSelectClause) throws ParseException, StandardException {
2855        ValueNode value = null;
2856    if (getToken(2).kind == PERIOD &&
2857                    getToken(4).kind == LEFT_PAREN) {
2858      value = routineInvocation();
2859                {if (true) return value;}
2860    } else if (jj_2_9(1)) {
2861      value = primaryExpressionXX(inSelectClause);
2862                {if (true) return value;}
2863    } else {
2864      jj_consume_token(-1);
2865      throw new ParseException();
2866    }
2867    throw new Error JavaDoc("Missing return statement in function");
2868  }
2869
2870/*
2871 * <A NAME="savepointStatement">savepointStatement</A>
2872
2873    savepointStatementClauses contains the UNIQUE, ON ROLLBACK RETAIN LOCKS, ON ROLLBACK RETAIN CURSORS clauses.
2874
2875    0 - Boolean - UNIQUE clause
2876    1 - Boolean - ON ROLLBACK RETAIN LOCKS clause
2877    2 - Boolean - ON ROLLBACK RETAIN CURSORS clause
2878 */

2879  final public QueryTreeNode savepointStatement() throws ParseException, StandardException {
2880        String JavaDoc savepointName = null;
2881        int savepointStatementType;
2882        Object JavaDoc[] savepointStatementClauses = new Object JavaDoc[3];
2883    switch (jj_nt.kind) {
2884    case SAVEPOINT:
2885      jj_consume_token(SAVEPOINT);
2886      savepointName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
2887      label_1:
2888      while (true) {
2889        savepointStatementClause(savepointStatementClauses);
2890        switch (jj_nt.kind) {
2891        case ON:
2892        case UNIQUE:
2893          ;
2894          break;
2895        default:
2896          jj_la1[28] = jj_gen;
2897          break label_1;
2898        }
2899      }
2900                //ON ROLLBACK RETAIN CURSORS is mandatory
2901
if (savepointStatementClauses[2] == null)
2902                                {if (true) throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, "MISSING ON ROLLBACK RETAIN CURSORS");}
2903                savepointStatementType = 1;
2904      break;
2905    case ROLLBACK:
2906      jj_consume_token(ROLLBACK);
2907      switch (jj_nt.kind) {
2908      case WORK:
2909        jj_consume_token(WORK);
2910        break;
2911      default:
2912        jj_la1[29] = jj_gen;
2913        ;
2914      }
2915      jj_consume_token(TO);
2916      jj_consume_token(SAVEPOINT);
2917      switch (jj_nt.kind) {
2918      case BINARY:
2919      case COALESCE:
2920      case COUNT:
2921      case D:
2922      case MODULE:
2923      case T:
2924      case TS:
2925      case VALUE:
2926      case VARBINARY:
2927      case ABS:
2928      case ABSVAL:
2929      case ACTION:
2930      case ALWAYS:
2931      case BLOB:
2932      case C:
2933      case CALLED:
2934      case CLOB:
2935      case COBOL:
2936      case COMMITTED:
2937      case CONCAT:
2938      case CONTAINS:
2939      case DATA:
2940      case DATE:
2941      case DAY:
2942      case DYNAMIC:
2943      case FORTRAN:
2944      case GENERATED:
2945      case IDENTITY_VAL_LOCAL:
2946      case INCREMENT:
2947      case INITIAL:
2948      case INTERVAL:
2949      case LANGUAGE:
2950      case LARGE:
2951      case LENGTH:
2952      case LEVEL:
2953      case LOCKS:
2954      case LOCKSIZE:
2955      case LOGGED:
2956      case MOD:
2957      case MODIFIES:
2958      case MODIFY:
2959      case MONTH:
2960      case _MORE:
2961      case MUMPS:
2962      case NAME:
2963      case NCLOB:
2964      case NULLABLE:
2965      case NUMBER:
2966      case OBJECT:
2967      case PASCAL:
2968      case PLI:
2969      case PRECISION:
2970      case RELEASE:
2971      case REPEATABLE:
2972      case RESTART:
2973      case RETURNS:
2974      case ROW:
2975      case SAVEPOINT:
2976      case SCALE:
2977      case SERIALIZABLE:
2978      case SQL_TSI_FRAC_SECOND:
2979      case SQL_TSI_SECOND:
2980      case SQL_TSI_MINUTE:
2981      case SQL_TSI_HOUR:
2982      case SQL_TSI_DAY:
2983      case SQL_TSI_WEEK:
2984      case SQL_TSI_MONTH:
2985      case SQL_TSI_QUARTER:
2986      case SQL_TSI_YEAR:
2987      case START:
2988      case STATEMENT:
2989      case SYNONYM:
2990      case THEN:
2991      case TIME:
2992      case TIMESTAMP:
2993      case TIMESTAMPADD:
2994      case TIMESTAMPDIFF:
2995      case TRUNCATE:
2996      case TYPE:
2997      case UNCOMMITTED:
2998      case USAGE:
2999      case WHEN:
3000      case CURDATE:
3001      case CURTIME:
3002      case DATABASE:
3003      case LONG:
3004      case AFTER:
3005      case BEFORE:
3006      case CLASS:
3007      case COMPRESS:
3008      case CONTENT:
3009      case CS:
3010      case DB2SQL:
3011      case DIRTY:
3012      case DOCUMENT:
3013      case EACH:
3014      case EMPTY:
3015      case EXCLUSIVE:
3016      case FN:
3017      case INDEX:
3018      case JAVA:
3019      case LCASE:
3020      case LOCATE:
3021      case LOCK:
3022      case MESSAGE_LOCALE:
3023      case METHOD:
3024      case MODE:
3025      case NEW:
3026      case NEW_TABLE:
3027      case OJ:
3028      case OFF:
3029      case OLD:
3030      case OLD_TABLE:
3031      case PARAMETER:
3032      case PASSING:
3033      case PROPERTIES:
3034      case READS:
3035      case REF:
3036      case REFERENCING:
3037      case RENAME:
3038      case RESET:
3039      case RESULT:
3040      case RETAIN:
3041      case RETURNING:
3042      case RR:
3043      case RS:
3044      case SEQUENCE:
3045      case SEQUENTIAL:
3046      case SETS:
3047      case SHARE:
3048      case SQLID:
3049      case SPECIFIC:
3050      case SQRT:
3051      case STABILITY:
3052      case STRIP:
3053      case STYLE:
3054      case TRIGGER:
3055      case UCASE:
3056      case UR:
3057      case WHITESPACE:
3058      case IDENTIFIER:
3059      case DELIMITED_IDENTIFIER:
3060        savepointName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
3061        break;
3062      default:
3063        jj_la1[30] = jj_gen;
3064        ;
3065      }
3066                savepointStatementType = 2;
3067      break;
3068    case RELEASE:
3069      jj_consume_token(RELEASE);
3070      switch (jj_nt.kind) {
3071      case TO:
3072        jj_consume_token(TO);
3073        break;
3074      default:
3075        jj_la1[31] = jj_gen;
3076        ;
3077      }
3078      jj_consume_token(SAVEPOINT);
3079      savepointName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
3080                savepointStatementType = 3;
3081      break;
3082    default:
3083      jj_la1[32] = jj_gen;
3084      jj_consume_token(-1);
3085      throw new ParseException();
3086    }
3087                {if (true) return (QueryTreeNode) nodeFactory.getNode(
3088                                                                C_NodeTypes.SAVEPOINT_NODE,
3089                                                                savepointName,
3090                                                                ReuseFactory.getInteger(savepointStatementType),
3091                                                                getContextManager());}
3092    throw new Error JavaDoc("Missing return statement in function");
3093  }
3094
3095  final public void savepointStatementClause(Object JavaDoc[] savepointStatementClauses) throws ParseException, StandardException {
3096        int clausePosition = -1;
3097    switch (jj_nt.kind) {
3098    case UNIQUE:
3099      jj_consume_token(UNIQUE);
3100                          clausePosition = 0;
3101      break;
3102    case ON:
3103      jj_consume_token(ON);
3104      jj_consume_token(ROLLBACK);
3105      jj_consume_token(RETAIN);
3106      clausePosition = LocksOrCursors();
3107      break;
3108    default:
3109      jj_la1[33] = jj_gen;
3110      jj_consume_token(-1);
3111      throw new ParseException();
3112    }
3113                if (clausePosition != -1) {
3114                        // check for repeated clause
3115
if (savepointStatementClauses[clausePosition] != null) {
3116
3117                                String JavaDoc which = SAVEPOINT_CLAUSE_NAMES[clausePosition];
3118                                {if (true) throw StandardException.newException(SQLState.LANG_DB2_MULTIPLE_ELEMENTS, which);}
3119                        }
3120
3121                        savepointStatementClauses[clausePosition] = Boolean.TRUE;
3122                }
3123  }
3124
3125/*
3126 * <A NAME="LocksOrCursors">LocksOrCursors</A>
3127 */

3128  final public int LocksOrCursors() throws ParseException {
3129    switch (jj_nt.kind) {
3130    case LOCKS:
3131      jj_consume_token(LOCKS);
3132                {if (true) return (1);}
3133      break;
3134    case CURSORS:
3135      jj_consume_token(CURSORS);
3136                {if (true) return (2);}
3137      break;
3138    default:
3139      jj_la1[34] = jj_gen;
3140      jj_consume_token(-1);
3141      throw new ParseException();
3142    }
3143    throw new Error JavaDoc("Missing return statement in function");
3144  }
3145
3146/*
3147 * <A NAME="globalTemporaryTableDeclaration">globalTemporaryTableDeclaration</A>
3148
3149    declareTableClauses contains the NOT LOGGED, on commit and on rollback clauses.
3150
3151    0 - Boolean - NOT LOGGED clause
3152    1 - Boolean - on commit behavior
3153    2 - Boolean - on rollback behavior
3154 */

3155  final public QueryTreeNode globalTemporaryTableDeclaration() throws ParseException, StandardException {
3156        TableName tableName;
3157        TableElementList tableElementList;
3158        Object JavaDoc[] declareTableClauses = new Object JavaDoc[3];
3159    jj_consume_token(DECLARE);
3160    jj_consume_token(GLOBAL);
3161    jj_consume_token(TEMPORARY);
3162    jj_consume_token(TABLE);
3163    tableName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH);
3164    tableElementList = tableElementList();
3165    label_2:
3166    while (true) {
3167      declareTableClause(declareTableClauses);
3168      if (jj_2_10(1)) {
3169        ;
3170      } else {
3171        break label_2;
3172      }
3173    }
3174                // NOT LOGGED is mandatory
3175
if (declareTableClauses[0] == null)
3176                                {if (true) throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, "MISSING NOT LOGGED");}
3177                // if ON COMMIT behavior not explicitly specified in DECLARE command, resort to default ON COMMIT DELETE ROWS
3178
if (declareTableClauses[1] == null)
3179                                declareTableClauses[1] = Boolean.TRUE;
3180                // if ON ROLLBACK behavior not explicitly specified in DECLARE command, resort to default ON ROLLBACK DELETE ROWS
3181
if (declareTableClauses[2] == null)
3182                                declareTableClauses[2] = Boolean.TRUE;
3183                {if (true) return (QueryTreeNode) nodeFactory.getNode(
3184                                                                C_NodeTypes.CREATE_TABLE_NODE,
3185                                                                tableName,
3186                                                                tableElementList,
3187                                                                (Properties)null,
3188                                                                (Boolean JavaDoc) declareTableClauses[1],
3189                                                                (Boolean JavaDoc) declareTableClauses[2],
3190                                                                getContextManager());}
3191    throw new Error JavaDoc("Missing return statement in function");
3192  }
3193
3194  final public void declareTableClause(Object JavaDoc[] declareTableClauses) throws ParseException, StandardException {
3195        int clausePosition = -1;
3196        Object JavaDoc clauseValue = null;
3197    switch (jj_nt.kind) {
3198    case NOT:
3199      jj_consume_token(NOT);
3200      jj_consume_token(LOGGED);
3201                                clauseValue = Boolean.TRUE; clausePosition = 0;
3202      break;
3203    default:
3204      jj_la1[35] = jj_gen;
3205      if (getToken(1).kind == ON && getToken(2).kind == COMMIT) {
3206        jj_consume_token(ON);
3207        jj_consume_token(COMMIT);
3208        clauseValue = onCommit();
3209        jj_consume_token(ROWS);
3210                                                                    clausePosition = 1;
3211      } else if (getToken(1).kind == ON && getToken(2).kind == ROLLBACK) {
3212        jj_consume_token(ON);
3213        jj_consume_token(ROLLBACK);
3214        jj_consume_token(DELETE);
3215        jj_consume_token(ROWS);
3216                                                  clauseValue = Boolean.TRUE; clausePosition = 2;
3217      } else {
3218        jj_consume_token(-1);
3219        throw new ParseException();
3220      }
3221    }
3222                if (clausePosition != -1) {
3223                        // check for repeated clause
3224
if (declareTableClauses[clausePosition] != null) {
3225
3226                                String JavaDoc which = TEMPORARY_TABLE_CLAUSE_NAMES[clausePosition];
3227                                {if (true) throw StandardException.newException(SQLState.LANG_DB2_MULTIPLE_ELEMENTS, which);}
3228                        }
3229
3230                        declareTableClauses[clausePosition] = clauseValue;
3231                }
3232  }
3233
3234/*
3235 * <A NAME="onCommit">onCommit</A>
3236 */

3237  final public Boolean JavaDoc onCommit() throws ParseException {
3238    switch (jj_nt.kind) {
3239    case PRESERVE:
3240      jj_consume_token(PRESERVE);
3241                {if (true) return (Boolean.FALSE);}
3242      break;
3243    case DELETE:
3244      jj_consume_token(DELETE);
3245                {if (true) return (Boolean.TRUE);}
3246      break;
3247    default:
3248      jj_la1[36] = jj_gen;
3249      jj_consume_token(-1);
3250      throw new ParseException();
3251    }
3252    throw new Error JavaDoc("Missing return statement in function");
3253  }
3254
3255/*
3256 * <A NAME="tableElementList">tableElementList</A>
3257 */

3258  final public TableElementList tableElementList() throws ParseException, StandardException {
3259        TableElementList tableElementList =
3260                                        (TableElementList) nodeFactory.getNode(
3261                                                                        C_NodeTypes.TABLE_ELEMENT_LIST,
3262                                                                        getContextManager());
3263    jj_consume_token(LEFT_PAREN);
3264    tableElement(tableElementList);
3265    label_3:
3266    while (true) {
3267      switch (jj_nt.kind) {
3268      case COMMA:
3269        ;
3270        break;
3271      default:
3272        jj_la1[37] = jj_gen;
3273        break label_3;
3274      }
3275      jj_consume_token(COMMA);
3276      tableElement(tableElementList);
3277    }
3278    jj_consume_token(RIGHT_PAREN);
3279                {if (true) return tableElementList;}
3280    throw new Error JavaDoc("Missing return statement in function");
3281  }
3282
3283/*
3284 * <A NAME="tableElement">tableElement</A>
3285 */

3286  final public void tableElement(TableElementList tableElementList) throws ParseException, StandardException {
3287        TableElementNode tableElement;
3288        //initialize following two booleans for every new table element so that the
3289
//values from previous tableElement doesn't impact the next tableElement
3290
explicitNotNull = false;
3291        explicitNull = false;
3292    switch (jj_nt.kind) {
3293    case BINARY:
3294    case COALESCE:
3295    case COUNT:
3296    case D:
3297    case MODULE:
3298    case T:
3299    case TS:
3300    case VALUE:
3301    case VARBINARY:
3302    case ABS:
3303    case ABSVAL:
3304    case ACTION:
3305    case ALWAYS:
3306    case BLOB:
3307    case C:
3308    case CALLED:
3309    case CLOB:
3310    case COBOL:
3311    case COMMITTED:
3312    case CONCAT:
3313    case CONTAINS:
3314    case DATA:
3315    case DATE:
3316    case DAY:
3317    case DYNAMIC:
3318    case FORTRAN:
3319    case GENERATED:
3320    case IDENTITY_VAL_LOCAL:
3321    case INCREMENT:
3322    case INITIAL:
3323    case INTERVAL:
3324    case LANGUAGE:
3325    case LARGE:
3326    case LENGTH:
3327    case LEVEL:
3328    case LOCKS:
3329    case LOCKSIZE:
3330    case LOGGED:
3331    case MOD:
3332    case MODIFIES:
3333    case MODIFY:
3334    case MONTH:
3335    case _MORE:
3336    case MUMPS:
3337    case NAME:
3338    case NCLOB:
3339    case NULLABLE:
3340    case NUMBER:
3341    case OBJECT:
3342    case PASCAL:
3343    case PLI:
3344    case PRECISION:
3345    case RELEASE:
3346    case REPEATABLE:
3347    case RESTART:
3348    case RETURNS:
3349    case ROW:
3350    case SAVEPOINT:
3351    case SCALE:
3352    case SERIALIZABLE:
3353    case SQL_TSI_FRAC_SECOND:
3354    case SQL_TSI_SECOND:
3355    case SQL_TSI_MINUTE:
3356    case SQL_TSI_HOUR:
3357    case SQL_TSI_DAY:
3358    case SQL_TSI_WEEK:
3359    case SQL_TSI_MONTH:
3360    case SQL_TSI_QUARTER:
3361    case SQL_TSI_YEAR:
3362    case START:
3363    case STATEMENT:
3364    case SYNONYM:
3365    case THEN:
3366    case TIME:
3367    case TIMESTAMP:
3368    case TIMESTAMPADD:
3369    case TIMESTAMPDIFF:
3370    case TRUNCATE:
3371    case TYPE:
3372    case UNCOMMITTED:
3373    case USAGE:
3374    case WHEN:
3375    case CURDATE:
3376    case CURTIME:
3377    case DATABASE:
3378    case LONG:
3379    case AFTER:
3380    case BEFORE:
3381    case CLASS:
3382    case COMPRESS:
3383    case CONTENT:
3384    case CS:
3385    case DB2SQL:
3386    case DIRTY:
3387    case DOCUMENT:
3388    case EACH:
3389    case EMPTY:
3390    case EXCLUSIVE:
3391    case FN:
3392    case INDEX:
3393    case JAVA:
3394    case LCASE:
3395    case LOCATE:
3396    case LOCK:
3397    case MESSAGE_LOCALE:
3398    case METHOD:
3399    case MODE:
3400    case NEW:
3401    case NEW_TABLE:
3402    case OJ:
3403    case OFF:
3404    case OLD:
3405    case OLD_TABLE:
3406    case PARAMETER:
3407    case PASSING:
3408    case PROPERTIES:
3409    case READS:
3410    case REF:
3411    case REFERENCING:
3412    case RENAME:
3413    case RESET:
3414    case RESULT:
3415    case RETAIN:
3416    case RETURNING:
3417    case RR:
3418    case RS:
3419    case SEQUENCE:
3420    case SEQUENTIAL:
3421    case SETS:
3422    case SHARE:
3423    case SQLID:
3424    case SPECIFIC:
3425    case SQRT:
3426    case STABILITY:
3427    case STRIP:
3428    case STYLE:
3429    case TRIGGER:
3430    case UCASE:
3431    case UR:
3432    case WHITESPACE:
3433    case IDENTIFIER:
3434    case DELIMITED_IDENTIFIER:
3435      tableElement = columnDefinition(tableElementList);
3436                tableElementList.addTableElement(tableElement);
3437      break;
3438    case CHECK:
3439    case CONSTRAINT:
3440    case FOREIGN:
3441    case PRIMARY:
3442    case UNIQUE:
3443      tableElement = tableConstraintDefinition();
3444                tableElementList.addTableElement(tableElement);
3445      break;
3446    default:
3447      jj_la1[38] = jj_gen;
3448      jj_consume_token(-1);
3449      throw new ParseException();
3450    }
3451  }
3452
3453/*
3454 * <A NAME="columnDefinition">columnDefinition</A>
3455 */

3456  final public TableElementNode columnDefinition(TableElementList tableElementList) throws ParseException, StandardException {
3457        DataTypeDescriptor typeDescriptor = null;
3458        ValueNode defaultNode = null;
3459        String JavaDoc columnName;
3460        long[] autoIncrementInfo = new long[4];
3461    /*
3462        ** RESOLVE: We are ignoring domains and collation.
3463        */

3464    
3465            /* identifier() used to be columnName() */
3466            columnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
3467    typeDescriptor = dataTypeDDL();
3468    switch (jj_nt.kind) {
3469    case CHECK:
3470    case CONSTRAINT:
3471    case _DEFAULT:
3472    case NOT:
3473    case PRIMARY:
3474    case REFERENCES:
3475    case UNIQUE:
3476    case WITH:
3477    case GENERATED:
3478      defaultNode = defaultAndConstraints(typeDescriptor, tableElementList, columnName, autoIncrementInfo);
3479      break;
3480    default:
3481      jj_la1[39] = jj_gen;
3482      ;
3483    }
3484                // Only pass autoincrement info for autoincrement columns
3485
if (autoIncrementInfo[QueryTreeNode.AUTOINCREMENT_IS_AUTOINCREMENT_INDEX] == 0)
3486                {
3487                        autoIncrementInfo = null;
3488                }
3489
3490                {if (true) return (TableElementNode) nodeFactory.getNode(
3491                                                                C_NodeTypes.COLUMN_DEFINITION_NODE,
3492                                                                columnName,
3493                                                                defaultNode,
3494                                                                typeDescriptor,
3495                                                                autoIncrementInfo,
3496                                                                getContextManager());}
3497    throw new Error JavaDoc("Missing return statement in function");
3498  }
3499
3500/*
3501 * <A NAME="defaultAndConstraints">defaultAndConstraints</A>
3502 */

3503  final public ValueNode defaultAndConstraints(DataTypeDescriptor typeDescriptor,
3504                                          TableElementList tableElementList,
3505                                          String JavaDoc columnName,
3506                                          long[] autoIncrementInfo) throws ParseException, StandardException {
3507        ValueNode defaultNode = null;
3508    switch (jj_nt.kind) {
3509    case CHECK:
3510    case CONSTRAINT:
3511    case NOT:
3512    case PRIMARY:
3513    case REFERENCES:
3514    case UNIQUE:
3515      columnConstraintDefinition(typeDescriptor, tableElementList, columnName);
3516      label_4:
3517      while (true) {
3518        switch (jj_nt.kind) {
3519        case CHECK:
3520        case CONSTRAINT:
3521        case NOT:
3522        case PRIMARY:
3523        case REFERENCES:
3524        case UNIQUE:
3525          ;
3526          break;
3527        default:
3528          jj_la1[40] = jj_gen;
3529          break label_4;
3530        }
3531        columnConstraintDefinition(typeDescriptor, tableElementList, columnName);
3532      }
3533      switch (jj_nt.kind) {
3534      case _DEFAULT:
3535      case WITH:
3536      case GENERATED:
3537        defaultNode = defaultClause(autoIncrementInfo, columnName);
3538        label_5:
3539        while (true) {
3540          switch (jj_nt.kind) {
3541          case CHECK:
3542          case CONSTRAINT:
3543          case NOT:
3544          case PRIMARY:
3545          case REFERENCES:
3546          case UNIQUE:
3547            ;
3548            break;
3549          default:
3550            jj_la1[41] = jj_gen;
3551            break label_5;
3552          }
3553          columnConstraintDefinition(typeDescriptor, tableElementList, columnName);
3554        }
3555        break;
3556      default:
3557        jj_la1[42] = jj_gen;
3558        ;
3559      }
3560                {if (true) return defaultNode;}
3561      break;
3562    case _DEFAULT:
3563    case WITH:
3564    case GENERATED:
3565      defaultNode = defaultClause(autoIncrementInfo, columnName);
3566      label_6:
3567      while (true) {
3568        switch (jj_nt.kind) {
3569        case CHECK:
3570        case CONSTRAINT:
3571        case NOT:
3572        case PRIMARY:
3573        case REFERENCES:
3574        case UNIQUE:
3575          ;
3576          break;
3577        default:
3578          jj_la1[43] = jj_gen;
3579          break label_6;
3580        }
3581        columnConstraintDefinition(typeDescriptor, tableElementList, columnName);
3582      }
3583                {if (true) return defaultNode;}
3584      break;
3585    default:
3586      jj_la1[44] = jj_gen;
3587      jj_consume_token(-1);
3588      throw new ParseException();
3589    }
3590    throw new Error JavaDoc("Missing return statement in function");
3591  }
3592
3593/*
3594 * <A NAME="dataTypeDDL">dataTypeDDL</A>
3595 */

3596  final public DataTypeDescriptor dataTypeDDL() throws ParseException, StandardException {
3597        DataTypeDescriptor typeDescriptor;
3598    if (commonDatatypeName(false)) {
3599
3600    } else {
3601      jj_consume_token(-1);
3602      throw new ParseException();
3603    }
3604    typeDescriptor = dataTypeCommon();
3605                {if (true) return typeDescriptor;}
3606    throw new Error JavaDoc("Missing return statement in function");
3607  }
3608
3609/*
3610 * <A NAME="dataTypeCast">dataTypeCast</A>
3611 */

3612  final public DataTypeDescriptor dataTypeCast() throws ParseException, StandardException {
3613        DataTypeDescriptor typeDescriptor;
3614    if (commonDatatypeName(true)) {
3615
3616    } else {
3617      jj_consume_token(-1);
3618      throw new ParseException();
3619    }
3620    typeDescriptor = dataTypeCommon();
3621                {if (true) return typeDescriptor;}
3622    throw new Error JavaDoc("Missing return statement in function");
3623  }
3624
3625/*
3626 * <A NAME="dataTypeCommon">dataTypeCommon</A>
3627 */

3628  final public DataTypeDescriptor dataTypeCommon() throws ParseException, StandardException {
3629        DataTypeDescriptor typeDescriptor;
3630        boolean checkCS = false;
3631    if (jj_2_11(1)) {
3632      if (getToken(2).kind != LARGE) {
3633
3634      } else {
3635        jj_consume_token(-1);
3636        throw new ParseException();
3637      }
3638      typeDescriptor = characterStringType();
3639    } else if (jj_2_12(1)) {
3640      if (getToken(3).kind != LARGE) {
3641
3642      } else {
3643        jj_consume_token(-1);
3644        throw new ParseException();
3645      }
3646      typeDescriptor = nationalCharacterStringType();
3647    } else if (jj_2_13(1)) {
3648      typeDescriptor = numericType();
3649    } else {
3650      switch (jj_nt.kind) {
3651      case DATE:
3652      case TIME:
3653      case TIMESTAMP:
3654        typeDescriptor = datetimeType();
3655        break;
3656      case BOOLEAN:
3657        jj_consume_token(BOOLEAN);
3658        checkInternalFeature(TypeId.BOOLEAN_NAME);
3659        typeDescriptor = new DataTypeDescriptor(TypeId.BOOLEAN_ID, true);
3660        break;
3661      case LONG:
3662        typeDescriptor = longType();
3663        break;
3664      case BINARY:
3665      case CHAR:
3666      case CHARACTER:
3667      case NATIONAL:
3668      case BLOB:
3669      case CLOB:
3670      case NCLOB:
3671        typeDescriptor = LOBType();
3672        break;
3673      case XML:
3674        typeDescriptor = XMLType();
3675        break;
3676      default:
3677        jj_la1[45] = jj_gen;
3678        jj_consume_token(-1);
3679        throw new ParseException();
3680      }
3681    }
3682                {if (true) return typeDescriptor;}
3683    throw new Error JavaDoc("Missing return statement in function");
3684  }
3685
3686/*
3687 * <A NAME="characterStringType">characterStringType</A>
3688 */

3689  final public DataTypeDescriptor characterStringType() throws ParseException, StandardException {
3690        int length = DEFAULT_STRING_COLUMN_LENGTH;
3691        Token varyingToken = null;
3692        int type;
3693    switch (jj_nt.kind) {
3694    case VARCHAR:
3695      jj_consume_token(VARCHAR);
3696      length = charLength();
3697                type = Types.VARCHAR;
3698      break;
3699    case CHAR:
3700    case CHARACTER:
3701      charOrCharacter();
3702      switch (jj_nt.kind) {
3703      case VARYING:
3704        // Length is optional for CHARACTER, not for plain CHARACTER VARYING
3705
varyingToken = jj_consume_token(VARYING);
3706        length = charLength();
3707        break;
3708      default:
3709        jj_la1[47] = jj_gen;
3710        switch (jj_nt.kind) {
3711        case LEFT_PAREN:
3712          length = charLength();
3713          break;
3714        default:
3715          jj_la1[46] = jj_gen;
3716          ;
3717        }
3718      }
3719                // If the user says CHARACTER VARYING, it's really VARCHAR
3720
type = (varyingToken == null ? Types.CHAR : Types.VARCHAR);
3721      break;
3722    default:
3723      jj_la1[48] = jj_gen;
3724      jj_consume_token(-1);
3725      throw new ParseException();
3726    }
3727    switch (jj_nt.kind) {
3728    case FOR:
3729      type = forBitData(type);
3730      break;
3731    default:
3732      jj_la1[49] = jj_gen;
3733      ;
3734    }
3735                checkTypeLimits(type,length);
3736                DataTypeDescriptor charDTD = DataTypeDescriptor.getBuiltInDataTypeDescriptor(type, length);
3737                {if (true) return charDTD;}
3738    throw new Error JavaDoc("Missing return statement in function");
3739  }
3740
3741/*
3742 * <A NAME="charOrCharacter">charOrCharacter</A>
3743 */

3744  final public void charOrCharacter() throws ParseException {
3745    switch (jj_nt.kind) {
3746    case CHAR:
3747      jj_consume_token(CHAR);
3748      break;
3749    case CHARACTER:
3750      jj_consume_token(CHARACTER);
3751      break;
3752    default:
3753      jj_la1[50] = jj_gen;
3754      jj_consume_token(-1);
3755      throw new ParseException();
3756    }
3757  }
3758
3759/*
3760 * <A NAME="charType">charType</A>
3761 */

3762  final public int charLength() throws ParseException, StandardException {
3763        int length;
3764    jj_consume_token(LEFT_PAREN);
3765    length = length();
3766    jj_consume_token(RIGHT_PAREN);
3767                {if (true) return length;}
3768    throw new Error JavaDoc("Missing return statement in function");
3769  }
3770
3771/*
3772** <A NAME="forBitData">forBitData</A>
3773*/

3774  final public int forBitData(int charType) throws ParseException {
3775    jj_consume_token(FOR);
3776    jj_consume_token(BIT);
3777    jj_consume_token(DATA);
3778                if (charType == Types.CHAR)
3779                        charType = Types.BINARY;
3780                else if (charType == Types.VARCHAR)
3781                        charType = Types.VARBINARY;
3782                else if (charType == Types.LONGVARCHAR)
3783                        charType = Types.LONGVARBINARY;
3784
3785                {if (true) return charType;}
3786    throw new Error JavaDoc("Missing return statement in function");
3787  }
3788
3789/*
3790 * <A NAME="nationalCharacterStringType">nationalCharacterStringType</A>
3791 */

3792  final public DataTypeDescriptor nationalCharacterStringType() throws ParseException, StandardException {
3793        DataTypeDescriptor dataTypeDescriptor;
3794        int length = DEFAULT_STRING_COLUMN_LENGTH;
3795        String JavaDoc type = null;
3796        Token varyingToken = null;
3797    switch (jj_nt.kind) {
3798    case NATIONAL:
3799      jj_consume_token(NATIONAL);
3800      charOrCharacter();
3801      switch (jj_nt.kind) {
3802      case VARYING:
3803        // Length is optional for NATIONAL CHARACTER , not for NATIONAL CHARACTER VARYING
3804
varyingToken = jj_consume_token(VARYING);
3805        length = charLength();
3806        break;
3807      default:
3808        jj_la1[52] = jj_gen;
3809        switch (jj_nt.kind) {
3810        case LEFT_PAREN:
3811          length = charLength();
3812          break;
3813        default:
3814          jj_la1[51] = jj_gen;
3815          ;
3816        }
3817      }
3818                // If the user says NATIONAL CHARACTER VARYING, it's really NATIONALVARCHAR
3819
type = (varyingToken == null ? TypeId.NATIONAL_CHAR_NAME :
3820                                TypeId.NATIONAL_VARCHAR_NAME);
3821      break;
3822    case NCHAR:
3823      jj_consume_token(NCHAR);
3824      switch (jj_nt.kind) {
3825      case VARYING:
3826        // Length is optional for NCHAR, not for NCHAR VARYING
3827
varyingToken = jj_consume_token(VARYING);
3828        length = charLength();
3829        break;
3830      default:
3831        jj_la1[54] = jj_gen;
3832        switch (jj_nt.kind) {
3833        case LEFT_PAREN:
3834          length = charLength();
3835          break;
3836        default:
3837          jj_la1[53] = jj_gen;
3838          ;
3839        }
3840      }
3841                // If the user says NCHAR VARYING, it's really NATIONALVARCHAR
3842
type = (varyingToken == null ? TypeId.NATIONAL_CHAR_NAME :
3843                                TypeId.NATIONAL_VARCHAR_NAME);
3844      break;
3845    case NVARCHAR:
3846      jj_consume_token(NVARCHAR);
3847      length = charLength();
3848                type = TypeId.NATIONAL_VARCHAR_NAME;
3849      break;
3850    default:
3851      jj_la1[55] = jj_gen;
3852      jj_consume_token(-1);
3853      throw new ParseException();
3854    }
3855                // need to re-enable according to SQL standard
3856
{if (true) throw StandardException.newException(SQLState.NOT_IMPLEMENTED, type);}
3857                // return DataTypeDescriptor.getBuiltInDataTypeDescriptor(type, length);
3858

3859    throw new Error JavaDoc("Missing return statement in function");
3860  }
3861
3862/*
3863 * <A NAME="LOBType">lobType</A>
3864 */

3865  final public DataTypeDescriptor LOBType() throws ParseException, StandardException {
3866        int length = 2147483647; // default to 2GB-1 if no length specified
3867
String JavaDoc type;
3868    switch (jj_nt.kind) {
3869    case BLOB:
3870      jj_consume_token(BLOB);
3871      switch (jj_nt.kind) {
3872      case LEFT_PAREN:
3873        length = lengthAndModifier();
3874        break;
3875      default:
3876        jj_la1[56] = jj_gen;
3877        ;
3878      }
3879                        type = TypeId.BLOB_NAME;
3880      break;
3881    case CLOB:
3882      jj_consume_token(CLOB);
3883      switch (jj_nt.kind) {
3884      case LEFT_PAREN:
3885        length = lengthAndModifier();
3886        break;
3887      default:
3888        jj_la1[57] = jj_gen;
3889        ;
3890      }
3891                        type = TypeId.CLOB_NAME;
3892      break;
3893    case NCLOB:
3894      jj_consume_token(NCLOB);
3895      length = lengthAndModifier();
3896                        type = TypeId.NCLOB_NAME;
3897                        // need to re-enable according to SQL standard
3898
{if (true) throw StandardException.newException(SQLState.NOT_IMPLEMENTED, type);}
3899      break;
3900    case BINARY:
3901      jj_consume_token(BINARY);
3902      jj_consume_token(LARGE);
3903      jj_consume_token(OBJECT);
3904      switch (jj_nt.kind) {
3905      case LEFT_PAREN:
3906        length = lengthAndModifier();
3907        break;
3908      default:
3909        jj_la1[58] = jj_gen;
3910        ;
3911      }
3912                        type = TypeId.BLOB_NAME;
3913      break;
3914    case CHAR:
3915    case CHARACTER:
3916      charOrCharacter();
3917      jj_consume_token(LARGE);
3918      jj_consume_token(OBJECT);
3919      switch (jj_nt.kind) {
3920      case LEFT_PAREN:
3921        length = lengthAndModifier();
3922        break;
3923      default:
3924        jj_la1[59] = jj_gen;
3925        ;
3926      }
3927                        type = TypeId.CLOB_NAME;
3928      break;
3929    case NATIONAL:
3930      jj_consume_token(NATIONAL);
3931      jj_consume_token(CHARACTER);
3932      jj_consume_token(LARGE);
3933      jj_consume_token(OBJECT);
3934      length = lengthAndModifier();
3935                        type = TypeId.NCLOB_NAME;
3936                        // need to re-enable according to SQL standard
3937
{if (true) throw StandardException.newException(SQLState.NOT_IMPLEMENTED, type);}
3938      break;
3939    default:
3940      jj_la1[60] = jj_gen;
3941      jj_consume_token(-1);
3942      throw new ParseException();
3943    }
3944                DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(type, length);
3945
3946                {if (true) return dtd;}
3947    throw new Error JavaDoc("Missing return statement in function");
3948  }
3949
3950/*
3951 * <A NAME="numericType">numericType</A>
3952 */

3953  final public DataTypeDescriptor numericType() throws ParseException, StandardException {
3954        DataTypeDescriptor typeDescriptor;
3955    switch (jj_nt.kind) {
3956    case DEC:
3957    case DECIMAL:
3958    case INT:
3959    case INTEGER:
3960    case NUMERIC:
3961    case SMALLINT:
3962    case LONGINT:
3963      typeDescriptor = exactNumericType();
3964                {if (true) return typeDescriptor;}
3965      break;
3966    default:
3967      jj_la1[61] = jj_gen;
3968      if (jj_2_14(1)) {
3969        typeDescriptor = approximateNumericType();
3970                {if (true) return typeDescriptor;}
3971      } else {
3972        jj_consume_token(-1);
3973        throw new ParseException();
3974      }
3975    }
3976    throw new Error JavaDoc("Missing return statement in function");
3977  }
3978
3979/*
3980 * <A NAME="exactNumericType">exactNumericType</A>
3981 */

3982  final public DataTypeDescriptor exactNumericType() throws ParseException, StandardException {
3983        int precision = TypeCompiler.DEFAULT_DECIMAL_PRECISION;
3984        int scale = TypeCompiler.DEFAULT_DECIMAL_SCALE;
3985        int type = Types.DECIMAL;
3986        String JavaDoc typeStr = "DECIMAL";
3987        int maxWidth;
3988        DataTypeDescriptor dtd = null;
3989    switch (jj_nt.kind) {
3990    case DEC:
3991    case DECIMAL:
3992    case NUMERIC:
3993      switch (jj_nt.kind) {
3994      case NUMERIC:
3995        jj_consume_token(NUMERIC);
3996                type = Types.NUMERIC;
3997                typeStr = "NUMERIC";
3998        break;
3999      case DECIMAL:
4000        jj_consume_token(DECIMAL);
4001        break;
4002      case DEC:
4003        jj_consume_token(DEC);
4004        break;
4005      default:
4006        jj_la1[62] = jj_gen;
4007        jj_consume_token(-1);
4008        throw new ParseException();
4009      }
4010      switch (jj_nt.kind) {
4011      case LEFT_PAREN:
4012        jj_consume_token(LEFT_PAREN);
4013        precision = precision();
4014        switch (jj_nt.kind) {
4015        case COMMA:
4016          jj_consume_token(COMMA);
4017          scale = scale();
4018          break;
4019        default:
4020          jj_la1[63] = jj_gen;
4021          ;
4022        }
4023        jj_consume_token(RIGHT_PAREN);
4024        break;
4025      default:
4026        jj_la1[64] = jj_gen;
4027        ;
4028      }
4029                if ((precision <= 0) ||
4030                        (precision > TypeCompiler.MAX_DECIMAL_PRECISION_SCALE))
4031                {
4032                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_PRECISION,
4033                                typeStr, String.valueOf(precision));}
4034                }
4035                else if ((scale < 0) ||
4036                                 (scale > TypeCompiler.MAX_DECIMAL_PRECISION_SCALE))
4037                {
4038                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_DECIMAL_SCALE,
4039                                typeStr, String.valueOf(scale));}
4040                }
4041                else if (scale > precision)
4042                {
4043                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_DECIMAL_PRECISION_SCALE,
4044                                String.valueOf(scale),
4045                                String.valueOf(precision));}
4046                }
4047                /*
4048        ** If we have a decimal point, need to count it
4049        ** towards maxwidth. Max width needs to account
4050        ** for the possible leading '0' and '-' and the
4051        ** decimal point. e.g., DEC(1,1) has a maxwidth
4052        ** of 4 (to handle "-0.1").
4053        */

4054                maxWidth = DataTypeUtilities.computeMaxWidth( precision, scale);
4055                {if (true) return getDataTypeServices(type, precision, scale, maxWidth);}
4056      break;
4057    case INT:
4058    case INTEGER:
4059    case SMALLINT:
4060    case LONGINT:
4061      dtd = exactIntegerType();
4062                        {if (true) return dtd;}
4063      break;
4064    default:
4065      jj_la1[65] = jj_gen;
4066      jj_consume_token(-1);
4067      throw new ParseException();
4068    }
4069    throw new Error JavaDoc("Missing return statement in function");
4070  }
4071
4072/*
4073 * <A NAME="exactNumericType">exactNumericType</A>
4074 */

4075  final public DataTypeDescriptor exactIntegerType() throws ParseException, StandardException {
4076    switch (jj_nt.kind) {
4077    case INT:
4078    case INTEGER:
4079      switch (jj_nt.kind) {
4080      case INTEGER:
4081        jj_consume_token(INTEGER);
4082        break;
4083      case INT:
4084        jj_consume_token(INT);
4085        break;
4086      default:
4087        jj_la1[66] = jj_gen;
4088        jj_consume_token(-1);
4089        throw new ParseException();
4090      }
4091                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER);}
4092      break;
4093    case SMALLINT:
4094      jj_consume_token(SMALLINT);
4095                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.SMALLINT);}
4096      break;
4097    case LONGINT:
4098      jj_consume_token(LONGINT);
4099                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT);}
4100      break;
4101    default:
4102      jj_la1[67] = jj_gen;
4103      jj_consume_token(-1);
4104      throw new ParseException();
4105    }
4106    throw new Error JavaDoc("Missing return statement in function");
4107  }
4108
4109/*
4110 * <A NAME="approximateNumericType">approximateNumericType</A>
4111 */

4112  final public DataTypeDescriptor approximateNumericType() throws ParseException, StandardException {
4113        int type = 0, scale = 0, width = 0;
4114        int prec = -1;
4115        DataTypeDescriptor dts = null;
4116    switch (jj_nt.kind) {
4117    case FLOAT:
4118      jj_consume_token(FLOAT);
4119      switch (jj_nt.kind) {
4120      case LEFT_PAREN:
4121        jj_consume_token(LEFT_PAREN);
4122        prec = precision();
4123        jj_consume_token(RIGHT_PAREN);
4124        break;
4125      default:
4126        jj_la1[68] = jj_gen;
4127        ;
4128      }
4129                /*
4130            When not specified, default is DOUBLE_PRECISION
4131         */

4132                if (prec == -1)
4133                        prec = TypeId.DOUBLE_PRECISION;
4134
4135                if (prec > 0 && prec <= TypeId.REAL_PRECISION)
4136                {
4137                        type = Types.REAL;
4138                        prec = TypeId.REAL_PRECISION;
4139                        scale = TypeId.REAL_SCALE;
4140                        width = TypeId.REAL_MAXWIDTH;
4141                }
4142                else if (prec > TypeId.REAL_PRECISION &&
4143                                 prec <= TypeId.DOUBLE_PRECISION)
4144                {
4145                        type = Types.DOUBLE;
4146                        prec = TypeId.DOUBLE_PRECISION;
4147                        scale = TypeId.DOUBLE_SCALE;
4148                        width = TypeId.DOUBLE_MAXWIDTH;
4149                }
4150                else
4151                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_PRECISION, "FLOAT", String.valueOf(prec));}
4152
4153                /*
4154            REMIND: this is a slight hack, in that exacting reading of
4155            the InformationSchema requires that the type the user typed
4156            in be visible to them in the InformationSchema views. But
4157            most implementations use synonyms or mappings at some point,
4158            and this is one of those places, for us.
4159         */

4160                {if (true) return getDataTypeServices(type, prec, scale, width);}
4161      break;
4162    case REAL:
4163      jj_consume_token(REAL);
4164                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.REAL);}
4165      break;
4166    default:
4167      jj_la1[69] = jj_gen;
4168      if (jj_2_15(1)) {
4169        dts = doubleType();
4170                {if (true) return dts;}
4171      } else {
4172        jj_consume_token(-1);
4173        throw new ParseException();
4174      }
4175    }
4176    throw new Error JavaDoc("Missing return statement in function");
4177  }
4178
4179/*
4180 * <A NAME="doubleType">doubleType</A>
4181 */

4182  final public DataTypeDescriptor doubleType() throws ParseException, StandardException {
4183    if (getToken(2).kind == PRECISION) {
4184      jj_consume_token(DOUBLE);
4185      jj_consume_token(PRECISION);
4186    } else {
4187      switch (jj_nt.kind) {
4188      case DOUBLE:
4189        jj_consume_token(DOUBLE);
4190        break;
4191      default:
4192        jj_la1[70] = jj_gen;
4193        jj_consume_token(-1);
4194        throw new ParseException();
4195      }
4196    }
4197                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.DOUBLE);}
4198    throw new Error JavaDoc("Missing return statement in function");
4199  }
4200
4201/*
4202 * <A NAME="longType">longType</A>
4203 */

4204  final public DataTypeDescriptor longType() throws ParseException, StandardException {
4205        DataTypeDescriptor dataTypeDescriptor;
4206    jj_consume_token(LONG);
4207    dataTypeDescriptor = longSubType();
4208                {if (true) return dataTypeDescriptor;}
4209    throw new Error JavaDoc("Missing return statement in function");
4210  }
4211
4212  final public DataTypeDescriptor longSubType() throws ParseException, StandardException {
4213        int lvcType = Types.LONGVARCHAR;
4214    switch (jj_nt.kind) {
4215    case VARCHAR:
4216      jj_consume_token(VARCHAR);
4217      switch (jj_nt.kind) {
4218      case FOR:
4219        lvcType = forBitData(lvcType);
4220        break;
4221      default:
4222        jj_la1[71] = jj_gen;
4223        ;
4224      }
4225                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(lvcType);}
4226      break;
4227    case NVARCHAR:
4228      jj_consume_token(NVARCHAR);
4229                // need to re-enable according to SQL standard
4230
{if (true) throw StandardException.newException(SQLState.NOT_IMPLEMENTED, TypeId.NATIONAL_LONGVARCHAR_NAME);}
4231                // return DataTypeDescriptor.getBuiltInDataTypeDescriptor(TypeId.NATIONAL_LONGVARCHAR_NAME);
4232

4233      break;
4234    default:
4235      jj_la1[72] = jj_gen;
4236      jj_consume_token(-1);
4237      throw new ParseException();
4238    }
4239    throw new Error JavaDoc("Missing return statement in function");
4240  }
4241
4242/*
4243 * <A NAME="XMLType">XMLType</A>
4244 */

4245  final public DataTypeDescriptor XMLType() throws ParseException, StandardException {
4246        DataTypeDescriptor value;
4247    jj_consume_token(XML);
4248                checkVersion(DataDictionary.DD_VERSION_DERBY_10_1, "XML");
4249                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(
4250                        StoredFormatIds.XML_TYPE_ID);}
4251    throw new Error JavaDoc("Missing return statement in function");
4252  }
4253
4254/*
4255 * <A NAME="xmlDocOrContent">xmlDocOrContent</A>
4256 *
4257 * Parse the XML keywords DOCUMENT and CONTENT. We don't
4258 * support CONTENT yet, so we throw an appropriate error
4259 * if we see it.
4260 *
4261 */

4262  final public void xmlDocOrContent() throws ParseException, StandardException {
4263    if ((getToken(1).kind != DOCUMENT) &&
4264                    (getToken(1).kind != CONTENT)) {
4265                {if (true) throw StandardException.newException(
4266                        SQLState.LANG_XML_KEYWORD_MISSING, "DOCUMENT",
4267                        ReuseFactory.getInteger(getToken(1).beginLine),
4268                        ReuseFactory.getInteger(getToken(1).beginColumn));}
4269    } else if (getToken(1).kind == CONTENT) {
4270      jj_consume_token(CONTENT);
4271                {if (true) throw StandardException.newException(
4272                        SQLState.LANG_UNSUPPORTED_XML_FEATURE, "CONTENT");}
4273    } else if (getToken(1).kind == DOCUMENT) {
4274      jj_consume_token(DOCUMENT);
4275                {if (true) return;}
4276    } else {
4277      jj_consume_token(-1);
4278      throw new ParseException();
4279    }
4280  }
4281
4282/*
4283 * <A NAME="javaType">javaType</A>
4284 */

4285  final public DataTypeDescriptor javaType() throws ParseException, StandardException {
4286        String JavaDoc javaClassName;
4287    javaClassName = javaClassName();
4288                {if (true) return getJavaClassDataTypeDescriptor(javaClassName);}
4289    throw new Error JavaDoc("Missing return statement in function");
4290  }
4291
4292/*
4293 * <A NAME = "javaDSL">javaDSL</A>
4294 *
4295 * A Java dot-separated list.
4296 */

4297  final public String JavaDoc javaDSL() throws ParseException {
4298        String JavaDoc dotSeparatedList;
4299    dotSeparatedList = caseSensitiveIdentifierPlusReservedWords();
4300    label_7:
4301    while (true) {
4302      switch (jj_nt.kind) {
4303      case PERIOD:
4304        ;
4305        break;
4306      default:
4307        jj_la1[73] = jj_gen;
4308        break label_7;
4309      }
4310      dotSeparatedList = javaDSLNameExtender(dotSeparatedList);
4311    }
4312                {if (true) return dotSeparatedList;}
4313    throw new Error JavaDoc("Missing return statement in function");
4314  }
4315
4316/*
4317 * <A NAME="javaClassName">javaClassName</A>
4318 */

4319  final public String JavaDoc javaClassName() throws ParseException {
4320        String JavaDoc javaClassName;
4321    javaClassName = javaDSL();
4322                {if (true) return javaClassName;}
4323    throw new Error JavaDoc("Missing return statement in function");
4324  }
4325
4326/*
4327 * <A NAME="javaDSLNameExtender">javaDSLNameExtender</A>
4328 */

4329  final public String JavaDoc javaDSLNameExtender(String JavaDoc dotSeparatedList) throws ParseException {
4330        String JavaDoc extender;
4331    jj_consume_token(PERIOD);
4332    extender = caseSensitiveIdentifierPlusReservedWords();
4333                {if (true) return dotSeparatedList + "." + extender;}
4334    throw new Error JavaDoc("Missing return statement in function");
4335  }
4336
4337/*
4338 * <A NAME="length">lengthAndModifier</A>
4339 */

4340  final public int lengthAndModifier() throws ParseException, StandardException {
4341        Token tok;
4342        Token tokmod = null;
4343    jj_consume_token(LEFT_PAREN);
4344    switch (jj_nt.kind) {
4345    case LENGTH_MODIFIER:
4346      tok = jj_consume_token(LENGTH_MODIFIER);
4347      break;
4348    case EXACT_NUMERIC:
4349      tok = jj_consume_token(EXACT_NUMERIC);
4350      switch (jj_nt.kind) {
4351      case IDENTIFIER:
4352        tokmod = jj_consume_token(IDENTIFIER);
4353        break;
4354      default:
4355        jj_la1[74] = jj_gen;
4356        ;
4357      }
4358      break;
4359    default:
4360      jj_la1[75] = jj_gen;
4361      jj_consume_token(-1);
4362      throw new ParseException();
4363    }
4364    jj_consume_token(RIGHT_PAREN);
4365                String JavaDoc s = tok.image + (tokmod==null ? "" : tokmod.image); // colapse cases;
4366
try
4367                {
4368                        char modifier = s.charAt(s.length()-1);
4369                        String JavaDoc number = s.substring(0, s.length()-1); // in case of ending w. letter
4370
long mul;
4371                        switch (modifier) {
4372                        case 'G':
4373                        case 'g':
4374                                mul =1073741824L; //1 Giga
4375
break;
4376                        case 'M':
4377                        case 'm':
4378                                mul=1048576L; // 1 Mega
4379
break;
4380                        case 'K':
4381                        case 'k':
4382                                mul=1024L; // 1 Kilo
4383
break;
4384                        default:
4385                                mul=1;
4386                                number = s; // no letter in end, need whole string
4387
break;
4388                        }
4389                        long specifiedLength = Long.parseLong(number) * mul;
4390
4391                        // match DB2 limits of 1 to 2147483647
4392
if ((specifiedLength > 0L) &&
4393                (specifiedLength <= Limits.DB2_LOB_MAXWIDTH))
4394            {
4395                                {if (true) return (int)specifiedLength;}
4396            }
4397
4398                        // DB2 allows 2G or 2048M or 2097152k that calculate out to
4399
// 2147483648, but sets the length to be one less.
4400
if (mul != 1 && specifiedLength == 2147483648L)
4401                                {if (true) return Limits.DB2_LOB_MAXWIDTH;}
4402
4403                }
4404                catch (NumberFormatException JavaDoc nfe)
4405                {
4406                }
4407
4408                {if (true) throw StandardException.newException(
4409            SQLState.LANG_INVALID_COLUMN_LENGTH, s);}
4410    throw new Error JavaDoc("Missing return statement in function");
4411  }
4412
4413/*
4414 * <A NAME="length">length</A>
4415 */

4416  final public int length() throws ParseException, StandardException {
4417        Token tok;
4418        int retval;
4419    tok = jj_consume_token(EXACT_NUMERIC);
4420                try
4421                {
4422                        retval = Integer.parseInt(tok.image);
4423
4424                        if (retval > 0)
4425                                {if (true) return retval;}
4426                }
4427                catch (NumberFormatException JavaDoc nfe)
4428                {
4429                }
4430                {if (true) throw StandardException.newException(SQLState.LANG_INVALID_COLUMN_LENGTH, tok.image);}
4431    throw new Error JavaDoc("Missing return statement in function");
4432  }
4433
4434/*
4435 * <A NAME="exactNumber">exactNumber</A>
4436*/

4437  final public long exactNumber() throws ParseException, StandardException {
4438        Token longToken;
4439        String JavaDoc sign = "";
4440    switch (jj_nt.kind) {
4441    case PLUS_SIGN:
4442    case MINUS_SIGN:
4443      sign = sign();
4444      break;
4445    default:
4446      jj_la1[76] = jj_gen;
4447      ;
4448    }
4449    longToken = jj_consume_token(EXACT_NUMERIC);
4450                try
4451                {
4452                        long longvalue = Long.parseLong(longToken.image);
4453                        if (sign.equals("-"))
4454                        {
4455                                {if (true) return -longvalue;}
4456                        }
4457                        else
4458                        {
4459                                {if (true) return longvalue;}
4460                        }
4461                }
4462                catch (NumberFormatException JavaDoc nfe)
4463                {
4464                        {if (true) throw
4465                        StandardException.newException(
4466                                   SQLState.LANG_INVALID_INTEGER_LITERAL, longToken.image);}
4467                }
4468    throw new Error JavaDoc("Missing return statement in function");
4469  }
4470
4471/*
4472 * <A NAME="precision">precision</A>
4473 */

4474  final public int precision() throws ParseException, StandardException {
4475        int uintValue;
4476    uintValue = uint_value();
4477                {if (true) return uintValue;}
4478    throw new Error JavaDoc("Missing return statement in function");
4479  }
4480
4481/*
4482 * <A NAME="uint_value">uint_value</A>
4483 */

4484  final public int uint_value() throws ParseException, StandardException {
4485        Token uintToken;
4486    /*
4487            because the parser won't match to UINT, we use EXACT_NUMERIC.
4488         */

4489            uintToken = jj_consume_token(EXACT_NUMERIC);
4490                try {
4491                        {if (true) return Integer.parseInt(uintToken.image);}
4492                } catch (NumberFormatException JavaDoc nfe) {
4493                        {if (true) throw StandardException.newException(SQLState.LANG_INVALID_INTEGER_LITERAL, uintToken.image);}
4494                }
4495    throw new Error JavaDoc("Missing return statement in function");
4496  }
4497
4498/*
4499 * <A NAME="scale">scale</A>
4500 */

4501  final public int scale() throws ParseException, StandardException {
4502        int uintValue;
4503    uintValue = uint_value();
4504                {if (true) return uintValue;}
4505    throw new Error JavaDoc("Missing return statement in function");
4506  }
4507
4508/*
4509 * <A NAME="datetimeType">datetimeType</A>
4510 */

4511  final public DataTypeDescriptor datetimeType() throws ParseException, StandardException {
4512        Token tzTok = null;
4513        int prec = -1;
4514    switch (jj_nt.kind) {
4515    case DATE:
4516      jj_consume_token(DATE);
4517                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.DATE);}
4518      break;
4519    case TIME:
4520      jj_consume_token(TIME);
4521                /*
4522            We do not try to set up a precision for time/timestamp
4523            values because this field gets mapped to the precision
4524            field in the JDBC driver that is for the number of
4525            decimal digits in the value. Precision for time is
4526            actually the scale of the seconds value.
4527
4528            If/when precision for times is supported, we may need
4529            to migrate the system catalog information to fill in
4530            the default values appropriately (the default for
4531            time is 0, fortunately; but for timestamp it is
4532            actually 9 due to java.sql.Timestamp's precision).
4533         */

4534                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.TIME);}
4535      break;
4536    case TIMESTAMP:
4537      jj_consume_token(TIMESTAMP);
4538                {if (true) return DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.TIMESTAMP);}
4539      break;
4540    default:
4541      jj_la1[77] = jj_gen;
4542      jj_consume_token(-1);
4543      throw new ParseException();
4544    }
4545    throw new Error JavaDoc("Missing return statement in function");
4546  }
4547
4548/*
4549 * <A NAME="timePrecision">timePrecision</A>
4550 */

4551  final public void qualifiedNameList(Vector JavaDoc list, int id_length_limit) throws ParseException, StandardException {
4552    qualifiedNameElement(list, id_length_limit);
4553    label_8:
4554    while (true) {
4555      switch (jj_nt.kind) {
4556      case COMMA:
4557        ;
4558        break;
4559      default:
4560        jj_la1[78] = jj_gen;
4561        break label_8;
4562      }
4563      jj_consume_token(COMMA);
4564      qualifiedNameElement(list, id_length_limit);
4565    }
4566  }
4567
4568  final public void qualifiedNameElement(Vector JavaDoc list, int id_length_limit) throws ParseException, StandardException {
4569        TableName qualifiedName = null;
4570    qualifiedName = qualifiedName(id_length_limit);
4571                list.addElement(qualifiedName);
4572  }
4573
4574/*
4575 * <A NAME="qualifiedName">qualifiedName</A>
4576 */

4577  final public TableName qualifiedName(int nodeType, int id_length_limit) throws ParseException, StandardException {
4578        //String catalogName = null;
4579
String JavaDoc schemaName = null;
4580        String JavaDoc qualifiedId;
4581        String JavaDoc firstName = null;
4582        String JavaDoc secondName = null;
4583    firstName = identifier(Limits.MAX_IDENTIFIER_LENGTH, false);
4584    if (getToken(1).kind == PERIOD &&
4585                                                                    getToken(2).kind != ASTERISK) {
4586      jj_consume_token(PERIOD);
4587      secondName = identifier(Limits.MAX_IDENTIFIER_LENGTH, false);
4588    } else {
4589      ;
4590    }
4591                if (secondName == null)
4592                {
4593                        qualifiedId = firstName;
4594                }
4595                else
4596                {
4597                        schemaName = firstName;
4598                        qualifiedId = secondName;
4599                }
4600
4601                //limit the qualifiedId to the id length limit passed to this method
4602
checkIdentifierLengthLimit(qualifiedId, id_length_limit);
4603                if (schemaName != null)
4604                        checkIdentifierLengthLimit(schemaName, Limits.MAX_IDENTIFIER_LENGTH);
4605
4606                {if (true) return (TableName) nodeFactory.getNode(
4607                                                                nodeType,
4608                                                                schemaName,
4609                                                                qualifiedId,
4610                                                                new Integer JavaDoc(lastIdentifierToken.beginOffset),
4611                                                                new Integer JavaDoc(lastIdentifierToken.endOffset),
4612                                                                getContextManager());}
4613    throw new Error JavaDoc("Missing return statement in function");
4614  }
4615
4616/*
4617 * <A NAME="queryExpression">queryExpression</A>
4618 *
4619 * We have to be carefull to get the associativity correct. According to the SQL spec
4620 * <non-join query expression> ::=
4621 * <non-join query term>
4622 * | <query expression body> UNION [ ALL ] <query term>
4623 * | <query expression body> EXCEPT [ ALL ] <query term>
4624 * Meaning that
4625 * t1 UNION ALL t2 UNION t3
4626 * is equivalent to
4627 * (t1 UNION ALL t2) UNION t3
4628 * However recursive descent parsers want recursion to be on the right, so this kind of associativity is unnatural
4629 * for our parser. The queryExpression method must know whether it is being called as the right hand side of a
4630 * set operator to produce a query tree with the correct associativity.
4631 */

4632  final public ResultSetNode queryExpression(ResultSetNode leftSide, int operatorType) throws ParseException, StandardException {
4633        ResultSetNode term;
4634    term = nonJoinQueryTerm(leftSide, operatorType);
4635    switch (jj_nt.kind) {
4636    case EXCEPT:
4637    case UNION:
4638      term = unionOrExcept(term);
4639      break;
4640    default:
4641      jj_la1[79] = jj_gen;
4642      ;
4643    }
4644                {if (true) return term;}
4645    throw new Error JavaDoc("Missing return statement in function");
4646  }
4647
4648/*
4649 * <A NAME="unionOrExcept">unionOrExcept</A>
4650 */

4651  final public ResultSetNode unionOrExcept(ResultSetNode term) throws ParseException, StandardException {
4652        ResultSetNode expression;
4653        Token tok = null;
4654    switch (jj_nt.kind) {
4655    case UNION:
4656      jj_consume_token(UNION);
4657      switch (jj_nt.kind) {
4658      case ALL:
4659      case DISTINCT:
4660        switch (jj_nt.kind) {
4661        case ALL:
4662          tok = jj_consume_token(ALL);
4663          break;
4664        case DISTINCT:
4665          jj_consume_token(DISTINCT);
4666          break;
4667        default:
4668          jj_la1[80] = jj_gen;
4669          jj_consume_token(-1);
4670          throw new ParseException();
4671        }
4672        break;
4673      default:
4674        jj_la1[81] = jj_gen;
4675        ;
4676      }
4677      expression = queryExpression(term,
4678                                                                      (tok != null) ? UNION_ALL_OP : UNION_OP);
4679                {if (true) return expression;}
4680      break;
4681    case EXCEPT:
4682      jj_consume_token(EXCEPT);
4683      switch (jj_nt.kind) {
4684      case ALL:
4685      case DISTINCT:
4686        switch (jj_nt.kind) {
4687        case ALL:
4688          tok = jj_consume_token(ALL);
4689          break;
4690        case DISTINCT:
4691          jj_consume_token(DISTINCT);
4692          break;
4693        default:
4694          jj_la1[82] = jj_gen;
4695          jj_consume_token(-1);
4696          throw new ParseException();
4697        }
4698        break;
4699      default:
4700        jj_la1[83] = jj_gen;
4701        ;
4702      }
4703      expression = queryExpression(term,
4704                                                                      (tok != null) ? EXCEPT_ALL_OP : EXCEPT_OP);
4705                {if (true) return expression;}
4706      break;
4707    default:
4708      jj_la1[84] = jj_gen;
4709      jj_consume_token(-1);
4710      throw new ParseException();
4711    }
4712    throw new Error JavaDoc("Missing return statement in function");
4713  }
4714
4715/*
4716 * <A NAME="nonJoinQueryTerm">nonJoinQueryTerm</A>
4717 *
4718 * Be careful with the associativity of INTERSECT. According to the SQL spec
4719 * t1 INTERSECT t2 INTERSECT ALL t3
4720 * is equivalent to
4721 * (t1 INTERSECT t2) INTERSECT ALL t3
4722 * which is not the same as
4723 * t1 INTERSECT (t2 INTERSECT ALL t3)
4724 * See the comment on queryExpression.
4725 */

4726  final public ResultSetNode nonJoinQueryTerm(ResultSetNode leftSide, int operatorType) throws ParseException, StandardException {
4727        ResultSetNode term;
4728    term = nonJoinQueryPrimary();
4729    switch (jj_nt.kind) {
4730    case INTERSECT:
4731      term = intersect(term);
4732      break;
4733    default:
4734      jj_la1[85] = jj_gen;
4735      ;
4736    }
4737        switch( operatorType)
4738        {
4739        case NO_SET_OP:
4740            {if (true) return term;}
4741
4742        case UNION_OP:
4743            {if (true) return (ResultSetNode) nodeFactory.getNode(
4744                C_NodeTypes.UNION_NODE,
4745                leftSide,
4746                term,
4747                Boolean.FALSE,
4748                Boolean.FALSE,
4749                null,
4750                getContextManager());}
4751
4752        case UNION_ALL_OP:
4753            {if (true) return (ResultSetNode) nodeFactory.getNode(
4754                C_NodeTypes.UNION_NODE,
4755                leftSide,
4756                term,
4757                Boolean.TRUE,
4758                Boolean.FALSE,
4759                null,
4760                getContextManager());}
4761
4762        case EXCEPT_OP:
4763            {if (true) return (ResultSetNode) nodeFactory.getNode(
4764                C_NodeTypes.INTERSECT_OR_EXCEPT_NODE,
4765                ReuseFactory.getInteger( IntersectOrExceptNode.EXCEPT_OP),
4766                leftSide,
4767                term,
4768                Boolean.FALSE,
4769                null,
4770                getContextManager());}
4771
4772        case EXCEPT_ALL_OP:
4773            {if (true) return (ResultSetNode) nodeFactory.getNode(
4774                C_NodeTypes.INTERSECT_OR_EXCEPT_NODE,
4775                ReuseFactory.getInteger( IntersectOrExceptNode.EXCEPT_OP),
4776                leftSide,
4777                term,
4778                Boolean.TRUE,
4779                null,
4780                getContextManager());}
4781
4782        case INTERSECT_OP:
4783            {if (true) return (ResultSetNode) nodeFactory.getNode(
4784                C_NodeTypes.INTERSECT_OR_EXCEPT_NODE,
4785                ReuseFactory.getInteger( IntersectOrExceptNode.INTERSECT_OP),
4786                leftSide,
4787                term,
4788                Boolean.FALSE,
4789                null,
4790                getContextManager());}
4791
4792        case INTERSECT_ALL_OP:
4793            {if (true) return (ResultSetNode) nodeFactory.getNode(
4794                C_NodeTypes.INTERSECT_OR_EXCEPT_NODE,
4795                ReuseFactory.getInteger( IntersectOrExceptNode.INTERSECT_OP),
4796                leftSide,
4797                term,
4798                Boolean.TRUE,
4799                null,
4800                getContextManager());}
4801
4802
4803        default:
4804            if (SanityManager.DEBUG)
4805            {
4806                SanityManager.THROWASSERT( "Invalid set operator type: " + operatorType);
4807            }
4808            {if (true) return null;}
4809        }
4810    throw new Error JavaDoc("Missing return statement in function");
4811  }
4812
4813/*
4814 * <A NAME="intersect">intersect</A>
4815 */

4816  final public ResultSetNode intersect(ResultSetNode term) throws ParseException, StandardException {
4817        ResultSetNode expression;
4818        Token tok = null;
4819    jj_consume_token(INTERSECT);
4820    switch (jj_nt.kind) {
4821    case ALL:
4822    case DISTINCT:
4823      switch (jj_nt.kind) {
4824      case ALL:
4825        tok = jj_consume_token(ALL);
4826        break;
4827      case DISTINCT:
4828        jj_consume_token(DISTINCT);
4829        break;
4830      default:
4831        jj_la1[86] = jj_gen;
4832        jj_consume_token(-1);
4833        throw new ParseException();
4834      }
4835      break;
4836    default:
4837      jj_la1[87] = jj_gen;
4838      ;
4839    }
4840    expression = nonJoinQueryTerm(term, (tok != null) ? INTERSECT_ALL_OP : INTERSECT_OP);
4841                {if (true) return expression;}
4842    throw new Error JavaDoc("Missing return statement in function");
4843  }
4844
4845/*
4846 * <A NAME="nonJoinQueryPrimary">nonJoinQueryPrimary</A>
4847 */

4848  final public ResultSetNode nonJoinQueryPrimary() throws ParseException, StandardException {
4849        ResultSetNode primary;
4850    switch (jj_nt.kind) {
4851    case SELECT:
4852    case VALUES:
4853      primary = simpleTable();
4854                {if (true) return primary;}
4855      break;
4856    case LEFT_PAREN:
4857      jj_consume_token(LEFT_PAREN);
4858      primary = queryExpression(null, NO_SET_OP);
4859      jj_consume_token(RIGHT_PAREN);
4860                {if (true) return primary;}
4861      break;
4862    default:
4863      jj_la1[88] = jj_gen;
4864      jj_consume_token(-1);
4865      throw new ParseException();
4866    }
4867    throw new Error JavaDoc("Missing return statement in function");
4868  }
4869
4870/*
4871 * <A NAME="simpleTable">simpleTable</A>
4872 */

4873  final public ResultSetNode simpleTable() throws ParseException, StandardException {
4874        ResultSetNode resultSetNode;
4875    switch (jj_nt.kind) {
4876    case SELECT:
4877      resultSetNode = querySpecification();
4878                {if (true) return resultSetNode;}
4879      break;
4880    case VALUES:
4881      resultSetNode = tableValueConstructor();
4882                {if (true) return resultSetNode;}
4883      break;
4884    default:
4885      jj_la1[89] = jj_gen;
4886      jj_consume_token(-1);
4887      throw new ParseException();
4888    }
4889    throw new Error JavaDoc("Missing return statement in function");
4890  }
4891
4892/*
4893 * <A NAME="querySpecification">querySpecification</A>
4894 */

4895  final public ResultSetNode querySpecification() throws ParseException, StandardException {
4896        ResultColumnList selectList;
4897        SelectNode selectNode;
4898        boolean isDistinct = false;
4899    jj_consume_token(SELECT);
4900    if (jj_2_16(1)) {
4901      isDistinct = setQuantifier();
4902    } else {
4903      ;
4904    }
4905    selectList = selectList();
4906    selectNode = tableExpression(selectList);
4907                if (isDistinct) selectNode.makeDistinct();
4908                {if (true) return selectNode;}
4909    throw new Error JavaDoc("Missing return statement in function");
4910  }
4911
4912/*
4913 * <A NAME="setQuantifier">setQuantifier</A>
4914 */

4915  final public boolean setQuantifier() throws ParseException {
4916    if (getToken(1).kind == DISTINCT &&
4917                            !(
4918                                    getToken(2).kind == PERIOD ||
4919                                    getToken(2).kind == DOUBLE_COLON
4920                            )) {
4921      jj_consume_token(DISTINCT);
4922                {if (true) return true;}
4923    } else if (getToken(1).kind == ALL &&
4924                            !(
4925                                    getToken(2).kind == PERIOD ||
4926                                    getToken(2).kind == DOUBLE_COLON
4927                            )) {
4928      jj_consume_token(ALL);
4929                {if (true) return false;}
4930    } else {
4931      jj_consume_token(-1);
4932      throw new ParseException();
4933    }
4934    throw new Error JavaDoc("Missing return statement in function");
4935  }
4936
4937/*
4938 * <A NAME="selectList">selectList</A>
4939 */

4940  final public ResultColumnList selectList() throws ParseException, StandardException {
4941        ResultColumn allResultColumn;
4942        ResultColumnList resultColumns = (ResultColumnList) nodeFactory.getNode(
4943                                                                        C_NodeTypes.RESULT_COLUMN_LIST,
4944                                                                        getContextManager());
4945    switch (jj_nt.kind) {
4946    case ASTERISK:
4947      jj_consume_token(ASTERISK);
4948                allResultColumn = (ResultColumn) nodeFactory.getNode(
4949                                                                                C_NodeTypes.ALL_RESULT_COLUMN,
4950                                                                                null,
4951                                                                                getContextManager());
4952                /* Add the new AllResultColumn to the end of the list */
4953                resultColumns.addResultColumn(allResultColumn);
4954                {if (true) return resultColumns;}
4955      break;
4956    default:
4957      jj_la1[90] = jj_gen;
4958      if (jj_2_17(1)) {
4959        selectColumnList(resultColumns);
4960                {if (true) return resultColumns;}
4961      } else {
4962        jj_consume_token(-1);
4963        throw new ParseException();
4964      }
4965    }
4966    throw new Error JavaDoc("Missing return statement in function");
4967  }
4968
4969  final public void selectColumnList(ResultColumnList resultColumns) throws ParseException, StandardException {
4970    selectSublist(resultColumns);
4971    label_9:
4972    while (true) {
4973      switch (jj_nt.kind) {
4974      case COMMA:
4975        ;
4976        break;
4977      default:
4978        jj_la1[91] = jj_gen;
4979        break label_9;
4980      }
4981      jj_consume_token(COMMA);
4982      selectSublist(resultColumns);
4983    }
4984  }
4985
4986/*
4987 * <A NAME="selectSublist">selectSublist</A>
4988 */

4989  final public void selectSublist(ResultColumnList resultColumns) throws ParseException, StandardException {
4990        ResultColumn resultColumn;
4991        ResultColumn allResultColumn;
4992        TableName tableName;
4993    if (getToken(2).kind == PERIOD &&
4994                            (
4995                                    getToken(3).kind == ASTERISK ||
4996                                    (getToken(4).kind == PERIOD && getToken(5).kind == ASTERISK)
4997                            )) {
4998      tableName = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH);
4999      jj_consume_token(PERIOD);
5000      jj_consume_token(ASTERISK);
5001                allResultColumn = (ResultColumn) nodeFactory.getNode(
5002                                                                                C_NodeTypes.ALL_RESULT_COLUMN,
5003                                                                                tableName,
5004                                                                                getContextManager());
5005                /* Add the new AllResultColumn to the end of the list */
5006                resultColumns.addResultColumn(allResultColumn);
5007    } else if (jj_2_18(1)) {
5008      resultColumn = derivedColumn(resultColumns);
5009                /* Add the new ResultColumn to the end of the list */
5010                resultColumns.addResultColumn(resultColumn);
5011    } else {
5012      jj_consume_token(-1);
5013      throw new ParseException();
5014    }
5015  }
5016
5017/*
5018 * <A NAME="derivedColumn">derivedColumn</A>
5019 */

5020  final public ResultColumn derivedColumn(ResultColumnList resultColumns) throws ParseException, StandardException {
5021        ValueNode columnExpression;
5022        String JavaDoc columnName = null;
5023    //true to additiveExpression ensures that for the derived columns, we will not allow boolean values inside (),
5024
//eg (2 > 1) should be disallowed in the select clause
5025
columnExpression = additiveExpression(null, 0, true);
5026    switch (jj_nt.kind) {
5027    case AS:
5028    case BINARY:
5029    case COALESCE:
5030    case COUNT:
5031    case D:
5032    case MODULE:
5033    case T:
5034    case TS:
5035    case VALUE:
5036    case VARBINARY:
5037    case ABS:
5038    case ABSVAL:
5039    case ACTION:
5040    case ALWAYS:
5041    case BLOB:
5042    case C:
5043    case CALLED:
5044    case CLOB:
5045    case COBOL:
5046    case COMMITTED:
5047    case CONCAT:
5048    case CONTAINS:
5049    case DATA:
5050    case DATE:
5051    case DAY:
5052    case DYNAMIC:
5053    case FORTRAN:
5054    case GENERATED:
5055    case IDENTITY_VAL_LOCAL:
5056    case INCREMENT:
5057    case INITIAL:
5058    case INTERVAL:
5059    case LANGUAGE:
5060    case LARGE:
5061    case LENGTH:
5062    case LEVEL:
5063    case LOCKS:
5064    case LOCKSIZE:
5065    case LOGGED:
5066    case MOD:
5067    case MODIFIES:
5068    case MODIFY:
5069    case MONTH:
5070    case _MORE:
5071    case MUMPS:
5072    case NAME:
5073    case NCLOB:
5074    case NULLABLE:
5075    case NUMBER:
5076    case OBJECT:
5077    case PASCAL:
5078    case PLI:
5079    case PRECISION:
5080    case RELEASE:
5081    case REPEATABLE:
5082    case RESTART:
5083    case RETURNS:
5084    case ROW:
5085    case SAVEPOINT:
5086    case SCALE:
5087    case SERIALIZABLE:
5088    case SQL_TSI_FRAC_SECOND:
5089    case SQL_TSI_SECOND:
5090    case SQL_TSI_MINUTE:
5091    case SQL_TSI_HOUR:
5092    case SQL_TSI_DAY:
5093    case SQL_TSI_WEEK:
5094    case SQL_TSI_MONTH:
5095    case SQL_TSI_QUARTER:
5096    case SQL_TSI_YEAR:
5097    case START:
5098    case STATEMENT:
5099    case SYNONYM:
5100    case THEN:
5101    case TIME:
5102    case TIMESTAMP:
5103    case TIMESTAMPADD:
5104    case TIMESTAMPDIFF:
5105    case TRUNCATE:
5106    case TYPE:
5107    case UNCOMMITTED:
5108    case USAGE:
5109    case WHEN:
5110    case CURDATE:
5111    case CURTIME:
5112    case DATABASE:
5113    case LONG:
5114    case AFTER:
5115    case BEFORE:
5116    case CLASS:
5117    case COMPRESS:
5118    case CONTENT:
5119    case CS:
5120    case DB2SQL:
5121    case DIRTY:
5122    case DOCUMENT:
5123    case EACH:
5124    case EMPTY:
5125    case EXCLUSIVE:
5126    case FN:
5127    case INDEX:
5128    case JAVA:
5129    case LCASE:
5130    case LOCATE:
5131    case LOCK:
5132    case MESSAGE_LOCALE:
5133    case METHOD:
5134    case MODE:
5135    case NEW:
5136    case NEW_TABLE:
5137    case OJ:
5138    case OFF:
5139    case OLD:
5140    case OLD_TABLE:
5141    case PARAMETER:
5142    case PASSING:
5143    case PROPERTIES:
5144    case READS:
5145    case REF:
5146    case REFERENCING:
5147    case RENAME:
5148    case RESET:
5149    case RESULT:
5150    case RETAIN:
5151    case RETURNING:
5152    case RR:
5153    case RS:
5154    case SEQUENCE:
5155    case SEQUENTIAL:
5156    case SETS:
5157    case SHARE:
5158    case SQLID:
5159    case SPECIFIC:
5160    case SQRT:
5161    case STABILITY:
5162    case STRIP:
5163    case STYLE:
5164    case TRIGGER:
5165    case UCASE:
5166    case UR:
5167    case WHITESPACE:
5168    case IDENTIFIER:
5169    case DELIMITED_IDENTIFIER:
5170      columnName = asClause();
5171      break;
5172    default:
5173      jj_la1[92] = jj_gen;
5174      ;
5175    }
5176                /*
5177        ** If there is no AS clause, and the expression is a simple
5178        ** column, use the name of the column as the result column
5179        ** name.
5180        */

5181                if ((columnName == null) && (columnExpression instanceof ColumnReference))
5182                {
5183                        columnName = ((ColumnReference) columnExpression).columnName;
5184                }
5185
5186                {if (true) return (ResultColumn) nodeFactory.getNode(
5187                                                C_NodeTypes.RESULT_COLUMN,
5188                                                columnName,
5189                                                columnExpression,
5190                                                getContextManager());}
5191    throw new Error JavaDoc("Missing return statement in function");
5192  }
5193
5194/*
5195 * <A NAME="asClause">asClause</A>
5196 */

5197  final public String JavaDoc asClause() throws ParseException, StandardException {
5198        String JavaDoc columnName;
5199    switch (jj_nt.kind) {
5200    case AS:
5201      jj_consume_token(AS);
5202      break;
5203    default:
5204      jj_la1[93] = jj_gen;
5205      ;
5206    }
5207    columnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true);
5208                {if (true) return columnName;}
5209    throw new Error JavaDoc("Missing return statement in function");
5210  }
5211
5212/*
5213 * <A NAME="valueExpression">valueExpression</A>
5214 *
5215 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5216 * If in select or values clause, we do not want to allow boolean values.
5217 */

5218  final public ValueNode valueExpression(boolean inSelectClause) throws ParseException, StandardException {
5219        ValueNode leftOperand;
5220    leftOperand = orExpression(null, inSelectClause);
5221    label_10:
5222    while (true) {
5223      switch (jj_nt.kind) {
5224      case OR:
5225        ;
5226        break;
5227      default:
5228        jj_la1[94] = jj_gen;
5229        break label_10;
5230      }
5231      jj_consume_token(OR);
5232      leftOperand = orExpression(leftOperand, inSelectClause);
5233    }
5234                {if (true) return leftOperand;}
5235    throw new Error JavaDoc("Missing return statement in function");
5236  }
5237
5238/*
5239 * <A NAME="orExpression">orExpression</A>
5240 *
5241 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5242 * If in select or values clause, we do not want to allow boolean values.
5243 */

5244  final public ValueNode orExpression(ValueNode farLeftOperand, boolean inSelectClause) throws ParseException, StandardException {
5245        ValueNode leftOperand;
5246    leftOperand = andExpression(null, inSelectClause);
5247    label_11:
5248    while (true) {
5249      switch (jj_nt.kind) {
5250      case AND:
5251        ;
5252        break;
5253      default:
5254        jj_la1[95] = jj_gen;
5255        break label_11;
5256      }
5257      jj_consume_token(AND);
5258      leftOperand = andExpression(leftOperand, inSelectClause);
5259    }
5260                if (farLeftOperand == null)
5261                {
5262                        {if (true) return leftOperand;}
5263                }
5264                else
5265                {
5266                        {if (true) return (ValueNode) nodeFactory.getNode(
5267                                                                                C_NodeTypes.OR_NODE,
5268                                                                                farLeftOperand,
5269                                                                                leftOperand,
5270                                                                                getContextManager());}
5271                }
5272    throw new Error JavaDoc("Missing return statement in function");
5273  }
5274
5275/*
5276 * <A NAME="andExpression">andExpression</A>
5277 *
5278 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5279 * If in select or values clause, we do not want to allow boolean values.
5280 */

5281  final public ValueNode andExpression(ValueNode farLeftOperand, boolean inSelectClause) throws ParseException, StandardException {
5282        Token tok = null;
5283        ValueNode test;
5284    if (getToken(1).kind == NOT && !(getToken(2).kind == PERIOD ||
5285                            getToken(2).kind == DOUBLE_COLON)) {
5286      tok = jj_consume_token(NOT);
5287    } else {
5288      ;
5289    }
5290    test = isSearchCondition(inSelectClause);
5291                /* Put the NOT on top of test */
5292                if (tok != null)
5293                {
5294                        test = (ValueNode) nodeFactory.getNode(
5295                                                                        C_NodeTypes.NOT_NODE,
5296                                                                        test,
5297                                                                        getContextManager());
5298                }
5299
5300                if (farLeftOperand != null)
5301                {
5302                        test = (ValueNode) nodeFactory.getNode(
5303                                                                                C_NodeTypes.AND_NODE,
5304                                                                                farLeftOperand,
5305                                                                                test,
5306                                                                                getContextManager());
5307                }
5308                {if (true) return test;}
5309    throw new Error JavaDoc("Missing return statement in function");
5310  }
5311
5312/*
5313 * <A NAME="isSearchCondition">isSearchCondition</A>
5314 *
5315 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5316 * If in select or values clause, we do not want to allow boolean values.
5317 */

5318  final public ValueNode isSearchCondition(boolean inSelectClause) throws ParseException, StandardException {
5319        ValueNode result;
5320        ValueNode booleanPrimary;
5321        Token isToken = null;
5322        Token notToken = null;
5323        Token truthValue = null;
5324    booleanPrimary = booleanPrimary(inSelectClause);
5325    switch (jj_nt.kind) {
5326    case IS:
5327      isToken = jj_consume_token(IS);
5328      switch (jj_nt.kind) {
5329      case NOT:
5330        notToken = jj_consume_token(NOT);
5331        break;
5332      default:
5333        jj_la1[96] = jj_gen;
5334        ;
5335      }
5336      jj_consume_token(NULL);
5337      break;
5338    default:
5339      jj_la1[97] = jj_gen;
5340      ;
5341    }
5342                if ( isToken != null )
5343                {
5344                                result = (ValueNode) nodeFactory.getNode(
5345                                                                                        C_NodeTypes.IS_NULL_NODE,
5346                                                                                        booleanPrimary,
5347                                                                                        getContextManager());
5348
5349                                /* Put the NOT on top of the tree */
5350                                if (notToken != null)
5351                                {
5352                                        result = (ValueNode) nodeFactory.getNode(
5353                                                                                        C_NodeTypes.NOT_NODE,
5354                                                                                        result,
5355                                                                                        getContextManager());
5356                                }
5357                }
5358                else { result = booleanPrimary; }
5359
5360                {if (true) return result;}
5361    throw new Error JavaDoc("Missing return statement in function");
5362  }
5363
5364/*
5365 * <A NAME="booleanPrimary">booleanPrimary</A>
5366 *
5367 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5368 * If in select or values clause, we do not want to allow boolean values.
5369 */

5370  final public ValueNode booleanPrimary(boolean inSelectClause) throws ParseException, StandardException {
5371        ValueNode primary;
5372        ValueNode searchCondition;
5373    primary = predicate(inSelectClause);
5374                {if (true) return primary;}
5375    throw new Error JavaDoc("Missing return statement in function");
5376  }
5377
5378/*
5379 * <A NAME="predicate">predicate</A>
5380 *
5381 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5382 * If in select or values clause, we do not want to allow boolean values.
5383 */

5384  final public ValueNode predicate(boolean inSelectClause) throws ParseException, StandardException {
5385        ValueNode value;
5386    if (jj_2_19(1)) {
5387      value = additiveExpression(null, 0, inSelectClause);
5388    } else {
5389      switch (jj_nt.kind) {
5390      case EXISTS:
5391        value = existsExpression();
5392        break;
5393      default:
5394        jj_la1[98] = jj_gen;
5395        jj_consume_token(-1);
5396        throw new ParseException();
5397      }
5398    }
5399    label_12:
5400    while (true) {
5401      if (remainingPredicateFollows()) {
5402        ;
5403      } else {
5404        break label_12;
5405      }
5406      value = remainingPredicate(value, inSelectClause);
5407    }
5408                {if (true) return value;}
5409    throw new Error JavaDoc("Missing return statement in function");
5410  }
5411
5412/*
5413 * <A NAME="remainingPredicates">remainingPredicates</A>
5414 *
5415 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5416 * If in select or values clause, we do not want to allow boolean values.
5417 */

5418  final public ValueNode remainingPredicate(ValueNode value, boolean inSelectClause) throws ParseException, StandardException {
5419        Token tok = null;
5420    switch (jj_nt.kind) {
5421    case LESS_THAN_OPERATOR:
5422    case LESS_THAN_OR_EQUALS_OPERATOR:
5423    case EQUALS_OPERATOR:
5424    case NOT_EQUALS_OPERATOR:
5425    case NOT_EQUALS_OPERATOR2:
5426    case GREATER_THAN_OPERATOR:
5427    case GREATER_THAN_OR_EQUALS_OPERATOR:
5428      value = remainingNonNegatablePredicate(value, inSelectClause);
5429                {if (true) return value;}
5430      break;
5431    case BETWEEN:
5432    case IN:
5433    case LIKE:
5434    case NOT:
5435      switch (jj_nt.kind) {
5436      case NOT:
5437        tok = jj_consume_token(NOT);
5438        break;
5439      default:
5440        jj_la1[99] = jj_gen;
5441        ;
5442      }
5443      value = remainingNegatablePredicate(value, inSelectClause);
5444                /* Put the NOT on top of the tree */
5445                if (tok != null)
5446                {
5447                        value = (ValueNode) nodeFactory.getNode(
5448                                                                                C_NodeTypes.NOT_NODE,
5449                                                                                value,
5450                                                                                getContextManager());
5451                }
5452
5453                {if (true) return value;}
5454      break;
5455    default:
5456      jj_la1[100] = jj_gen;
5457      jj_consume_token(-1);
5458      throw new ParseException();
5459    }
5460    throw new Error JavaDoc("Missing return statement in function");
5461  }
5462
5463/*
5464 * <A NAME="remainingNonNegatablePredicate">remainingNonNegatablePredicate</A>
5465 *
5466 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5467 * If in select or values clause, we do not want to allow boolean values.
5468 */

5469  final public ValueNode remainingNonNegatablePredicate(ValueNode leftOperand, boolean inSelectClause) throws ParseException, StandardException {
5470        int operator;
5471        String JavaDoc javaClassName;
5472        Token tok = null;
5473        ValueNode tree = null;
5474        ValueNode likePattern;
5475        ValueNode betweenLeft;
5476        ValueNode betweenRight;
5477    operator = compOp();
5478    if ((getToken(1).kind == ALL || getToken(1).kind == ANY ||
5479                            getToken(1).kind == SOME) && getToken(2).kind == LEFT_PAREN) {
5480      operator = quantifier(operator);
5481      jj_consume_token(LEFT_PAREN);
5482      leftOperand = tableSubquery(operator, leftOperand);
5483      jj_consume_token(RIGHT_PAREN);
5484    } else if (jj_2_20(1)) {
5485      leftOperand = additiveExpression(leftOperand, operator, inSelectClause);
5486    } else {
5487      jj_consume_token(-1);
5488      throw new ParseException();
5489    }
5490                {if (true) return leftOperand;}
5491    throw new Error JavaDoc("Missing return statement in function");
5492  }
5493
5494/*
5495 * <A NAME="remainingNegatablePredicate">remainingNegatablePredicate</A>
5496 *
5497 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5498 * If in select or values clause, we do not want to allow boolean values.
5499 */

5500  final public ValueNode remainingNegatablePredicate(ValueNode leftOperand, boolean inSelectClause) throws ParseException, StandardException {
5501        ValueNode tree = null;
5502        ValueNode likePattern;
5503        ValueNode betweenLeft;
5504        ValueNode betweenRight;
5505        ValueNode escapeValue = null;
5506    switch (jj_nt.kind) {
5507    case IN:
5508      jj_consume_token(IN);
5509      tree = inPredicateValue(leftOperand);
5510                {if (true) return tree;}
5511      break;
5512    case LIKE:
5513      jj_consume_token(LIKE);
5514      likePattern = additiveExpression(null, 0, inSelectClause);
5515      switch (jj_nt.kind) {
5516      case ESCAPE:
5517      case LEFT_BRACE:
5518        switch (jj_nt.kind) {
5519        case ESCAPE:
5520          jj_consume_token(ESCAPE);
5521          escapeValue = additiveExpression(null, 0, inSelectClause);
5522          break;
5523        case LEFT_BRACE:
5524          jj_consume_token(LEFT_BRACE);
5525          jj_consume_token(ESCAPE);
5526          escapeValue = additiveExpression(null, 0, inSelectClause);
5527          jj_consume_token(RIGHT_BRACE);
5528          break;
5529        default:
5530          jj_la1[101] = jj_gen;
5531          jj_consume_token(-1);
5532          throw new ParseException();
5533        }
5534        break;
5535      default:
5536        jj_la1[102] = jj_gen;
5537        ;
5538      }
5539                tree = (ValueNode) nodeFactory.getNode(
5540                                                                C_NodeTypes.LIKE_OPERATOR_NODE,
5541                                                                leftOperand,
5542                                                                likePattern,
5543                                                                escapeValue,
5544                                                                getContextManager());
5545
5546                {if (true) return tree;}
5547      break;
5548    case BETWEEN:
5549      jj_consume_token(BETWEEN);
5550      betweenLeft = additiveExpression(null, 0, inSelectClause);
5551      jj_consume_token(AND);
5552      betweenRight = additiveExpression(null, 0, inSelectClause);
5553                ValueNodeList betweenList = (ValueNodeList) nodeFactory.getNode(
5554                                                                                                        C_NodeTypes.VALUE_NODE_LIST,
5555                                                                                                        getContextManager());
5556                betweenList.addElement(betweenLeft);
5557                betweenList.addElement(betweenRight);
5558                tree = (ValueNode) nodeFactory.getNode(
5559                                                                C_NodeTypes.BETWEEN_OPERATOR_NODE,
5560                                                                leftOperand,
5561                                                                betweenList,
5562                                                                getContextManager());
5563
5564                {if (true) return tree;}
5565      break;
5566    default:
5567      jj_la1[103] = jj_gen;
5568      jj_consume_token(-1);
5569      throw new ParseException();
5570    }
5571    throw new Error JavaDoc("Missing return statement in function");
5572  }
5573
5574/*
5575 * <A NAME="compOp">compOp</A>
5576 */

5577  final public int compOp() throws ParseException, StandardException {
5578    switch (jj_nt.kind) {
5579    case EQUALS_OPERATOR:
5580      jj_consume_token(EQUALS_OPERATOR);
5581                {if (true) return BinaryOperatorNode.EQ;}
5582      break;
5583    case NOT_EQUALS_OPERATOR:
5584      jj_consume_token(NOT_EQUALS_OPERATOR);
5585                {if (true) return BinaryOperatorNode.NE;}
5586      break;
5587    case NOT_EQUALS_OPERATOR2:
5588      jj_consume_token(NOT_EQUALS_OPERATOR2);
5589                {if (true) return BinaryOperatorNode.NE;}
5590      break;
5591    case LESS_THAN_OPERATOR:
5592      jj_consume_token(LESS_THAN_OPERATOR);
5593                {if (true) return BinaryOperatorNode.LT;}
5594      break;
5595    case GREATER_THAN_OPERATOR:
5596      jj_consume_token(GREATER_THAN_OPERATOR);
5597                {if (true) return BinaryOperatorNode.GT;}
5598      break;
5599    case LESS_THAN_OR_EQUALS_OPERATOR:
5600      jj_consume_token(LESS_THAN_OR_EQUALS_OPERATOR);
5601                {if (true) return BinaryOperatorNode.LE;}
5602      break;
5603    case GREATER_THAN_OR_EQUALS_OPERATOR:
5604      jj_consume_token(GREATER_THAN_OR_EQUALS_OPERATOR);
5605                {if (true) return BinaryOperatorNode.GE;}
5606      break;
5607    default:
5608      jj_la1[104] = jj_gen;
5609      jj_consume_token(-1);
5610      throw new ParseException();
5611    }
5612    throw new Error JavaDoc("Missing return statement in function");
5613  }
5614
5615/*
5616 * <A NAME="additiveExpression">additiveExpression</A>
5617 *
5618 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5619 * If in select or values clause, we do not want to allow boolean values.
5620 */

5621  final public ValueNode additiveExpression(ValueNode farLeftOperand, int compOp, boolean inSelectClause) throws ParseException, StandardException {
5622        ValueNode leftOperand;
5623        int operator;
5624        int nodeType;
5625    leftOperand = multiplicativeExpression(null, 0, inSelectClause);
5626    label_13:
5627    while (true) {
5628      switch (jj_nt.kind) {
5629      case PLUS_SIGN:
5630      case MINUS_SIGN:
5631        ;
5632        break;
5633      default:
5634        jj_la1[105] = jj_gen;
5635        break label_13;
5636      }
5637      operator = additiveOperator();
5638      leftOperand = multiplicativeExpression(leftOperand, operator, inSelectClause);
5639    }
5640                if (farLeftOperand == null)
5641                        {if (true) return leftOperand;}
5642
5643                switch (compOp)
5644                {
5645                  case BinaryOperatorNode.EQ:
5646                        nodeType = C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE;
5647                        break;
5648
5649                  case BinaryOperatorNode.NE:
5650                        nodeType = C_NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE;
5651                        break;
5652
5653                  case BinaryOperatorNode.LT:
5654                        nodeType = C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE;
5655                        break;
5656
5657                  case BinaryOperatorNode.GT:
5658                        nodeType = C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE;
5659                        break;
5660
5661                  case BinaryOperatorNode.LE:
5662                        nodeType = C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE;
5663                        break;
5664
5665                  case BinaryOperatorNode.GE:
5666                        nodeType = C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE;
5667                        break;
5668
5669                  default:
5670                        if (SanityManager.DEBUG)
5671                        SanityManager.THROWASSERT("Unknown comparison operator " + compOp);
5672                        nodeType = 0;
5673                        break;
5674                }
5675
5676                {if (true) return (ValueNode) nodeFactory.getNode(
5677                                                        nodeType,
5678                                                        farLeftOperand,
5679                                                        leftOperand,
5680                                                        getContextManager());}
5681    throw new Error JavaDoc("Missing return statement in function");
5682  }
5683
5684/*
5685 * <A NAME="additiveOperator">additiveOperator</A>
5686 */

5687  final public int additiveOperator() throws ParseException, StandardException {
5688        Token tok;
5689    switch (jj_nt.kind) {
5690    case PLUS_SIGN:
5691      tok = jj_consume_token(PLUS_SIGN);
5692                {if (true) return BinaryOperatorNode.PLUS;}
5693      break;
5694    case MINUS_SIGN:
5695      tok = jj_consume_token(MINUS_SIGN);
5696                {if (true) return BinaryOperatorNode.MINUS;}
5697      break;
5698    default:
5699      jj_la1[106] = jj_gen;
5700      jj_consume_token(-1);
5701      throw new ParseException();
5702    }
5703    throw new Error JavaDoc("Missing return statement in function");
5704  }
5705
5706/*
5707 * <A NAME="multiplicativeExpression">multiplicativeExpression</A>
5708 *
5709 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5710 * If in select or values clause, we do not want to allow boolean values.
5711 */

5712  final public ValueNode multiplicativeExpression(ValueNode farLeftOperand, int additiveOperator, boolean inSelectClause) throws ParseException, StandardException {
5713        ValueNode leftOperand;
5714        int multOp;
5715    leftOperand = unaryExpression(null, 0, inSelectClause);
5716    label_14:
5717    while (true) {
5718      switch (jj_nt.kind) {
5719      case ASTERISK:
5720      case SOLIDUS:
5721      case CONCATENATION_OPERATOR:
5722        ;
5723        break;
5724      default:
5725        jj_la1[107] = jj_gen;
5726        break label_14;
5727      }
5728      multOp = multiplicativeOperator();
5729      leftOperand = unaryExpression(leftOperand, multOp, inSelectClause);
5730    }
5731                if (farLeftOperand == null)
5732                        {if (true) return leftOperand;}
5733
5734                switch (additiveOperator)
5735                {
5736                  case BinaryOperatorNode.PLUS:
5737                        {if (true) return (ValueNode) nodeFactory.getNode(
5738                                                                        C_NodeTypes.BINARY_PLUS_OPERATOR_NODE,
5739                                                                        farLeftOperand,
5740                                                                        leftOperand,
5741                                                                        getContextManager()
5742                                                                        );}
5743
5744                  case BinaryOperatorNode.MINUS:
5745                        {if (true) return (ValueNode) nodeFactory.getNode(
5746                                                                        C_NodeTypes.BINARY_MINUS_OPERATOR_NODE,
5747                                                                        farLeftOperand,
5748                                                                        leftOperand,
5749                                                                        getContextManager()
5750                                                                        );}
5751
5752                  default:
5753                        if (SanityManager.DEBUG)
5754                        SanityManager.THROWASSERT(
5755                                        "Unexpected operator value of " + additiveOperator);
5756                        {if (true) return null;}
5757                }
5758    throw new Error JavaDoc("Missing return statement in function");
5759  }
5760
5761/*
5762 * <A NAME="multiplicativeOperator">multiplicativeOperator</A>
5763 */

5764  final public int multiplicativeOperator() throws ParseException, StandardException {
5765    switch (jj_nt.kind) {
5766    case ASTERISK:
5767      jj_consume_token(ASTERISK);
5768                {if (true) return BinaryOperatorNode.TIMES;}
5769      break;
5770    case SOLIDUS:
5771      jj_consume_token(SOLIDUS);
5772                {if (true) return BinaryOperatorNode.DIVIDE;}
5773      break;
5774    case CONCATENATION_OPERATOR:
5775      jj_consume_token(CONCATENATION_OPERATOR);
5776                {if (true) return BinaryOperatorNode.CONCATENATE;}
5777      break;
5778    default:
5779      jj_la1[108] = jj_gen;
5780      jj_consume_token(-1);
5781      throw new ParseException();
5782    }
5783    throw new Error JavaDoc("Missing return statement in function");
5784  }
5785
5786/*
5787 * <A NAME="unaryExpression">unaryExpression</A>
5788 *
5789 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5790 * If in select or values clause, we do not want to allow boolean values.
5791 */

5792  final public ValueNode unaryExpression(ValueNode farLeftOperand, int multiplicativeOperator, boolean inSelectClause) throws ParseException, StandardException {
5793        ValueNode value;
5794        String JavaDoc sign = null;
5795        int tokKind1;
5796        int tokKind2;
5797    if (( (tokKind1 = getToken(1).kind) == PLUS_SIGN ||
5798                                               tokKind1 == MINUS_SIGN )
5799                                            &&
5800                                            ( (tokKind2 = getToken(2).kind) != EXACT_NUMERIC &&
5801                                               tokKind2 != APPROXIMATE_NUMERIC)) {
5802      sign = sign();
5803    } else {
5804      ;
5805    }
5806    value = primaryExpression(inSelectClause);
5807                if ("-".equals(sign))
5808                {
5809                        value = (ValueNode) nodeFactory.getNode(
5810                                                                                C_NodeTypes.UNARY_MINUS_OPERATOR_NODE,
5811                                                                                value,
5812                                                                                getContextManager());
5813                }
5814                else if ("+".equals(sign))
5815                {
5816                        value = (ValueNode) nodeFactory.getNode(
5817                                                                                C_NodeTypes.UNARY_PLUS_OPERATOR_NODE,
5818                                                                                value,
5819                                                                                getContextManager());
5820                }
5821                else if (SanityManager.DEBUG)
5822                {
5823                        if (sign != null)
5824                        {
5825                                SanityManager.THROWASSERT("Unknown unary operator '"
5826                                                                                        + sign
5827                                                                                        + "'");
5828                        }
5829                }
5830
5831                {if (true) return multOp(farLeftOperand, value, multiplicativeOperator);}
5832    throw new Error JavaDoc("Missing return statement in function");
5833  }
5834
5835/*
5836 * <A NAME="sign">sign</A>
5837 */

5838  final public String JavaDoc sign() throws ParseException {
5839        Token s;
5840    switch (jj_nt.kind) {
5841    case PLUS_SIGN:
5842      s = jj_consume_token(PLUS_SIGN);
5843                {if (true) return s.image;}
5844      break;
5845    case MINUS_SIGN:
5846      s = jj_consume_token(MINUS_SIGN);
5847                {if (true) return s.image;}
5848      break;
5849    default:
5850      jj_la1[109] = jj_gen;
5851      jj_consume_token(-1);
5852      throw new ParseException();
5853    }
5854    throw new Error JavaDoc("Missing return statement in function");
5855  }
5856
5857/*
5858 * <A NAME="primaryExpressionXX">primaryExpressionXX</A>
5859 *
5860 * @param inSelectClause will be true if this method got called while parsing the select or values clause
5861 * If in select or values clause, we do not want to allow boolean values.
5862 */

5863  final public ValueNode primaryExpressionXX(boolean inSelectClause) throws ParseException, StandardException {
5864        ValueNode value;
5865    value = primary(inSelectClause);
5866    label_15:
5867    while (true) {
5868      if (jj_2_21(1)) {
5869        ;
5870      } else {
5871        break label_15;
5872      }
5873      value = nonStaticMethodCallOrFieldAccess(value);
5874    }
5875                {if (true) return value;}
5876    throw new Error JavaDoc("Missing return statement in function");
5877  }
5878
5879  final public ValueNode nonStaticMethodCallOrFieldAccess(ValueNode receiver) throws ParseException, StandardException {
5880        ValueNode value;
5881    value = nonStaticMethodInvocation(receiver);
5882                {if (true) return value;}
5883    throw new Error JavaDoc("Missing return statement in function");
5884  }
5885
5886/*
5887 * <A NAME="nonStaticMethodInvocation">nonStaticMethodInvocation</A>
5888 */

5889  final public ValueNode nonStaticMethodInvocation(ValueNode receiver) throws ParseException, StandardException {
5890        Vector JavaDoc parameterList = new Vector JavaDoc();
5891        MethodCallNode methodNode;
5892        ParameterNode parameterNode;
5893    if (getToken(3).kind == LEFT_PAREN) {
5894      switch (jj_nt.kind) {
5895      case FIELD_REFERENCE:
5896        jj_consume_token(FIELD_REFERENCE);
5897        break;
5898      case PERIOD:
5899        jj_consume_token(PERIOD);
5900        break;
5901      default:
5902        jj_la1[110] = jj_gen;
5903        jj_consume_token(-1);
5904        throw new ParseException();
5905      }
5906      methodNode = methodName(receiver);
5907      methodCallParameterList(parameterList);
5908                /*
5909        ** ? parameters are not allowed for the receiver --
5910        ** unless the receiver is standing in for a named parameter,
5911        ** whose type is therefore known.
5912        */

5913                if (receiver instanceof ParameterNode)
5914                {
5915                        {if (true) throw StandardException.newException(SQLState.LANG_PARAMETER_RECEIVER,
5916                                                                                                methodNode.getMethodName());}
5917                }
5918
5919                methodNode.addParms(parameterList);
5920
5921                /*
5922        ** Assume this is being returned to the SQL domain. If it turns
5923        ** out that this is being returned to the Java domain, we will
5924        ** get rid of this node.
5925        */

5926                {if (true) return (ValueNode) nodeFactory.getNode(
5927                                                                C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,
5928                                                                methodNode,
5929                                                                getContextManager());}
5930    } else {
5931      switch (jj_nt.kind) {
5932      case PERIOD:
5933        jj_consume_token(PERIOD);
5934        methodNode = methodName(receiver);
5935                /*
5936        ** ? parameters are not allowed for the receiver --
5937        ** unless the receiver is standing in for a named parameter,
5938        ** whose type is therefore known.
5939        */

5940                if (receiver instanceof ParameterNode)
5941                {
5942                        {if (true) throw StandardException.newException(SQLState.LANG_PARAMETER_RECEIVER,
5943                                                                                                methodNode.getMethodName());}
5944                }
5945
5946                methodNode.addParms(parameterList);
5947
5948                /*
5949        ** Assume this is being returned to the SQL domain. If it turns
5950        ** out that this is being returned to the Java domain, we will
5951        ** get rid of this node.
5952        */

5953                {if (true) return (ValueNode) nodeFactory.getNode(
5954                                                                C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,
5955                                                                methodNode,
5956                                                                getContextManager());}
5957        break;
5958      default:
5959        jj_la1[111] = jj_gen;
5960        jj_consume_token(-1);
5961        throw new ParseException();
5962      }
5963    }
5964    throw new Error JavaDoc("Missing return statement in function");
5965  }
5966
5967/*
5968 * <A NAME="methodName">methodName</A>
5969 */

5970  final public MethodCallNode methodName(ValueNode receiver) throws ParseException, StandardException {
5971        String JavaDoc methodName;
5972    /*
5973        ** NOTE: allowing a delimited identifier as a method name is necessary,
5974        ** because Java is case-sensitive. But this also allows identifiers that
5975        ** do not match Java syntax. This will probably not cause a problem
5976        ** in later phases, like binding and code generation.
5977        */

5978            methodName = caseSensitiveIdentifierPlusReservedWords();
5979                {if (true) return (MethodCallNode) nodeFactory.getNode(
5980                                                                                C_NodeTypes.NON_STATIC_METHOD_CALL_NODE,
5981                                                                                methodName,
5982                                                                                receiver,
5983                                                                                getContextManager());}
5984    throw new Error JavaDoc("Missing return statement in function");
5985  }
5986
5987/*
5988 * <A NAME="staticMethodName">staticMethodName</A>
5989 */

5990  final public MethodCallNode staticMethodName(String JavaDoc javaClassName) throws ParseException, StandardException {
5991        String JavaDoc methodName;
5992    /*
5993        ** NOTE: allowing a delimited identifier as a method name is necessary,
5994        ** because Java is case-sensitive. But this also allows identifiers that
5995        ** do not match Java syntax. This will probably not cause a problem
5996        ** in later phases, like binding and code generation.
5997        */

5998            methodName = caseSensitiveIdentifierPlusReservedWords();
5999                {if (true) return (MethodCallNode) nodeFactory.getNode(
6000                                                                C_NodeTypes.STATIC_METHOD_CALL_NODE,
6001                                                                methodName,
6002                                                                javaClassName,
6003                                                                getContextManager());}
6004    throw new Error JavaDoc("Missing return statement in function");
6005  }
6006
6007/*
6008 * <A NAME="methodParameter">methodParameter</A>
6009 */

6010  final public void methodParameter(Vector JavaDoc parameterList) throws ParseException, StandardException {
6011        ValueNode parameter;
6012    if (jj_2_22(1)) {
6013      parameter = additiveExpression(null,0, false);
6014                parameterList.addElement(parameter);
6015    } else {
6016      switch (jj_nt.kind) {
6017      case NULL:
6018        parameter = nullSpecification();
6019                parameterList.addElement(parameter);
6020        break;
6021      default:
6022        jj_la1[112] = jj_gen;
6023        jj_consume_token(-1);
6024        throw new ParseException();
6025      }
6026    }
6027  }
6028
6029/*
6030 * <A NAME="primary">primary</A>
6031 *
6032 * @param inSelectClause will be true if this method got called while parsing the select or values clause
6033 * If in select or values clause, we do not want to allow boolean values.
6034 */

6035  final public ValueNode primary(boolean inSelectClause) throws ParseException, StandardException {
6036        String JavaDoc javaClassName;
6037        ValueNode value;
6038    if (javaClassFollows()) {
6039      value = staticClassReference();
6040                {if (true) return value;}
6041    } else if (jj_2_23(1)) {
6042      value = valueExpressionPrimary(inSelectClause);
6043                {if (true) return value;}
6044    } else {
6045      jj_consume_token(-1);
6046      throw new ParseException();
6047    }
6048    throw new Error JavaDoc("Missing return statement in function");
6049  }
6050
6051/*
6052 * <A NAME="staticClassReference">staticClassReference</A>
6053 */

6054  final public ValueNode staticClassReference() throws ParseException, StandardException {
6055        String JavaDoc javaClassName;
6056        ValueNode value;
6057    javaClassName = javaClass();
6058    jj_consume_token(DOUBLE_COLON);
6059    value = staticClassReferenceType(javaClassName);
6060                {if (true) return value;}
6061    throw new Error JavaDoc("Missing return statement in function");
6062  }
6063
6064/*
6065 * <A NAME="staticClassReferenceType">staticClassReferenceType</A>
6066 */

6067  final public ValueNode staticClassReferenceType(String JavaDoc javaClassName) throws ParseException, StandardException {
6068        ValueNode value;
6069    if ((getToken(2).kind == LEFT_PAREN)) {
6070      value = staticMethodInvocation(javaClassName);
6071                {if (true) return value;}
6072    } else {
6073      switch (jj_nt.kind) {
6074      case ADD:
6075      case ALL:
6076      case ALLOCATE:
6077      case ALTER:
6078      case AND:
6079      case ANY:
6080      case ARE:
6081      case AS:
6082      case ASC:
6083      case ASSERTION:
6084      case AT:
6085      case AUTHORIZATION:
6086      case AVG:
6087      case BEGIN:
6088      case BETWEEN:
6089      case BINARY:
6090      case BIT:
6091      case BOTH:
6092      case BY:
6093      case CASCADE:
6094      case CASCADED:
6095      case CASE:
6096      case CAST:
6097      case CHAR:
6098      case CHARACTER:
6099      case CHECK:
6100      case CLOSE:
6101      case COALESCE:
6102      case COLLATE:
6103      case COLLATION:
6104      case COLUMN:
6105      case COMMIT:
6106      case CONNECT:
6107      case CONNECTION:
6108      case CONSTRAINT:
6109      case CONSTRAINTS:
6110      case CONTINUE:
6111      case CONVERT:
6112      case CORRESPONDING:
6113      case COUNT:
6114      case CREATE:
6115      case CURRENT:
6116      case CURRENT_DATE:
6117      case CURRENT_TIME:
6118      case CURRENT_TIMESTAMP:
6119      case CURRENT_USER:
6120      case CURSOR:
6121      case D:
6122      case DEALLOCATE:
6123      case DEC:
6124      case DECIMAL:
6125      case DECLARE:
6126      case _DEFAULT:
6127      case DEFERRABLE:
6128