Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

Foxpro database Auto ID field

Hi,

I use vb6 and foxpro database, Pls advice how to do an auto id field.
0
aarontham
Asked:
aarontham
  • 3
1 Solution
 
CarlWarnerCommented:
Later releases of Visual FoxPro, starting with VFP8 and now VFP9, have added the ability to use AuoIncrementing fields built right into the tables as a newer type of integer field.

Integer (Autoinc) field type
Integer Field Type
http://msdn.microsoft.com/library/en-us/dv_foxhelp9/html/e2e6eeaf-b170-4a8c-b826-c5127938d8d6.asp?frame=true

How to: Set Autoincrementing Field Values
http://msdn.microsoft.com/library/en-us/dv_foxhelp9/html/d4fd7029-4f84-45ee-b0de-75eb1dc45bd3.asp?frame=true

In previous versions, Fox developers had to roll their own autoincrementing capabilities for their FoxPro tables/.dbfs, if they wanted to go that way.  Here is one example article on how to do that in earlier versions:

An Autoincrementing Class
http://www.lespinter.com/PC/ShowArticle.aspx?ArtNum=221
0
 
CarlWarnerCommented:
Many Fox developers never use an auto-ID capability.  It could be that, pretty unique to the xBASE world of which FoxPro is a part, is the fact that each record/row in a FoxPro table/.dbf has an internal record number that is ordered by when a record was added/inserted to the table.  In a shared data session, it will stay constant and is used heavily by many Fox developers for quick navigation within the table.

One way to get that info out is via a quick SQL query such as the following with VFP:

SELECT *, RECNO() as recnum FROM customers

That will return not only all of the data, but each record number reference in the new field called "recnum" that results by virtue of using the VFP RECNO() function.

I mentioned that it is constant within a shared session because, once that table is PACKed by a maintenance routine in exclusive mode, the records marked for deletion are left out and the record number sequence is changed because records end up missing.  A data maintenance routine could also have the capability of re-ordering the data position by an index order if that is what the Fox developer chose to do.  So, even without deleted records in the mix that get removed by a PACK, most, if not all, record numbers could be different after a maintenance routine.  But, again, that will not affect an active data session by one or more users where the database and its tables are in shared mode.  A PACK command or a maintenance routine that copies the data back in a new order would require EXCLUSIVE use of those tables.  That can't happen if you are still working in the tables.

So, it may be you could find a use for the Fox internal record number now that you know it exists.
0
 
CarlWarnerCommented:
Glad I could help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now