Board index » delphi » D1: Problem with creating indexes after BatchMove

D1: Problem with creating indexes after BatchMove

Quote
Jonas Gunnarsson wrote:

> Hi!

> I have a database with a lots of tables, and indexes. When using TBatchMove
> to copy tables to a different location(directory) the indexes is missing, so
> I thought the DbiRegenIndexes should do the trick, but some thing is wrong;
> Table property Exclusive is set to True when created, and all databases is
> closed in current session

>   procedure RegenIndexes(TblName: TTable);
>   begin
>     Check(DbiRegenIndexes(TblName.Handle));
>   end;

> my code to call the procedure have two tables one original-table and one
> archive-table and one orginal-to-archive-batchmove instance. All tables in
> TablesList have atleast one primary and one secondary index. Some tables
> also have referential integrity between eatch other, the code snip is;

>     for index:= 0 to TablesList.Count - 1 do
>     begin
>       CurrentTableName:= TablesList.Strings[index];
>       OrgTable.TableName:= CurrentTableName;
>       ArcTable.TableName:= CurrentTableName;
>       OrgTable.Open;
>       {PackTable(OrgTable);}
>       Org2ArcBatchMove.Execute;
>       OrgTable.Close;
>       ArcTable.Open;
>       RegenIndexes(ArcTable);
>       ArcTable.Close;
>     end;

> --
> Jonas

The BatchMove does not copy the indexes. If you need to have a new copy
of the table, you need something like the following.

procedure copytable(src,dest:ttable);
begin
        if src.active then src.Close;
        src.fieldDefs.Update;
        src.IndexDefs.Update;
        dest.fieldDefs.Assign(src.FieldDefs);
        dest.IndexDefs.Assign(src.IndexDefs);
        dest.CreateTable;
end;
Dave

 

Re:D1: Problem with creating indexes after BatchMove


Hi!

I have a database with a lots of tables, and indexes. When using TBatchMove
to copy tables to a different location(directory) the indexes is missing, so
I thought the DbiRegenIndexes should do the trick, but some thing is wrong;
Table property Exclusive is set to True when created, and all databases is
closed in current session

  procedure RegenIndexes(TblName: TTable);
  begin
    Check(DbiRegenIndexes(TblName.Handle));
  end;

my code to call the procedure have two tables one original-table and one
archive-table and one orginal-to-archive-batchmove instance. All tables in
TablesList have atleast one primary and one secondary index. Some tables
also have referential integrity between eatch other, the code snip is;

    for index:= 0 to TablesList.Count - 1 do
    begin
      CurrentTableName:= TablesList.Strings[index];
      OrgTable.TableName:= CurrentTableName;
      ArcTable.TableName:= CurrentTableName;
      OrgTable.Open;
      {PackTable(OrgTable);}
      Org2ArcBatchMove.Execute;
      OrgTable.Close;
      ArcTable.Open;
      RegenIndexes(ArcTable);
      ArcTable.Close;
    end;

--
Jonas

Re:D1: Problem with creating indexes after BatchMove


Quote
>I have a database with a lots of tables, and indexes. When using TBatchMove
>to copy tables to a different location(directory) the indexes is missing, so
>I thought the DbiRegenIndexes should do the trick, but some thing is wrong;
>Table property Exclusive is set to True when created, and all databases is
>closed in current session

No.  There is no index to regenerate.  batchmove does not copy indexes
To coapy a table and its indexes use dbiCopyTable  (see BDE32.hlp)

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:D1: Problem with creating indexes after BatchMove


Hi,

The BDE32.hlp, dbiCopyTable says;

Usage

This function is used to copy tables of the same driver type. It cannot copy
a table across databases or driver types. To transfer data from one database
type to another, see DbiBatchMove.

So, I guess you can't use dbiCopyTable to copy to a new location(dir) ?

Is there a BDE16.hlp-file?

--
Jonas

Brian Bushay TeamB skrev i meddelandet
<3748ff6f.7737...@forums.borland.com>...

Quote

