Правильная ссылка на эту страницу
http://az-design.ru/Support/DataBase/002b1000_en.shtml

Introduction

Arkhangelskiy Andrey

Russian

       As push to development and research of tree structures Dmitry Kuzmenko's clause has served (http://www.ibase.ru) With the same name. At all usefulness of clause of D.Kuzmenko, the problem has appeared much more widely and application of tree structures in a DB opens new functionalities.

Used tools

 

Instructions to the performer: do not give in to despair and fear even if the thirteenth attempt has appeared unsuccessful! Similar programs are named introspective, and there is a theorem in which affirms, that it is possible to write the introspective program in any "powerful enough" language. All usual programming languages — powerful enough.

Charles Uezerell "Etudes for programmers"

       Real developments were carried on by means of Borland Delphi 7, Firebird 2.0, IBObjects 4.3, Raize Components 4.0. Therefore some features of implementation of codes are possible.
       There was a big temptation to make all examples on the basis of Turbo Delphi Explorer and InterBase 7.5 Developer Edition so that the reader could try all examples without additional expenses. But library IBX is eliminated from the Explorer-version, and the library dbExpres has no bidirectional cursors that does not allow to use TDBGrid.
       On the other hand, there are some libraries of direct access to server InterBase/Firebird, operation with which has essential distinctions. To them concern:
       InterBaseXpress (IBX) — contains components with the open source texts for operation with a database and executions of service functions which are delivered with some products Borland, such as Delphi, Kulix, C++ Builder. Tab Interbase Is a part Delphi 7.
       IBObjects — unites two for a long time known systems of components for Firebird and InterBase, which allow developers to use tools Borland IDE (Delphi, Kulix, C++ Builder) for implementation of all possibilities Firebird. One system is compatible to libraries Borland TDataset and other components of indirect developers which inherit TDataset architecture. Another, known as " native IBO ", includes an own class of the data sources (data source) and set of controlling units for data management. IBO4_6_B_Eval.zip it is possible to find on an applied compact disc. Behind the additional information access on http://www.ibobjects.com.
       FIBPlus — the powerful set of components for Delphi, Kulix and C ++ Builder is grounded on Borland TDataset architecture and gives complete compatibility with many components of commercial character and the open codes. It gives a simple way of conversion of components Borland InterBaseXpress. Behind the additional information access on http://www.devrace.com.
       Thus, all examples are written and probality in Delphi 7 with usage of three above described libraries. Directories with projects of examples look like:
       ExampleXX — for library InterBaseXpress (IBX),
       ExampleXXIBO — for library IBObjects (IBO),
       ExampleXXFIB — for library FIBPlus,
       — Where XX number of an example.
       For some examples Raize Components 4.0 components which are absent in standard delivery Delphi are required. In these cases fragments of the equipment designs created on the basis of IBObjects are used.
       For more information access on http://www.raize.com.

Construction of the Database

       The database for testing examples is presented in the form of SQL-scripts. Why?
       — Look remarkable book Hellen Borry "Firebird. A manual of a database designer", SPb., BHV-Petersburg, 2006y (p.258-267),
       — Scripts allow to gather a DB from zero under any server and it is easy to correct the arisen or old errors. So to my practice there was a case when enough greater DB "has not wanted" to migrate from FB1.53 in FB2.0 through backup/restore because of an error in structure which was ignored FB1.53 and has appeared only in FB2.0;
       — Not always it is possible to change structure of a DB by means of such tools as EMS IBManager or IBExpert. From practice: it was necessary to change a data type in the simple empty table, but in primary key floor to which it has been linked more than 20 tables and set of procedures. For change by means of IBExpert it would be required to delete links with tables, to change a data type, to restore links. It would demand not only a lot of time, but also probability of an error would be great. By the way, the error in the previous case has been accepted by means of EMS IBManager;
       — Scripts allow to carry on modular development and to gather various DB for concrete applications;
       — And, at last, if you can make something by means of SQL-scripts you can make it in any program. Return position is not always true.
       All scripts of creation of a DB are in directory FB_SQL on an applied compact disc. Structure of the directory following:
       — Radically there are files DBCreate.doc, DBCreate.txt, FillengDB.bat and isql.exe. And the file isql.exe is placed in this directory only for convenience of construction of a batch file. The correct version can be taken from the directory bin server Firebird/InterBase installed for you.
       — In subdirectory dat SQL-scripts for filling tables with data contain. The name of each script starts about the names of the table given for which in it to contain. For some tables there can be some scripts.
       — In subdirectory res results of execution of scripts, for the further analysis and search of errors are saved.
       The main script contains in file DBCreate.doc that allows to edit, use easily it navigating of Microsoft Word, to gather a table of contents and to print out in a convenient format. To receive a working SQL-script it is enough to save file DBCreate.doc in ASCII format.
       Those examples which are absent in source codes, are taken from real developments, therefore names of components and variables did not vary.

Connection to a database

       For usage of examples create on the computer the directory and copy in it all examples from an applied compact disc. In this directory will form by a DB and in the same place examples will search for a DB in the form of file DB_Tree.fb.
       In all examples connection to a DB occurs approximately equally.
       For examples on the basis of components IBX connection is fulfilled as follows:

procedure TForm1.FormCreate (Sender: TObject);
Var
   db: String;
   ps: Integer;
begin
   IBDatabase1.Connected: = False;
   db: = ExtractFilePath(Application.ExeName);
   db: = ReverseString (db); Delete (db, 1,1); // to delete \
   ps: = Pos ('\', db); Delete (db, 1, ps); // to find following \ and to delete
   db: = ReverseString(db) + ' \DB_Tree.fb '; // to turn string and to add a DB
   IBDatabase1.DatabaseName: = db;
   IBDatabase1.Connected: = True;
end;

       First connection if it is is broken off. The matter is that at usage of components IBX arises unpleasant систуация. If any properties Query connection with a DB is automatically installed are edited. After travel on other components, about the installed connection it is possible to forget simply. Therefore after construction of the project the situation when the application starts to be connected to a DB without appropriate parameters is possible. For exception of it compulsory disconnecting from a DB also is entered.
       Further the path to a DB is calculated. For this purpose the path to the application is defined, one level of directories from path is deleted and the name of a DB is added.
       The name of a DB writes in property DatabaseName of IBDatabase1 component then connection is installed.
       Login and Password in all examples it is installed obviously and has values:
       Login = SYSDBA,
       Password = masterkey.
       I.e. defaults for Interbase and Firebird.
       For examples on the basis of components IBO there are minor alterations:

procedure TForm1.FormCreate (Sender: TObject);
Var
   db: String;
   ps: Integer;
begin
   IB_Connection1.Disconnect;
   db: = ExtractFilePath(Application. ExeName);
   db: = ReverseString(db); Delete (db, 1,1);
   ps: = Pos ('\', db); Delete (db, 1, ps);
   db: = ReverseString (db) + '\DB_Tree.fb';
   IB_Connection1.DatabaseName: = db;
   IB_Connection1.Username: = 'SYSDBA';
   IB_Connection1.Password: = 'masterkey';
   IB_Connection1.Connect;
end;

       Difference only that for connection to a DB IB_Connection1 component is used and the user name and the password write in procedure FormCreate.

 

Debugging of programs with inquiries

       In some examples additional operators for debugging inquiries to a DB are included. The used system outputs that information which the programmer has specified in these operators in the protocol. For inclusion/turn off of test bed it is necessary:
       — To open dialogue " Project options ";
       — To find a tab "Directories/Conditionals";
       — On this tab to find panel " Conditionals " and in Conditional defines floor to write (to delete) variable AZDEBUG.
       For operation of this test bed following strings are brought in the text of the program:

var
{$IFDEF AZDEBUG} flError: TextFile; {$ENDIF}

       — Defines a variable for a log file.

procedure TForm1.FormCreate (Sender: TObject);
Var
   db: String;
begin
{$IFDEF AZDEBUG}
  db: = ExtractFilePath(Application. ExeName) + 'Example08_err.txt';
  AssignFile(flError, db);
  ReWrite(flError);
  WriteReprtText('<<<Example 08 Start>>>');
{$ENDIF}

       — The filename of the protocol which represents a filename of the application with addition '_err' is defined and has .txt extension. At once in a log file the string designating is output has started operation.
       For output of the information two procedures are used:

{$IFDEF AZDEBUG}
procedure TForm1.WriteReprtText (txt: String);
begin
  WriteLn (flError, txt); Flush (flError);
end;

       First procedure WriteReportText simply outputs the text which is specified in an entry variable txt. Typical usage — in the beginning of each procedure is useful for inserting procedure call WriteReportText, a variable txt which contains the name of procedure.

procedure TForm1.WriteReprtStrings (Name: String; Str: TStrings);
Var
  cn: Integer;
begin
  WriteLn(flError,' +>>>' +Name + ': ');
  For cn: = 0 to Str.Count-1 do Begin
      writeln(flError, Str.Strings [cn]);
  end;
  WriteLn (flError, '->>>'); Flush (flError);
end;
{$ENDIF}

       Second procedure WriteReportStrings outputs in a log file the array of strings, for example, Query. SQL which procedure makes out additional strings specifying addressed to the array of strings and tags of the beginning and the end of this array.
       Below the example of usage of these procedures is resulted:

procedure TForm1.tvGoodsExpanding (Sender: TObject; Node: TTreeNode;
                                  var AllowExpansion: Boolean);
Var
   RowChild: Integer;
   z: Integer;
   sFld, sCod: String;
   ChildNode, NewNode: TTreeNode;
begin
  inherited;
{$IFDEF AZDEBUG} WriteReprtText ('TForm1.tvGoodsExpanding'); {$ENDIF}
  If isNoClose then begin
     If Node.HasChildren then begin
        Node.DeleteChildren; z: = Node. ImageIndex;
        qrTVGoods.Close; qrTVGoods. SQL.Clear;
        qrTVGoods.SQL.Add(sqlSelect);
        qrTVGoods.SQL.Add(sqlWhere+IntToStr(z));
        qrTVGoods.SQL.Add(sqlOrder);
{$IFDEF AZDEBUG} WriteReprtStrings('qrTVGoods.SQL', qrTVGoods.SQL); {$ENDIF}
        qrTVGoods.Open; qrTVGoods.First;
....
end;

       Procedure call WriteReportString should be fulfilled before execution qrTVGoods. Open so that errors in inquiry have not prevented to output it in a log file. Procedure call WriteReportText in this case allows to watch sequence of events which arise by operation of the program.
       For completion of test bed it is necessary to close a log file in procedure FormClose:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   IBDatabase1.Connected := False;
{$IFDEF AZDEBUG} WriteReprtText('<<< Example05 End >>>');  {$ENDIF}
{$IFDEF AZDEBUG} CloseFile(flError); {$ENDIF}
end;

 

That is on an applied compact disc

       The applied compact disc contains, except for a DB, examples and the additional software. Structure of a disk following:

DB_TREE.FB - a DB constructed under Firebird 2.0
FB_SQL - the Directory of source texts of a DB and scripts
FB_SQL\dat - the Directory of scripts of filling of a DB
FB_SQL\res - the Directory резутатов executions of SQL-scripts
FB_SQL\udf - in the directory there is a file az-udf.dll which it is necessary
                  To copy in directory Firebird \udf. In this udf to contain
                  Some functions of separate examples necessary for operation.
Soft - In the directory is Firebird 2.0 for Windows32, and also
                Demos of components for operation with Firebird
Example00IBO   - Usage IBO_TreeView
Example01      - Mapping of table People in the form of a tree (IBX)
Example01IBO   - Mapping of table People in the form of a tree (IBO)
Example02      - Mapping of table People with structure Data
Example03      - the Quick reference on units of measure (IBX)
Example03IBO   - the Quick reference on units of measure (IBO)
Example04      - Mapping of table Persons
Example05      - Mapping of table Goods (1 variant)
Example06      - Mapping of table GoodsNew (2 variant)
Example07      - the Program of preparation of VAZKompl complexes (simplified вар.)
Example07IBORz - the Program of preparation of VAZKompl complexes (commercial вар.)
Example08      - Calculation of complexity of repair АМТС (simplified вар.)
Example08IBORz - Calculation of complexity of repair АМТС (commercial вар.)
Example09      - the Small accounting program
Example10      - Search of the path between two servers of the underground (on IBX)
Example10IBO   - Search of the path between two servers of the underground (on IBO)

All (except for the directory "Soft") can be downloaded examples - the size 15Mb
Example download 867 times.

© 01.07.2007, Arkhangelskiy A.G.

<<Prev. Table of contents
The beginning of section
Next>>




Дата последнего изменения:
Thursday, 21-Aug-2014 09:10:44 MSK


Постоянный адрес статьи:
http://az-design.ru/Support/DataBase/002b1000_en.shtml