18th Chapter-delphi Client Server application Development (III.) (3)

Source: Internet
Author: User
Tags aliases database join join joins table name

18.3.1.2 Custom Database Server registration parameters

Most database servers contain security features that restrict database access. Typically, the server requires a registered username and password before the user can access the database.

If the server needs to be registered, in the design phase, Delphi prompts you when you try to join, such as when the ttable part describes the database table name.

By default, the Delphi application displays the standard registration dialog when it opens a connection to the database server. If the join is established, the Registration dialog box does not appear.

Server registration can be handled in the following ways:

1. Set the Loginprompt property of the Tdatabase part to true. This allows the standard Registration dialog box to open when an application attempts to establish a database join.

2. Set the Loginprompt property to False and include the username and password parameters in the params property of the tdatabase part. For example:

USERNAME = SYSDBA

PASSWORD = Mosterkey

However, this method is not recommended because it can compromise database security

3. Use the Tdatabase part's Onlogin event to set the registration parameters. The Onlogin event gets a copy of the Tdatabase registration parameter array and uses the values attribute to change these parameters. Such as:

loginparams.values[' SERVER NAME ': = ' myservername ';

loginparams.values[' USER NAME ']: = ' myuername ';

loginparams.values[' PASSWORD ']: = ' mypassword ';

These parameters are used to establish a join when the control returns from the database registration event handling process.

18.3.1.3 Create application-specific aliases

The tdatabase aliases describes the location of the database table and the connection parameters of the database server. Usually outside of Delphi, the BDE Configuration tool (BDECFG32) is used. EXE), and the alias is present in the BDE configuration file idapi32.cfg.

Users can also use Tdatabase to create aliases that are available only in the application, and aliases created with Tdatabase are not added to the BDE configuration file. Any dataset part can use these aliases by describing the DatabaseName property. To customize the parameters of these local aliases, double-click the Tdatabase part with the left mouse button or select database Editor,delphi from the tdatabase part to open the Data Properties Editor (db property Editor).

18.3.1.4 controls the connection of the database

The connected property of the tdatabase part, indicating whether the tdatabase part establishes a join to the database server. Connected is set to True when the application opens a table in the database. Setting the connected to true establishes a connection to the database.

1. Maintain database joins

The Tdatabase Keepconnection property describes whether you want to join a database when there is no database table open.

If your application needs to turn off multiple tables more than once in a single database, keepconnection to True can give your application better performance.

When Keepconnection is true, the application can maintain a join of the database even if no table is open. You can then open and close the database table repeatedly without having to register each join.

2. Use Tsesstion control join

The tsesstion part has a keepconnections attribute that is oriented to the entire application. If Session.keepconnections is true, the database joins for all tdatabase parts are persistent.

TSession provides global control of database joins for applications. The Databases property in TSession is an array of all active databases in the session, and the Databasescount property describes the number of active databases.

3. Description NET and Private directory

The TSession netfiledir attribute describes the path to the BDE network control directory. The TSession Privatedir Property Description stores the path to the directory that handles temporary files that handle local SQL expressions.

18.3.1.5 Get Database Information

TSession has many information about the user getting the database, and each method takes the tstringlist part as an incoming parameter and returns the information to Tstringlist.

1. Getaliasnames method

Statement: Procedure Getaliasnames (list:tstringlist);

The Getaliasnames method eliminates the parameters in the list and writes the names of all the defined BDE aliases to the list. Application-generated aliases are not included.

2. Getaliasparams method

Statement: Procedure Getaliasparams (const aliasname:string; List:tstringlist);

The Getaliasparams method clears the contents of the list and writes the BDE alias to the list for Alianame parameters.

3. Getdatabasenames method

Statement: Procedure Getdatabasenames (list:tstrings);

The Getdatabasenames method clears the contents of the list and writes the names of all BDE aliases and application-defined aliases to the list.

4. Getdrivernames method

Statement: Procedure Getdrivernames (list:tstrings);

The Getdrivernames method clears the contents of the list and writes BDE the currently installed driver name to the list.

5. Getdriverparams method

Statement: Procedure Getdriverparams (const drivername:string; List:tstrings);

The Getdriverparams method eliminates the contents of the list and writes the default parameter named DriveName driver to the list.

6. Gettablenames method

Statement: Procedure Gettablenames (const DatabaseName, pattern:strings;

Extensions, Systemtable:boolean; List:tstrings);

The Gettablenames method eliminates the contents of the list and writes the names of all the tables in the database named DatabaseName to the list. The pattern parameter restricts the table name. For SQL Servers, setting Systemetables to True will get system tables and user tables. For non-SQL databases, setting extensions to True will include the extension in the table name.

18.3.2 Processing Client/server Transaction control

There are two ways to manage transaction control in database applications that use implicit control and display control:

Using the properties and methods of Tdatabase components for explicit control

Using transitive SQL control transactions for tquery parts

Delphi also supports local transaction processing for Paradox and dBASE tables

18.3.2.1 Transaction Control Overview

When using Delphi to create a database application, Delphi provides transaction control for all database access.

A transaction is a set of operations in which the operations of one or more databases must be successfully executed before they are committed. If one of the operations fails, all operations fail, that is, the transaction is atomic.

Even if a hardware failure occurs, the transaction is guaranteed to be database consistent. When multiple users are allowed concurrent access, the transaction also maintains data integrity.

For example, an application may update the Orders table to indicate acceptance of an order for a particular item, and then update the Innentory table to reflect a decrease in inventory. If a hardware error occurs before the second update after the first update, the database is in an inconsistent state because the inventory does not reflect the order. Under transaction control, two expressions are committed at the same time, and if one of the expressions fails, it is returned (rolled back).

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.