Menu

Easiest way to check if a table is linked?

Help
2015-02-10
2015-02-11
  • Martin Jericho

    Martin Jericho - 2015-02-10

    The Table class doesn't have any isLinked() method. Internally I can see
    that the private TableInfo class stores that information but I can't see
    any way to access it through the public API.

    Do I have to find the table name in MSysObjects and check for Type=6 or
    is there an easier way to find out?

    Thanks
    Martin

     
    • James Ahlborn

      James Ahlborn - 2015-02-10

      Well, "is linked" isn't really a property of the Table itself. From the perspective of the "other" database" the Table is just a normal table.

      Probably the easiest way to check if a Table is "linked" with respect to a given database would be to check the the owning database.

      if(curDb != someTable.getDatabase()) {
        // ... this is a linked table with respect to curDb ...
      }
      
       

      Last edit: James Ahlborn 2015-02-10
  • Martin Jericho

    Martin Jericho - 2015-02-11

    Thanks James that's exactly what I was after.

    Maybe you could have a flag in the Table object to indicate that it was fetched from a different database to the one it belongs to, even if it is meaningless out of that context. Or alternatively provide a Database.getLinkedTables() or Database.getLinkedTableNames() method. I doubt many users would think of the technique you've provided.

    Thanks for the great library!

     
  • Martin Jericho

    Martin Jericho - 2015-02-11

    Actually I have another suggestion as well. If a linked table's destination database doesn't exist the iterator throws a FileNotFoundException. That means the only way to iterate the local tables is to call getTableNames(), get each Table object by name, if a FileNotFoundException is thrown ignore that table, otherwise check if it is linked and ignore if so. To avoid the exceptions completely I'd have to go through the MSysObjects table and check types, flags etc.

    It would be nice if the Database class offered a getLocalTableNames() and/or getLinkedTableNames() method to make this simpler.

     

Log in to post a comment.