>>I have a database with a lots of tables, and indexes. When using
TBatchMove
>>to copy tables to a different location(directory) the indexes is missing,
so
>>I thought the DbiRegenIndexes should do the trick, but some thing is
wrong;
>>Table property Exclusive is set to True when created, and all databases is
>>closed in current session

>No.  There is no index to regenerate.  batchmove does not copy indexes
>To coapy a table and its indexes use dbiCopyTable  (see BDE32.hlp)

>--
>Brian Bushay (TeamB)
>Bbus...@NMPLS.com

Re:D1: Problem with creating indexes after BatchMove


Dave,
The code you suggested works fine for the first table, the next I get error
"Index already exist" Index ByLonChannel, the two tables is like

Lon_type.db
  *Lon_channel_type :A16
  +Name :A50

Domain.db
  *Domain :A16
  +Name :A50
  +Lon_channel_type :A16

where * is primaryindex and + is secondaryindex(all my tables use
referentialintegrity)

any tip?

--
Jonas

Dave Bolt skrev i meddelandet <3738AFED.6...@compuserve.com>...

Quote
>Jonas Gunnarsson wrote:

>> Hi!

>> I have a database with a lots of tables, and indexes. When using
TBatchMove
>> to copy tables to a different location(directory) the indexes is missing,
so
>> I thought the DbiRegenIndexes should do the trick, but some thing is
wrong;
>> Table property Exclusive is set to True when created, and all databases
is
>> closed in current session

>>   procedure RegenIndexes(TblName: TTable);
>>   begin
>>     Check(DbiRegenIndexes(TblName.Handle));
>>   end;

>> my code to call the procedure have two tables one original-table and one
>> archive-table and one orginal-to-archive-batchmove instance. All tables
in
>> TablesList have atleast one primary and one secondary index. Some tables
>> also have referential integrity between eatch other, the code snip is;

>>     for index:= 0 to TablesList.Count - 1 do
>>     begin
>>       CurrentTableName:= TablesList.Strings[index];
>>       OrgTable.TableName:= CurrentTableName;
>>       ArcTable.TableName:= CurrentTableName;
>>       OrgTable.Open;
>>       {PackTable(OrgTable);}
>>       Org2ArcBatchMove.Execute;
>>       OrgTable.Close;
>>       ArcTable.Open;
>>       RegenIndexes(ArcTable);
>>       ArcTable.Close;
>>     end;

>> --
>> Jonas
>The BatchMove does not copy the indexes. If you need to have a new copy
>of the table, you need something like the following.

>procedure copytable(src,dest:ttable);
>begin
> if src.active then src.Close;
> src.fieldDefs.Update;
> src.IndexDefs.Update;
> dest.fieldDefs.Assign(src.FieldDefs);
> dest.IndexDefs.Assign(src.IndexDefs);
> dest.CreateTable;
>end;
>Dave

Re:D1: Problem with creating indexes after BatchMove


Hi!

dbiCopyTable works across databases, my code for D1 is

  procedure CopyTable(hTmpDb: hDbiDb; SrcTableName, DestTableName:
TFileName);
  var
    pszSrcTableName, pszDestTableName: array[0..79] of Char;
  begin
    FillChar(pszSrcTableName, sizeof(pszSrcTableName), 0);
    StrPCopy(pszSrcTableName, SrcTableName);
    FillChar(pszDestTableName, sizeof(pszDestTableName), 0);
    StrPCopy(pszDestTableName, DestTableName);
    Check(DbiCopyTable(hTmpDb, True, pszSrcTableName, nil,
pszDestTableName));
  end;

and my call is

    for index:= 0 to TablesList.Count - 1 do
    begin
      CurrentTableName:= NormalTablesList.Strings[index];
      OrgTable.TableName:= CurrentTableName;
     { ArcTable.TableName:= CurrentTableName;}
      OrgTable.Open;
      CopyTable(OrgTable.dbhandle,
                OrgDatabasePath+'\'+CurrentTableName,
                ArcDatabasePath+'\'+CurrentTableName);
      OrgTable.Close;
    end;

--
Jonas

Re:D1: Problem with creating indexes after BatchMove


Quote
>So, I guess you can't use dbiCopyTable to copy to a new location(dir) ?

you can use it to copy a table to another directory.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads