Test if sql from a report object and sql from all parameter sources (if any) are valid

@param con database connection
@param report report object
@return return message error if sql is not valid, null otherwise
434352
public static String isValidSqlWithMessage(Connection con, Report report) {
		String sql = getSql(report);
		List<QueryParameter> parameters = report.getParameters();
		String message = isValidSqlWithMessage(con, sql, parameters);
		if (message == null) {
			for (QueryParameter qp : parameters) {
				if (qp.isManualSource()) {
					String parMessage = isValidSqlWithMessage(con, qp.getSource(), parameters);
					if (parMessage != null) {
						parMessage = "Parameter '" + qp.getName() + "'\n" + parMessage;
						return parMessage;
					}
				}
 			}
		} 
		return message;		
	}
710626
private String validateDialect(String confParam)
   {
      for (String dbType : DBConstants.DB_DIALECTS)
      {
         if (confParam.equals(dbType))
         {
            return dbType;
         }
      }

      return DBConstants.DB_DIALECT_AUTO; // by default
   }
581945
public static Object stringToSqlValue(String value, int sqlType, boolean isRequired, boolean isEmptyStringNulled) {
        // 设置变量
        String sourceValue = value;
        if (SqlUtils.isTextType(sqlType)) {
            if ((sourceValue == null) || (true == StringUtils.isEmpty(sourceValue) && isEmptyStringNulled)) {
                return isRequired ? REQUIRED_FIELD_NULL_SUBSTITUTE : null;
            } else {
                return sourceValue;
            }
        } else {
            if (StringUtils.isEmpty(sourceValue)) {
                return isEmptyStringNulled ? null : sourceValue;// oracle的返回null，保持兼容
            } else {
                Class<?> requiredType = sqlTypeToJavaTypeMap.get(sqlType);
                if (requiredType == null) {
                    throw new IllegalArgumentException("unknow java.sql.Types - " + sqlType);
                } else if (requiredType.equals(String.class)) {
                    return sourceValue;
                } else if (true == isNumeric(sqlType)) {
                    return convertUtilsBean.convert(sourceValue.trim(), requiredType);
                } else {
                    return convertUtilsBean.convert(sourceValue, requiredType);
                }
            }
        }
    }
1323183
protected boolean isValidQuery(String query) {
        if (query == null) {
            return true;
        }
        
        return QUERY_PATTERN.matcher(query).matches();
    }
677029
public void setReport(Report report) {
		this.report = report;
		if (this.report.getQuery() != null) {
			this.report.getQuery().setDialect(dialect);
		}
	}
623397
function (expr, cb, joinCond) {
            expr = (isUndefined(expr) || isNull(expr) || (Array.isArray(expr) && !expr.length)) ? null : expr;
            if (expr && cb) {
                return new BooleanExpression(joinCond || "AND", this._filterExpr(expr, null, joinCond), this._filterExpr(cb, null, joinCond));
            } else if (cb) {
                expr = cb;
            }
            if (isInstanceOf(expr, Expression)) {
                if (isInstanceOf(expr, NumericExpression, StringExpression)) {
                    throw new QueryError("Invalid SQL Expression type : " + expr);
                }
                return expr;
            } else if (Array.isArray(expr)) {
                if (expr.length) {
                    var first = expr[0];
                    if (isString(first)) {
                        return new PlaceHolderLiteralString(first, expr.slice(1), true);
                    } else if (Expression.isConditionSpecifier(expr)) {
                        return BooleanExpression.fromValuePairs(expr, joinCond);
                    } else {
                        return BooleanExpression.fromArgs([joinCond || "AND"].concat(expr.map(function (e) {
                            return this._filterExpr(e, null, "AND");
                        }, this)));
                    }
                }
            } else if (isFunction(expr)) {
                return this._filterExpr(expr.call(sql, sql), null, joinCond);
            } else if (isBoolean(expr)) {
                return new BooleanExpression("NOOP", expr);
            } else if (isString(expr)) {
                return this.stringToIdentifier(expr);
            } else if (isInstanceOf(expr, LiteralString)) {
                return new LiteralString("(" + expr + ")");
            } else if (isHash(expr)) {
                return BooleanExpression.fromValuePairs(expr, joinCond);
            } else {
                throw new QueryError("Invalid filter argument");
            }
        }
