Solved

How to fix orphan DBF

Posted on 2014-02-06
9
634 Views
Last Modified: 2014-02-06
I want to remove the backlink to the DBC, in order to open the DBF, although it is orphan. The DBF is unknown, and it should be opened programatically, without user intervention.

There is no need to recreate the DBC, only to open the DBF. I have tried the code below, but not successful. Anybody that can give a solultion?

LPARAMETERS cFile
close databases all
cFiel = ForceExt(cFil, 'DBF')
nHnd = FOPEN(cFil, 2)

cStr = Fread(nHnd, 400)
nPos1 = 0
nPos2 = At('.dbc', cStr) + 2
jj = nPos2
for jj=nPos2 to 1 step -1
      cTkn = Substr(cStr, jj, 1)
      if cTkn = Chr(13)
            nPos1 = jj
      endif
next
for jj=nPos1 to nPos2
      =Fseek(nHnd, jj)
      =Fwrite(nHnd, Chr(0))
next
=Fseek(nHnd, 28)
=Fwrite(nHnd, Chr(0))
=Fclose(nHnd)
0
Comment
Question by:krhag28
  • 5
  • 3
9 Comments
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
The code needs a small fix:
LPARAMETERS cFile

close databases all
cFil = ForceExt(cFile, 'DBF')
nHnd = FOPEN(cFil, 2)

cStr = Fread(nHnd, 400)
nPos1 = 0
nPos2 = At('.dbc', cStr) + 2
jj = nPos2
for jj=nPos2 to 1 step -1
      cTkn = Substr(cStr, jj, 1)
      if cTkn = Chr(13)
            nPos1 = jj
      endif
next
for jj=nPos1 to nPos2
      =Fseek(nHnd, jj)
      =Fwrite(nHnd, Chr(0))
next

*-- This code removes MEMO file and CDX indication
*=Fseek(nHnd, 28)
*=Fwrite(nHnd, Chr(0))

=Fclose(nHnd) 

Open in new window


BUT be careful!  If user selects non DBF file having DBF extension it will overwrite it...  Above code also does not work for tables having too many columns...

So it would need some additional tuning. I can provide better code later.
0
 

Expert Comment

by:krhag
Comment Utility
I have tried it on a DBF which has CDX as well as DBC backlinks, and unfortunately the DBF seems to get corrupt, Foxpro reports Not a table...

I attach the table after manipulation with your code (including the last lines).

(txt extension because of upload restrictions)
Accounts.txt
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
Yes, this is the case I've mentioned above... Fortunately, the fix is easy. Open the table in Hex editor and write 30h to the first byte. The Hex editor is a part of VFP tools:

DO HOME()+'\tools\hexedit\hexedit.app'


=====================  SOLUTION to the question ==============================
To remove the database reference from DBF table is also very easy because VFP offers command to do this work:

FREE TABLE d:\path\table.DBF

I should look at the help earlier...

Remember the free table cannot support database stuff like long column names, triggers, field validations etc. You should copy the DBF file (+FPT and CDX) to some temp folder as the first step.
0
 

Expert Comment

by:krhag
Comment Utility
Thanks for your comments. However, what I need is code to remove references completely without user intervention - using hex editor is not an option in this case.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:krhag
Comment Utility
I will test the FREE TABLE command...
0
 

Expert Comment

by:krhag
Comment Utility
Free table seems to work fine :)  so it was more simple than expected.
0
 

Author Closing Comment

by:krhag28
Comment Utility
Simple solution, but nevertheless useful!
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
FREE TABLE should work but I'll post the updated code as I promised. The biggest problem of the code is it does not read the table structure but just the first 400 bytes so if you select any table having approx. 13 or more columns it must corrupt the table header...

The Hex editor was not the solution for your users but for you only.
0
 

Expert Comment

by:krhag
Comment Utility
Thanx.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report to PDF and TIF 31 779
Save Table Settings 6 258
diarydate calendar in vfp retrun data to form 7 398
Foxpro V9 query to compare two columns 5 283
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now