PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 1ms

/h2/src/main/org/h2/command/Parser.java

http://h2database.googlecode.com/
Java | 5949 lines | 5553 code | 169 blank | 227 comment | 1681 complexity | a58dfe4f8c1c65b9913b805a6bc30771 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
  3. * Version 1.0, and under the Eclipse Public License, Version 1.0
  4. * (http://h2database.com/html/license.html).
  5. * Initial Developer: H2 Group
  6. *
  7. * Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
  8. * Support for the operator "&&" as an alias for SPATIAL_INTERSECTS
  9. */
  10. package org.h2.command;
  11. import java.math.BigDecimal;
  12. import java.math.BigInteger;
  13. import java.nio.charset.Charset;
  14. import java.text.Collator;
  15. import java.util.ArrayList;
  16. import java.util.HashSet;
  17. import org.h2.api.ErrorCode;
  18. import org.h2.api.Trigger;
  19. import org.h2.command.ddl.AlterIndexRename;
  20. import org.h2.command.ddl.AlterSchemaRename;
  21. import org.h2.command.ddl.AlterTableAddConstraint;
  22. import org.h2.command.ddl.AlterTableAlterColumn;
  23. import org.h2.command.ddl.AlterTableDropConstraint;
  24. import org.h2.command.ddl.AlterTableRename;
  25. import org.h2.command.ddl.AlterTableRenameColumn;
  26. import org.h2.command.ddl.AlterUser;
  27. import org.h2.command.ddl.AlterView;
  28. import org.h2.command.ddl.Analyze;
  29. import org.h2.command.ddl.CreateAggregate;
  30. import org.h2.command.ddl.CreateConstant;
  31. import org.h2.command.ddl.CreateFunctionAlias;
  32. import org.h2.command.ddl.CreateIndex;
  33. import org.h2.command.ddl.CreateLinkedTable;
  34. import org.h2.command.ddl.CreateRole;
  35. import org.h2.command.ddl.CreateSchema;
  36. import org.h2.command.ddl.CreateSequence;
  37. import org.h2.command.ddl.CreateTable;
  38. import org.h2.command.ddl.CreateTableData;
  39. import org.h2.command.ddl.CreateTrigger;
  40. import org.h2.command.ddl.CreateUser;
  41. import org.h2.command.ddl.CreateUserDataType;
  42. import org.h2.command.ddl.CreateView;
  43. import org.h2.command.ddl.DeallocateProcedure;
  44. import org.h2.command.ddl.DefineCommand;
  45. import org.h2.command.ddl.DropAggregate;
  46. import org.h2.command.ddl.DropConstant;
  47. import org.h2.command.ddl.DropDatabase;
  48. import org.h2.command.ddl.DropFunctionAlias;
  49. import org.h2.command.ddl.DropIndex;
  50. import org.h2.command.ddl.DropRole;
  51. import org.h2.command.ddl.DropSchema;
  52. import org.h2.command.ddl.DropSequence;
  53. import org.h2.command.ddl.DropTable;
  54. import org.h2.command.ddl.DropTrigger;
  55. import org.h2.command.ddl.DropUser;
  56. import org.h2.command.ddl.DropUserDataType;
  57. import org.h2.command.ddl.DropView;
  58. import org.h2.command.ddl.GrantRevoke;
  59. import org.h2.command.ddl.PrepareProcedure;
  60. import org.h2.command.ddl.SetComment;
  61. import org.h2.command.ddl.TruncateTable;
  62. import org.h2.command.dml.AlterSequence;
  63. import org.h2.command.dml.AlterTableSet;
  64. import org.h2.command.dml.BackupCommand;
  65. import org.h2.command.dml.Call;
  66. import org.h2.command.dml.Delete;
  67. import org.h2.command.dml.ExecuteProcedure;
  68. import org.h2.command.dml.Explain;
  69. import org.h2.command.dml.Insert;
  70. import org.h2.command.dml.Merge;
  71. import org.h2.command.dml.NoOperation;
  72. import org.h2.command.dml.Query;
  73. import org.h2.command.dml.Replace;
  74. import org.h2.command.dml.RunScriptCommand;
  75. import org.h2.command.dml.ScriptCommand;
  76. import org.h2.command.dml.Select;
  77. import org.h2.command.dml.SelectOrderBy;
  78. import org.h2.command.dml.SelectUnion;
  79. import org.h2.command.dml.Set;
  80. import org.h2.command.dml.SetTypes;
  81. import org.h2.command.dml.TransactionCommand;
  82. import org.h2.command.dml.Update;
  83. import org.h2.constraint.ConstraintReferential;
  84. import org.h2.engine.Constants;
  85. import org.h2.engine.Database;
  86. import org.h2.engine.DbObject;
  87. import org.h2.engine.FunctionAlias;
  88. import org.h2.engine.Procedure;
  89. import org.h2.engine.Right;
  90. import org.h2.engine.Session;
  91. import org.h2.engine.SysProperties;
  92. import org.h2.engine.User;
  93. import org.h2.engine.UserAggregate;
  94. import org.h2.engine.UserDataType;
  95. import org.h2.expression.Aggregate;
  96. import org.h2.expression.Alias;
  97. import org.h2.expression.CompareLike;
  98. import org.h2.expression.Comparison;
  99. import org.h2.expression.ConditionAndOr;
  100. import org.h2.expression.ConditionExists;
  101. import org.h2.expression.ConditionIn;
  102. import org.h2.expression.ConditionInSelect;
  103. import org.h2.expression.ConditionNot;
  104. import org.h2.expression.Expression;
  105. import org.h2.expression.ExpressionColumn;
  106. import org.h2.expression.ExpressionList;
  107. import org.h2.expression.Function;
  108. import org.h2.expression.FunctionCall;
  109. import org.h2.expression.JavaAggregate;
  110. import org.h2.expression.JavaFunction;
  111. import org.h2.expression.Operation;
  112. import org.h2.expression.Parameter;
  113. import org.h2.expression.Rownum;
  114. import org.h2.expression.SequenceValue;
  115. import org.h2.expression.Subquery;
  116. import org.h2.expression.TableFunction;
  117. import org.h2.expression.ValueExpression;
  118. import org.h2.expression.Variable;
  119. import org.h2.expression.Wildcard;
  120. import org.h2.index.Index;
  121. import org.h2.message.DbException;
  122. import org.h2.result.SortOrder;
  123. import org.h2.schema.Schema;
  124. import org.h2.schema.Sequence;
  125. import org.h2.table.Column;
  126. import org.h2.table.FunctionTable;
  127. import org.h2.table.IndexColumn;
  128. import org.h2.table.RangeTable;
  129. import org.h2.table.Table;
  130. import org.h2.table.TableFilter;
  131. import org.h2.table.TableView;
  132. import org.h2.table.TableFilter.TableFilterVisitor;
  133. import org.h2.util.MathUtils;
  134. import org.h2.util.New;
  135. import org.h2.util.StatementBuilder;
  136. import org.h2.util.StringUtils;
  137. import org.h2.value.CompareMode;
  138. import org.h2.value.DataType;
  139. import org.h2.value.Value;
  140. import org.h2.value.ValueBoolean;
  141. import org.h2.value.ValueBytes;
  142. import org.h2.value.ValueDate;
  143. import org.h2.value.ValueDecimal;
  144. import org.h2.value.ValueInt;
  145. import org.h2.value.ValueLong;
  146. import org.h2.value.ValueNull;
  147. import org.h2.value.ValueString;
  148. import org.h2.value.ValueTime;
  149. import org.h2.value.ValueTimestamp;
  150. /**
  151. * The parser is used to convert a SQL statement string to an command object.
  152. *
  153. * @author Thomas Mueller
  154. * @author Noel Grandin
  155. * @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
  156. */
  157. public class Parser {
  158. // used during the tokenizer phase
  159. private static final int CHAR_END = 1, CHAR_VALUE = 2, CHAR_QUOTED = 3;
  160. private static final int CHAR_NAME = 4, CHAR_SPECIAL_1 = 5,
  161. CHAR_SPECIAL_2 = 6;
  162. private static final int CHAR_STRING = 7, CHAR_DOT = 8,
  163. CHAR_DOLLAR_QUOTED_STRING = 9;
  164. // this are token types
  165. private static final int KEYWORD = 1, IDENTIFIER = 2, PARAMETER = 3,
  166. END = 4, VALUE = 5;
  167. private static final int EQUAL = 6, BIGGER_EQUAL = 7, BIGGER = 8;
  168. private static final int SMALLER = 9, SMALLER_EQUAL = 10, NOT_EQUAL = 11,
  169. AT = 12;
  170. private static final int MINUS = 13, PLUS = 14, STRING_CONCAT = 15;
  171. private static final int OPEN = 16, CLOSE = 17, NULL = 18, TRUE = 19,
  172. FALSE = 20;
  173. private static final int CURRENT_TIMESTAMP = 21, CURRENT_DATE = 22,
  174. CURRENT_TIME = 23, ROWNUM = 24;
  175. private static final int SPATIAL_INTERSECTS = 25;
  176. private final Database database;
  177. private final Session session;
  178. /**
  179. * @see org.h2.engine.DbSettings#databaseToUpper
  180. */
  181. private final boolean identifiersToUpper;
  182. /** indicates character-type for each char in sqlCommand */
  183. private int[] characterTypes;
  184. private int currentTokenType;
  185. private String currentToken;
  186. private boolean currentTokenQuoted;
  187. private Value currentValue;
  188. private String originalSQL;
  189. /** copy of originalSQL, with comments blanked out */
  190. private String sqlCommand;
  191. /** cached array if chars from sqlCommand */
  192. private char[] sqlCommandChars;
  193. /** index into sqlCommand of previous token */
  194. private int lastParseIndex;
  195. /** index into sqlCommand of current token */
  196. private int parseIndex;
  197. private CreateView createView;
  198. private Prepared currentPrepared;
  199. private Select currentSelect;
  200. private ArrayList<Parameter> parameters;
  201. private String schemaName;
  202. private ArrayList<String> expectedList;
  203. private boolean rightsChecked;
  204. private boolean recompileAlways;
  205. private ArrayList<Parameter> indexedParameterList;
  206. public Parser(Session session) {
  207. this.database = session.getDatabase();
  208. this.identifiersToUpper = database.getSettings().databaseToUpper;
  209. this.session = session;
  210. }
  211. /**
  212. * Parse the statement and prepare it for execution.
  213. *
  214. * @param sql the SQL statement to parse
  215. * @return the prepared object
  216. */
  217. public Prepared prepare(String sql) {
  218. Prepared p = parse(sql);
  219. p.prepare();
  220. if (currentTokenType != END) {
  221. throw getSyntaxError();
  222. }
  223. return p;
  224. }
  225. /**
  226. * Parse a statement or a list of statements, and prepare it for execution.
  227. *
  228. * @param sql the SQL statement to parse
  229. * @return the command object
  230. */
  231. public Command prepareCommand(String sql) {
  232. try {
  233. Prepared p = parse(sql);
  234. boolean hasMore = isToken(";");
  235. if (!hasMore && currentTokenType != END) {
  236. throw getSyntaxError();
  237. }
  238. p.prepare();
  239. Command c = new CommandContainer(this, sql, p);
  240. if (hasMore) {
  241. String remaining = originalSQL.substring(parseIndex);
  242. if (remaining.trim().length() != 0) {
  243. CommandList list = new CommandList(this, sql, c, remaining);
  244. // list.addCommand(c);
  245. // do {
  246. // c = parseCommand();
  247. // list.addCommand(c);
  248. // } while (currentToken.equals(";"));
  249. c = list;
  250. }
  251. }
  252. return c;
  253. } catch (DbException e) {
  254. throw e.addSQL(originalSQL);
  255. }
  256. }
  257. /**
  258. * Parse the statement, but don't prepare it for execution.
  259. *
  260. * @param sql the SQL statement to parse
  261. * @return the prepared object
  262. */
  263. Prepared parse(String sql) {
  264. Prepared p;
  265. try {
  266. // first, try the fast variant
  267. p = parse(sql, false);
  268. } catch (DbException e) {
  269. if (e.getErrorCode() == ErrorCode.SYNTAX_ERROR_1) {
  270. // now, get the detailed exception
  271. p = parse(sql, true);
  272. } else {
  273. throw e.addSQL(sql);
  274. }
  275. }
  276. p.setPrepareAlways(recompileAlways);
  277. p.setParameterList(parameters);
  278. return p;
  279. }
  280. private Prepared parse(String sql, boolean withExpectedList) {
  281. initialize(sql);
  282. if (withExpectedList) {
  283. expectedList = New.arrayList();
  284. } else {
  285. expectedList = null;
  286. }
  287. parameters = New.arrayList();
  288. currentSelect = null;
  289. currentPrepared = null;
  290. createView = null;
  291. recompileAlways = false;
  292. indexedParameterList = null;
  293. read();
  294. return parsePrepared();
  295. }
  296. private Prepared parsePrepared() {
  297. int start = lastParseIndex;
  298. Prepared c = null;
  299. String token = currentToken;
  300. if (token.length() == 0) {
  301. c = new NoOperation(session);
  302. } else {
  303. char first = token.charAt(0);
  304. switch (first) {
  305. case '?':
  306. // read the ? as a parameter
  307. readTerm();
  308. // this is an 'out' parameter - set a dummy value
  309. parameters.get(0).setValue(ValueNull.INSTANCE);
  310. read("=");
  311. read("CALL");
  312. c = parseCall();
  313. break;
  314. case '(':
  315. c = parseSelect();
  316. break;
  317. case 'a':
  318. case 'A':
  319. if (readIf("ALTER")) {
  320. c = parseAlter();
  321. } else if (readIf("ANALYZE")) {
  322. c = parseAnalyze();
  323. }
  324. break;
  325. case 'b':
  326. case 'B':
  327. if (readIf("BACKUP")) {
  328. c = parseBackup();
  329. } else if (readIf("BEGIN")) {
  330. c = parseBegin();
  331. }
  332. break;
  333. case 'c':
  334. case 'C':
  335. if (readIf("COMMIT")) {
  336. c = parseCommit();
  337. } else if (readIf("CREATE")) {
  338. c = parseCreate();
  339. } else if (readIf("CALL")) {
  340. c = parseCall();
  341. } else if (readIf("CHECKPOINT")) {
  342. c = parseCheckpoint();
  343. } else if (readIf("COMMENT")) {
  344. c = parseComment();
  345. }
  346. break;
  347. case 'd':
  348. case 'D':
  349. if (readIf("DELETE")) {
  350. c = parseDelete();
  351. } else if (readIf("DROP")) {
  352. c = parseDrop();
  353. } else if (readIf("DECLARE")) {
  354. // support for DECLARE GLOBAL TEMPORARY TABLE...
  355. c = parseCreate();
  356. } else if (readIf("DEALLOCATE")) {
  357. c = parseDeallocate();
  358. }
  359. break;
  360. case 'e':
  361. case 'E':
  362. if (readIf("EXPLAIN")) {
  363. c = parseExplain();
  364. } else if (readIf("EXECUTE")) {
  365. c = parseExecute();
  366. }
  367. break;
  368. case 'f':
  369. case 'F':
  370. if (isToken("FROM")) {
  371. c = parseSelect();
  372. }
  373. break;
  374. case 'g':
  375. case 'G':
  376. if (readIf("GRANT")) {
  377. c = parseGrantRevoke(CommandInterface.GRANT);
  378. }
  379. break;
  380. case 'h':
  381. case 'H':
  382. if (readIf("HELP")) {
  383. c = parseHelp();
  384. }
  385. break;
  386. case 'i':
  387. case 'I':
  388. if (readIf("INSERT")) {
  389. c = parseInsert();
  390. }
  391. break;
  392. case 'm':
  393. case 'M':
  394. if (readIf("MERGE")) {
  395. c = parseMerge();
  396. }
  397. break;
  398. case 'p':
  399. case 'P':
  400. if (readIf("PREPARE")) {
  401. c = parsePrepare();
  402. }
  403. break;
  404. case 'r':
  405. case 'R':
  406. if (readIf("ROLLBACK")) {
  407. c = parseRollback();
  408. } else if (readIf("REVOKE")) {
  409. c = parseGrantRevoke(CommandInterface.REVOKE);
  410. } else if (readIf("RUNSCRIPT")) {
  411. c = parseRunScript();
  412. } else if (readIf("RELEASE")) {
  413. c = parseReleaseSavepoint();
  414. } else if (readIf("REPLACE")) {
  415. c = parseReplace();
  416. }
  417. break;
  418. case 's':
  419. case 'S':
  420. if (isToken("SELECT")) {
  421. c = parseSelect();
  422. } else if (readIf("SET")) {
  423. c = parseSet();
  424. } else if (readIf("SAVEPOINT")) {
  425. c = parseSavepoint();
  426. } else if (readIf("SCRIPT")) {
  427. c = parseScript();
  428. } else if (readIf("SHUTDOWN")) {
  429. c = parseShutdown();
  430. } else if (readIf("SHOW")) {
  431. c = parseShow();
  432. }
  433. break;
  434. case 't':
  435. case 'T':
  436. if (readIf("TRUNCATE")) {
  437. c = parseTruncate();
  438. }
  439. break;
  440. case 'u':
  441. case 'U':
  442. if (readIf("UPDATE")) {
  443. c = parseUpdate();
  444. }
  445. break;
  446. case 'v':
  447. case 'V':
  448. if (readIf("VALUES")) {
  449. c = parseValues();
  450. }
  451. break;
  452. case 'w':
  453. case 'W':
  454. if (readIf("WITH")) {
  455. c = parseWith();
  456. }
  457. break;
  458. case ';':
  459. c = new NoOperation(session);
  460. break;
  461. default:
  462. throw getSyntaxError();
  463. }
  464. if (indexedParameterList != null) {
  465. for (int i = 0, size = indexedParameterList.size();
  466. i < size; i++) {
  467. if (indexedParameterList.get(i) == null) {
  468. indexedParameterList.set(i, new Parameter(i));
  469. }
  470. }
  471. parameters = indexedParameterList;
  472. }
  473. if (readIf("{")) {
  474. do {
  475. int index = (int) readLong() - 1;
  476. if (index < 0 || index >= parameters.size()) {
  477. throw getSyntaxError();
  478. }
  479. Parameter p = parameters.get(index);
  480. if (p == null) {
  481. throw getSyntaxError();
  482. }
  483. read(":");
  484. Expression expr = readExpression();
  485. expr = expr.optimize(session);
  486. p.setValue(expr.getValue(session));
  487. } while (readIf(","));
  488. read("}");
  489. for (Parameter p : parameters) {
  490. p.checkSet();
  491. }
  492. parameters.clear();
  493. }
  494. }
  495. if (c == null) {
  496. throw getSyntaxError();
  497. }
  498. setSQL(c, null, start);
  499. return c;
  500. }
  501. private DbException getSyntaxError() {
  502. if (expectedList == null || expectedList.size() == 0) {
  503. return DbException.getSyntaxError(sqlCommand, parseIndex);
  504. }
  505. StatementBuilder buff = new StatementBuilder();
  506. for (String e : expectedList) {
  507. buff.appendExceptFirst(", ");
  508. buff.append(e);
  509. }
  510. return DbException.getSyntaxError(sqlCommand, parseIndex,
  511. buff.toString());
  512. }
  513. private Prepared parseBackup() {
  514. BackupCommand command = new BackupCommand(session);
  515. read("TO");
  516. command.setFileName(readExpression());
  517. return command;
  518. }
  519. private Prepared parseAnalyze() {
  520. Analyze command = new Analyze(session);
  521. if (readIf("SAMPLE_SIZE")) {
  522. command.setTop(getPositiveInt());
  523. }
  524. return command;
  525. }
  526. private TransactionCommand parseBegin() {
  527. TransactionCommand command;
  528. if (!readIf("WORK")) {
  529. readIf("TRANSACTION");
  530. }
  531. command = new TransactionCommand(session, CommandInterface.BEGIN);
  532. return command;
  533. }
  534. private TransactionCommand parseCommit() {
  535. TransactionCommand command;
  536. if (readIf("TRANSACTION")) {
  537. command = new TransactionCommand(session,
  538. CommandInterface.COMMIT_TRANSACTION);
  539. command.setTransactionName(readUniqueIdentifier());
  540. return command;
  541. }
  542. command = new TransactionCommand(session,
  543. CommandInterface.COMMIT);
  544. readIf("WORK");
  545. return command;
  546. }
  547. private TransactionCommand parseShutdown() {
  548. int type = CommandInterface.SHUTDOWN;
  549. if (readIf("IMMEDIATELY")) {
  550. type = CommandInterface.SHUTDOWN_IMMEDIATELY;
  551. } else if (readIf("COMPACT")) {
  552. type = CommandInterface.SHUTDOWN_COMPACT;
  553. } else if (readIf("DEFRAG")) {
  554. type = CommandInterface.SHUTDOWN_DEFRAG;
  555. } else {
  556. readIf("SCRIPT");
  557. }
  558. return new TransactionCommand(session, type);
  559. }
  560. private TransactionCommand parseRollback() {
  561. TransactionCommand command;
  562. if (readIf("TRANSACTION")) {
  563. command = new TransactionCommand(session,
  564. CommandInterface.ROLLBACK_TRANSACTION);
  565. command.setTransactionName(readUniqueIdentifier());
  566. return command;
  567. }
  568. if (readIf("TO")) {
  569. read("SAVEPOINT");
  570. command = new TransactionCommand(session,
  571. CommandInterface.ROLLBACK_TO_SAVEPOINT);
  572. command.setSavepointName(readUniqueIdentifier());
  573. } else {
  574. readIf("WORK");
  575. command = new TransactionCommand(session,
  576. CommandInterface.ROLLBACK);
  577. }
  578. return command;
  579. }
  580. private Prepared parsePrepare() {
  581. if (readIf("COMMIT")) {
  582. TransactionCommand command = new TransactionCommand(session,
  583. CommandInterface.PREPARE_COMMIT);
  584. command.setTransactionName(readUniqueIdentifier());
  585. return command;
  586. }
  587. String procedureName = readAliasIdentifier();
  588. if (readIf("(")) {
  589. ArrayList<Column> list = New.arrayList();
  590. for (int i = 0;; i++) {
  591. Column column = parseColumnForTable("C" + i, true);
  592. list.add(column);
  593. if (readIf(")")) {
  594. break;
  595. }
  596. read(",");
  597. }
  598. }
  599. read("AS");
  600. Prepared prep = parsePrepared();
  601. PrepareProcedure command = new PrepareProcedure(session);
  602. command.setProcedureName(procedureName);
  603. command.setPrepared(prep);
  604. return command;
  605. }
  606. private TransactionCommand parseSavepoint() {
  607. TransactionCommand command = new TransactionCommand(session,
  608. CommandInterface.SAVEPOINT);
  609. command.setSavepointName(readUniqueIdentifier());
  610. return command;
  611. }
  612. private Prepared parseReleaseSavepoint() {
  613. Prepared command = new NoOperation(session);
  614. readIf("SAVEPOINT");
  615. readUniqueIdentifier();
  616. return command;
  617. }
  618. private Schema getSchema(String schemaName) {
  619. if (schemaName == null) {
  620. return null;
  621. }
  622. Schema schema = database.findSchema(schemaName);
  623. if (schema == null) {
  624. if (equalsToken("SESSION", schemaName)) {
  625. // for local temporary tables
  626. schema = database.getSchema(session.getCurrentSchemaName());
  627. } else if (database.getMode().sysDummy1 &&
  628. "SYSIBM".equals(schemaName)) {
  629. // IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1
  630. } else {
  631. throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
  632. }
  633. }
  634. return schema;
  635. }
  636. private Schema getSchema() {
  637. return getSchema(schemaName);
  638. }
  639. private Column readTableColumn(TableFilter filter) {
  640. String tableAlias = null;
  641. String columnName = readColumnIdentifier();
  642. if (readIf(".")) {
  643. tableAlias = columnName;
  644. columnName = readColumnIdentifier();
  645. if (readIf(".")) {
  646. String schema = tableAlias;
  647. tableAlias = columnName;
  648. columnName = readColumnIdentifier();
  649. if (readIf(".")) {
  650. String catalogName = schema;
  651. schema = tableAlias;
  652. tableAlias = columnName;
  653. columnName = readColumnIdentifier();
  654. if (!equalsToken(catalogName, database.getShortName())) {
  655. throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_1,
  656. catalogName);
  657. }
  658. }
  659. if (!equalsToken(schema, filter.getTable().getSchema()
  660. .getName())) {
  661. throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schema);
  662. }
  663. }
  664. if (!equalsToken(tableAlias, filter.getTableAlias())) {
  665. throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1,
  666. tableAlias);
  667. }
  668. }
  669. if (database.getSettings().rowId) {
  670. if (Column.ROWID.equals(columnName)) {
  671. return filter.getRowIdColumn();
  672. }
  673. }
  674. return filter.getTable().getColumn(columnName);
  675. }
  676. private Update parseUpdate() {
  677. Update command = new Update(session);
  678. currentPrepared = command;
  679. int start = lastParseIndex;
  680. TableFilter filter = readSimpleTableFilter();
  681. command.setTableFilter(filter);
  682. read("SET");
  683. if (readIf("(")) {
  684. ArrayList<Column> columns = New.arrayList();
  685. do {
  686. Column column = readTableColumn(filter);
  687. columns.add(column);
  688. } while (readIf(","));
  689. read(")");
  690. read("=");
  691. Expression expression = readExpression();
  692. if (columns.size() == 1) {
  693. // the expression is parsed as a simple value
  694. command.setAssignment(columns.get(0), expression);
  695. } else {
  696. for (int i = 0, size = columns.size(); i < size; i++) {
  697. Column column = columns.get(i);
  698. Function f = Function.getFunction(database, "ARRAY_GET");
  699. f.setParameter(0, expression);
  700. f.setParameter(1, ValueExpression.get(ValueInt.get(i + 1)));
  701. f.doneWithParameters();
  702. command.setAssignment(column, f);
  703. }
  704. }
  705. } else {
  706. do {
  707. Column column = readTableColumn(filter);
  708. read("=");
  709. Expression expression;
  710. if (readIf("DEFAULT")) {
  711. expression = ValueExpression.getDefault();
  712. } else {
  713. expression = readExpression();
  714. }
  715. command.setAssignment(column, expression);
  716. } while (readIf(","));
  717. }
  718. if (readIf("WHERE")) {
  719. Expression condition = readExpression();
  720. command.setCondition(condition);
  721. }
  722. if (readIf("LIMIT")) {
  723. Expression limit = readTerm().optimize(session);
  724. command.setLimit(limit);
  725. }
  726. setSQL(command, "UPDATE", start);
  727. return command;
  728. }
  729. private TableFilter readSimpleTableFilter() {
  730. Table table = readTableOrView();
  731. String alias = null;
  732. if (readIf("AS")) {
  733. alias = readAliasIdentifier();
  734. } else if (currentTokenType == IDENTIFIER) {
  735. if (!equalsToken("SET", currentToken)) {
  736. // SET is not a keyword (PostgreSQL supports it as a table name)
  737. alias = readAliasIdentifier();
  738. }
  739. }
  740. return new TableFilter(session, table, alias, rightsChecked,
  741. currentSelect);
  742. }
  743. private Delete parseDelete() {
  744. Delete command = new Delete(session);
  745. Expression limit = null;
  746. if (readIf("TOP")) {
  747. limit = readTerm().optimize(session);
  748. }
  749. currentPrepared = command;
  750. int start = lastParseIndex;
  751. readIf("FROM");
  752. TableFilter filter = readSimpleTableFilter();
  753. command.setTableFilter(filter);
  754. if (readIf("WHERE")) {
  755. Expression condition = readExpression();
  756. command.setCondition(condition);
  757. }
  758. if (readIf("LIMIT") && limit == null) {
  759. limit = readTerm().optimize(session);
  760. }
  761. command.setLimit(limit);
  762. setSQL(command, "DELETE", start);
  763. return command;
  764. }
  765. private IndexColumn[] parseIndexColumnList() {
  766. ArrayList<IndexColumn> columns = New.arrayList();
  767. do {
  768. IndexColumn column = new IndexColumn();
  769. column.columnName = readColumnIdentifier();
  770. columns.add(column);
  771. if (readIf("ASC")) {
  772. // ignore
  773. } else if (readIf("DESC")) {
  774. column.sortType = SortOrder.DESCENDING;
  775. }
  776. if (readIf("NULLS")) {
  777. if (readIf("FIRST")) {
  778. column.sortType |= SortOrder.NULLS_FIRST;
  779. } else {
  780. read("LAST");
  781. column.sortType |= SortOrder.NULLS_LAST;
  782. }
  783. }
  784. } while (readIf(","));
  785. read(")");
  786. return columns.toArray(new IndexColumn[columns.size()]);
  787. }
  788. private String[] parseColumnList() {
  789. ArrayList<String> columns = New.arrayList();
  790. do {
  791. String columnName = readColumnIdentifier();
  792. columns.add(columnName);
  793. } while (readIfMore());
  794. return columns.toArray(new String[columns.size()]);
  795. }
  796. private Column[] parseColumnList(Table table) {
  797. ArrayList<Column> columns = New.arrayList();
  798. HashSet<Column> set = New.hashSet();
  799. if (!readIf(")")) {
  800. do {
  801. Column column = parseColumn(table);
  802. if (!set.add(column)) {
  803. throw DbException.get(ErrorCode.DUPLICATE_COLUMN_NAME_1,
  804. column.getSQL());
  805. }
  806. columns.add(column);
  807. } while (readIfMore());
  808. }
  809. return columns.toArray(new Column[columns.size()]);
  810. }
  811. private Column parseColumn(Table table) {
  812. String id = readColumnIdentifier();
  813. if (database.getSettings().rowId && Column.ROWID.equals(id)) {
  814. return table.getRowIdColumn();
  815. }
  816. return table.getColumn(id);
  817. }
  818. private boolean readIfMore() {
  819. if (readIf(",")) {
  820. return !readIf(")");
  821. }
  822. read(")");
  823. return false;
  824. }
  825. private Prepared parseHelp() {
  826. StringBuilder buff = new StringBuilder(
  827. "SELECT * FROM INFORMATION_SCHEMA.HELP");
  828. int i = 0;
  829. ArrayList<Value> paramValues = New.arrayList();
  830. while (currentTokenType != END) {
  831. String s = currentToken;
  832. read();
  833. if (i == 0) {
  834. buff.append(" WHERE ");
  835. } else {
  836. buff.append(" AND ");
  837. }
  838. i++;
  839. buff.append("UPPER(TOPIC) LIKE ?");
  840. paramValues.add(ValueString.get("%" + s + "%"));
  841. }
  842. return prepare(session, buff.toString(), paramValues);
  843. }
  844. private Prepared parseShow() {
  845. ArrayList<Value> paramValues = New.arrayList();
  846. StringBuilder buff = new StringBuilder("SELECT ");
  847. if (readIf("CLIENT_ENCODING")) {
  848. // for PostgreSQL compatibility
  849. buff.append("'UNICODE' AS CLIENT_ENCODING FROM DUAL");
  850. } else if (readIf("DEFAULT_TRANSACTION_ISOLATION")) {
  851. // for PostgreSQL compatibility
  852. buff.append("'read committed' AS DEFAULT_TRANSACTION_ISOLATION " +
  853. "FROM DUAL");
  854. } else if (readIf("TRANSACTION")) {
  855. // for PostgreSQL compatibility
  856. read("ISOLATION");
  857. read("LEVEL");
  858. buff.append("'read committed' AS TRANSACTION_ISOLATION " +
  859. "FROM DUAL");
  860. } else if (readIf("DATESTYLE")) {
  861. // for PostgreSQL compatibility
  862. buff.append("'ISO' AS DATESTYLE FROM DUAL");
  863. } else if (readIf("SERVER_VERSION")) {
  864. // for PostgreSQL compatibility
  865. buff.append("'8.1.4' AS SERVER_VERSION FROM DUAL");
  866. } else if (readIf("SERVER_ENCODING")) {
  867. // for PostgreSQL compatibility
  868. buff.append("'UTF8' AS SERVER_ENCODING FROM DUAL");
  869. } else if (readIf("TABLES")) {
  870. // for MySQL compatibility
  871. String schema = Constants.SCHEMA_MAIN;
  872. if (readIf("FROM")) {
  873. schema = readUniqueIdentifier();
  874. }
  875. buff.append("TABLE_NAME, TABLE_SCHEMA FROM "
  876. + "INFORMATION_SCHEMA.TABLES "
  877. + "WHERE TABLE_SCHEMA=? ORDER BY TABLE_NAME");
  878. paramValues.add(ValueString.get(schema));
  879. } else if (readIf("COLUMNS")) {
  880. // for MySQL compatibility
  881. read("FROM");
  882. String tableName = readIdentifierWithSchema();
  883. String schemaName = getSchema().getName();
  884. paramValues.add(ValueString.get(tableName));
  885. if (readIf("FROM")) {
  886. schemaName = readUniqueIdentifier();
  887. }
  888. buff.append("C.COLUMN_NAME FIELD, "
  889. + "C.TYPE_NAME || '(' || C.NUMERIC_PRECISION || ')' TYPE, "
  890. + "C.IS_NULLABLE \"NULL\", "
  891. + "CASE (SELECT MAX(I.INDEX_TYPE_NAME) FROM "
  892. + "INFORMATION_SCHEMA.INDEXES I "
  893. + "WHERE I.TABLE_SCHEMA=C.TABLE_SCHEMA "
  894. + "AND I.TABLE_NAME=C.TABLE_NAME "
  895. + "AND I.COLUMN_NAME=C.COLUMN_NAME)"
  896. + "WHEN 'PRIMARY KEY' THEN 'PRI' "
  897. + "WHEN 'UNIQUE INDEX' THEN 'UNI' ELSE '' END KEY, "
  898. + "IFNULL(COLUMN_DEFAULT, 'NULL') DEFAULT "
  899. + "FROM INFORMATION_SCHEMA.COLUMNS C "
  900. + "WHERE C.TABLE_NAME=? AND C.TABLE_SCHEMA=? "
  901. + "ORDER BY C.ORDINAL_POSITION");
  902. paramValues.add(ValueString.get(schemaName));
  903. } else if (readIf("DATABASES") || readIf("SCHEMAS")) {
  904. // for MySQL compatibility
  905. buff.append("SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA");
  906. }
  907. boolean b = session.getAllowLiterals();
  908. try {
  909. // need to temporarily enable it, in case we are in
  910. // ALLOW_LITERALS_NUMBERS mode
  911. session.setAllowLiterals(true);
  912. return prepare(session, buff.toString(), paramValues);
  913. } finally {
  914. session.setAllowLiterals(b);
  915. }
  916. }
  917. private static Prepared prepare(Session s, String sql,
  918. ArrayList<Value> paramValues) {
  919. Prepared prep = s.prepare(sql);
  920. ArrayList<Parameter> params = prep.getParameters();
  921. if (params != null) {
  922. for (int i = 0, size = params.size(); i < size; i++) {
  923. Parameter p = params.get(i);
  924. p.setValue(paramValues.get(i));
  925. }
  926. }
  927. return prep;
  928. }
  929. private boolean isSelect() {
  930. int start = lastParseIndex;
  931. while (readIf("(")) {
  932. // need to read ahead, it could be a nested union:
  933. // ((select 1) union (select 1))
  934. }
  935. boolean select = isToken("SELECT") || isToken("FROM");
  936. parseIndex = start;
  937. read();
  938. return select;
  939. }
  940. private Merge parseMerge() {
  941. Merge command = new Merge(session);
  942. currentPrepared = command;
  943. read("INTO");
  944. Table table = readTableOrView();
  945. command.setTable(table);
  946. if (readIf("(")) {
  947. if (isSelect()) {
  948. command.setQuery(parseSelect());
  949. read(")");
  950. return command;
  951. }
  952. Column[] columns = parseColumnList(table);
  953. command.setColumns(columns);
  954. }
  955. if (readIf("KEY")) {
  956. read("(");
  957. Column[] keys = parseColumnList(table);
  958. command.setKeys(keys);
  959. }
  960. if (readIf("VALUES")) {
  961. do {
  962. ArrayList<Expression> values = New.arrayList();
  963. read("(");
  964. if (!readIf(")")) {
  965. do {
  966. if (readIf("DEFAULT")) {
  967. values.add(null);
  968. } else {
  969. values.add(readExpression());
  970. }
  971. } while (readIfMore());
  972. }
  973. command.addRow(values.toArray(new Expression[values.size()]));
  974. } while (readIf(","));
  975. } else {
  976. command.setQuery(parseSelect());
  977. }
  978. return command;
  979. }
  980. private Insert parseInsert() {
  981. Insert command = new Insert(session);
  982. currentPrepared = command;
  983. read("INTO");
  984. Table table = readTableOrView();
  985. command.setTable(table);
  986. Column[] columns = null;
  987. if (readIf("(")) {
  988. if (isSelect()) {
  989. command.setQuery(parseSelect());
  990. read(")");
  991. return command;
  992. }
  993. columns = parseColumnList(table);
  994. command.setColumns(columns);
  995. }
  996. if (readIf("DIRECT")) {
  997. command.setInsertFromSelect(true);
  998. }
  999. if (readIf("SORTED")) {
  1000. command.setSortedInsertMode(true);
  1001. }
  1002. if (readIf("DEFAULT")) {
  1003. read("VALUES");
  1004. Expression[] expr = {};
  1005. command.addRow(expr);
  1006. } else if (readIf("VALUES")) {
  1007. read("(");
  1008. do {
  1009. ArrayList<Expression> values = New.arrayList();
  1010. if (!readIf(")")) {
  1011. do {
  1012. if (readIf("DEFAULT")) {
  1013. values.add(null);
  1014. } else {
  1015. values.add(readExpression());
  1016. }
  1017. } while (readIfMore());
  1018. }
  1019. command.addRow(values.toArray(new Expression[values.size()]));
  1020. // the following condition will allow (..),; and (..);
  1021. } while (readIf(",") && readIf("("));
  1022. } else if (readIf("SET")) {
  1023. if (columns != null) {
  1024. throw getSyntaxError();
  1025. }
  1026. ArrayList<Column> columnList = New.arrayList();
  1027. ArrayList<Expression> values = New.arrayList();
  1028. do {
  1029. columnList.add(parseColumn(table));
  1030. read("=");
  1031. Expression expression;
  1032. if (readIf("DEFAULT")) {
  1033. expression = ValueExpression.getDefault();
  1034. } else {
  1035. expression = readExpression();
  1036. }
  1037. values.add(expression);
  1038. } while (readIf(","));
  1039. command.setColumns(columnList.toArray(new Column[columnList.size()]));
  1040. command.addRow(values.toArray(new Expression[values.size()]));
  1041. } else {
  1042. command.setQuery(parseSelect());
  1043. }
  1044. if (database.getMode().onDuplicateKeyUpdate) {
  1045. if (readIf("ON")) {
  1046. read("DUPLICATE");
  1047. read("KEY");
  1048. read("UPDATE");
  1049. do {
  1050. Column column = parseColumn(table);
  1051. read("=");
  1052. Expression expression;
  1053. if (readIf("DEFAULT")) {
  1054. expression = ValueExpression.getDefault();
  1055. } else {
  1056. expression = readExpression();
  1057. }
  1058. command.addAssignmentForDuplicate(column, expression);
  1059. } while (readIf(","));
  1060. }
  1061. }
  1062. if (database.getMode().isolationLevelInSelectOrInsertStatement) {
  1063. parseIsolationClause();
  1064. }
  1065. return command;
  1066. }
  1067. /**
  1068. * MySQL compatibility. REPLACE is similar to MERGE.
  1069. */
  1070. private Replace parseReplace() {
  1071. Replace command = new Replace(session);
  1072. currentPrepared = command;
  1073. read("INTO");
  1074. Table table = readTableOrView();
  1075. command.setTable(table);
  1076. if (readIf("(")) {
  1077. if (isSelect()) {
  1078. command.setQuery(parseSelect());
  1079. read(")");
  1080. return command;
  1081. }
  1082. Column[] columns = parseColumnList(table);
  1083. command.setColumns(columns);
  1084. }
  1085. if (readIf("VALUES")) {
  1086. do {
  1087. ArrayList<Expression> values = New.arrayList();
  1088. read("(");
  1089. if (!readIf(")")) {
  1090. do {
  1091. if (readIf("DEFAULT")) {
  1092. values.add(null);
  1093. } else {
  1094. values.add(readExpression());
  1095. }
  1096. } while (readIfMore());
  1097. }
  1098. command.addRow(values.toArray(new Expression[values.size()]));
  1099. } while (readIf(","));
  1100. } else {
  1101. command.setQuery(parseSelect());
  1102. }
  1103. return command;
  1104. }
  1105. private TableFilter readTableFilter(boolean fromOuter) {
  1106. Table table;
  1107. String alias = null;
  1108. if (readIf("(")) {
  1109. if (isSelect()) {
  1110. Query query = parseSelectUnion();
  1111. read(")");
  1112. query.setParameterList(New.arrayList(parameters));
  1113. query.init();
  1114. Session s;
  1115. if (createView != null) {
  1116. s = database.getSystemSession();
  1117. } else {
  1118. s = session;
  1119. }
  1120. alias = session.getNextSystemIdentifier(sqlCommand);
  1121. table = TableView.createTempView(s, session.getUser(), alias,
  1122. query, currentSelect);
  1123. } else {
  1124. TableFilter top;
  1125. if (database.getSettings().nestedJoins) {
  1126. top = readTableFilter(false);
  1127. top = readJoin(top, currentSelect, false, false);
  1128. top = getNested(top);
  1129. } else {
  1130. top = readTableFilter(fromOuter);
  1131. top = readJoin(top, currentSelect, false, fromOuter);
  1132. }
  1133. read(")");
  1134. alias = readFromAlias(null);
  1135. if (alias != null) {
  1136. top.setAlias(alias);
  1137. }
  1138. return top;
  1139. }
  1140. } else if (readIf("VALUES")) {
  1141. table = parseValuesTable().getTable();
  1142. } else {
  1143. String tableName = readIdentifierWithSchema(null);
  1144. Schema schema = getSchema();
  1145. boolean foundLeftBracket = readIf("(");
  1146. if (foundLeftBracket && readIf("INDEX")) {
  1147. // Sybase compatibility with
  1148. // "select * from test (index table1_index)"
  1149. readIdentifierWithSchema(null);
  1150. read(")");
  1151. foundLeftBracket = false;
  1152. }
  1153. if (foundLeftBracket) {
  1154. Schema mainSchema = database.getSchema(Constants.SCHEMA_MAIN);
  1155. if (equalsToken(tableName, RangeTable.NAME)) {
  1156. Expression min = readExpression();
  1157. read(",");
  1158. Expression max = readExpression();
  1159. read(")");
  1160. table = new RangeTable(mainSchema, min, max, false);
  1161. } else {
  1162. Expression expr = readFunction(schema, tableName);
  1163. if (!(expr instanceof FunctionCall)) {
  1164. throw getSyntaxError();
  1165. }
  1166. FunctionCall call = (FunctionCall) expr;
  1167. if (!call.isDeterministic()) {
  1168. recompileAlways = true;
  1169. }
  1170. table = new FunctionTable(mainSchema, session, expr, call);
  1171. }
  1172. } else if (equalsToken("DUAL", tableName)) {
  1173. table = getDualTable(false);
  1174. } else if (database.getMode().sysDummy1 &&
  1175. equalsToken("SYSDUMMY1", tableName)) {
  1176. table = getDualTable(false);
  1177. } else {
  1178. table = readTableOrView(tableName);
  1179. }
  1180. }
  1181. alias = readFromAlias(alias);
  1182. return new TableFilter(session, table, alias, rightsChecked,
  1183. currentSelect);
  1184. }
  1185. private String readFromAlias(String alias) {
  1186. if (readIf("AS")) {
  1187. alias = readAliasIdentifier();
  1188. } else if (currentTokenType == IDENTIFIER) {
  1189. // left and right are not keywords (because they are functions as
  1190. // well)
  1191. if (!isToken("LEFT") && !isToken("RIGHT") && !isToken("FULL")) {
  1192. alias = readAliasIdentifier();
  1193. }
  1194. }
  1195. return alias;
  1196. }
  1197. private Prepared parseTruncate() {
  1198. read("TABLE");
  1199. Table table = readTableOrView();
  1200. TruncateTable command = new TruncateTable(session);
  1201. command.setTable(table);
  1202. return command;
  1203. }
  1204. private boolean readIfExists(boolean ifExists) {
  1205. if (readIf("IF")) {
  1206. read("EXISTS");
  1207. ifExists = true;
  1208. }
  1209. return ifExists;
  1210. }
  1211. private Prepared parseComment() {
  1212. int type = 0;
  1213. read("ON");
  1214. boolean column = false;
  1215. if (readIf("TABLE") || readIf("VIEW")) {
  1216. type = DbObject.TABLE_OR_VIEW;
  1217. } else if (readIf("COLUMN")) {
  1218. column = true;
  1219. type = DbObject.TABLE_OR_VIEW;
  1220. } else if (readIf("CONSTANT")) {
  1221. type = DbObject.CONSTANT;
  1222. } else if (readIf("CONSTRAINT")) {
  1223. type = DbObject.CONSTRAINT;
  1224. } else if (readIf("ALIAS")) {
  1225. type = DbObject.FUNCTION_ALIAS;
  1226. } else if (readIf("INDEX")) {
  1227. type = DbObject.INDEX;
  1228. } else if (readIf("ROLE")) {
  1229. type = DbObject.ROLE;
  1230. } else if (readIf("SCHEMA")) {
  1231. type = DbObject.SCHEMA;
  1232. } else if (readIf("SEQUENCE")) {
  1233. type = DbObject.SEQUENCE;
  1234. } else if (readIf("TRIGGER")) {
  1235. type = DbObject.TRIGGER;
  1236. } else if (readIf("USER")) {
  1237. type = DbObject.USER;
  1238. } else if (readIf("DOMAIN")) {
  1239. type = DbObject.USER_DATATYPE;
  1240. } else {
  1241. throw getSyntaxError();
  1242. }
  1243. SetComment command = new SetComment(session);
  1244. String objectName;
  1245. if (column) {
  1246. // can't use readIdentifierWithSchema() because
  1247. // it would not read schema.table.column correctly
  1248. // if the db name is equal to the schema name
  1249. ArrayList<String> list = New.arrayList();
  1250. do {
  1251. list.add(readUniqueIdentifier());
  1252. } while (readIf("."));
  1253. schemaName = session.getCurrentSchemaName();
  1254. if (list.size() == 4) {
  1255. if (!equalsToken(database.getShortName(), list.get(0))) {
  1256. throw DbException.getSyntaxError(sqlCommand, parseIndex,
  1257. "database name");
  1258. }
  1259. list.remove(0);
  1260. }
  1261. if (list.size() == 3) {
  1262. schemaName = list.get(0);
  1263. list.remove(0);
  1264. }
  1265. if (list.size() != 2) {
  1266. throw DbException.getSyntaxError(sqlCommand, parseIndex,
  1267. "table.column");
  1268. }
  1269. objectName = list.get(0);
  1270. command.setColumn(true);
  1271. command.setColumnName(list.get(1));
  1272. } else {
  1273. objectName = readIdentifierWithSchema();
  1274. }
  1275. command.setSchemaName(schemaName);
  1276. command.setObjectName(objectName);
  1277. command.setObjectType(type);
  1278. read("IS");
  1279. command.setCommentExpression(readExpression());
  1280. return command;
  1281. }
  1282. private Prepared parseDrop() {
  1283. if (readIf("TABLE")) {
  1284. boolean ifExists = readIfExists(false);
  1285. String tableName = readIdentifierWithSchema();
  1286. DropTable command = new DropTable(session, getSchema());
  1287. command.setTableName(tableName);
  1288. while (readIf(",")) {
  1289. tableName = readIdentifierWithSchema();
  1290. DropTable next = new DropTable(session, getSchema());
  1291. next.setTableName(tableName);
  1292. command.addNextDropTable(next);
  1293. }
  1294. ifExists = readIfExists(ifExists);
  1295. command.setIfExists(ifExists);
  1296. if (readIf("CASCADE")) {
  1297. command.setDropAction(ConstraintReferential.CASCADE);
  1298. readIf("CONSTRAINTS");
  1299. } else if (readIf("RESTRICT")) {
  1300. command.setDropAction(ConstraintReferential.RESTRICT);
  1301. } else if (readIf("IGNORE")) {
  1302. command.setDropAction(ConstraintReferential.SET_DEFAULT);
  1303. }
  1304. return command;
  1305. } else if (readIf("INDEX")) {
  1306. boolean ifExists = readIfExists(false);
  1307. String indexName = readIdentifierWithSchema();
  1308. DropIndex command = new DropIndex(session, getSchema());
  1309. command.setIndexName(indexName);
  1310. ifExists = readIfExists(ifExists);
  1311. command.setIfExists(ifExists);
  1312. return command;
  1313. } else if (readIf("USER")) {
  1314. boolean ifExists = readIfExists(false);
  1315. DropUser command = new DropUser(session);
  1316. command.setUserName(readUniqueIdentifier());
  1317. ifExists = readIfExists(ifExists);
  1318. readIf("CASCADE");
  1319. command.setIfExists(ifExists);
  1320. return command;
  1321. } else if (readIf("SEQUENCE")) {
  1322. boolean ifExists = readIfExists(false);
  1323. String sequenceName = readIdentifierWithSchema();
  1324. DropSequence command = new DropSequence(session, getSchema());
  1325. command.setSequenceName(sequenceName);
  1326. ifExists = readIfExists(ifExists);
  1327. command.setIfExists(ifExists);
  1328. return command;
  1329. } else if (readIf("CONSTANT")) {
  1330. boolean ifExists = readIfExists(false);
  1331. String constantName = readIdentifierWithSchema();
  1332. DropConstant command = new DropConstant(session, getSchema());
  1333. command.setConstantName(constantName);
  1334. ifExists = readIfExists(ifExists);
  1335. command.setIfExists(ifExists);
  1336. return command;
  1337. } else if (readIf("TRIGGER")) {
  1338. boolean ifExists = readIfExists(false);

Large files files are truncated, but you can click here to view the full file