893623
private void checkUnicity(ValidationStampFilter filter) {
        // Check project vs branch
        if (filter.getProject() != null && filter.getBranch() != null) {
            throw new IllegalStateException("Filter cannot be associated with both a project and a branch.");
        }
        // Gets the existing filter for the name in this scope
        MapSqlParameterSource params = params("name", filter.getName())
                .addValue("project", filter.getProject() != null ? filter.getProject().id() : null)
                .addValue("branch", filter.getBranch() != null ? filter.getBranch().id() : null)
                .addValue("id", filter.getId() != null && filter.getId().isSet() ? filter.id() : null);
        String sql;
        // Branch
        if (filter.getBranch() != null) {
            sql = "SELECT ID FROM VALIDATION_STAMP_FILTERS WHERE PROJECT IS NULL AND BRANCH = :branch AND NAME = :name";
        }
        // Project
        else if (filter.getProject() != null) {
            sql = "SELECT ID FROM VALIDATION_STAMP_FILTERS WHERE PROJECT = :project AND BRANCH IS NULL AND NAME = :name";
        }
        // Global
        else {
            sql = "SELECT ID FROM VALIDATION_STAMP_FILTERS WHERE PROJECT IS NULL AND BRANCH IS NULL AND NAME = :name";
        }
        // ID
        if (filter.getId() != null && filter.getId().isSet()) {
            sql += " AND ID <> :id";
        }
        // Check
        Optional<Integer> o = getOptional(
                sql,
                params,
                Integer.class
        );
        if (o.isPresent()) {
            throw new ValidationStampFilterNameAlreadyDefinedException(filter.getName());
        }
    }
830533
public static byte isValid(String reportVersion) {
		if (isOlderUnsupportedVersion(reportVersion)) {
			return REPORT_INVALID_OLDER;
		} else if (isNewerUnsupportedVersion(reportVersion)) {
			return REPORT_INVALID_NEWER;
		} else {
			return REPORT_VALID;
		}
	}
970381
public boolean execute(Sql sql) throws SQLException {
		
		long start =  System.currentTimeMillis();
		
		if (sql.validate() == false) {
			return false;
		}
		
		boolean result = false;
		
		PreparedStatement stmt = null;
		try {
			stmt = this.createStatment(conn, sql);
			stmt.execute();
			
			result = true;
		} catch (SQLException e) {
			throw e;
		} finally {
			try {
				if (stmt != null && stmt.isClosed() == false) {
					stmt.close();
				}
			} catch (SQLException e) {
				logger.error(e.getMessage(), e);
			}
		}
		
		logger.debug(String.format("Execute %s used %d ms", sql.getSql(), System.currentTimeMillis() - start));

		return result;
	}
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");
    }
316273
public void validate() throws SQLConfigurationException {
        if (this.url == null) {
            throw new SQLConfigurationException("url is a required property");
        }
        if (this.username == null) {
            throw new SQLConfigurationException("username is a required property");
        }
	/* password isn't required in many databases
        if (this.password == null) {
            throw new SQLConfigurationException("password is a required property");
        }
	*/
        if (this.name == null) {
            throw new SQLConfigurationException("name is a required property");
        }
        if (this.driver == null) {
            throw new SQLConfigurationException("driver is a required property");
        }
    }
1078566
private static void submitSQLQuery(QdsClient client) throws Exception {
        String sampleSqlQuery =
            "select * from default_qubole_airline_origin_destination limit 100";

        SparkCommandBuilder sparkBuilder = client.command().spark();

        // Give a name to the command. (Optional)
        sparkBuilder.name("spark-sql-test");

        // Setting the sql query
        sparkBuilder.sql(sampleSqlQuery);

        CommandResponse commandResponse = sparkBuilder.invoke().get();
        ResultLatch resultLatch = new ResultLatch(client, commandResponse.getId());
        ResultValue resultValue = resultLatch.awaitResult();
        System.out.println(resultValue.getResults());

        String s = client.command().logs("" + commandResponse.getId()).invoke().get();
        System.err.println(s);
    }
1330811
public Map<String, Serializable> getReportUserParametersForEdit(Report report) throws Exception {
        Map<String, Serializable> result = new LinkedHashMap<String, Serializable>();
        JasperReport jr = getJasperReport(report);
        Map<String, Serializable> map = JasperReportsUtil.getJasperReportUserParameters(jr);
        for (String key : map.keySet()) {
            JasperParameter jp = (JasperParameter) map.get(key);            
            JasperParameterSource sp = getParameterSources(report, jp);
            // this parameter is not defined inside the file
            if (sp == null) {
                sp = new JasperParameterSource(jp.getName());
                sp.setValueClassName(JasperReportsUtil.getValueClassName(storageService, report.getDataSource(), jp));
            }
            result.put(sp.getName(), sp);
        }
        return result;
    }
