我正在尝试对任何类型的数据库中的表进行简单的搜索。下面的查询使用的数据库最多,但我找不到一个在mysql上工作的解决方案。我的数据库中的表是由active objects框架生成的,因此我不能更改这些实例的名称或配置。
下面是在除MySQL之外的所有数据库上运行良好的查询:
从"AO_69D057_FILTER“中选择*,其中"SHARED”= true,"CONTAINS_PROJECT“= true,并选择”CONTAINS_PROJECT“(”FILTER_NAME“),就像上方(‘%pr%’)。
由于某些原因,MySql无法在双引号中使用表名。如果我使用未引号的表名,它可以在MySQL上工作,而不能在Postgres上工作。Postgres将表名转换为小写,因为它没有引号。AO正在生成大写的表名。
我也尝试使用别名,但由于语句的评估层次结构,所以不能使用。
如何解决表名问题,有什么建议吗?
发布于 2021-09-22 11:47:11
我也有同样的问题。我根据得到的异常选择查询。在数据库搜索的第一次调用中,我尝试不带引号的(如果失败),然后尝试带有引号的。然后,我相应地设置useQueryWithQuotes变量,以便在以后的调用中不需要检查异常。下面是我正在使用的代码片段。
private Boolean useQueryWithQuotes=null;
private final String queryWithQuotes = "\"OWNER\"=? or \"PRIVATE\"=?";
private final String queryWithoutQuotes = "OWNER=? or PRIVATE=?";
public Response getReports() {
List<ReportEntity> reports = null;
if(useQueryWithQuotes==null){
synchronized(this){
try {
reports = new ArrayList<ReportEntity>( Arrays.asList(ao.find(ReportEntity.class, Query.select().where(queryWithoutQuotes, getUserKey(), false))) );
useQueryWithQuotes = false;
} catch (net.java.ao.ActiveObjectsException e) {
log("exception:" + e);
log("trying query with quotes");
reports = new ArrayList<ReportEntity>( Arrays.asList(ao.find(ReportEntity.class, queryWithQuotes, getUserKey(), false)));
useQueryWithQuotes = true;
}
}
}else{
String query = useQueryWithQuotes ? queryWithQuotes : queryWithoutQuotes;
reports = new ArrayList<ReportEntity>( Arrays.asList(ao.find(ReportEntity.class, query, getUserKey(), false)));
}
...
}https://stackoverflow.com/questions/38485166
复制相似问题