Corrupt Index Delphi 4/Paradox7

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.
RalphPorterAsked:
Who is Participating?
 
nnbbb09Commented:
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
 
RalphPorterAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.