Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 7 of 7 total |
Best way to erase all tables linked to database |
Sun, May 17 2009 7:32 PM | Permanent Link |
Kai | Hi ~
what is the best way to physically delete all tables linked to a TDBIsamDatabase, regardless of whether they are open or not. Loop though the components in my datamodule or is there something better at the DBIsam level? TIA Kai |
Tue, May 19 2009 4:02 PM | Permanent Link |
"Jeff Cook" | Kai wrote:
> Hi ~ > > what is the best way to physically delete all tables linked to a > TDBIsamDatabase, regardless of whether they are open or not. > Loop though the components in my datamodule or is there something > better at the DBIsam level? > > TIA > Kai Kia Orana Kai Looking at the v3 manual, you can use GetTableNames to get a list of tables in the database, so something like ... var i: integer; sl: TStringList; begin sl := TStringList.Create; try Database1.GetTableNames(sl,False); Query1.SQL.Clear; for i := 0 to sl.count -1 do Query1.SQL.Add('DROP TABLE ' + sl[i] + ';'); Query1.ExecSQL; finally sl.Free; end; end; Kia Manuia Jeff ============ Manual extract ============================ procedure GetTableNames(List: TStrings; SystemTables: Boolean = False); Populates a string list with the names of tables in the database. Description Call GetTableNames to retrieve a list of tables in the associated database. List is a TStrings descendant that receives the table names. Any existing strings are deleted from the list before GetTableNames adds the names of all tables in the database. SystemTables specifies whether the list of table names should include only the database's system tables. If SystemTables is True, only the system tables are added to List. If SystemTables is False, the list is filled with ordinary tables. For example, the following line fills a list box with the names of all tables in the database: Database1.GetTableNames(ListBox1.Items, False); Populates a string list with the names of tables in the database. procedure GetTableNames(List: TStrings; SystemTables: Boolean = False); Description Call GetTableNames to retrieve a list of tables in the associated database. List is a TStrings descendant that receives the table names. Any existing strings are deleted from the list before GetTableNames adds the names of all tables in the database. SystemTables specifies whether the list of table names should include only the database's system tables. If SystemTables is True, only the system tables are added to List. If SystemTables is False, the list is filled with ordinary tables. For example, the following line fills a list box with the names of all tables in the database: Database1.GetTableNames(ListBox1.Items, False); -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Tue, May 19 2009 4:05 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Kai,
<< what is the best way to physically delete all tables linked to a TDBIsamDatabase, regardless of whether they are open or not. Loop though the components in my datamodule or is there something better at the DBIsam level? >> Well, you can't delete a table if it's open, but here's an easy way to handle it: var TablesList: TStrings; I: Integer; TempTable: TDBISAMTable; begin TablesList:=TStringList.Create; try TempTable:=TDBISAMTable.Create(nil); try Session.GetTableNames('MyDatabase',TablesList); for I:=0 to TablesList.Count-1 do begin TempTable.DatabaseName:='MyDatabase'; TempTable.TableName:=TablesList[I]; TempTable.DeleteTable; // You could put a try..except around this end; finally FreeAndNil(TempTable); end; finally FreeAndNil(TablesList); end; end; That code will ensure that all tables in the database are deleted, provided that they are closed. -- Tim Young Elevate Software www.elevatesoft.com |
Tue, May 19 2009 6:37 PM | Permanent Link |
"Robert" | "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message news:BDD9C829-753F-41D2-83C6-5BC3F344DF23@news.elevatesoft.com... > > Well, you can't delete a table if it's open, What's wrong with Database.CloseDatasets? Before you go thru the delete loop. Robert |
Thu, May 21 2009 3:24 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Robert,
<< What's wrong with Database.CloseDatasets? Before you go thru the delete loop. >> There's nothing wrong with it at all, but it will not deal with the issue of another session or user having the table open. It was not possible to tell by the description of the issue whether "open" meant "open by this process only" or "open by any process or session". -- Tim Young Elevate Software www.elevatesoft.com |
Thu, May 21 2009 5:58 PM | Permanent Link |
"Robert" | "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message news:BFAEE24E-5BA1-4257-9CAA-3FF473FCDAA4@news.elevatesoft.com... > Robert, > > << What's wrong with Database.CloseDatasets? Before you go thru the delete > loop. >> > > There's nothing wrong with it at all, but it will not deal with the issue > of another session or user having the table open. It was not possible to > tell by the description of the issue whether "open" meant "open by this > process only" or "open by any process or session". > Hmmm, I assumed that if you go around deleting tables, it means you have exclusive access to the database. Never assume nothing, I guess. Robert |
Tue, May 26 2009 1:05 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Robert,
<< Hmmm, I assumed that if you go around deleting tables, it means you have exclusive access to the database. Never assume nothing, I guess. >> A lot of applications create tables that are, in effect, somewhat permanent and somewhat temporary, meaning that they exist in the database but may be only used by a certain type of client application, and may be altered or dropped/recreated in certain cases. -- Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Sunday, May 19, 2024 at 08:46 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |