diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-21 08:54:44 +0100 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-21 11:29:44 +0100 |
commit | e43f05f5b1a88d1b1fae0743a17e85c5ecd4fc52 (patch) | |
tree | fcbe222c61717ec6ea49a51feeddb0be3fa21111 /connectivity | |
parent | 7358cf00822a916b1690ffd86822a28d3996e288 (diff) |
Simplify some sql statements with multiple conditions. (firebird-sdbc)
By prepending a "WHERE (0=1)" we can avoid having to detect when
we specifically need to add "OR"s, and vice-versa for "AND", simplifying
the code.
Change-Id: Idde5c0691788051f87eb1e868bf6b74a8ae72da3
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/firebird/DatabaseMetaData.cxx | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 2aa1bc89f8fd..215d84fda3bc 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -1136,33 +1136,27 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( "relfields.RDB$NULL_FLAG " // 9 "FROM RDB$RELATION_FIELDS relfields " "JOIN RDB$FIELDS fields " - "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) "); + "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) " + "WHERE (1 = 1) "); - if (!tableNamePattern.isEmpty() && !columnNamePattern.isEmpty()) - { - queryBuf.append("WHERE "); - } if (!tableNamePattern.isEmpty()) { OUString sAppend; if (tableNamePattern.match("%")) - sAppend = "relfields.RDB$RELATION_NAME LIKE '%' "; + sAppend = "AND relfields.RDB$RELATION_NAME LIKE '%' "; else - sAppend = "relfields.RDB$RELATION_NAME = '%' "; + sAppend = "AND relfields.RDB$RELATION_NAME = '%' "; queryBuf.append(sAppend.replaceAll("%", tableNamePattern)); } if (!columnNamePattern.isEmpty()) { - if (!tableNamePattern.isEmpty()) - queryBuf.append("AND "); - OUString sAppend; if (columnNamePattern.match("%")) - sAppend = "relfields.RDB$FIELD_NAME LIKE '%' "; + sAppend = "AND relfields.RDB$FIELD_NAME LIKE '%' "; else - sAppend = "relfields.RDB$FIELD_NAME = '%' "; + sAppend = "AND relfields.RDB$FIELD_NAME = '%' "; queryBuf.append(sAppend.replaceAll("%", columnNamePattern)); } @@ -1339,21 +1333,19 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( } else { + queryBuf.append("( (0 = 1) "); for (int i = 0; i < types.getLength(); i++) { - if (i) - queryBuf.append("OR "); - if (types[i] == "SYSTEM TABLE") - queryBuf.append("(RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) "); + queryBuf.append("OR (RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) "); else if (types[i] == "TABLE") - queryBuf.append("(RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) "); + queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) "); else if (types[i] == "VIEW") - queryBuf.append("(RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) "); + queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) "); else throw SQLException(); // TODO: implement other types, see above. - } + queryBuf.append(") "); } if (!tableNamePattern.isEmpty()) @@ -1367,8 +1359,6 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( queryBuf.append(sAppend.replaceAll(wld, tableNamePattern)); } - - queryBuf.append(" ORDER BY RDB$RELATION_TYPE, RDB$RELATION_NAME"); OUString query = queryBuf.makeStringAndClear(); |