1. Create a temporary table
Data input is an inevitable link in developing database programs. In the Client/Server structure, the client may have to enter a batch of data before submitting it to the server's backend database. This requires a temporary data table to be established locally (client) to store the data entered by the user. After submission, clear the data after being submitted. Local table data. The benefits of this method are: improve input efficiency and reduce network burden.
Since the amount of data entered by a user at a time is generally small (not more than a few hundred records), temporary tables can be built in memory, which makes the processing faster.
Method 1: Use the query control (TQuery)
Step 1: Put the query control (TQuery) on the form and set the connected data table.
Step 2: Make TQuery. CachedUpdates=True;
TQuery. RequestLive=True
Step 3: Add a Where substatement after the original SQL statement, and ask that the SQL query result is empty after adding this Where substatement.
For example:
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′
In this way, the temporary table is established.
Method 2: Create temporary tables using code
The code is as follows:
function CreateTableInMemory(const AFieldDefs:TFieldDefs):TDataSet;
var
TempTable: TClientDataSet;
Begin
TempTable:=nil;
Result:=nil;
if AFieldDefs$#@60;$#@62;nil then
Begin
try
TempTable:=TClientDataSet.Create(application);
TempTable.FieldDefs.Assign(AFieldDefs);
TempTable.CreateDataSet;
Result:=(TempTable as TDataSet);
Except
if TempTable$#@60;$#@62;nil then
TempTable.Free;
Result:=nil;
raise;
end
end
end;
In the program, use it 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(′ ue′,ftInteger,0,False);
end;
with DataSource1 do
Begin
DataSet:=CreateTableInMemory(ADataSet.FieldDefs);
DataSet.Open;
end;
ADataSet.Free;
end;
Temporary table creation is complete.
Method 1 is simple to use, but because the query control is used to query the server backend database when clearing data, the speed is slightly slower, and it is not suitable for situations where each field in a temporary table is pieced together by several data table fields. Method 2 has a wide range of applications and fast speed, but requires writing code. (The usage method of TFieldDefs in the code is very simple, see Delphi's online help).
2. Configure the data engine (BDE, SQL Link)
When distributing database programs, you need to carry a data engine (BDE, SQL Link), and after the client installs the program, you also need to configure a data engine, such as username, password (PassWord), etc. If manually configured, the workload is relatively large (depending on the number of clients).
[IDAPI Alias]
usesname=SYSDBA
password=masterkey
After installing the program, the data engine is automatically configured.
3. Use functions in InterBase database
Programmers may feel inconvenient (only four) when using InterBase as a background database when they provide too few functions (only four) and cannot easily write complex stored procedures. InterBase itself cannot write functions, but it can use external functions (called functions in 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 and ENTRY_POINT is the function name.
It can be used after declaration, for example:
select SUBSTR(country)
from country
This example uses the IBLocal database that comes with Delphi installation. Users can also write functions themselves to expand InterBase. For more content, please see the database related article topics, or