![]() |
![]() |
|
![]() |
Finding Links Between Tables © 2001Manuele Grueff In many situations would be nice to know before tinkering with a table (copying records from another source, restructuring, and many other situations) if it depends on other tables, or, as may say, what's the "order" of the table. I mean that if for example you have an "Articles" table and an "Orders" table, if you're a good fella you should have a referential integrity bond between the two: Records in the Orders table should point to an article in the other table, by means of a nice Id field which has to be bound by Ref. int. Now suppose that you want to copy the contents of the two tables from an alias to another (one obvious situation is when you're upgrading an app to a newer version, and want to regenerate tables on the way): you can't do this in a casual manner, since no record can be appended to Orders before the corresponding Article has been inserted; you should then copy first the content of articles, and then the contents of Orders. I've built a simple recursive routine (surely you can write a better one! but it does indeed function) that tells you the "order" of a table: in the latter example, Articles would be of order=0 and Orders would be of order=1, and so on: if we had a table depending on Orders, it'll be of order=2, and ... you can easily figure the rest! Here's my code snippet (it needs the table name or full path and returns the "order"): method gettableorder(tblname string) longint var order, neworder longint tmptc1, tmptc2 tcursor endvar ;tracerwrite("Calculating order of table "+tblname+"...") tmptc1.open(tblname) tmptc1.enumrefintstruct(tmptc2) order=0 scan tmptc2 for tmptc2.slave="Y": neworder=gettableorder(tmptc2.othertable)+1 if neworder>order then order=neworder endif endscan return order endMethodEnjoy and comment freely at grueff@atipica.it! Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|