| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.command.dml; |
| 7 |
|
| 8 |
import java.text.Collator; |
| 9 |
|
| 10 |
import org.h2.api.ErrorCode; |
| 11 |
import org.h2.command.CommandInterface; |
| 12 |
import org.h2.command.Parser; |
| 13 |
import org.h2.command.Prepared; |
| 14 |
import org.h2.engine.Constants; |
| 15 |
import org.h2.engine.Database; |
| 16 |
import org.h2.engine.Mode; |
| 17 |
import org.h2.engine.SessionLocal; |
| 18 |
import org.h2.engine.Setting; |
| 19 |
import org.h2.expression.Expression; |
| 20 |
import org.h2.expression.TimeZoneOperation; |
| 21 |
import org.h2.expression.ValueExpression; |
| 22 |
import org.h2.message.DbException; |
| 23 |
import org.h2.message.Trace; |
| 24 |
import org.h2.mode.DefaultNullOrdering; |
| 25 |
import org.h2.result.ResultInterface; |
| 26 |
import org.h2.schema.Schema; |
| 27 |
import org.h2.security.auth.AuthenticatorFactory; |
| 28 |
import org.h2.table.Table; |
| 29 |
import org.h2.util.DateTimeUtils; |
| 30 |
import org.h2.util.StringUtils; |
| 31 |
import org.h2.util.TimeZoneProvider; |
| 32 |
import org.h2.value.CompareMode; |
| 33 |
import org.h2.value.DataType; |
| 34 |
import org.h2.value.Value; |
| 35 |
import org.h2.value.ValueInteger; |
| 36 |
import org.h2.value.ValueNull; |
| 37 |
|
| 38 |
/** |
| 39 |
* This class represents the statement |
| 40 |
* SET |
| 41 |
*/ |
| 42 |
public class Set extends Prepared { |
| 43 |
|
| 44 |
private final int type; |
| 45 |
private Expression expression; |
| 46 |
private String stringValue; |
| 47 |
private String[] stringValueList; |
| 48 |
|
| 49 |
public Set(SessionLocal session, int type) { |
| 50 |
super(session); |
| 51 |
this.type = type; |
| 52 |
} |
| 53 |
|
| 54 |
public void setString(String v) { |
| 55 |
this.stringValue = v; |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public boolean isTransactional() { |
| 60 |
switch (type) { |
| 61 |
case SetTypes.CLUSTER: |
| 62 |
case SetTypes.VARIABLE: |
| 63 |
case SetTypes.QUERY_TIMEOUT: |
| 64 |
case SetTypes.LOCK_TIMEOUT: |
| 65 |
case SetTypes.TRACE_LEVEL_SYSTEM_OUT: |
| 66 |
case SetTypes.TRACE_LEVEL_FILE: |
| 67 |
case SetTypes.THROTTLE: |
| 68 |
case SetTypes.SCHEMA: |
| 69 |
case SetTypes.SCHEMA_SEARCH_PATH: |
| 70 |
case SetTypes.CATALOG: |
| 71 |
case SetTypes.RETENTION_TIME: |
| 72 |
case SetTypes.LAZY_QUERY_EXECUTION: |
| 73 |
case SetTypes.NON_KEYWORDS: |
| 74 |
case SetTypes.TIME_ZONE: |
| 75 |
case SetTypes.VARIABLE_BINARY: |
| 76 |
case SetTypes.TRUNCATE_LARGE_LENGTH: |
| 77 |
case SetTypes.WRITE_DELAY: |
| 78 |
return true; |
| 79 |
default: |
| 80 |
} |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public long update() { |
| 86 |
Database database = getDatabase(); |
| 87 |
String name = SetTypes.getTypeName(type); |
| 88 |
switch (type) { |
| 89 |
case SetTypes.ALLOW_LITERALS: { |
| 90 |
session.getUser().checkAdmin(); |
| 91 |
int value = getIntValue(); |
| 92 |
if (value < 0 || value > 2) { |
| 93 |
throw DbException.getInvalidValueException("ALLOW_LITERALS", value); |
| 94 |
} |
| 95 |
synchronized (database) { |
| 96 |
database.setAllowLiterals(value); |
| 97 |
addOrUpdateSetting(name, null, value); |
| 98 |
} |
| 99 |
break; |
| 100 |
} |
| 101 |
case SetTypes.CACHE_SIZE: { |
| 102 |
session.getUser().checkAdmin(); |
| 103 |
int value = getIntValue(); |
| 104 |
if (value < 0) { |
| 105 |
throw DbException.getInvalidValueException("CACHE_SIZE", value); |
| 106 |
} |
| 107 |
synchronized (database) { |
| 108 |
database.setCacheSize(value); |
| 109 |
addOrUpdateSetting(name, null, value); |
| 110 |
} |
| 111 |
break; |
| 112 |
} |
| 113 |
case SetTypes.CLUSTER: { |
| 114 |
if (Constants.CLUSTERING_ENABLED.equals(stringValue)) { |
| 115 |
// this value is used when connecting |
| 116 |
// ignore, as the cluster setting is checked later |
| 117 |
break; |
| 118 |
} |
| 119 |
String value = StringUtils.quoteStringSQL(stringValue); |
| 120 |
if (!value.equals(database.getCluster())) { |
| 121 |
if (!value.equals(Constants.CLUSTERING_DISABLED)) { |
| 122 |
// anybody can disable the cluster |
| 123 |
// (if he can't access a cluster node) |
| 124 |
session.getUser().checkAdmin(); |
| 125 |
} |
| 126 |
database.setCluster(value); |
| 127 |
// use the system session so that the current transaction |
| 128 |
// (if any) is not committed |
| 129 |
SessionLocal sysSession = database.getSystemSession(); |
| 130 |
synchronized (sysSession) { |
| 131 |
synchronized (database) { |
| 132 |
addOrUpdateSetting(sysSession, name, value, 0); |
| 133 |
sysSession.commit(true); |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
break; |
| 138 |
} |
| 139 |
case SetTypes.COLLATION: { |
| 140 |
session.getUser().checkAdmin(); |
| 141 |
CompareMode compareMode; |
| 142 |
StringBuilder buff = new StringBuilder(stringValue); |
| 143 |
if (stringValue.equals(CompareMode.OFF)) { |
| 144 |
compareMode = CompareMode.getInstance(null, 0); |
| 145 |
} else { |
| 146 |
int strength = getIntValue(); |
| 147 |
buff.append(" STRENGTH "); |
| 148 |
if (strength == Collator.IDENTICAL) { |
| 149 |
buff.append("IDENTICAL"); |
| 150 |
} else if (strength == Collator.PRIMARY) { |
| 151 |
buff.append("PRIMARY"); |
| 152 |
} else if (strength == Collator.SECONDARY) { |
| 153 |
buff.append("SECONDARY"); |
| 154 |
} else if (strength == Collator.TERTIARY) { |
| 155 |
buff.append("TERTIARY"); |
| 156 |
} |
| 157 |
compareMode = CompareMode.getInstance(stringValue, strength); |
| 158 |
} |
| 159 |
synchronized (database) { |
| 160 |
CompareMode old = database.getCompareMode(); |
| 161 |
if (old.equals(compareMode)) { |
| 162 |
break; |
| 163 |
} |
| 164 |
Table table = database.getFirstUserTable(); |
| 165 |
if (table != null) { |
| 166 |
throw DbException.get(ErrorCode.COLLATION_CHANGE_WITH_DATA_TABLE_1, table.getTraceSQL()); |
| 167 |
} |
| 168 |
addOrUpdateSetting(name, buff.toString(), 0); |
| 169 |
database.setCompareMode(compareMode); |
| 170 |
} |
| 171 |
break; |
| 172 |
} |
| 173 |
case SetTypes.CREATE_BUILD: { |
| 174 |
session.getUser().checkAdmin(); |
| 175 |
if (database.isStarting()) { |
| 176 |
// just ignore the command if not starting |
| 177 |
// this avoids problems when running recovery scripts |
| 178 |
int value = getIntValue(); |
| 179 |
synchronized (database) { |
| 180 |
addOrUpdateSetting(name, null, value); |
| 181 |
} |
| 182 |
} |
| 183 |
break; |
| 184 |
} |
| 185 |
case SetTypes.DATABASE_EVENT_LISTENER: { |
| 186 |
session.getUser().checkAdmin(); |
| 187 |
database.setEventListenerClass(stringValue); |
| 188 |
break; |
| 189 |
} |
| 190 |
case SetTypes.DB_CLOSE_DELAY: { |
| 191 |
session.getUser().checkAdmin(); |
| 192 |
int value = getIntValue(); |
| 193 |
if (value == -1) { |
| 194 |
// -1 is a special value for in-memory databases, |
| 195 |
// which means "keep the DB alive and use the same |
| 196 |
// DB for all connections" |
| 197 |
} else if (value < 0) { |
| 198 |
throw DbException.getInvalidValueException("DB_CLOSE_DELAY", value); |
| 199 |
} |
| 200 |
synchronized (database) { |
| 201 |
database.setCloseDelay(value); |
| 202 |
addOrUpdateSetting(name, null, value); |
| 203 |
} |
| 204 |
break; |
| 205 |
} |
| 206 |
case SetTypes.DEFAULT_LOCK_TIMEOUT: { |
| 207 |
session.getUser().checkAdmin(); |
| 208 |
int value = getIntValue(); |
| 209 |
if (value < 0) { |
| 210 |
throw DbException.getInvalidValueException("DEFAULT_LOCK_TIMEOUT", value); |
| 211 |
} |
| 212 |
synchronized (database) { |
| 213 |
addOrUpdateSetting(name, null, value); |
| 214 |
} |
| 215 |
break; |
| 216 |
} |
| 217 |
case SetTypes.DEFAULT_TABLE_TYPE: { |
| 218 |
session.getUser().checkAdmin(); |
| 219 |
int value = getIntValue(); |
| 220 |
synchronized (database) { |
| 221 |
database.setDefaultTableType(value); |
| 222 |
addOrUpdateSetting(name, null, value); |
| 223 |
} |
| 224 |
break; |
| 225 |
} |
| 226 |
case SetTypes.EXCLUSIVE: { |
| 227 |
session.getUser().checkAdmin(); |
| 228 |
int value = getIntValue(); |
| 229 |
switch (value) { |
| 230 |
case 0: |
| 231 |
if (!database.unsetExclusiveSession(session)) { |
| 232 |
throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); |
| 233 |
} |
| 234 |
break; |
| 235 |
case 1: |
| 236 |
if (!database.setExclusiveSession(session, false)) { |
| 237 |
throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); |
| 238 |
} |
| 239 |
break; |
| 240 |
case 2: |
| 241 |
if (!database.setExclusiveSession(session, true)) { |
| 242 |
throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); |
| 243 |
} |
| 244 |
break; |
| 245 |
default: |
| 246 |
throw DbException.getInvalidValueException("EXCLUSIVE", value); |
| 247 |
} |
| 248 |
break; |
| 249 |
} |
| 250 |
case SetTypes.JAVA_OBJECT_SERIALIZER: { |
| 251 |
session.getUser().checkAdmin(); |
| 252 |
synchronized (database) { |
| 253 |
Table table = database.getFirstUserTable(); |
| 254 |
if (table != null) { |
| 255 |
throw DbException.get(ErrorCode.JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE, |
| 256 |
table.getTraceSQL()); |
| 257 |
} |
| 258 |
database.setJavaObjectSerializerName(stringValue); |
| 259 |
addOrUpdateSetting(name, stringValue, 0); |
| 260 |
} |
| 261 |
break; |
| 262 |
} |
| 263 |
case SetTypes.IGNORECASE: { |
| 264 |
session.getUser().checkAdmin(); |
| 265 |
int value = getIntValue(); |
| 266 |
synchronized (database) { |
| 267 |
database.setIgnoreCase(value == 1); |
| 268 |
addOrUpdateSetting(name, null, value); |
| 269 |
} |
| 270 |
break; |
| 271 |
} |
| 272 |
case SetTypes.LOCK_MODE: { |
| 273 |
session.getUser().checkAdmin(); |
| 274 |
int value = getIntValue(); |
| 275 |
synchronized (database) { |
| 276 |
database.setLockMode(value); |
| 277 |
addOrUpdateSetting(name, null, value); |
| 278 |
} |
| 279 |
break; |
| 280 |
} |
| 281 |
case SetTypes.LOCK_TIMEOUT: { |
| 282 |
int value = getIntValue(); |
| 283 |
if (value < 0) { |
| 284 |
throw DbException.getInvalidValueException("LOCK_TIMEOUT", value); |
| 285 |
} |
| 286 |
session.setLockTimeout(value); |
| 287 |
break; |
| 288 |
} |
| 289 |
case SetTypes.MAX_LENGTH_INPLACE_LOB: { |
| 290 |
session.getUser().checkAdmin(); |
| 291 |
int value = getIntValue(); |
| 292 |
if (value < 0) { |
| 293 |
throw DbException.getInvalidValueException("MAX_LENGTH_INPLACE_LOB", value); |
| 294 |
} |
| 295 |
synchronized (database) { |
| 296 |
database.setMaxLengthInplaceLob(value); |
| 297 |
addOrUpdateSetting(name, null, value); |
| 298 |
} |
| 299 |
break; |
| 300 |
} |
| 301 |
case SetTypes.MAX_LOG_SIZE: { |
| 302 |
session.getUser().checkAdmin(); |
| 303 |
int value = getIntValue(); |
| 304 |
if (value < 0) { |
| 305 |
throw DbException.getInvalidValueException("MAX_LOG_SIZE", value); |
| 306 |
} |
| 307 |
break; |
| 308 |
} |
| 309 |
case SetTypes.MAX_MEMORY_ROWS: { |
| 310 |
session.getUser().checkAdmin(); |
| 311 |
int value = getIntValue(); |
| 312 |
if (value < 0) { |
| 313 |
throw DbException.getInvalidValueException("MAX_MEMORY_ROWS", value); |
| 314 |
} |
| 315 |
synchronized (database) { |
| 316 |
database.setMaxMemoryRows(value); |
| 317 |
addOrUpdateSetting(name, null, value); |
| 318 |
} |
| 319 |
break; |
| 320 |
} |
| 321 |
case SetTypes.MAX_MEMORY_UNDO: { |
| 322 |
session.getUser().checkAdmin(); |
| 323 |
int value = getIntValue(); |
| 324 |
if (value < 0) { |
| 325 |
throw DbException.getInvalidValueException("MAX_MEMORY_UNDO", value); |
| 326 |
} |
| 327 |
synchronized (database) { |
| 328 |
addOrUpdateSetting(name, null, value); |
| 329 |
} |
| 330 |
break; |
| 331 |
} |
| 332 |
case SetTypes.MAX_OPERATION_MEMORY: { |
| 333 |
session.getUser().checkAdmin(); |
| 334 |
int value = getIntValue(); |
| 335 |
if (value < 0) { |
| 336 |
throw DbException.getInvalidValueException("MAX_OPERATION_MEMORY", value); |
| 337 |
} |
| 338 |
database.setMaxOperationMemory(value); |
| 339 |
break; |
| 340 |
} |
| 341 |
case SetTypes.MODE: { |
| 342 |
Mode mode = Mode.getInstance(stringValue); |
| 343 |
if (mode == null) { |
| 344 |
throw DbException.get(ErrorCode.UNKNOWN_MODE_1, stringValue); |
| 345 |
} |
| 346 |
if (database.getMode() != mode) { |
| 347 |
session.getUser().checkAdmin(); |
| 348 |
database.setMode(mode); |
| 349 |
} |
| 350 |
break; |
| 351 |
} |
| 352 |
case SetTypes.OPTIMIZE_REUSE_RESULTS: { |
| 353 |
session.getUser().checkAdmin(); |
| 354 |
database.setOptimizeReuseResults(getIntValue() != 0); |
| 355 |
break; |
| 356 |
} |
| 357 |
case SetTypes.QUERY_TIMEOUT: { |
| 358 |
int value = getIntValue(); |
| 359 |
if (value < 0) { |
| 360 |
throw DbException.getInvalidValueException("QUERY_TIMEOUT", value); |
| 361 |
} |
| 362 |
session.setQueryTimeout(value); |
| 363 |
break; |
| 364 |
} |
| 365 |
case SetTypes.REDO_LOG_BINARY: { |
| 366 |
DbException.getUnsupportedException("MV_STORE + SET REDO_LOG_BINARY"); |
| 367 |
break; |
| 368 |
} |
| 369 |
case SetTypes.REFERENTIAL_INTEGRITY: { |
| 370 |
session.getUser().checkAdmin(); |
| 371 |
int value = getIntValue(); |
| 372 |
if (value < 0 || value > 1) { |
| 373 |
throw DbException.getInvalidValueException("REFERENTIAL_INTEGRITY", value); |
| 374 |
} |
| 375 |
database.setReferentialIntegrity(value == 1); |
| 376 |
break; |
| 377 |
} |
| 378 |
case SetTypes.QUERY_STATISTICS: { |
| 379 |
session.getUser().checkAdmin(); |
| 380 |
int value = getIntValue(); |
| 381 |
if (value < 0 || value > 1) { |
| 382 |
throw DbException.getInvalidValueException("QUERY_STATISTICS", value); |
| 383 |
} |
| 384 |
database.setQueryStatistics(value == 1); |
| 385 |
break; |
| 386 |
} |
| 387 |
case SetTypes.QUERY_STATISTICS_MAX_ENTRIES: { |
| 388 |
session.getUser().checkAdmin(); |
| 389 |
int value = getIntValue(); |
| 390 |
if (value < 1) { |
| 391 |
throw DbException.getInvalidValueException("QUERY_STATISTICS_MAX_ENTRIES", value); |
| 392 |
} |
| 393 |
database.setQueryStatisticsMaxEntries(value); |
| 394 |
break; |
| 395 |
} |
| 396 |
case SetTypes.SCHEMA: { |
| 397 |
Schema schema = database.getSchema(expression.optimize(session).getValue(session).getString()); |
| 398 |
session.setCurrentSchema(schema); |
| 399 |
break; |
| 400 |
} |
| 401 |
case SetTypes.SCHEMA_SEARCH_PATH: { |
| 402 |
session.setSchemaSearchPath(stringValueList); |
| 403 |
break; |
| 404 |
} |
| 405 |
case SetTypes.CATALOG: { |
| 406 |
String shortName = database.getShortName(); |
| 407 |
String value = expression.optimize(session).getValue(session).getString(); |
| 408 |
if (value == null || !database.equalsIdentifiers(shortName, value) |
| 409 |
&& !database.equalsIdentifiers(shortName, value.trim())) { |
| 410 |
throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_1, stringValue); |
| 411 |
} |
| 412 |
break; |
| 413 |
} |
| 414 |
case SetTypes.TRACE_LEVEL_FILE: |
| 415 |
session.getUser().checkAdmin(); |
| 416 |
if (getPersistedObjectId() == 0) { |
| 417 |
// don't set the property when opening the database |
| 418 |
// this is for compatibility with older versions, because |
| 419 |
// this setting was persistent |
| 420 |
database.getTraceSystem().setLevelFile(getIntValue()); |
| 421 |
} |
| 422 |
break; |
| 423 |
case SetTypes.TRACE_LEVEL_SYSTEM_OUT: |
| 424 |
session.getUser().checkAdmin(); |
| 425 |
if (getPersistedObjectId() == 0) { |
| 426 |
// don't set the property when opening the database |
| 427 |
// this is for compatibility with older versions, because |
| 428 |
// this setting was persistent |
| 429 |
database.getTraceSystem().setLevelSystemOut(getIntValue()); |
| 430 |
} |
| 431 |
break; |
| 432 |
case SetTypes.TRACE_MAX_FILE_SIZE: { |
| 433 |
session.getUser().checkAdmin(); |
| 434 |
int value = getIntValue(); |
| 435 |
if (value < 0) { |
| 436 |
throw DbException.getInvalidValueException("TRACE_MAX_FILE_SIZE", value); |
| 437 |
} |
| 438 |
int size = value * (1024 * 1024); |
| 439 |
synchronized (database) { |
| 440 |
database.getTraceSystem().setMaxFileSize(size); |
| 441 |
addOrUpdateSetting(name, null, value); |
| 442 |
} |
| 443 |
break; |
| 444 |
} |
| 445 |
case SetTypes.THROTTLE: { |
| 446 |
int value = getIntValue(); |
| 447 |
if (value < 0) { |
| 448 |
throw DbException.getInvalidValueException("THROTTLE", value); |
| 449 |
} |
| 450 |
session.setThrottle(value); |
| 451 |
break; |
| 452 |
} |
| 453 |
case SetTypes.VARIABLE: { |
| 454 |
Expression expr = expression.optimize(session); |
| 455 |
session.setVariable(stringValue, expr.getValue(session)); |
| 456 |
break; |
| 457 |
} |
| 458 |
case SetTypes.WRITE_DELAY: { |
| 459 |
session.getUser().checkAdmin(); |
| 460 |
int value = getIntValue(); |
| 461 |
if (value < 0) { |
| 462 |
throw DbException.getInvalidValueException("WRITE_DELAY", value); |
| 463 |
} |
| 464 |
synchronized (database) { |
| 465 |
database.setWriteDelay(value); |
| 466 |
addOrUpdateSetting(name, null, value); |
| 467 |
} |
| 468 |
break; |
| 469 |
} |
| 470 |
case SetTypes.RETENTION_TIME: { |
| 471 |
session.getUser().checkAdmin(); |
| 472 |
int value = getIntValue(); |
| 473 |
if (value < 0) { |
| 474 |
throw DbException.getInvalidValueException("RETENTION_TIME", value); |
| 475 |
} |
| 476 |
synchronized (database) { |
| 477 |
database.setRetentionTime(value); |
| 478 |
addOrUpdateSetting(name, null, value); |
| 479 |
} |
| 480 |
break; |
| 481 |
} |
| 482 |
case SetTypes.LAZY_QUERY_EXECUTION: { |
| 483 |
int value = getIntValue(); |
| 484 |
if (value != 0 && value != 1) { |
| 485 |
throw DbException.getInvalidValueException("LAZY_QUERY_EXECUTION", |
| 486 |
value); |
| 487 |
} |
| 488 |
session.setLazyQueryExecution(value == 1); |
| 489 |
break; |
| 490 |
} |
| 491 |
case SetTypes.BUILTIN_ALIAS_OVERRIDE: { |
| 492 |
session.getUser().checkAdmin(); |
| 493 |
int value = getIntValue(); |
| 494 |
if (value != 0 && value != 1) { |
| 495 |
throw DbException.getInvalidValueException("BUILTIN_ALIAS_OVERRIDE", |
| 496 |
value); |
| 497 |
} |
| 498 |
database.setAllowBuiltinAliasOverride(value == 1); |
| 499 |
break; |
| 500 |
} |
| 501 |
case SetTypes.AUTHENTICATOR: { |
| 502 |
session.getUser().checkAdmin(); |
| 503 |
boolean value = expression.optimize(session).getBooleanValue(session); |
| 504 |
try { |
| 505 |
synchronized (database) { |
| 506 |
if (value) { |
| 507 |
database.setAuthenticator(AuthenticatorFactory.createAuthenticator()); |
| 508 |
} else { |
| 509 |
database.setAuthenticator(null); |
| 510 |
} |
| 511 |
addOrUpdateSetting(name, value ? "TRUE" : "FALSE", 0); |
| 512 |
} |
| 513 |
} catch (Exception e) { |
| 514 |
// Errors during start are ignored to allow to open the database |
| 515 |
if (database.isStarting()) { |
| 516 |
database.getTrace(Trace.DATABASE).error(e, |
| 517 |
"{0}: failed to set authenticator during database start ", expression.toString()); |
| 518 |
} else { |
| 519 |
throw DbException.convert(e); |
| 520 |
} |
| 521 |
} |
| 522 |
break; |
| 523 |
} |
| 524 |
case SetTypes.IGNORE_CATALOGS: { |
| 525 |
session.getUser().checkAdmin(); |
| 526 |
int value = getIntValue(); |
| 527 |
synchronized (database) { |
| 528 |
database.setIgnoreCatalogs(value == 1); |
| 529 |
addOrUpdateSetting(name, null, value); |
| 530 |
} |
| 531 |
break; |
| 532 |
} |
| 533 |
case SetTypes.NON_KEYWORDS: |
| 534 |
session.setNonKeywords(Parser.parseNonKeywords(stringValueList)); |
| 535 |
break; |
| 536 |
case SetTypes.TIME_ZONE: |
| 537 |
session.setTimeZone(expression == null ? DateTimeUtils.getTimeZone() |
| 538 |
: parseTimeZone(expression.getValue(session))); |
| 539 |
break; |
| 540 |
case SetTypes.VARIABLE_BINARY: |
| 541 |
session.setVariableBinary(expression.getBooleanValue(session)); |
| 542 |
break; |
| 543 |
case SetTypes.DEFAULT_NULL_ORDERING: { |
| 544 |
DefaultNullOrdering defaultNullOrdering; |
| 545 |
try { |
| 546 |
defaultNullOrdering = DefaultNullOrdering.valueOf(StringUtils.toUpperEnglish(stringValue)); |
| 547 |
} catch (RuntimeException e) { |
| 548 |
throw DbException.getInvalidValueException("DEFAULT_NULL_ORDERING", stringValue); |
| 549 |
} |
| 550 |
if (database.getDefaultNullOrdering() != defaultNullOrdering) { |
| 551 |
session.getUser().checkAdmin(); |
| 552 |
database.setDefaultNullOrdering(defaultNullOrdering); |
| 553 |
} |
| 554 |
break; |
| 555 |
} |
| 556 |
case SetTypes.TRUNCATE_LARGE_LENGTH: |
| 557 |
session.setTruncateLargeLength(expression.getBooleanValue(session)); |
| 558 |
break; |
| 559 |
default: |
| 560 |
throw DbException.getInternalError("type="+type); |
| 561 |
} |
| 562 |
// the meta data information has changed |
| 563 |
database.getNextModificationDataId(); |
| 564 |
// query caches might be affected as well, for example |
| 565 |
// when changing the compatibility mode |
| 566 |
database.getNextModificationMetaId(); |
| 567 |
return 0; |
| 568 |
} |
| 569 |
|
| 570 |
private static TimeZoneProvider parseTimeZone(Value v) { |
| 571 |
if (DataType.isCharacterStringType(v.getValueType())) { |
| 572 |
TimeZoneProvider timeZone; |
| 573 |
try { |
| 574 |
timeZone = TimeZoneProvider.ofId(v.getString()); |
| 575 |
} catch (RuntimeException ex) { |
| 576 |
throw DbException.getInvalidValueException("TIME ZONE", v.getTraceSQL()); |
| 577 |
} |
| 578 |
return timeZone; |
| 579 |
} else if (v == ValueNull.INSTANCE) { |
| 580 |
throw DbException.getInvalidValueException("TIME ZONE", v); |
| 581 |
} |
| 582 |
return TimeZoneProvider.ofOffset(TimeZoneOperation.parseInterval(v)); |
| 583 |
} |
| 584 |
|
| 585 |
private int getIntValue() { |
| 586 |
expression = expression.optimize(session); |
| 587 |
return expression.getValue(session).getInt(); |
| 588 |
} |
| 589 |
|
| 590 |
public void setInt(int value) { |
| 591 |
this.expression = ValueExpression.get(ValueInteger.get(value)); |
| 592 |
} |
| 593 |
|
| 594 |
public void setExpression(Expression expression) { |
| 595 |
this.expression = expression; |
| 596 |
} |
| 597 |
|
| 598 |
private void addOrUpdateSetting(String name, String s, int v) { |
| 599 |
addOrUpdateSetting(session, name, s, v); |
| 600 |
} |
| 601 |
|
| 602 |
private void addOrUpdateSetting(SessionLocal session, String name, String s, int v) { |
| 603 |
Database database = session.getDatabase(); |
| 604 |
assert Thread.holdsLock(database); |
| 605 |
if (database.isReadOnly()) { |
| 606 |
return; |
| 607 |
} |
| 608 |
Setting setting = database.findSetting(name); |
| 609 |
boolean addNew = false; |
| 610 |
if (setting == null) { |
| 611 |
addNew = true; |
| 612 |
int id = getObjectId(); |
| 613 |
setting = new Setting(database, id, name); |
| 614 |
} |
| 615 |
if (s != null) { |
| 616 |
if (!addNew && setting.getStringValue().equals(s)) { |
| 617 |
return; |
| 618 |
} |
| 619 |
setting.setStringValue(s); |
| 620 |
} else { |
| 621 |
if (!addNew && setting.getIntValue() == v) { |
| 622 |
return; |
| 623 |
} |
| 624 |
setting.setIntValue(v); |
| 625 |
} |
| 626 |
if (addNew) { |
| 627 |
database.addDatabaseObject(session, setting); |
| 628 |
} else { |
| 629 |
database.updateMeta(session, setting); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
@Override |
| 634 |
public boolean needRecompile() { |
| 635 |
return false; |
| 636 |
} |
| 637 |
|
| 638 |
@Override |
| 639 |
public ResultInterface queryMeta() { |
| 640 |
return null; |
| 641 |
} |
| 642 |
|
| 643 |
public void setStringArray(String[] list) { |
| 644 |
this.stringValueList = list; |
| 645 |
} |
| 646 |
|
| 647 |
@Override |
| 648 |
public int getType() { |
| 649 |
return CommandInterface.SET; |
| 650 |
} |
| 651 |
|
| 652 |
} |