Solved

Corrupt Index Delphi 4/Paradox7

Posted on 2001-06-21
2
972 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

21 Experts available now in Live!

Get 1:1 Help Now