Fibplus dev

Solo disponible en BuenasTareas
  • Páginas : 24 (5881 palabras )
  • Descarga(s) : 0
  • Publicado : 3 de noviembre de 2010
Leer documento completo
Vista previa del texto
FIBPlus Developer’s Guide Part I
Database connection
To connect to a database (DB) you should use the TpFIBDatabase component. For more details about its properties and methods read FIBPlus help file.

Connection parameters
Connection parameters are typical for InterBase/Firebird server:
• • • • • •

path to a database file; user name and password; user role; charset; dialect; clientlibrary (gds32.dll for InterBase and fbclient.dll for Firebird).

To set all the properties at once you can use a built-in connection setting dialog (see picture 1). The dialog «Database Editor» can be invoked from the component context menu (right click on the component) at design-time. Here you may set all necessary parameters, including getting them from/saving them to Alias. You may also checkwhether the parameters are correct by using a test connection.

Figure 1. Connection Properties TpFIBDatabase

Similar to the actions in the dialog, you can do the same in the application code.

To connect to a database you should call the Open method or set the Connected property to True. It’s also possible to use this code to connect to a database:
function Login(DataBase: TpFIBDatabase;dbpath, uname, upass, urole: string): Boolean; begin if DataBase.Connected then DataBase.Connected := False; with FDataBase.ConnectParams do begin UserName := uname; Password := upass; RoleName := urole; end; DataBase.DBName := dbpath; try DataBase.Connected := True; except on e: Exception do ShowMessage(e.Message); end; Result := DataBase.Connected; end;

To close the connection either call theClose method or set the Connected property to False. You can also close all datasets and connected transactions at once:
procedure Logout(DataBase: TpFIBDatabase); var i: Integer; begin if not DataBase.Connected then Exit; for i := 0 to DataBase.TransactionCount - 1 do if TpFIBTransaction(DataBase.Transactions[i]).InTransaction then TpFIBTransaction(DataBase.Transactions[i]).RollbackDataBase.CloseDataSets; DataBase.Close; end;

How to create and drop database
It’s very easy to create a new DB. You need to set DB parameters and call the CreateDatabase method:
Delphi with Database1 do begin DBParams.Clear; DBParams.Add('USER ''SYSDBA'' PASSWORD ''masterkey'''); DBParams.Add('PAGE_SIZE = 2048'); DBParams.Add('DEFAULT CHARACTER SET WIN1251'); DBName := 'SERV_DB:C:\DB\TEST.IB';SQLDialect := 3; end; try Database1.CreateDataBase; except // Error handling end; C++ Database1->DBParams->Clear(); Database1->DBParams->Add("USER 'SYSDBA' PASSWORD 'masterkey'"); Database1->DBParams->Add("PAGE_SIZE = 2048"); Database1->DBParams->Add("DEFAULT CHARACTER SET WIN1251"); Database1->DBName = "SERV_DB:C:\DB\TEST.GDB"; Database1->SQLDialect = 3; try { Database1->CreateDatabase(); } catch (...) {// Error }

To drop a database, use the DropDatabase method. Note: you should be connected to the database when using this method.

Metadata caching
FIBPlus enables developers to get system information about field tables automatically, set in TpFIBDataSet such field properties as Required (for NOT NULL fields), ReadOnly (for calculated fields) and DefaultExpression (for fields with defaultdatabase values). This feature is very useful for both programmers and users, because programmers do not need to set property values manually when writing client applications, and users get clearer messages when working with the programme e.g. if any field is NOT NULL, and the user attempts to leave it empty, he will see a message «Field ‘…’ must have a value.». This is more understandable than asystem InterBase/Firebird PRIMARY KEY violation error. The same with calculated fields, it is not possible to edit such fields, so FIBPlus will set the ReadOnly property to True for all calculated fields, and the user will not get a vague message on trying to change the field values in TDBGrid. This feature has one disadvantage, which is revealed on low speed connections. To get information on...
tracking img