Develop database programs three

zhaozj2021-02-11  164

1. Establishing a temporary table data entry is an inevitable link to develop database programs. 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: Use Query Controls Step 1: Place the Query Control (TQuery) on the form, 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. 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' This temporary table is established.

Method 2: Use code to create a temporary table the following code: function CreateTableInMemory (const AFieldDefs: TFieldDefs): TDataSet; var TempTable: TClientDataSet; begin TempTable: = nil; Result: = nil; if AFieldDefs <> nil then begin try TempTable: = TClientDataSet .Create (application); tempTable.fielddefs.assign (Afielddefs); Temptable.created; Result: = (Temptable as tdatan); Except if Temptable <> nil damptable.free;

Result: = nil; raise; end end

Used in the program: procedure tform1.button1click (sender: TOBJECT); var adtataset: tdatanet; begin adtaset: = tdatanet.create (self); with adataset.fielddefs do begin add ('name', ftstring, 30, FALSE); Add ('Value', ftinteger, 0, false);

WITH DATASOURCE1 Do Begin DataSet: = CreateTableInMemory (adtaset.fielddefs); dataset.open;

Adataset.free;

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 the database program is distributed, you need to carry the data engine (BDE, SQL LINK), and you need to configure the data engine 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. For example: [IDAPI alias] Usesname = sysdba password = masterkey installer After the data engine is completely configured.

3. Using the function programmer in the Interbase database, when using InterBase as a background database, it is inconvenient to provide the function (only four), and the complex stored procedure cannot be easily prepared. 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 also write functions to expand Interbase.

转载请注明原文地址:https://www.9cbs.com/read-5170.html

New Post(0)