1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 package org.melati.poem.dbms;
46
47 import java.sql.SQLException;
48 import java.sql.DatabaseMetaData;
49 import java.sql.ResultSet;
50
51 import org.melati.poem.PoemType;
52 import org.melati.poem.SQLPoemType;
53 import org.melati.poem.DoublePoemType;
54 import org.melati.poem.BinaryPoemType;
55 import org.melati.poem.StringPoemType;
56
57
58
59
60 public class Mckoi extends AnsiStandard {
61
62
63 public static final int mckoiTextHack = 2147483647;
64
65
66 public static final int mckoiBinaryHack = 2147483647;
67
68
69
70 public Mckoi() {
71 setDriverClassName("com.mckoi.JDBCDriver");
72 }
73
74
75
76
77
78 public String getBinarySqlDefinition(int size) {
79
80 return "LONGVARBINARY";
81 }
82
83
84
85
86
87 public String getStringSqlDefinition(int size) throws SQLException {
88 if (size < 0) {
89 return "TEXT";
90 }
91 return super.getStringSqlDefinition(size);
92 }
93
94
95
96
97
98 public String getQuotedName (String name) {
99
100 if (name.equals("unique")) return super.getQuotedName(name);
101 if (name.equals("from")) return super.getQuotedName(name);
102 return name;
103 }
104
105
106
107
108 public String getSqlDefinition(String sqlTypeName) {
109 if (sqlTypeName.equals("INT")) {
110 return ("INTEGER");
111 }
112
113
114
115
116
117 return super.getSqlDefinition(sqlTypeName);
118 }
119
120
121
122
123
124 public <S,O>PoemType<O> canRepresent(PoemType<S> storage, PoemType<O> type) {
125 if (storage instanceof StringPoemType &&
126 type instanceof StringPoemType) {
127
128 if (((StringPoemType)storage).getSize() == mckoiTextHack &&
129 ((StringPoemType)type).getSize() == -1
130 && !(!storage.getNullable() && type.getNullable())
131 ) {
132 return type;
133 } else {
134 return storage.canRepresent(type);
135 }
136 } else if (storage instanceof BinaryPoemType &&
137 type instanceof BinaryPoemType
138 && !(!storage.getNullable() && type.getNullable())
139 ) {
140 if (((BinaryPoemType)storage).getSize() == mckoiBinaryHack &&
141 ((BinaryPoemType)type).getSize() == -1) {
142 return type;
143 } else {
144 return storage.canRepresent(type);
145 }
146 } else {
147 return storage.canRepresent(type);
148 }
149 }
150
151
152
153
154
155 public SQLPoemType<?> defaultPoemTypeOfColumnMetaData(ResultSet md)
156 throws SQLException {
157
158 if(md.getString("TYPE_NAME").equals("NUMERIC"))
159 return new DoublePoemType(md.getInt("NULLABLE")==
160 DatabaseMetaData.columnNullable);
161 else
162 return super.defaultPoemTypeOfColumnMetaData(md);
163 }
164
165
166
167
168
169
170 public String givesCapabilitySQL(Integer userTroid, String capabilityExpr) {
171 return
172 "SELECT " + getQuotedName("groupmembership") + ".* " +
173 "FROM " + getQuotedName("groupmembership") + " LEFT JOIN " +
174 getQuotedName("groupcapability") +
175 " ON " + getQuotedName("groupmembership") + "." + getQuotedName("group") +
176 " = " + getQuotedName("groupcapability") + "." + getQuotedName("group") +
177 " WHERE " + getQuotedName("user") + " = " + userTroid + " " +
178 "AND " + getQuotedName("groupcapability") + "." + getQuotedName("group") +
179 " IS NOT NULL " +
180 "AND " + getQuotedName("capability") + " = " + capabilityExpr;
181 }
182
183 }
184
185
186
187
188
189
190
191
192
193
194
195