Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
Line 25... |
Line 25... |
25 |
import org.openconcerto.utils.ProcessStreams;
|
25 |
import org.openconcerto.utils.ProcessStreams;
|
26 |
import org.openconcerto.utils.RTInterruptedException;
|
26 |
import org.openconcerto.utils.RTInterruptedException;
|
27 |
import org.openconcerto.utils.StringUtils;
|
27 |
import org.openconcerto.utils.StringUtils;
|
28 |
import org.openconcerto.utils.Tuple2;
|
28 |
import org.openconcerto.utils.Tuple2;
|
29 |
import org.openconcerto.utils.cc.ITransformer;
|
29 |
import org.openconcerto.utils.cc.ITransformer;
|
- |
|
30 |
import org.openconcerto.xml.XMLCodecUtils;
|
30 |
|
31 |
|
- |
|
32 |
import java.beans.DefaultPersistenceDelegate;
|
31 |
import java.io.BufferedReader;
|
33 |
import java.io.BufferedReader;
|
32 |
import java.io.BufferedWriter;
|
34 |
import java.io.BufferedWriter;
|
33 |
import java.io.File;
|
35 |
import java.io.File;
|
34 |
import java.io.FileInputStream;
|
36 |
import java.io.FileInputStream;
|
35 |
import java.io.FileOutputStream;
|
37 |
import java.io.FileOutputStream;
|
Line 49... |
Line 51... |
49 |
import java.util.List;
|
51 |
import java.util.List;
|
50 |
import java.util.Map;
|
52 |
import java.util.Map;
|
51 |
import java.util.Set;
|
53 |
import java.util.Set;
|
52 |
import java.util.regex.Pattern;
|
54 |
import java.util.regex.Pattern;
|
53 |
|
55 |
|
54 |
class SQLSyntaxMS extends SQLSyntax {
|
56 |
public class SQLSyntaxMS extends SQLSyntax {
|
55 |
|
57 |
|
56 |
static private final IdentityHashMap<String, String> DATE_SPECS;
|
58 |
static private final IdentityHashMap<String, String> DATE_SPECS;
|
57 |
|
59 |
|
58 |
static {
|
60 |
static {
|
59 |
DATE_SPECS = new IdentityHashMap<String, String>();
|
61 |
DATE_SPECS = new IdentityHashMap<String, String>();
|
Line 64... |
Line 66... |
64 |
DATE_SPECS.put(DateProp.DAY_NAME_IN_WEEK, "dddd");
|
66 |
DATE_SPECS.put(DateProp.DAY_NAME_IN_WEEK, "dddd");
|
65 |
DATE_SPECS.put(DateProp.HOUR, "HH");
|
67 |
DATE_SPECS.put(DateProp.HOUR, "HH");
|
66 |
DATE_SPECS.put(DateProp.MINUTE, "mm");
|
68 |
DATE_SPECS.put(DateProp.MINUTE, "mm");
|
67 |
DATE_SPECS.put(DateProp.SECOND, "ss");
|
69 |
DATE_SPECS.put(DateProp.SECOND, "ss");
|
68 |
DATE_SPECS.put(DateProp.MICROSECOND, "ffffff");
|
70 |
DATE_SPECS.put(DateProp.MICROSECOND, "ffffff");
|
- |
|
71 |
|
- |
|
72 |
XMLCodecUtils.register(SQLSyntaxMS.class, new DefaultPersistenceDelegate(new String[] {}));
|
69 |
}
|
73 |
}
|
70 |
|
74 |
|
71 |
SQLSyntaxMS() {
|
75 |
public SQLSyntaxMS() {
|
72 |
super(SQLSystem.MSSQL, DATE_SPECS);
|
76 |
super(SQLSystem.MSSQL, DATE_SPECS);
|
73 |
this.typeNames.addAll(Boolean.class, "bit");
|
77 |
this.typeNames.addAll(Boolean.class, "bit");
|
74 |
// tinyint is unsigned
|
78 |
// tinyint is unsigned
|
75 |
this.typeNames.addAll(Short.class, "smallint", "tinyint");
|
79 |
this.typeNames.addAll(Short.class, "smallint", "tinyint");
|
76 |
this.typeNames.addAll(Integer.class, "int");
|
80 |
this.typeNames.addAll(Integer.class, "int");
|
Line 238... |
Line 242... |
238 |
public boolean isDeadLockException(SQLException exn) {
|
242 |
public boolean isDeadLockException(SQLException exn) {
|
239 |
return SQLUtils.findWithSQLState(exn).getErrorCode() == 1205;
|
243 |
return SQLUtils.findWithSQLState(exn).getErrorCode() == 1205;
|
240 |
}
|
244 |
}
|
241 |
|
245 |
|
242 |
@Override
|
246 |
@Override
|
- |
|
247 |
public boolean isTableNotFoundException(Exception exn) {
|
- |
|
248 |
// TODO
|
- |
|
249 |
throw new UnsupportedOperationException();
|
- |
|
250 |
}
|
- |
|
251 |
|
- |
|
252 |
@Override
|
- |
|
253 |
public String getSetLockTimeoutQuery(int millis) {
|
- |
|
254 |
return "SET LOCK_TIMEOUT " + millis;
|
- |
|
255 |
}
|
- |
|
256 |
|
- |
|
257 |
@Override
|
- |
|
258 |
public String getShowLockTimeoutQuery() {
|
- |
|
259 |
return "SELECT @@LOCK_TIMEOUT";
|
- |
|
260 |
}
|
- |
|
261 |
|
- |
|
262 |
@Override
|
243 |
public Map<ClauseType, List<String>> getAlterField(SQLField f, Set<Properties> toAlter, String type, String defaultVal, Boolean nullable) {
|
263 |
public Map<ClauseType, List<String>> getAlterField(SQLField f, Set<Properties> toAlter, String type, String defaultVal, Boolean nullable) {
|
244 |
final ListMap<ClauseType, String> res = new ListMap<ClauseType, String>();
|
264 |
final ListMap<ClauseType, String> res = new ListMap<ClauseType, String>();
|
245 |
if (toAlter.contains(Properties.TYPE) || toAlter.contains(Properties.NULLABLE)) {
|
265 |
if (toAlter.contains(Properties.TYPE) || toAlter.contains(Properties.NULLABLE)) {
|
246 |
final String newType = toAlter.contains(Properties.TYPE) ? type : getType(f);
|
266 |
final String newType = toAlter.contains(Properties.TYPE) ? type : getType(f);
|
247 |
final boolean newNullable = toAlter.contains(Properties.NULLABLE) ? nullable : getNullable(f);
|
267 |
final boolean newNullable = toAlter.contains(Properties.NULLABLE) ? nullable : getNullable(f);
|
Line 613... |
Line 633... |
613 |
|
633 |
|
614 |
@Override
|
634 |
@Override
|
615 |
public String quoteForTimestampFormat(String text) {
|
635 |
public String quoteForTimestampFormat(String text) {
|
616 |
return StringUtils.doubleQuote(text);
|
636 |
return StringUtils.doubleQuote(text);
|
617 |
}
|
637 |
}
|
- |
|
638 |
|
- |
|
639 |
@Override
|
- |
|
640 |
public String getSessionIDExpression() {
|
- |
|
641 |
return "@@SPID";
|
- |
|
642 |
}
|
- |
|
643 |
|
- |
|
644 |
@Override
|
- |
|
645 |
public String getSessionsQuery(final DBSystemRoot sysRoot, final boolean includeSelf) {
|
- |
|
646 |
final String allRows = "SELECT ps.spid as \"ID\", cmd as \"QUERY\", users.name as \"USER_NAME\" FROM sys.sysprocesses ps\n"
|
- |
|
647 |
//
|
- |
|
648 |
+ "JOIN sys.sysdatabases db on db.dbid = ps.dbid\nJOIN sys.sysusers users on users.uid = ps.uid\\n"
|
- |
|
649 |
//
|
- |
|
650 |
+ " WHERE db.name=" + quoteString(sysRoot.getName());
|
- |
|
651 |
if (includeSelf)
|
- |
|
652 |
return allRows;
|
- |
|
653 |
return allRows + " and ps.spid != " + this.getSessionIDExpression();
|
- |
|
654 |
}
|
- |
|
655 |
|
- |
|
656 |
@Override
|
- |
|
657 |
public String getVersionFunction() {
|
- |
|
658 |
// if this doesn't work, try SERVERPROPERTY('ProductVersion')
|
- |
|
659 |
return "@@VERSION";
|
- |
|
660 |
}
|
618 |
}
|
661 |
}
|