Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Copy/delete a BDE table Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Copy/delete a BDE table 25-Aug-02
Category
BDE
Language
Delphi 2.x
Views
115
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 
Copy/delete a BDE table

Answer:

Here is an example of a routine that I use for copying and deleting tables. It uses 
DB, DBTables, DbiProcs,DbiErrs, and DbiTypes.

You simply provide the directory to copy from, the source table name, the directory 
to copy to, and the destination table name, and the BDE will copy the entire table, 
indexes and all to the new file.

The delete function takes the path to delete from and the name of the table to 
delete, the BDE takes care of deleting all associated files (indexes, etc.).

These procedures have been pulled off a form of mine, and I've edited them to 
remove some dependencies that existed with that form. They should now be completely 
stand-alone.

1   procedure TConvertForm.CopyTable(FromDir, SrcTblName, ToDir, DestTblName: 
2   string);
3   var
4     DBHandle: HDBIDB;
5     ResultCode: DBIResult;
6     Src, Dest, Err: array[0..255] of Char;
7     SrcTbl, DestTbl: TTable;
8   begin
9     SrcTbl := TTable.Create(Application);
10    DestTbl := TTable.Create(Application);
11    try
12      SrcTbl.DatabaseName := FromDir;
13      SrcTbl.TableName := SrcTblName;
14      SrcTbl.Open;
15      DBHandle := SrcTbl.DBHandle;
16      SrcTbl.Close;
17      ResultCode := DbiCopyTable(DBHandle, false,
18        StrPCopy(Src, FromDir + '\' + SrcTblName), nil,
19        StrPCopy(Dest, ToDir + '\' + DestTblName));
20      if ResultCode <> DBIERR_NONE then
21      begin
22        DbiGetErrorString(ResultCode, Err);
23        raise EDatabaseError.Create('While copying ' +
24          FromDir + '\' + SrcTblName + ' to ' +
25          ToDir + '\' + DestTblName + ', the '
26          + ' database engine   generated the error '''
27          + StrPas(Err) + '''');
28      end;
29    finally
30      SrcTbl.Free;
31      DestTbl.Free;
32    end;
33  end;
34  
35  procedure TConvertForm.DeleteTable(Dir, TblName: string);
36  var
37    DBHandle: HDBIDB;
38    ResultCode: DBIResult;
39    tbl, Err: array[0..255] of Char;
40    SrcTbl, DestTbl: TTable;
41  begin
42    SrcTbl := TTable.Create(Application);
43    try
44      SrcTbl.DatabaseName := Dir;
45      SrcTbl.TableName := TblName;
46      SrcTbl.Open;
47      DBHandle := SrcTbl.DBHandle;
48      SrcTbl.Close;
49      ResultCode := DbiDeleteTable(DBHandle,
50        StrPCopy(Tbl, Dir + '\' + TblName), nil);
51      if ResultCode <> DBIERR_NONE then
52      begin
53        DbiGetErrorString(ResultCode, Err);
54        raise EDatabaseError.Create('While deleting ' +
55          Dir + '\' + TblName + ', the database ' +
56          'engine generated the error ''' + StrPas(Err) + '''');
57      end;
58    finally
59      SrcTbl.Free;
60    end;
61  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC