Returns an optional warning message if needed, <code>null</code> if not.<p>

@param db the selected database key

@return html warning, or <code>null</code> if no warning
16294
public String checkVariables(String db) {

        StringBuffer html = new StringBuffer(512);
        if (m_con == null) {
            return null; // prior error, trying to get a connection
        }
        Exception exception = null;
        if (db.equals("mysql")) {
            String statement = "SELECT @@max_allowed_packet;";
            Statement stmt = null;
            ResultSet rs = null;
            long maxAllowedPacket = 0;
            try {
                stmt = m_con.createStatement();
                rs = stmt.executeQuery(statement);
                if (rs.next()) {
                    maxAllowedPacket = rs.getLong(1);
                }
            } catch (Exception e) {
                exception = e;
            } finally {
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException e) {
                        // ignore
                    }
                }
            }
            if (exception == null) {
                int megabyte = 1024 * 1024;
                if (maxAllowedPacket > 0) {
                    html.append("<p>MySQL system variable <code>'max_allowed_packet'</code> is set to ");
                    html.append(maxAllowedPacket);
                    html.append(" Byte (");
                    html.append((maxAllowedPacket / megabyte) + "MB).</p>\n");
                }
                html.append(
                    "<p>Please note that it will not be possible for OpenCms to handle files bigger than this value in the VFS.</p>\n");
                int requiredMaxAllowdPacket = 16;
                if (maxAllowedPacket < (requiredMaxAllowdPacket * megabyte)) {
                    m_errors.add(
                        "<p><b>Your <code>'max_allowed_packet'</code> variable is set to less than "
                            + (requiredMaxAllowdPacket * megabyte)
                            + " Byte ("
                            + requiredMaxAllowdPacket
                            + "MB).</b></p>\n"
                            + "<p>The required value for running OpenCms is at least "
                            + requiredMaxAllowdPacket
                            + "MB."
                            + "Please change your MySQL configuration (in the <code>my.ini</code> or <code>my.cnf</code> file).</p>\n");
                }
            } else {
                html.append(
                    "<p><i>OpenCms was not able to detect the value of your <code>'max_allowed_packet'</code> variable.</i></p>\n");
                html.append(
                    "<p>Please note that it will not be possible for OpenCms to handle files bigger than this value.</p>\n");
                html.append(
                    "<p><b>The recommended value for running OpenCms is 16MB, please set it in your MySQL configuration (in your <code>my.ini</code> or <code>my.cnf</code> file).</b></p>\n");
                html.append(CmsException.getStackTraceAsString(exception));
            }
        }
        if (html.length() == 0) {
            return null;
        }
        return html.toString();
    }
710006
public static function load($db = null)
    {
        if (!isset(self::$_instance)) {
            self::$_instance = new Validator($db);
        }

        return self::$_instance;
    }
128748
public String getNullValueSelect()
    {
        String ret = null;
        if (!this.types.isEmpty())  {
            ret = Context.getDbType().getNullValueSelect(this.types.iterator().next());
        }
        return ret;
    }
745640
private static void notifyServers(Database db) {

        Iterator it = serverMap.keySet().iterator();

        for (; it.hasNext(); ) {
            Server  server    = (Server) it.next();
            HashSet databases = (HashSet) serverMap.get(server);

            if (databases.contains(db)) {
// A VoltDB extension to disable a package dependency
/* disable 2 lines ...
                server.notify(ServerConstants.SC_DATABASE_SHUTDOWN,
                              db.databaseID);
... disabled 2 lines */
// End of VoltDB extension
            }
        }
    }
626946
static void removeDatabase(Database database) {

        int     dbID = database.databaseID;
        String  type = database.getType();
        String  path = database.getPath();
        // A VoltDB extension to work around ENG-6044
        /* disable 2 lines ...
        Object  key  = path;
        HashMap databaseMap;
           ... disabled 2 lines */
        // End of VoltDB extension

        notifyServers(database);

        // A VoltDB extension to work around ENG-6044
        /* disable 11 lines ...
        if (type == DatabaseURL.S_FILE) {
            databaseMap = fileDatabaseMap;
            key         = filePathToKey(path);
        } else if (type == DatabaseURL.S_RES) {
            databaseMap = resDatabaseMap;
        } else if (type == DatabaseURL.S_MEM) {
            databaseMap = memDatabaseMap;
        } else {
            throw (Error.runtimeError(
                ErrorCode.U_S0500, "DatabaseManager.lookupDatabaseObject()"));
        }
           ... disabled 11 lines */

        assert(type == DatabaseURL.S_MEM);
        java.util.HashMap<String, Database> databaseMap = memDatabaseMap;
        String key = path;
        // End of VoltDB extension

        databaseIDMap.remove(dbID);
        databaseMap.remove(key);

        if (databaseIDMap.isEmpty()) {
            ValuePool.resetPool();
        }
    }
329679
private void updateDb(String dbName, String webapp) {

        m_mainLayout.removeAllComponents();
        m_setupBean.setDatabase(dbName);
        CmsDbSettingsPanel panel = new CmsDbSettingsPanel(m_setupBean);
        m_panel[0] = panel;
        panel.initFromSetupBean(webapp);
        m_mainLayout.addComponent(panel);
    }
192464
protected I_CmsUpdateDBPart getInstanceForDb(I_CmsUpdateDBPart dbUpdater, String dbName) {

        String clazz = dbUpdater.getClass().getName();
        int pos = clazz.lastIndexOf('.');
        clazz = clazz.substring(0, pos) + "." + dbName + clazz.substring(pos);
        try {
            return (I_CmsUpdateDBPart)Class.forName(clazz).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
156527
private String extractSQLForJavaDoc(final SQLiteModelMethod method) {
		final One<Boolean> usedInWhere = new One<>(false);
		String sqlForJavaDoc = JQLChecker.getInstance().replace(method, method.jql, new JQLReplacerListenerImpl(method) {

			@Override
			public String onColumnNameToUpdate(String columnName) {
				return currentEntity.findPropertyByName(columnName).columnName;
			}

			@Override
			public String onColumnName(String columnName) {
				return currentEntity.findPropertyByName(columnName).columnName;
			}

			@Override
			public String onBindParameter(String bindParameterName, boolean inStatement) {
				if (!usedInWhere.value0) {
					if (bindParameterName.contains(".")) {
						String[] a = bindParameterName.split("\\.");

						if (a.length == 2) {
							bindParameterName = a[1];
						}
					}

					return ":" + bindParameterName;
				} else {
					return null;
				}
			}

			@Override
			public void onWhereStatementBegin(Where_stmtContext ctx) {
				usedInWhere.value0 = true;
			}

			@Override
			public void onWhereStatementEnd(Where_stmtContext ctx) {
				usedInWhere.value0 = false;
			};

		});
		return sqlForJavaDoc;
	}
999228
public static acolyte.jdbc.Connection connection(StatementHandler handler) {
        return connection(handler, (Properties) null);
    }
1148107
protected String nullify(String sql) {
        /*
         * Some drivers (Oracle classes12.zip) have difficulty resolving data
         * type if setObject(null). We will modify the query to pass 'null', 'is
         * null', and 'is not null'
         */
        //could be more efficient by compiling expressions in advance.
        int firstWhere = findWhereKeyword(sql);
        if (firstWhere >= 0) {
            Pattern[] patterns = {Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
                    Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)"),
                    Pattern.compile("(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)"),};
            String[] replacements = {"$1 is not $2null$3", "$1 is not $2null$3", "$1 is $2null$3",};
            for (int i = 0; i < patterns.length; i++) {
                Matcher matcher = patterns[i].matcher(sql);
                while (matcher.matches()) {
                    sql = matcher.replaceAll(replacements[i]);
                    matcher = patterns[i].matcher(sql);
                }
            }
        }
        return sql.replaceAll("\\?'\"\\?", "null");
    }
1206952
@Override
    public HttpMessage get(int index) {
        try {
            return historyReferences.get(index).getHttpMessage();
        } catch (HttpMalformedHeaderException | DatabaseException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Failed to get the message from DB: " + e.getMessage(), e);
            }
        }
        return null;
    }
1326288
function(db) {
    if (!db.type) {
      return defaultDbType;
    }

    return dbTypes.find(function(dbType) {
      return dbType.name === db.type;
    }) || null;
  }
95010
public void addWarning(SQLWarning warn) {
    // Add the warning to the chain
    if (firstWarning != null) {
      firstWarning.setNextWarning(warn);
    } else {
      firstWarning = warn;
    }

  }
