Establish a temporary table
Data input is an inevitable link to the development of the database program. In the Client / Server structure, the client may be submitted to the server's background database, which requires the local (client) to establish a temporary data table to store data input data, after submit, clear Local table data. The advantage of this method is to improve input efficiency and reduce network burden.
Since the data amount of the user is in a general case (no more than hundreds of records), the temporary table can be built in memory so that the processing speed is faster.
Method 1: Using Query Controls (TQuery)
Step 1: Place the query control (TQuery) on the form and set the connected data sheet.
Step 2: Make TQuery. Cachedupdates = true;
TQuery. RequestLive = TRUE
Step 3: Add a WHERE child statement after the original SQL statement, requiring the result of the SQL query after adding this WHERE child statement.
E.g:
Select Biolife. "Species no", Category, Common_Name, Biolife. "Species Name", Biolife. "Length (cm)", Length_IN, Notes, Graphic
From "biolife.db" Biolife
Where biolife.category = 'a' and biolife.category = 'b'
Such a temporary table is established.
Method 2: Create a temporary table using code
code show as below:
Function CreateTableInMemory (const Afielddefs: tfielddefs): TDataSet;
VAR
Temptable: TclientDataSet;
Begin
Temptable: = NIL;
Result: = NIL;
IF Afielddefs <> nil dam
Begin
Try
Temptable: = TclientDataSet.create (Application);
Temptable.fielddefs.assign (AfieldDefs);
Temptable.created;
Result: = (Temptable as TdataSet);
Except
IF Temptable <> nil dam
Temptable.free;
Result: = NIL;
Raise;
end
end
END;
Use it in the program as follows:
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Adataset: TDataSet;
Begin
Adataset: = TDataSet.create (Self);
With adataset.fielddefs do
Begin
Add ('Name', FTString, 30, False);
Add ('Value', Ftinteger, 0, False);
END;
With datasource1 do
Begin
DataSet: = CreateTableInMemory; Adataset.fieldDefs;
DataSet.open;
END;
Adataset.free;
END;
Temporary table creation is completed.
Method 1 is simple, but since the query control is used to empty the data, you need to query the server backbench database, so the speed is slightly slow, and it is not applicable to the status of the fields of the temporary table by the fields of several data tables. Method 2 has a wide range of applications, fast, but needs to write code. (The method of using TfieldDefs is very simple, see Delphi's online help). 2. Configure the data engine (BDE, SQL LINK)
When database programs are distributed, you need to carry data engine (BDE, SQL LINK), and configure data engines after the client is installed, such as username, password (password), etc. If manually configured, the workload is relatively large (depending on the number of clients). The installshield for delphi does not seem to have this option. In fact, installshield for delphi can do it, there is a * .iwz text file in the directory of the installer, as long as it is manually added in the [Idapi Alias] clip. E.g:
[IDAPI Alias]
Usesname = sysdba
Password = MasterKey
The data engine is automatically configured after the installer.
3. Use functions in the InterBase database
Programmers may be inconvenient to use interbase as a backend database (only four), which cannot be easily written in a complex stored procedure. Interbase itself cannot write a function, but it can use an external function (call the function in the DLL). The following example shows how to declare the substr function in InterBase.
Declare External Function Substr
CString (80), Smallint, Smallint
Returns cstring (80)
Entry_point "ib_udf_substr" module_name "ib_udf"
Where: Module_name is the name of the DLL, entry_point is the function name.
You can use it after the declaration, for example:
SELECT SUBSTR (Country)
From country
This example uses the IBLocal database that comes with Delphi installation. Users can write functions themselves to expand Interbase