1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.expression; |
7 | |
8 | import org.h2.api.ErrorCode; |
9 | import org.h2.engine.Session; |
10 | import org.h2.message.DbException; |
11 | import org.h2.table.ColumnResolver; |
12 | import org.h2.table.TableFilter; |
13 | import org.h2.util.StringUtils; |
14 | import org.h2.value.Value; |
15 | |
16 | /** |
17 | * A wildcard expression as in SELECT * FROM TEST. |
18 | * This object is only used temporarily during the parsing phase, and later |
19 | * replaced by column expressions. |
20 | */ |
21 | public class Wildcard extends Expression { |
22 | private final String schema; |
23 | private final String table; |
24 | |
25 | public Wildcard(String schema, String table) { |
26 | this.schema = schema; |
27 | this.table = table; |
28 | } |
29 | |
30 | @Override |
31 | public boolean isWildcard() { |
32 | return true; |
33 | } |
34 | |
35 | @Override |
36 | public Value getValue(Session session) { |
37 | throw DbException.throwInternalError(); |
38 | } |
39 | |
40 | @Override |
41 | public int getType() { |
42 | throw DbException.throwInternalError(); |
43 | } |
44 | |
45 | @Override |
46 | public void mapColumns(ColumnResolver resolver, int level) { |
47 | throw DbException.get(ErrorCode.SYNTAX_ERROR_1, table); |
48 | } |
49 | |
50 | @Override |
51 | public Expression optimize(Session session) { |
52 | throw DbException.get(ErrorCode.SYNTAX_ERROR_1, table); |
53 | } |
54 | |
55 | @Override |
56 | public void setEvaluatable(TableFilter tableFilter, boolean b) { |
57 | DbException.throwInternalError(); |
58 | } |
59 | |
60 | @Override |
61 | public int getScale() { |
62 | throw DbException.throwInternalError(); |
63 | } |
64 | |
65 | @Override |
66 | public long getPrecision() { |
67 | throw DbException.throwInternalError(); |
68 | } |
69 | |
70 | @Override |
71 | public int getDisplaySize() { |
72 | throw DbException.throwInternalError(); |
73 | } |
74 | |
75 | @Override |
76 | public String getTableAlias() { |
77 | return table; |
78 | } |
79 | |
80 | @Override |
81 | public String getSchemaName() { |
82 | return schema; |
83 | } |
84 | |
85 | @Override |
86 | public String getSQL() { |
87 | if (table == null) { |
88 | return "*"; |
89 | } |
90 | return StringUtils.quoteIdentifier(table) + ".*"; |
91 | } |
92 | |
93 | @Override |
94 | public void updateAggregate(Session session) { |
95 | DbException.throwInternalError(); |
96 | } |
97 | |
98 | @Override |
99 | public boolean isEverything(ExpressionVisitor visitor) { |
100 | if (visitor.getType() == ExpressionVisitor.QUERY_COMPARABLE) { |
101 | return true; |
102 | } |
103 | throw DbException.throwInternalError(); |
104 | } |
105 | |
106 | @Override |
107 | public int getCost() { |
108 | throw DbException.throwInternalError(); |
109 | } |
110 | |
111 | } |