mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 15:52:26 +01:00
Removed first slash in [[ref:libraries/...]] wiki links.
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1612 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -45,7 +45,7 @@ You can then access or modify [[ref:libraries/store/reference/db_table_flatshort
|
||||
end
|
||||
</code>
|
||||
|
||||
{{note|to access attributes data with ''code'', you need to use the [[ref:/libraries/store/reference/db_table_description_flatshort|DB_TABLE_DESCRIPTION]] object associated to your [[ref:libraries/store/reference/db_table_flatshort|DB_TABLE]] object. }}
|
||||
{{note|to access attributes data with ''code'', you need to use the [[ref:libraries/store/reference/db_table_description_flatshort|DB_TABLE_DESCRIPTION]] object associated to your [[ref:libraries/store/reference/db_table_flatshort|DB_TABLE]] object. }}
|
||||
|
||||
===2.3. Getting objects metadata===
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
[[Property:weight|1]]
|
||||
[[Property:uuid|80cd0938-6837-3c17-8515-b4ac60a51d09]]
|
||||
Each interface class has an implementation counterpart that implements specific DBMS handling. The class prefix indicates clearly its layer, for instance:
|
||||
* [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] is the interface to perform a database selection query.
|
||||
* [[ref:/libraries/store/reference/database_selection_flatshort|DATABASE_SELECTION]] [ [[ref:/libraries/store/reference/database_flatshort|DATABASE]] ] is its implementation.
|
||||
* [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] is the interface to perform a database selection query.
|
||||
* [[ref:libraries/store/reference/database_selection_flatshort|DATABASE_SELECTION]] [ [[ref:libraries/store/reference/database_flatshort|DATABASE]] ] is its implementation.
|
||||
|
||||
The abstract [[ref:/libraries/store/reference/database_flatshort|DATABASE]] class represents a DBMS, i.e. it is the Eiffel-side database call interface. It is inherited for instance by the instantiable <eiffel>ORACLE</eiffel> and <eiffel>ODBC</eiffel> classes.
|
||||
The abstract [[ref:libraries/store/reference/database_flatshort|DATABASE]] class represents a DBMS, i.e. it is the Eiffel-side database call interface. It is inherited for instance by the instantiable <eiffel>ORACLE</eiffel> and <eiffel>ODBC</eiffel> classes.
|
||||
|
||||
EiffelStore enables to link common interface objects with database-specific implementation objects using a '''handle'''. This handle also enables to switch between different databases.
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[[Property:title|Data Modification]]
|
||||
[[Property:weight|1]]
|
||||
[[Property:uuid|ef5568ff-dc7c-4c85-0174-335fdab1bd84]]
|
||||
Use the [[ref:/libraries/store/reference/db_change_flatshort|DB_CHANGE]] class to perform any operation on your database that does not require access to a result. You can for instance modify table row content, drop table rows, create and delete tables.
|
||||
Use the [[ref:libraries/store/reference/db_change_flatshort|DB_CHANGE]] class to perform any operation on your database that does not require access to a result. You can for instance modify table row content, drop table rows, create and delete tables.
|
||||
|
||||
{{note|Take a look at the [[Data Object Coupling|Data Storing]] capability if you want to '''insert''' table rows. }}
|
||||
|
||||
[[ref:/libraries/store/reference/db_change_flatshort|DB_CHANGE]] allows you to modify the database data using the SQL language:
|
||||
[[ref:libraries/store/reference/db_change_flatshort|DB_CHANGE]] allows you to modify the database data using the SQL language:
|
||||
* Prepare your SQL query and use modify:
|
||||
<code>
|
||||
modification: DB_CHANGE
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
[[Property:weight|4]]
|
||||
[[Property:uuid|c51311cd-8782-0bc3-3ef7-000ea6eee37c]]
|
||||
A smart way to work with relational databases is to have Eiffel objects directly mapping relational tables. Three EiffelStore classes enable this coupling:
|
||||
* [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] objects [[#describe|describe a relational table]] and allow Eiffel to create objects mapping database tables.
|
||||
* [[ref:/libraries/store/reference/db_store_flatshort|DB_STORE]] works directly with [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] objects to [[#insert|insert data into relational tables]] .
|
||||
* [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] can [[#map|map a database query result into Eiffel objects]] .
|
||||
* [[ref:libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] objects [[#describe|describe a relational table]] and allow Eiffel to create objects mapping database tables.
|
||||
* [[ref:libraries/store/reference/db_store_flatshort|DB_STORE]] works directly with [[ref:libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] objects to [[#insert|insert data into relational tables]] .
|
||||
* [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] can [[#map|map a database query result into Eiffel objects]] .
|
||||
|
||||
==Describing relational tables with DB_REPOSITORY==
|
||||
|
||||
A [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] object stores available information about a table. To access this information, you mainly have to give the table name and load the table description:
|
||||
A [[ref:libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] object stores available information about a table. To access this information, you mainly have to give the table name and load the table description:
|
||||
<code>
|
||||
repository: DB_REPOSITORY
|
||||
|
||||
@@ -25,8 +25,8 @@ A [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] obje
|
||||
{{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:
|
||||
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>
|
||||
class CONTACTS
|
||||
|
||||
@@ -50,10 +50,10 @@ feature -- Settings
|
||||
|
||||
==Inserting data in the database==
|
||||
|
||||
[[ref:/libraries/store/reference/db_store_flatshort|DB_STORE]] lets you easily insert rows into a table using:
|
||||
* the table description provided by [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] .
|
||||
[[ref:libraries/store/reference/db_store_flatshort|DB_STORE]] lets you easily insert rows into a table using:
|
||||
* the table description provided by [[ref:libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] .
|
||||
* a class mapping the relational table.
|
||||
This is straight-forward since you only have to give [[ref:/libraries/store/reference/db_store_flatshort|DB_STORE]] the object filled with the table values. Suppose you want to add a contact into your database:
|
||||
This is straight-forward since you only have to give [[ref:libraries/store/reference/db_store_flatshort|DB_STORE]] the object filled with the table values. Suppose you want to add a contact into your database:
|
||||
<code>
|
||||
storage: DB_STORE
|
||||
contacts_rep: DB_REPOSITORY
|
||||
@@ -70,7 +70,7 @@ This is straight-forward since you only have to give [[ref:/libraries/store/refe
|
||||
|
||||
==Accessing database content with Eiffel objects==
|
||||
|
||||
[[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] lets you map data retrieved from the database into Eiffel objects: Result column names must match object attributes names so you can use for instance classes created by [[ref:/libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] . Class <eiffel>DB_ACTION</eiffel> redefines ACTION and can be used to retrieve Eiffel objects directly into an ARRAYED_LIST:
|
||||
[[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] lets you map data retrieved from the database into Eiffel objects: Result column names must match object attributes names so you can use for instance classes created by [[ref:libraries/store/reference/db_repository_flatshort|DB_REPOSITORY]] . Class <eiffel>DB_ACTION</eiffel> redefines ACTION and can be used to retrieve Eiffel objects directly into an ARRAYED_LIST:
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
list_filling: DB_ACTION [CONTACTS]
|
||||
@@ -89,7 +89,7 @@ This is straight-forward since you only have to give [[ref:/libraries/store/refe
|
||||
</code>
|
||||
|
||||
|
||||
{{note|You can see how actions are used in [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] . }}
|
||||
{{note|You can see how actions are used in [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] . }}
|
||||
<br/>
|
||||
|
||||
{{seealso|<br/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[Property:title|Database control]]
|
||||
[[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:
|
||||
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:
|
||||
* Handling database errors.
|
||||
* Connecting to the database.
|
||||
* Committing changes in the database.
|
||||
@@ -10,7 +10,7 @@ Use the [[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] clas
|
||||
|
||||
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 use [[ref:/libraries/store/reference/db_control_flatshort|DB_CONTROL]] to obtain 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 your 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>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[[Property:title|Database Selection]]
|
||||
[[Property:weight|2]]
|
||||
[[Property:uuid|de759a74-b3e1-c937-e620-67526c116925]]
|
||||
Use the [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] class to select data from the database. Once you have selected the data, you can [[Selection Access|access]] it with convenience using adaptative EiffelStore structures.
|
||||
Use the [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] class to select data from the database. Once you have selected the data, you can [[Selection Access|access]] it with convenience using adaptative EiffelStore structures.
|
||||
|
||||
{{note|Take a look at the [[Data Object Coupling|Database/Eiffel objects Coupling]] if you need information about your database structure. }}
|
||||
|
||||
[[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] enables your application to get database content using SQL 'select' queries:
|
||||
[[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] enables your application to get database content using SQL 'select' queries:
|
||||
* You can carry out 'select' queries in an intuitive way using directly the SQL language:
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[[Property:uuid|37222a07-a8f8-e57d-45f0-3b28cd66d660]]
|
||||
If you have to execute database queries which only differ in the expression values, you can create a template query and then bind variables into this template for each execution.
|
||||
|
||||
This mechanism can be applied for requests with a result ([[ref:/libraries/store/reference/db_selection_chart|DB_SELECTION]] ) or without ([[ref:/libraries/store/reference/db_change_chart|DB_CHANGE]] ). Hence both classes inherits from STRING_HDL that actually handle variable binding.
|
||||
This mechanism can be applied for requests with a result ([[ref:libraries/store/reference/db_selection_chart|DB_SELECTION]] ) or without ([[ref:libraries/store/reference/db_change_chart|DB_CHANGE]] ). Hence both classes inherits from STRING_HDL that actually handle variable binding.
|
||||
|
||||
To use variable binding:
|
||||
* [[#create|Create]] a template query.
|
||||
@@ -24,7 +24,7 @@ Variables syntax is simple: the ':' special character followed by the variable n
|
||||
selection.set_query ("Select * from CONTACTS where Firstname = ':" + Bind_var + "'")
|
||||
</code>
|
||||
|
||||
{{note|The code example shows how to bind variables to a [[ref:/libraries/store/reference/db_selection_chart|DB_SELECTION]] object but the mechanism is exactly the same for [[ref:/libraries/store/reference/db_change_chart|DB_CHANGE]] objects. }}
|
||||
{{note|The code example shows how to bind variables to a [[ref:libraries/store/reference/db_selection_chart|DB_SELECTION]] object but the mechanism is exactly the same for [[ref:libraries/store/reference/db_change_chart|DB_CHANGE]] objects. }}
|
||||
|
||||
==Binding variables to a query==
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ To use DB_RESULT, process in 2 steps:
|
||||
|
||||
==Retrieving DB_RESULT objects==
|
||||
|
||||
[[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] class provides different ways to customize result loading:
|
||||
* You want to access an '''unique''' row: [[ref:/libraries/store/reference/db_result_flatshort|DB_RESULT]] object is accessible via cursor:
|
||||
[[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] class provides different ways to customize result loading:
|
||||
* You want to access an '''unique''' row: [[ref:libraries/store/reference/db_result_flatshort|DB_RESULT]] object is accessible via cursor:
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
my_result: DB_RESULT
|
||||
@@ -27,7 +27,7 @@ To use DB_RESULT, process in 2 steps:
|
||||
end
|
||||
</code>
|
||||
|
||||
* You want to load a '''complete list''' of rows: [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] can store [[ref:/libraries/store/reference/db_result_flatshort|DB_RESULT]] objects in a list. To do this, you have mainly to provide a LIST object to DB_SELECTION with set_container:
|
||||
* You want to load a '''complete list''' of rows: [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] can store [[ref:libraries/store/reference/db_result_flatshort|DB_RESULT]] objects in a list. To do this, you have mainly to provide a LIST object to DB_SELECTION with set_container:
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
container: ARRAYED_LIST [DB_RESULT]
|
||||
@@ -48,10 +48,10 @@ To use DB_RESULT, process in 2 steps:
|
||||
end
|
||||
</code>
|
||||
|
||||
{{tip|Provide [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] with the LIST structure convenient for what you need to do with the results. }}
|
||||
{{tip|Provide [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] with the LIST structure convenient for what you need to do with the results. }}
|
||||
|
||||
* You want to '''select part''' of the result set: you can set an action in [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] that will be executed each time a row is loaded. This action can for instance manipulate current row and define a stop condition.
|
||||
** You need to define a descendant of class ACTION and set it to [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] :
|
||||
* You want to '''select part''' of the result set: you can set an action in [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] that will be executed each time a row is loaded. This action can for instance manipulate current row and define a stop condition.
|
||||
** You need to define a descendant of class ACTION and set it to [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] :
|
||||
<code>
|
||||
class
|
||||
MY_ACTION
|
||||
@@ -75,7 +75,7 @@ inherit
|
||||
Result := i >= Max_result
|
||||
end
|
||||
</code>
|
||||
** Then set action to [[ref:/libraries/store/reference/db_selection_flatshort|DB_SELECTION]] :
|
||||
** Then set action to [[ref:libraries/store/reference/db_selection_flatshort|DB_SELECTION]] :
|
||||
<code>
|
||||
selection: DB_SELECTION
|
||||
action: MY_ACTION
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
[[Property:uuid|9979af90-07c3-8b20-448e-04454a75c801]]
|
||||
When sending requests to the database, the request is first parsed then executed. Instead of parsing many times the same requests, i.e. with only changes in expression values, most of RDBMS enable to '''precompile''' requests. These requests can then be executed as routines and are identified by a name and a signature.
|
||||
|
||||
EiffelStore lets you use stored procedures with [[ref:/libraries/store/reference/db_proc_flatshort|DB_PROC]] class to:
|
||||
EiffelStore lets you use stored procedures with [[ref:libraries/store/reference/db_proc_flatshort|DB_PROC]] class to:
|
||||
* [[#execute|Execute]] a stored procedure.
|
||||
* [[#create|Create]] a stored procedure.
|
||||
|
||||
==Executing a stored procedure==
|
||||
|
||||
To execute a stored procedure:
|
||||
* Create a [[ref:/libraries/store/reference/db_proc_flatshort|DB_PROC]] object and load the stored procedure you want to use:
|
||||
* Create a [[ref:libraries/store/reference/db_proc_flatshort|DB_PROC]] object and load the stored procedure you want to use:
|
||||
<code>
|
||||
procedure: DB_PROC
|
||||
|
||||
@@ -23,9 +23,9 @@ To execute a stored procedure:
|
||||
end
|
||||
</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).
|
||||
* 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]] . }}
|
||||
{{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.
|
||||
|
||||
Reference in New Issue
Block a user