mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 15:52:26 +01:00
Author:halw
Date:2008-10-02T21:44:24.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@68 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
[[Property:uuid|f443ed73-14bb-9a3a-b7c7-35c2660e7784]]
|
||||
The EiffelStore library lets the user associate database elements with Eiffel objects. These database elements are basically database table rows, database view rows or more generally sets of database attribute values. The easiest way to manipulate database elements is to insert their content into Eiffel objects and to work on these Eiffel objects as database elements.
|
||||
|
||||
A first solution to implement this is to use some adaptable structures that will fit to any database element. This is done in EiffelStore through the [[ref:libraries/store/reference/db_tuple_flatshort|DB_TUPLE]] class, which contains mainly an [[ref:libraries/base/reference/array_chart|ARRAY]] [[[ref:libraries/base/reference/string_8_chart|STRING]] ] containing element attribute names and an [[ref:libraries/base/reference/array_chart|ARRAY]] [[[ref:libraries/base/reference/any_chart|ANY]] ] containing element attribute values. This solution has one major drawback: any static checking is impossible: the developer cannot be sure at compile time of the nature of a [[ref:libraries/store/reference/db_tuple_flatshort|DB_TUPLE]] , i.e. what it represents, and cannot know if attributes number, names and types are correct. To overcome this problem, a second solution is to use data structures that statically fits to the expected database element, as introduced in the [[Data Object Coupling|DataObject Coupling]] section.
|
||||
A first solution to implement this is to use some adaptable structures that will fit to any database element. This is done in EiffelStore through the [[ref:libraries/store/reference/db_tuple_flatshort|DB_TUPLE]] class, which contains mainly an <code>ARRAY [STRING]</code> containing element attribute names and an <code>ARRAY [ANY]</code> containing element attribute values. This solution has one major drawback: any static checking is impossible: the developer cannot be sure at compile time of the nature of a [[ref:libraries/store/reference/db_tuple_flatshort|DB_TUPLE]] , i.e. what it represents, and cannot know if attributes number, names and types are correct. To overcome this problem, a second solution is to use data structures that statically fits to the expected database element, as introduced in the [[Data Object Coupling|DataObject Coupling]] section.
|
||||
|
||||
The major problem of this technique is that structures are static: one structure, so one class instead of one object, should be created for each database element.
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@ The abstract [[ref:/libraries/store/reference/database_flatshort|DATABASE]] cla
|
||||
EiffelStore enables to link common interface objects with database-specific implementation objects using a '''handle'''. This handle also enables to switch between different databases.
|
||||
|
||||
Let us see in 4 steps how EiffelStore implements this handle system:
|
||||
* The [[#handle|active database handle]] .
|
||||
* The [[#association|association between interface and implementation]] objects.
|
||||
* The [[#access|access to the DBMS call interface]] from the implementation layer.
|
||||
* The [[#selection|active database selection]] from the database application.0
|
||||
|
||||
==The active database handle==
|
||||
|
||||
|
||||
@@ -34,4 +34,3 @@ Use the [[ref:/libraries/store/reference/db_change_flatshort|DB_CHANGE]] class
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ A [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] obje
|
||||
end
|
||||
</code>
|
||||
|
||||
|
||||
{{tip|Loading a table description is often a costly operation: table has to be fetched among existing tables then every table column description must be loaded. Hence it is better to store and reuse a repository (maybe with a HASH_TABLE) once it has been loaded. }}
|
||||
|
||||
|
||||
Using the table information, [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] then helps generating Eiffel classes mapping relational tables:
|
||||
* You can directly use {[[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] }.generate_class. Generated class may look like:
|
||||
<code>
|
||||
@@ -40,6 +42,7 @@ Using the table information, [[ref:/libraries/store/reference/db_repository_flat
|
||||
...
|
||||
</code>
|
||||
|
||||
|
||||
{{note|The EiffelStore Wizard uses the generation.generator cluster to generate the classes mapped to your database. }}
|
||||
|
||||
|
||||
@@ -79,6 +82,7 @@ This is straight-forward since you only have to give [[ref:/libraries/store/refe
|
||||
end
|
||||
</code>
|
||||
|
||||
|
||||
{{note|You can see how actions are used in [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] . }}
|
||||
<br/>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[Property:title|Database Connection]]
|
||||
[[Property:weight|0]]
|
||||
[[Property:uuid|2cf2cb7c-e28d-5d06-b03e-e2b17c1f6879]]
|
||||
# To connect to your database, you have to create a '''handle''': this handle actually links the interface classes with corresponding implementation classes mapped to your DBMS. This handle is implemented by the DATABASE_APPL class:
|
||||
* To connect to your database, you have to create a '''handle''': this handle actually links the interface classes with corresponding implementation classes mapped to your DBMS. This handle is implemented by the DATABASE_APPL class:
|
||||
<code>
|
||||
database_appl: DATABASE_APPL [ODBC]
|
||||
-- Database handle.
|
||||
@@ -15,9 +15,10 @@
|
||||
|
||||
{{tip|You can manage handles to many databases: as an instance of <eiffel>DATABASE_APPL</eiffel> stands for a specific database handle, you only have to create one instance of <eiffel>DATABASE_APPL</eiffel> for every DBMS handle you wish to create. Do not forget to call set_base to activate appropriate handle. }}
|
||||
|
||||
|
||||
{{note|The generic parameter of <eiffel>DATABASE_APPL</eiffel> specifies the actual DBMS used. }}
|
||||
|
||||
# Once your handle is created, you have to create a session manager which will allow you to manage your database, specifically to establish connection, disconnect and also handle errors. The class <eiffel>DB_CONTROL</eiffel> enables your application to plainly control the functioning and status of your database and to request any information about it.
|
||||
* Once your handle is created, you have to create a session manager which will allow you to manage your database, specifically to establish connection, disconnect and also handle errors. The class <eiffel>DB_CONTROL</eiffel> enables your application to plainly control the functioning and status of your database and to request any information about it.
|
||||
<code>
|
||||
session_control: DB_CONTROL
|
||||
-- Session control.
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
[[Property:weight|7]]
|
||||
[[Property:uuid|432c6e51-36d5-b469-c924-eb821713256a]]
|
||||
Use the [[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] class to check or change database status and behavior. The main operations you are likely to use are:
|
||||
* [[#errors|Handling]] database errors.
|
||||
* [[#connection|Connecting]] to the database.
|
||||
* [[#commit|Committing]] changes in the database.
|
||||
* Handling database errors.
|
||||
* Connecting to the database.
|
||||
* Committing changes in the database.
|
||||
|
||||
==Handling database errors==
|
||||
|
||||
Every EiffelStore interface class has an is_ok feature. This enables to check directly if the last database operation has been successful.
|
||||
|
||||
When an error is detected, you can access through [[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] further information about the error:
|
||||
When an error is detected, you can use [[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] to obtain further information about the error:
|
||||
* error_message provides a description of the error that occurred.
|
||||
* error_code returns a code corresponding to the error type. This code enables to handle specific errors within your code without parsing the error_message.
|
||||
* warning_message provides a warning message about the last transaction performed.
|
||||
@@ -19,7 +19,7 @@ Once you have handled your error, for instance by displaying the error_message o
|
||||
|
||||
==Managing database connection==
|
||||
|
||||
[[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] lets you connect, check connection and disconnect from the database.
|
||||
[[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] lets you connect, check your connection, and disconnect from the database.
|
||||
|
||||
The following example sum up these capabilities:
|
||||
<code>
|
||||
@@ -34,9 +34,9 @@ The following example sum up these capabilities:
|
||||
|
||||
==Committing changes in the database==
|
||||
|
||||
Every modification you do in the database are usually not directly saved. This enables to limit damage caused by mishandlings. You can then manage database modification through 2 commands:
|
||||
With many database systems, modifications you make to the database are usually not saved immediately. Rather, changes are accumulated in a "transaction". At some point the entire transaction is committed to the database (i.e., the changes are actually made to the data) or the entire transaction is rolled back (i.e., absolutely no changes are made to the data.) You can manage database modification through 2 commands:
|
||||
* ''Commit'' saves the changes in the database.
|
||||
* ''Rollback'' restores the database content corresponding to last commitment.
|
||||
* ''Rollback'' restores the database content to its state after the most recent commit.
|
||||
|
||||
The following example illustrates the use of these commands:
|
||||
<code>
|
||||
@@ -57,7 +57,7 @@ The following example illustrates the use of these commands:
|
||||
|
||||
The loop performs a multi-step transaction. If transaction is not carried out entirely, the database could stay in an invalid state: this code ensures that database remains in a valid state.
|
||||
|
||||
{{warning| '''Caution''': Some databases can be in an auto-commit mode. Furthermore, some special database commands can automatically commit database changes. }}
|
||||
{{caution|Some databases can be in an auto-commit mode. Furthermore, some special database commands can automatically commit database changes. }}
|
||||
|
||||
{{seealso|<br/>
|
||||
[[Database Connection|Database connection]] <br/>
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
[[Property:title|EiffelStore Interface Layer]]
|
||||
[[Property:weight|0]]
|
||||
[[Property:uuid|abd6c880-e0d8-0961-8cd2-d2ca43c1ce28]]
|
||||
The Interface layer gathers a set of classes covering all the capabilities an application need to interface efficiently with a DBMS.
|
||||
|
||||
The interface affords these main capabilities:
|
||||
* [[Database Connection|Connecting]] to the database.
|
||||
* [[Data Modification|Modifying]] database objects.
|
||||
* [[Database Selection|Selecting]] data from the database.
|
||||
* [[Selection Access|Accessing]] data selected from the database.
|
||||
* [[Data Object Coupling|Coupling]] database objects with Eiffel objects.
|
||||
* [[Query variables|Binding variables]] in a database query.
|
||||
* Using [[Stored Procedures|stored procedures]] .
|
||||
* Dealing with database [[Database control|status and behavior]] .
|
||||
|
||||
{{note|In general, each of these capabilities corresponds to one EiffelStore class. }}
|
||||
|
||||
{{seealso|<br/>
|
||||
[[EiffelStore Implementation Layer|The implementation layer]] }}
|
||||
The Interface layer gathers a set of classes covering all the capabilities an application need to interface efficiently with a DBMS.
|
||||
|
||||
Each of the following sections describes a particular database capability accessed through the EiffelStore interface layer. In general, each of these capabilities is made available in the interface layer by one class.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[[Property:uuid|3b4fdde3-d903-55c8-0068-cee2407db280]]
|
||||
Once you have [[Database Selection|selected data]] from the database, it returns a set of rows containing queried columns values. Each row loaded with DB_SELECTION is stored in a DB_RESULT object. The easiest way to access the data is thus to refer to DB_RESULT objects themselves.
|
||||
|
||||
|
||||
{{note|Take a look at the [[Data Object Coupling|Database/Eiffel objects Coupling]] to learn advanced data handling features. }}
|
||||
|
||||
To use DB_RESULT, process in 2 steps:
|
||||
@@ -64,7 +65,6 @@ To use DB_RESULT, process in 2 steps:
|
||||
Result := i >= Max_result
|
||||
end
|
||||
</code>
|
||||
|
||||
** Then set action to [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] :
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
@@ -93,6 +93,7 @@ A DB_RESULT object merely carries data retrieved from the database. You have to
|
||||
end
|
||||
</code>
|
||||
|
||||
|
||||
{{seealso|<br/>
|
||||
[[Database Selection|Performing a database selection.]] <br/>
|
||||
[[Data Object Coupling|Coupling database data and Eiffel objects.]] <br/>
|
||||
@@ -100,5 +101,3 @@ A DB_RESULT object merely carries data retrieved from the database. You have to
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,10 +22,13 @@ To execute a stored procedure:
|
||||
</code>
|
||||
|
||||
* Execute the procedure through a [[ref:/libraries/store/reference/db_selection_chart|DB_SELECTION]] (if a result is expected) or a [[ref:/libraries/store/reference/db_change_chart|DB_CHANGE ]] object (otherwise).
|
||||
|
||||
{{note|Requests with a result ([[ref:/libraries/store/reference/db_selection_chart|DB_SELECTION]] ) or without ([[ref:/libraries/store/reference/db_change_chart|DB_CHANGE]] ) are both abstract '''expressions'''. DB_PROC executes an abstract expression using an object of [[ref:/libraries/store/reference/db_expression_chart|DB_EXPRESSION]] type, which corresponds to an abstract expression. [[ref:/libraries/store/reference/db_selection_chart|DB_SELECTION]] and [[ref:/libraries/store/reference/db_change_chart|DB_CHANGE]] inherits from [[ref:/libraries/store/reference/db_expression_chart|DB_EXPRESSION]] . }}
|
||||
|
||||
You can execute your request mostly like a basic one:
|
||||
** Create your request.
|
||||
** Bind request variables. Variables are stored procedure arguments.
|
||||
|
||||
{{note|Take a look at how to [[Query variables|bind variables]] to a query. }}
|
||||
|
||||
** Execute the query through the DB_PROC object.
|
||||
@@ -62,6 +65,7 @@ The following example shows how to overwrite a procedure in the database:
|
||||
end
|
||||
</code>
|
||||
|
||||
|
||||
{{seealso|<br/>
|
||||
[[Database Selection|Performing a database selection.]] <br/>
|
||||
[[Data Object Coupling|Coupling database data and Eiffel objects.]] <br/>
|
||||
|
||||
@@ -9,6 +9,3 @@ Other cluster can facilitate your database management:
|
||||
* The [[EiffelStore Generation Cluster|generation cluster]] , with the EiffelStore wizard, generates a facilitated and dynamic interface with your database.
|
||||
* The [[EiffelStore DataView Cluster|dataview cluster]] lets you create a customized database GUI.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user