Elegant BDE (1)
(Copyright Notice: This article is for 9CBS only, please contact the author or 9CBS connection with the author or 9cbs) BDE is the abbreviation of Borland Database Engine, that is, the data engine of Balan, she is the earliest introduced database connection technology introduced, but the soil, she is now Falling to the point where there are very people who have recently developed a pardox database, using BDE, revisit the old dream, think that the BDE elegant temperament is still, the management of the database is not poor than ADO, and simple and convenient. Let us take a look at our old friends. J
First, the alias mechanism of the database
Alias is the name used to represent a database resource. Simply put to tell you what type of library you use (BDE clearly call what API is handled), the name of the library (which is clear, where is your library, where is the location), etc. A series of connected Parameters.
It's just this alias, I think the connection with the database is also convenient than ADO!
It is actually very simple to create the BDE Administrator. It can be seen that the main window of the BDE Administrator consists of two panels: the panel on the left includes two tabs, where Database is used to manage the data alias, Configuration is used to manage BDE's database driver and some global parameter settings. Here we put the cursor on the Database list item of the Database tab, click New NEW in the shortcut menu (in the above menu, you can also find her), you can transfer the new database album dialog box, in the pop-up NEW Database alias will let you select the name of the database driver through the drop-down box, and then click OK. Of course, this alias is the system default, you can modify it. At this time, the newly created alias is automatically entered, and you can edit the alias. After the editing is complete, right-click this alias, select Apple in the shortcut menu, and click Ok in the pop-up dialog, this You can save the modifications made in front. Delete Don't tell me, don't you click this alias, look at there is a guy called Delete in the shortcut menu: P
Second, the establishment and deletion of the table
The establishment and deletion of the table is the key to the database operation, and in the unified form of BDE, it has brought great convenience to our programming, because at this time, I don't have to consider too many types of libraries he is, I don't know how much I have to bring us only.
This article focuses on the establishment and deletion of the table under TTABLE.
Creative Creatable
Let's take a look at the sample program:
// ..........
If (! tblmyTable-> EXISTS) // check the form exist, exists is used to see if the table exists, existence returns TRUE
{
TBLMYTABLE-> Active = false; // Modify table must be closed
TBLMYTABLE-> DatabaseName = "bcdemos"; // Set the alias
TBLMYTABLE-> TableType = TTPARADOX; / / Setting Table, the table is the Paradox database
TBLMYTABLE-> TABLENAME = "MyTable"; // Set the name of the table
TBLMYTABLE-> Fielddefs-> Clear (); // Clear the existing data segment definition
TBLMYTABLE-> Fielddefs-> Add ("Field1", ftinteger, 0, true); // Add fields to the table
............ // Add other fields for the table
TBLMYTABLE-> CLEXDEXFS-> CLEAR (); // Clear index definition TBLMYTABLE-> Indexdexfs-> add ("", "field1", TINDEXOPTIONS () << ixprimary << ixunique); // Add Index Definition
............ // Add other index definitions
TBLMYTABLE-> CREATETABLE (); // Create a table in the format above
}
// ..........
Let's take a look at the definition and usage of two adds:
Add Field Add
Void_fastcall add (const onstercall, tfieldtype dattype, int size, bool reauired);
Name is used to specify the field name;
DataType is used to specify the type of fields, with 36 species such as ftunknown, ftstring, ftsmallint, ftinteger, ftword, ftboolean, ftfloat, and ftcurrency. Note that the field type must be defined by BCB;
Size specifies field dimensions;
Required is used to specify whether the field is allowed to be non-empty.
Add an indexed Add
Void_fastcall add (const around, constings, tindexoptions);
N Name used to specify the name of the index created;
F is used to specify the fields you need to use (multiple fields are separated by semicolons);
Options is used to specify the requirements that must meet the fields listed in the parameter f. It is a set type variable that can take several values such as IxPrimary, Ixunique, IxDescending, IxExpression, IxcaseInSitive, and Ixnonmaitained.
Delete the deleteTable, which is as follows:
Void _fastcall deleteTable (void);
Let's take a look at the example:
Void _fastcall tfrmmain :: btndeleteclick (TOBJECT * SENDER)
{
IF (tblmyTable-> Active) // Check if a table is opened
TBLMYTABLE-> Active = false; // Turn the table first
TBLMYTABLE-> DatabaseName = DatabaseName; // Specify the alias of the library
TBLMYTABLE-> TABLENAME = "MyTable '; // Name of the specified table
IF (tblmyTable-> EXISTS) // look at whether it is present
TBLMYTABLE-> deleteTable (); // Delete this table
}
(Fail)