Solved

Corrupt Index Delphi 4/Paradox7

Posted on 2001-06-21
2
974 Views
Last Modified: 2007-12-19
Hi,

   To set the scene, I have a DBgrid and input fields below the source is an SQL Query object. The grid/input is SQL based to allow reselection according to criteria etc. This one screen therefore supplies enquiry,insert and update facility over one table.

My problem is that on rare occasions the underlying table is reporting a corrupted index but I can never reproduce it.

I'm pretty sure that I've written the application in such a way that it wont leave an update half way through etc

I have observed the accumulation of _QSQ?.DB files, these I presume to be temporary files created for the SQL view?
Generally these files vanish as the application is closed but this is not always happening. On one occasion I was informed that a power cut had occured - at least six records prior to the cut had not been recorded and on restarting the system the index was corrupt, I can understand why an index corruption may have ocurred here but why the missing data?

 So to ask specifics:

1) Can anyone tell me what _QSQ.DB files are?

2) When using an SQL Query object to update a data file is the data cached or written directly to disk (I have CachedUpdates=False). How can I ensure it is written straight to disk?

3) Is it best practice to explicitly open and close tables/Queries at application start/finish. Delphi always seems to handle this for me, I think :)

4) what is the most likely cause of Index corruption? I presume an uncompleted update.

5) Is it just me :)

Thanks Folks,

Regards,


        Ralph.
0
Comment
Question by:RalphPorter
2 Comments
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 200 total points
ID: 6215370
Ralphm

No it's not just you. The BDE can be a real pain sometimes. We've had the same problem with updates not being committed after a post, so if the application terminates abnormally then a batch of records would go missing.

1. The QSQ tables are temporary bde tables creating when running sql statements. These should be placed in the BDE private directory and deleted when the session is closed.

2. Check your LOCAL SHARE property in BDE administrator and ensure it is set to true. This seemed to cure the problem with records going missing).

3. I always explicitly open/close tables/queries as and when they are needed. Although Delphi should close the connection as the object is freed.

4. I think the most likely cause of index corruption is abnormal termination of the application. At least that's what it seems like to me.

This is a procedure that I found on the web that allows you to set various BDE parameter values.

Call it like this to set LOCALSHARE to true everytime the application starts up

SetBDEParameter('\SYSTEM\INIT\;LOCAL SHARE','TRUE');


procedure SetBDEParameter(Param: string; Value: string);
var
  hCfg: hDBICfg;
  Config: SYSConfig;
  Path, Option: string;
  ParamCount, I: word;
  pFields, pFld: pFLDDesc;
  pRecBuf, pRec: pBYTE;
  Found, SelfInitialized: boolean;
  rslt: DBIResult;

begin

  {$Ifdef WIN32}

  hCfg := nil; pFld := nil; pRec := nil; Found := False; SelfInitialized := False;
  try
    if Pos(';', Param) = 0 then
      raise EDatabaseError.Create('Invalid parameter passed to function.  There must ' +
         'be a semi-colon delimited sting passed');
    Path := Copy(Param, 0, Pos(';', Param) - 1);
    Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', Param));
    rslt := DbiGetSysConfig(Config);

    if rslt <> DBIERR_NONE then
    begin
      if rslt = DBIERR_NOTINITIALIZED  then // Engine not initialized error...
      begin
        SelfInitialized := True;
        DbiInit(nil);
        Check(DbiGetSysConfig(Config));
      end
      else
        Check(rslt);
    end;

    Check(DbiOpenConfigFile(Config.szIniFile, FALSE, hCfg));
    Check(DbiCfgGetRecord(hCfg, PChar(Path), ParamCount, nil, nil));

    pFields := AllocMem(ParamCount * sizeof(FLDDesc));
    pFld := pFields;
    pRecBuf := AllocMem(10000);
    pRec := pRecBuf;

    { Get the node values... }

    Check(DbiCfgGetRecord(hCfg, PChar(Path), ParamCount, pFields, pRecBuf));

    for I := 0 to ParamCount - 1 do
    begin
      if pFields^.szName = Option then
      begin
        StrPCopy(PChar(pRecBuf), Value);
        Check(DbiCfgModifyRecord(hCfg,  PChar(Path), ParamCount, pFld, pRec));
        Found := True;
      end;

      Inc(pFields);
      Inc(pRecBuf, 128);
    end;

    if Found = False then
      raise EDatabaseError.Create(Param + ' entry was not found in configuration file');

  finally
    if pFld <> nil then
      FreeMem(pFld);
    if pRec <> nil then
      FreeMem(pRec);

    if hCfg <> nil then
    Check(DbiCloseConfigFile(hCfg, TRUE, TRUE, FALSE));

    if SelfInitialized = True then
      DbiExit;
  end;

  {$Else}
     raise EDatabaseError.Create('Non supported function in 16 bit');
  {$EndIf}

end;

p.s. the Borland community site seems to have a lot of tips on getting the best out of the BDE. http://community.borland.com

regards

Jo
0
 

Author Comment

by:RalphPorter
ID: 6228036
Hi Jo,

     Sorry for the delay, I couldn't seem to get on the server for some reason. Anyway thanks for the informative answer I have taken your advice and now of course I must wait to see if the problem is resolved or not. Thanks again.

Best Regards,

        Ralph.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 139
Show Listview image from database (String field) 5 113
Delphi Form ownership 4 73
How to define IfThen functions in one common unit? 4 44
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now