3977
protected void validateSqlString(String originalSql) {
        if (originalSql == null) {
            throw new IllegalArgumentException(ERROR_SQL_QUERY_NULL);
        }
        if (processor.hasUnnamedParameters(originalSql) == true) {
            throw new IllegalArgumentException(ERROR_FOUND_UNNAMED_PARAMETER);
        }
    }
1025075
public Object javaToSql(Object source)
    {
        if (source instanceof String)
        {
            if (((String)source).trim().length() == 0)
         	    return null;
        }
        return source;
    }
919860
public Set<String> execute(final ConnectionResource _con)
        throws SQLException
    {
        final Set<String> ret = new HashSet<>();
        if (getIds().length > 1 || checkUpdateRequired(_con)) {
            final StringBuilder cmd = new StringBuilder()
                .append(Context.getDbType().getSQLPart(SQLPart.UPDATE)).append(" ")
                .append(Context.getDbType().getTableQuote())
                .append(getTableName())
                .append(Context.getDbType().getTableQuote()).append(" ")
                .append(Context.getDbType().getSQLPart(SQLPart.SET)).append(" ");

            // append SQL values
            boolean first = true;
            for (final ColumnWithSQLValue col : getColumnWithSQLValues())  {
                if (first)  {
                    first = false;
                } else  {
                    cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                }
                cmd.append(Context.getDbType().getColumnQuote())
                    .append(col.getColumnName())
                    .append(Context.getDbType().getColumnQuote())
                    .append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append(col.getSqlValue());
            }

            // append values
            for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
                if (first)  {
                    first = false;
                } else  {
                    cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                }
                cmd.append(Context.getDbType().getColumnQuote())
                    .append(col.getColumnName())
                    .append(Context.getDbType().getColumnQuote())
                    .append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append("?");
                ret.add(col.getColumnName());
            }

            // append where clause
            cmd.append(" ").append(Context.getDbType().getSQLPart(SQLPart.WHERE)).append(" ")
                .append(Context.getDbType().getColumnQuote())
                .append(getIdColumn())
                .append(Context.getDbType().getColumnQuote());

            if (this.ids.length == 1) {
                cmd.append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append("?");
            } else {
                cmd.append(" ").append(Context.getDbType().getSQLPart(SQLPart.IN)).append(" ")
                    .append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_OPEN));
                first = true;
                for (@SuppressWarnings("unused") final long id : this.ids) {
                    if (first)  {
                        first = false;
                    } else  {
                        cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                    }
                    cmd.append("?");
                }
                cmd.append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_CLOSE));
            }

            if (SQLUpdate.LOG.isDebugEnabled()) {
                SQLUpdate.LOG.debug(cmd.toString());
            }

            final PreparedStatement stmt = _con.prepareStatement(cmd.toString());
            int index = 1;
            for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
                if (SQLUpdate.LOG.isDebugEnabled()) {
                    SQLUpdate.LOG.debug("    " + index + " = " + col.getValue());
                }
                col.set(index++, stmt);
            }

            for (final long id : this.ids) {
                SQLUpdate.LOG.debug("    " + index + " = " + id);
                stmt.setLong(index++, id);
            }

            try  {
                final int rows = stmt.executeUpdate();
                if (rows == 0) {
                    throw new SQLException("Object for SQL table '" + getTableName()
                            + "' with ids '" + this.ids + "' does not exists and was not updated.");
                }
            } finally  {
                stmt.close();
            }
        }
        return ret;
    }
23565
@NonNull
  public static CqlIdentifier fromCql(@NonNull String cql) {
    Preconditions.checkNotNull(cql, "cql must not be null");
    final String internal;
    if (Strings.isDoubleQuoted(cql)) {
      internal = Strings.unDoubleQuote(cql);
    } else {
      internal = cql.toLowerCase();
      Preconditions.checkArgument(
          !Strings.needsDoubleQuotes(internal), "Invalid CQL form [%s]: needs double quotes", cql);
    }
    return fromInternal(internal);
  }