| Summary: | Firebird: impossible to delete an external table | ||
|---|---|---|---|
| Product: | LibreOffice | Reporter: | Julien Nabet <serval2412> |
| Component: | Base | Assignee: | Julien Nabet <serval2412> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | medium | ||
| Version: | 7.4.0.0 alpha0+ | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | target:7.4.0 target:7.3.0.2 | ||
| Crash report or crash signature: | Regression By: | ||
|
Description
Julien Nabet
2021-12-29 11:24:41 UTC
Some analysis shows that to display tables, ODatabaseMetaData::getTables is called and it goes in the else part of this block:
1339 // TODO: GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM
1340 if (!types.hasElements() || (types.getLength() == 1 && types[0].match(wld)))
1341 {
1342 // All table types? I.e. includes system tables.
1343 queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) ");
1344 }
1345 else
1346 {
1347 queryBuf.append("( (0 = 1) ");
1348 for (OUString const & t : types)
1349 {
1350 if (t == "SYSTEM TABLE")
1351 queryBuf.append("OR (RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) ");
1352 else if (t == "TABLE")
1353 queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) ");
1354 else if (t == "VIEW")
1355 queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) ");
1356 else
1357 throw SQLException(); // TODO: implement other types, see above.
1358 }
1359 queryBuf.append(") ");
1360 }
when trying to remove the table, it goes in the if part.
see:
https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/DatabaseMetaData.cxx?r=5b20bb65#1347
Now investigating about RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1, these values come from src/jrd/constants.h
214 // relation types
215
216 enum rel_t {
217 rel_persistent = 0,
218 rel_view = 1,
219 rel_external = 2,
220 rel_virtual = 3,
221 rel_global_temp_preserve = 4,
222 rel_global_temp_delete = 5
223 };
so we retrieve rel_persistent (for "regular" tables and views)
but we need rel_external.
=>
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index f63468f0813f..c8356a32a82b 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1339,8 +1339,10 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
// TODO: GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM
if (!types.hasElements() || (types.getLength() == 1 && types[0].match(wld)))
{
+ // from Firebird: src/jrd/constants.h
+ // rel_persistent = 0, rel_view = 1, rel_external = 2
// All table types? I.e. includes system tables.
- queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) ");
+ queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1 OR RDB$RELATION_TYPE = 2) ");
}
else
{
After this first change, we got now a popup error when trying to delete the table:
irebird_sdbc error:
*Dynamic SQL Error
*SQL error code = -104
*Token unknown - line 1, column 6
*"EXT1"
caused by
'isc_dsql_prepare'
/home/julien/lo/libreoffice/connectivity/source/drivers/firebird/Util.cxx:68
The pb is again in the function ODatabaseMetaData::getTables some lines below when trying to retrieve the value of sTableType:
1397 OUString sTableType;
1398
1399 if (nSystemFlag == 1)
1400 {
1401 sTableType = "SYSTEM TABLE";
1402 }
1403 else if (aIsView)
1404 {
1405 sTableType = "VIEW";
1406 }
1407 else
1408 {
1409 if (nTableType == 0)
1410 sTableType = "TABLE";
1411 }
Since nTableType = 2, sTableType stays empty and some debugging shows that the DROP command generated is incomplete.
Julien Nabet committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/13de0ade50bec34be612ba4a3196c2efd9ce3b4e tdf#146471: Firebird: impossible to delete an external table It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback. Backport for 7.3 waiting for review here: https://gerrit.libreoffice.org/c/core/+/127584 Julien Nabet committed a patch related to this issue. It has been pushed to "libreoffice-7-3": https://git.libreoffice.org/core/commit/d12094654d83f28b292200367939ca7e6144732b tdf#146471: Firebird: impossible to delete an external table It will be available in 7.3.0.2. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback. |