View Javadoc
1   /*
2   Copyright (c) 2008 Health Market Science, Inc.
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.impl.query;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  import java.util.regex.Pattern;
22  
23  import com.healthmarketscience.jackcess.DataType;
24  import com.healthmarketscience.jackcess.query.Query;
25  
26  /**
27   * Constants used by the query data parsing.
28   *
29   * @author James Ahlborn
30   */
31  public class QueryFormat
32  {
33  
34    private QueryFormat() {}
35  
36    public static final int SELECT_QUERY_OBJECT_FLAG = 0;
37    public static final int MAKE_TABLE_QUERY_OBJECT_FLAG = 80;
38    public static final int APPEND_QUERY_OBJECT_FLAG = 64;
39    public static final int UPDATE_QUERY_OBJECT_FLAG = 48;
40    public static final int DELETE_QUERY_OBJECT_FLAG = 32;
41    public static final int CROSS_TAB_QUERY_OBJECT_FLAG = 16;
42    public static final int DATA_DEF_QUERY_OBJECT_FLAG = 96;
43    public static final int PASSTHROUGH_QUERY_OBJECT_FLAG = 112;
44    public static final int UNION_QUERY_OBJECT_FLAG = 128;
45    // dbQSPTBulk = 144
46    // dbQCompound = 160
47    // dbQProcedure = 224
48    // dbQAction = 240
49  
50    // mask which removes superfluous flags from object flags
51    static final int OBJECT_FLAG_MASK = 0xF0;
52  
53    public static final String COL_ATTRIBUTE = "Attribute";
54    public static final String COL_EXPRESSION = "Expression";
55    public static final String COL_FLAG = "Flag";
56    public static final String COL_EXTRA = "LvExtra";
57    public static final String COL_NAME1 = "Name1";
58    public static final String COL_NAME2 = "Name2";
59    public static final String COL_OBJECTID = "ObjectId";
60    public static final String COL_ORDER = "Order";
61  
62    public static final Byte START_ATTRIBUTE = 0;
63    public static final Byte TYPE_ATTRIBUTE = 1;
64    public static final Byte PARAMETER_ATTRIBUTE = 2;
65    public static final Byte FLAG_ATTRIBUTE = 3;
66    public static final Byte REMOTEDB_ATTRIBUTE = 4;
67    public static final Byte TABLE_ATTRIBUTE = 5;
68    public static final Byte COLUMN_ATTRIBUTE = 6;
69    public static final Byte JOIN_ATTRIBUTE = 7;
70    public static final Byte WHERE_ATTRIBUTE = 8;
71    public static final Byte GROUPBY_ATTRIBUTE = 9;
72    public static final Byte HAVING_ATTRIBUTE = 10;
73    public static final Byte ORDERBY_ATTRIBUTE = 11;
74    public static final Byte END_ATTRIBUTE = (byte)255;
75  
76    public static final short UNION_FLAG = 0x02;
77  
78    public static final Short TEXT_FLAG = (short)DataType.TEXT.getValue();
79  
80    public static final String DESCENDING_FLAG = "D";
81  
82    public static final short SELECT_STAR_SELECT_TYPE = 0x01;
83    public static final short DISTINCT_SELECT_TYPE = 0x02;
84    public static final short OWNER_ACCESS_SELECT_TYPE = 0x04;
85    public static final short DISTINCT_ROW_SELECT_TYPE = 0x08;
86    public static final short TOP_SELECT_TYPE = 0x10;
87    public static final short PERCENT_SELECT_TYPE = 0x20;
88  
89    public static final short APPEND_VALUE_FLAG = (short)0x8000;
90  
91    public static final short CROSSTAB_PIVOT_FLAG = 0x01;
92    public static final short CROSSTAB_NORMAL_FLAG = 0x02;
93  
94    public static final String UNION_PART1 = "X7YZ_____1";
95    public static final String UNION_PART2 = "X7YZ_____2";
96  
97    public static final String DEFAULT_TYPE = "";
98  
99    public static final Pattern QUOTABLE_CHAR_PAT = Pattern.compile("\\W");
100 
101   public static final Pattern IDENTIFIER_SEP_PAT = Pattern.compile("\\.");
102   public static final char IDENTIFIER_SEP_CHAR = '.';
103 
104   public static final String NEWLINE = System.lineSeparator();
105 
106 
107   public static final Map<Short,String> PARAM_TYPE_MAP =
108     new HashMap<Short,String>();
109   static {
110     PARAM_TYPE_MAP.put((short)0, "Value");
111     PARAM_TYPE_MAP.put((short)DataType.BOOLEAN.getValue(), "Bit");
112     PARAM_TYPE_MAP.put((short)DataType.TEXT.getValue(), "Text");
113     PARAM_TYPE_MAP.put((short)DataType.BYTE.getValue(), "Byte");
114     PARAM_TYPE_MAP.put((short)DataType.INT.getValue(), "Short");
115     PARAM_TYPE_MAP.put((short)DataType.LONG.getValue(), "Long");
116     PARAM_TYPE_MAP.put((short)DataType.MONEY.getValue(), "Currency");
117     PARAM_TYPE_MAP.put((short)DataType.FLOAT.getValue(), "IEEESingle");
118     PARAM_TYPE_MAP.put((short)DataType.DOUBLE.getValue(), "IEEEDouble");
119     PARAM_TYPE_MAP.put((short)DataType.SHORT_DATE_TIME.getValue(), "DateTime");
120     PARAM_TYPE_MAP.put((short)DataType.BINARY.getValue(), "Binary");
121     PARAM_TYPE_MAP.put((short)DataType.OLE.getValue(), "LongBinary");
122     PARAM_TYPE_MAP.put((short)DataType.GUID.getValue(), "Guid");
123   }
124 
125   public static final Map<Short,String> JOIN_TYPE_MAP =
126     new HashMap<Short,String>();
127   static {
128     JOIN_TYPE_MAP.put((short)1, " INNER JOIN ");
129     JOIN_TYPE_MAP.put((short)2, " LEFT JOIN ");
130     JOIN_TYPE_MAP.put((short)3, " RIGHT JOIN ");
131   }
132 
133   public static final Map<Short,Query.Type> TYPE_MAP =
134     new HashMap<Short,Query.Type>();
135   static {
136     for(Query.Type type : Query.Type.values()) {
137       if(type != Query.Type.UNKNOWN) {
138         TYPE_MAP.put(type.getValue(), type);
139       }
140     }
141   }
142 
143 }