1346233
protected void warnSQLFailureState(SQLFailureException cause) {
        if (cause instanceof EntityAlreadyExistsException) {
            return; // the exception is obviously application exception so no warning
        }
        try {
            final String msg = buildSQLFailureState(cause);
            logger.warn(msg); // only warning here, the cause will be caught by logging filter
        } catch (RuntimeException continued) {
            logger.info("Failed to show warning of SQL failure state: " + Integer.toHexString(cause.hashCode()), continued);
        }
    }
1245551
protected void dropDatabase(String database)
  {

    log.debug("dropping possible existing database");
    closeAllConnections(database);
    getJdbcTemplate().execute("DROP DATABASE IF EXISTS " + database);

  }
923871
public static ParsedSql parseSqlStatement(final String sql) {
        Assert.notNull(sql, "SQL must not be null");

        Set<String> namedParameters = new HashSet<>();
        String sqlToUse = sql;
        List<ParameterHolder> parameterList = new ArrayList<>();

        char[] statement = sql.toCharArray();
        int namedParameterCount = 0;
        int unnamedParameterCount = 0;
        int totalParameterCount = 0;

        int escapes = 0;
        int i = 0;
        while (i < statement.length) {
            int skipToPosition;
            while (i < statement.length) {
                skipToPosition = skipCommentsAndQuotes(statement, i);
                if (i == skipToPosition) {
                    break;
                } else {
                    i = skipToPosition;
                }
            }
            if (i >= statement.length) {
                break;
            }
            char c = statement[i];
            if (c == ':' || c == '&') {
                int j = i + 1;
                if (j < statement.length && statement[j] == ':' && c == ':') {
                    // Postgres-style "::" casting operator should be skipped
                    i = i + 2;
                    continue;
                }
                String parameter;
                if (j < statement.length && c == ':' && statement[j] == '{') {
                    // :{x} style parameter
                    while (j < statement.length && !('}' == statement[j])) {
                        j++;
                        if (':' == statement[j] || '{' == statement[j]) {
                            throw new CommonRuntimeException("Parameter name contains invalid character '" +
                                    statement[j] + "' at position " + i + " in statement: " + sql);
                        }
                    }
                    if (j >= statement.length) {
                        throw new CommonRuntimeException(
                                "Non-terminated named parameter declaration at position " + i + " in statement: " + sql);
                    }
                    if (j - i > 3) {
                        parameter = sql.substring(i + 2, j);
                        namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
                        totalParameterCount = addNamedParameter(parameterList, totalParameterCount, escapes, i, j + 1, parameter);
                    }
                    j++;
                } else {
                    while (j < statement.length && !isParameterSeparator(statement[j])) {
                        j++;
                    }
                    if (j - i > 1) {
                        parameter = sql.substring(i + 1, j);
                        namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
                        totalParameterCount = addNamedParameter(parameterList, totalParameterCount, escapes, i, j, parameter);
                    }
                }
                i = j - 1;
            } else {
                if (c == '\\') {
                    int j = i + 1;
                    if (j < statement.length && statement[j] == ':') {
                        // escaped ":" should be skipped
                        sqlToUse = sqlToUse.substring(0, i - escapes) + sqlToUse.substring(i - escapes + 1);
                        escapes++;
                        i = i + 2;
                        continue;
                    }
                }
                if (c == '?') {
                    int j = i + 1;
                    if (j < statement.length && (statement[j] == '?' || statement[j] == '|' || statement[j] == '&')) {
                        // Postgres-style "??", "?|", "?&" operator should be skipped
                        i = i + 2;
                        continue;
                    }
                    unnamedParameterCount++;
                    totalParameterCount++;
                }
            }
            i++;
        }

        ParsedSql parsedSql = new ParsedSql(sqlToUse);
        parsedSql.setParameterList(parameterList);
        parsedSql.setNamedParameterCount(namedParameterCount);
        parsedSql.setUnnamedParameterCount(unnamedParameterCount);
        parsedSql.setTotalParameterCount(totalParameterCount);
        return parsedSql;
    }
2807
public static function setDefaultDbo(AbstractDatabaseDriver $db = null)
    {
        self::$db = $db;

        if ($db) {
            $driver = $db->getName();

            self::$instances[$driver] = $db;
        }
    }