Delphi Examples: DbiQExec

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiQExec

Return to chapter overview

Create a table on disk by using a given SQL statement.

The filename is also passed as the parameter TblName. The function returns the number of rows in the result table. This example uses the following input:

 fDbiQExec(Database1.Handle, 'QUERY.DB', 'SELECT * FROM TEST;');

 fDbiQExec(Table1.DBHandle, 'QUERY2.DB', 'SELECT * FROM CUSTOMER');

 

The function is:

function fDbiQExec(hTmpDb: hDBIDB; TblName, SQL: String): Longint;

var

 hStmt: hDBIStmt;

 hQryCur, hNewCur: hDBICur;

 iRecCount: LongInt;

begin

 hQryCur := nil;

 hNewCur := nil;

 hStmt := nil;

try

   Check(DbiQAlloc(hTmpDb, qrylangSQL, hStmt));

   Check(DbiQPrepare(hStmt, PChar(SQL)));

   Check(DbiQExec(hStmt, @hQryCur));

   Check(DbiQInstantiateAnswer(hStmt, hQryCur, PChar(TblName), szPARADOX,

     True, @hNewCur));

   Check(DbiGetRecordCount(hNewCur, iRecCount));

   Result := iRecCount;

finally

  if (hStmt <> nil) then

     Check(DbiQFree(hStmt));

  if (hNewCur <> nil) then

     Check(DbiCloseCursor(hNewCur));

end;

end;