How to lose weight to table in BCB

Source: Internet
Author: User
Tags dbase pack table name

Using BCB for multimedia database development It is often found that when you delete a record from the table, the size of the file is not reduced accordingly. This makes the table file more and more large after you insert the deletion multiple times. This behavior occurs because the Ttable control's Delete method does not actually delete records from the table, but only adds a deletion flag before the record. The table is compressed with a pack statement in dBASE and FoxPro, but there are no corresponding functions in the Ttable class. In fact, the BDE API functions have provided dbipacktable to compress dBASE or FoxPro tables, but this function does not work for Paradox tables. To give the Paradox table to lose weight to use the Dbidorestructure function to complete, the following routine completes the Pack Paradox table function.

This function Pack the Paradox table. Write by Zodiac
void __fastcall TForm1::P ackparadoxtable (hdbidb HDB, ansistring tblname)
{
Paradox table use a quite different way to be packed than
DBase or Foxpro table, it use the dbidorestructure is not the
Dbipacktable
Dbiresult rslt;
Crtbldesc Tbldesc;
Filled the structure Crtbidesc with 0
memset ((void *) &tbldesc,0,sizeof (CRTBLDESC));
Copy the table name and type to the structure
lstrcpy (Tbldesc.sztblname,tblname.c_str ());
lstrcpy (Tbldesc.sztbltype,szparadox);
Set Bpack to True to specify Pack Function
Tbldesc.bpack=true;
Pack the table
Rslt=dbidorestructure (Hdb,1,&tbldesc,null,null,null,false);
if (Rslt!=dbierr_none)
Application->messagebox ("Cannot compress table", "Compress data table error", mb_iconerror);
}

Note that the table must be closed before restructure. The following routine calls Packparadoxtable.

void __fastcall TForm1::P acktable (ansistring table_name)
{
Pack the table
Ttable *temp_table=new ttable (FORM1);
Temp_table->databasename= "Yourdatabasealias";
temp_table->tablename=table_name;
temp_table->exclusive=true;
Temp_table->open ();
Get the Database Handle
Hdbidb hdb=temp_table->dbhandle;
Temp_table->close ();
Packparadoxtable (Hdb,table_name);
Temp_table->close ();
Temp_table->free ();
}

For FoxPro and dBASE packs See the Dbipacktable function description of the BDE API help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.