Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-9, 2005 Key Biscayne, Florida Table Types and Programming Styles John J Tuohy Data Access Worldwide
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Record Identity The Visual DataFlex Framework requires that every record in a Table have a unique Identifier Record Identity is used to re-find records Used by the Runtime (e.g., DDOs) Used by commands (e.g., reread) Used by the Framework (e.g., packages) Used within developer’s code Requirements Must provide a unique method for identifying the record Must be permanent (mostly) Must provide fastest possible access to single record Must support a generic style of programming that can be applied to all tables
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Using Recnum for Record Identity Represented as a single numeric field Uses known data-type (number) and field location (field zero) Provides fastest possible access to Embedded database Provides fastest possible access to PSQL database Works well if you can define your tables structure Consistent programming syntax across all tables It’s what DataFlex has always used
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Recnum Syntax // Low level commands using recnum Reread : Integer iTempRec Move Customer.Recnum to iTempRec Clear Customer : If (iTempRec<>0) Begin Move iTempRec to Customer.Recnum Find EQ Customer by recnum End // Data Dictionary methods using recnum Integer iTempRec Integer iFile Get Current_Record of hoDDO to iTempRec Send Clear to hoDDO : Get Main_File of hoDDO to iFile Send Find_by_Recnum of hoDDO iFile iTempRec
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Recnum limitations If your table does not have a unique numeric field, you cannot use the table in your application This limits you ability to connect to existing tables
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Using Primary Key for Record Identity Almost all tables support a primary key Even Tables with Recnums should also have a primary key Primary keys can be defined as one or more columns Primary key column(s) can be of any data-type(s) and location(s)
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Primary Key Syntax // low level commands using primary key String sTempId Move Customer.Customer_Id to sTempId Clear Customer : If (sTempId<>””) Begin Move sTempId to Customer.Customer_Id Find EQ Customer by 1 // find EQ by index 1 End // Data Dictionary methods using primary key String sTempId Get Field_Current_Value of hoDDO Field Customer.Customer_Id to sTempId Send Clear to hoDDO : Move sTempId to Customer.Customer_Id Send Find of hoDDO EQ 1 // find EQ mode and index 1
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Primary Key Limitations Each Primary Key table definition is unique. There is no generic way to access primary key information in a program that works with all tables It may not be the fastest way to get at a record
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Using RowId for Record Identity It is a virtual field There will never be a RowId column in your table A table’s column, columns or some other attribute will be mapped to RowId Special syntax has been created to support RowId All tables now support the use of RowId syntax The RowId syntax is generic – all tables can use the same syntax
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida RowId Syntax // Low level commands using RowId RowId riTempId Boolean bFound Move (GetRowId(Customer.File_Number)) to riTempId Clear Customer : If not (IsNullRowId(riTempId)) Begin Move (FindByRowId(Customer.File_Number,riTempId)) to bFound End // Data Dictionary methods using RowId RowId riTempId Get CurrentRowId of hoDDO to riTempId Send Clear to hoDDO : Send FindByRowId of hoDDO Customer.File_Number riTempId
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida RowId Limitations None
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida The RowId Interface New Data Type RowIdRowId riRowId riRowId2 Property RowId priLastRecord New Global Functions GetRowIdMove (GetRowId,iFile)) to riRowId FindByRowIdMove (FindByRowId, iFile, riRowId) to bFound NullRowIdMove (NullRowId()) to riRowId IsNullRowIdMove (IsNullRowId(riRowId)) to bIsNull IsSameRowIdMove (IsSameRowId(riRowId,riRowId2) to bSame SerializeRowIdMove (SerializeRowId(riRowId)) to sSerialRowId DeSerializeRowIdMove (DeSerializeRowId(sSerialRowId)) to riRowId New DataDictionary Interface FindByRowIdSend FindByRowId of hoDD iFile riRowId ReadByRowIdSend ReadByRowId of hoDD iFile riRowId CurrentRowIdGet CurrentRowId of hoDD iFile to riRowId HasRecordGet HasRecord of hoDD to bHasRecord OnNewCurrentRecordSend OnNewCurrentRecord riOldId riNewId
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida The Recnum “side-effects” Interface You may not need any other index You can traverse through a table via index.0 It provides an order (sometimes) You can use it in relationships You may use it as your primary key It's an easy way to make indexes unique It’s used to inactivate a record Undocumented and often unintentional interaction between find operations and the value of recnum The RowId Interface has no side-effect behaviors
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Programming Changes for RowId Changes made by DAW in Visual DataFlex 11.0 Runtime changed to use RowId (e.g. reread, DDOs) All packages were re-written to use RowId All Sample were changed to use RowId All wizard generate RowId code Database Builder changed to support RowId Connectivity API changed to support RowId Drivers changed to support RowId
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Programming Changes for RowId Developer required changes None
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Table Types: Recnum & Non-Recnum A Table can be either Recnum or Non-Recnum enabled When you define a new table you can choose to provide a recnum field. Some databases will always have a recnum (Embedded Database,P.SQL) while others are optional Defined in database builder Database Builder will attempt to make the best choice for you Embedded Database and P.SQL always use recnum When connecting to an SQL table (e.g. MSSQL) a recnum field will be defined if a “recnum-like” field is found; otherwise, Database Builder will attempt to use the Primary key for its RowId When you use RowId programming syntax it does matter what you table type is – you code remains the same.
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Should I continue to use Recnum Tables? It’s your choice Recnum support will not go away! Use of Recnum is a time tested technique Many developers have much code invested in Recnum usage You can mix Recnum and RowId style programming All tables support the RowId syntax You can use RowId or Recnum syntax with Recnum Tables You must use RowId syntax with non-Recnum Tables All tables can be defined to support Recnum If you control the database table definitions you can always supply a recnum field
Open Solutions for a Changing World™ Copyright 2005, Data Access Worldwide June 6-8,2005 Key Biscayne, Florida Developer Strategies for Using RowId Syntax 1.Write your new code to using RowId Syntax Pros:Allows your code to work with non-Recnum tables New syntax is clearer with no side-effects Easier for new developers to learn Cons:Learning curve - You already know the old syntax Overhead of mixed syntax application 2.Change you class packages to use RowId Syntax Pros:Allows your class code to work with non-Recnum tables Cons:If you change it, you will break it. It's work 3.Change your old code to use RowId Syntax Pros:New syntax is clearer with no side-effects Cons:If you change it, you will break it. It's work End result is your application runs the same