1
/* Copyright (c) 1995-2000, The Hypersonic SQL Group.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* Neither the name of the Hypersonic SQL Group nor the names of its
15
* contributors may be used to endorse or promote products derived from this
16
* software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
22
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
* This software consists of voluntary contributions made by many individuals
31
* on behalf of the Hypersonic SQL Group.
34
* For work added by the HSQL Development Group:
36
* Copyright (c) 2001-2005, The HSQL Development Group
37
* All rights reserved.
39
* Redistribution and use in source and binary forms, with or without
40
* modification, are permitted provided that the following conditions are met:
42
* Redistributions of source code must retain the above copyright notice, this
43
* list of conditions and the following disclaimer.
45
* Redistributions in binary form must reproduce the above copyright notice,
46
* this list of conditions and the following disclaimer in the documentation
47
* and/or other materials provided with the distribution.
49
* Neither the name of the HSQL Development Group nor the names of its
50
* contributors may be used to endorse or promote products derived from this
51
* software without specific prior written permission.
53
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
54
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
57
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
/* Copyright (c) 1995-2000, The Hypersonic SQL Group.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* Neither the name of the Hypersonic SQL Group nor the names of its
15
* contributors may be used to endorse or promote products derived from this
16
* software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
22
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
* This software consists of voluntary contributions made by many individuals
31
* on behalf of the Hypersonic SQL Group.
34
* For work added by the HSQL Development Group:
36
* Copyright (c) 2001-2005, The HSQL Development Group
37
* All rights reserved.
39
* Redistribution and use in source and binary forms, with or without
40
* modification, are permitted provided that the following conditions are met:
42
* Redistributions of source code must retain the above copyright notice, this
43
* list of conditions and the following disclaimer.
45
* Redistributions in binary form must reproduce the above copyright notice,
46
* this list of conditions and the following disclaimer in the documentation
47
* and/or other materials provided with the distribution.
49
* Neither the name of the HSQL Development Group nor the names of its
50
* contributors may be used to endorse or promote products derived from this
51
* software without specific prior written permission.
53
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
54
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
57
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67
67
package org.hsqldb;
69
69
import java.io.IOException;
547
558
* @return column index map
548
559
* @throws HsqlException if a column is not found or is duplicate
550
private int[] processColumnList(Table t) throws HsqlException {
558
list = new HsqlArrayList();
561
tokenizer.getThis(Token.T_OPENBRACKET);
564
token = tokenizer.getSimpleName();
569
if (list.size() != set.size()) {
570
throw Trace.error(Trace.COLUMN_ALREADY_EXISTS,
571
Trace.ERROR_IN_CONSTRAINT_COLUMN_LIST);
574
token = tokenizer.getSimpleToken();
576
if (token.equals(Token.T_DESC) || token.equals(Token.T_ASC)) {
577
token = tokenizer.getSimpleToken(); // OJ: eat it up
580
if (token.equals(Token.T_COMMA)) {
584
if (token.equals(Token.T_CLOSEBRACKET)) {
588
throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
561
private int[] processColumnList(Table t,
562
boolean acceptAscDesc)
563
throws HsqlException {
565
HashMappedList list = Parser.processColumnList(tokenizer,
567
int size = list.size();
568
int[] col = new int[size];
594
570
for (int i = 0; i < size; i++) {
595
col[i] = t.getColumnNr((String) list.get(i));
571
col[i] = t.getColumnNr((String) list.getKey(i));
602
* Responsible for tail end of CREATE INDEX DDL. <p>
604
* Indexes defined in DDL scripts are handled by this method. If the
605
* name of an existing index begins with "SYS_", the name is changed to
606
* begin with "USER_". The name should be unique within the database.
607
* For compatibility with old database, non-unique names are modified
608
* and assigned a new name. <p>
610
* In 1.7.2 no new index is created if an equivalent already exists. <p>
615
* @param indexName index
617
* @param indexNameQuoted is quoted
618
* @param unique is unique
619
* @throws HsqlException
621
private void addIndexOn(Table t, String indexName,
622
boolean indexNameQuoted,
623
boolean unique) throws HsqlException {
625
HsqlName indexHsqlName;
628
database.schemaManager.checkIndexExists(indexName, t.getSchemaName(),
631
indexHsqlName = newIndexHsqlName(indexName, indexNameQuoted);
632
indexColumns = processColumnList(t);
635
session.setScripting(true);
637
TableWorks tableWorks = new TableWorks(session, t);
639
tableWorks.createIndex(indexColumns, indexHsqlName, unique, false,
644
578
* Responsible for handling the execution of CREATE TRIGGER SQL
645
579
* statements. <p>
1276
1225
tokenizer.getThis(Token.T_ROWS);
1279
HsqlArrayList tempConstraints = processCreateConstraints(t,
1280
constraint, pkCols);
1283
1229
session.commit();
1285
1231
Constraint primaryConst = (Constraint) tempConstraints.get(0);
1287
if (primaryConst.constName == null) {
1288
primaryConst.constName = t.makeSysPKName();
1233
t.createPrimaryKey(null, primaryConst.core.mainColArray, true);
1235
if (primaryConst.core.mainColArray != null) {
1236
if (primaryConst.constName == null) {
1237
primaryConst.constName = t.makeSysPKName();
1240
Constraint newconstraint =
1241
new Constraint(primaryConst.constName,
1242
primaryConst.core.mainColArray);
1244
t.addConstraint(newconstraint);
1245
database.schemaManager.registerConstraintName(
1246
primaryConst.constName.name, t.getName());
1291
database.schemaManager.registerIndexName(
1292
primaryConst.constName.name, t.getName());
1293
database.schemaManager.registerConstraintName(
1294
primaryConst.constName.name, t.getName());
1295
t.createPrimaryKey(primaryConst.constName,
1296
primaryConst.core.mainColArray, true);
1298
1249
for (int i = 1; i < tempConstraints.size(); i++) {
1299
1250
Constraint tempConst = (Constraint) tempConstraints.get(i);
1514
1465
HsqlName[] colList = null;
1467
// fredt - a bug in 1.8.0.0 and previous versions causes view
1468
// definitions to script without double quotes around column names
1469
// in certain cases; the workaround here discards such scripted column
1470
// lists when used in OOo
1516
1471
if (tokenizer.isGetThis(Token.T_OPENBRACKET)) {
1517
HsqlArrayList list = Parser.getColumnNames(database, null,
1520
colList = new HsqlName[list.size()];
1521
colList = (HsqlName[]) list.toArray(colList);
1473
HsqlArrayList list = Parser.getColumnNames(database, null,
1476
colList = new HsqlName[list.size()];
1477
colList = (HsqlName[]) list.toArray(colList);
1479
//added lines to make sure all valid columns are quoted
1480
if (database.isStoredFileAccess()) {
1481
for (int i = 0; i < colList.length; i++) {
1482
if (!colList[i].isNameQuoted) {
1489
} catch (HsqlException e) {
1491
//added lines to catch unquoted names with spaces
1492
if (database.isStoredFileAccess()) {
1493
while (!tokenizer.getString().equals(
1494
Token.T_CLOSEBRACKET)) {}
1524
1501
tokenizer.getThis(Token.T_AS);
1525
1502
tokenizer.setPartMarker();
1527
1504
Parser parser = new Parser(session, database, tokenizer);
1530
if (tokenizer.isGetThis(Token.T_OPENBRACKET)) {
1531
brackets += Parser.parseOpenBrackets(tokenizer) + 1;
1534
tokenizer.getThis(Token.T_SELECT);
1505
int brackets = parser.parseOpenBracketsSelect();
1538
1508
// accept ORDER BY or ORDRY BY with LIMIT - accept unions
1539
1509
select = parser.parseSelect(brackets, true, false, true, true);
1541
1511
if (select.sIntoTable != null) {
1542
throw (Trace.error(Trace.TABLE_NOT_FOUND));
1512
throw (Trace.error(Trace.INVALID_IDENTIFIER, Token.INTO));
1545
1515
select.prepareResult(session);