Author:halw

Date:2008-12-09T17:39:05.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@131 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
halw
2008-12-09 17:39:05 +00:00
parent 8782e3dbe7
commit 0726470766
7 changed files with 103 additions and 86 deletions

View File

@@ -18,5 +18,5 @@ Community input is welcome. If you are interested in improving and developing Ei
To become a contributor, you should be proficient in Eiffel technology and have good written English skills. To become an editor, you should already be a contributor and have contributed significant improvements or additions to the documentation. To become a contributor, you should be proficient in Eiffel technology and have good written English skills. To become an editor, you should already be a contributor and have contributed significant improvements or additions to the documentation.
If you are interested in becoming a contributor, please send an email to info@eiffel.com with a short description of your Eiffel experience and any other relevant background. If you are interested in becoming a contributor, please [http://doc.eiffel.com/contact contact us] or send an email to info@eiffel.com with a short description of your Eiffel experience and any other relevant background.

View File

@@ -22,8 +22,8 @@ The <eiffel>HANDLE_USE </eiffel>class provides access to the unique <eiffel>HAND
* Database status information: * Database status information:
<code> <code>
status: DB_STATUS status: DB_STATUS
-- Status of active database -- Status of active database
</code> </code>
@@ -35,13 +35,13 @@ Every interface class inherits from the <eiffel>HANDLE_USE</eiffel> class and ca
The creation procedure for a <eiffel>DB_CHANGE</eiffel> object is for instance: The creation procedure for a <eiffel>DB_CHANGE</eiffel> object is for instance:
<code> <code>
make make
-- Create an interface object to change active base. -- Create an interface object to change active base.
do do
implementation := handle.database.db_change implementation := handle.database.db_change
create ht.make (name_table_size) create ht.make (name_table_size)
implementation.set_ht (ht) implementation.set_ht (ht)
end end
</code> </code>
==Access to the DBMS call interface== ==Access to the DBMS call interface==
@@ -65,16 +65,18 @@ Let us give some details about the set_base feature:
The corresponding code looks like: The corresponding code looks like:
<code> <code>
session_status: DB_STATUS session_status: DB_STATUS
-- A session management object reference. -- A session management object reference.
...
set_base ...
...
update_handle set_base
if session_status = Void then ...
create session_status.make update_handle
end if session_status = Void then
handle.set_status (session_status) create session_status.make
end
handle.set_status (session_status)
... ...
</code> </code>

View File

@@ -23,13 +23,15 @@ Once you have handled your error, for instance by displaying the error_message o
The following example sum up these capabilities: The following example sum up these capabilities:
<code> <code>
session_control: DB_CONTROL session_control: DB_CONTROL
...
session_control.connect ...
if session_control.is_connected then
-- Perform your transactions here. session_control.connect
session_control.disconnect if session_control.is_connected then
end -- Perform your transactions here.
session_control.disconnect
end
</code> </code>
==Committing changes in the database== ==Committing changes in the database==
@@ -40,19 +42,21 @@ With many database systems, modifications you make to the database are usually n
The following example illustrates the use of these commands: The following example illustrates the use of these commands:
<code> <code>
session_control: DB_CONTROL session_control: DB_CONTROL
...
from ...
until
transaction_completed or else not session_control.is_ok from
loop until
-- Perform your transaction here. transaction_completed or else not session_control.is_ok
end loop
if session_control.is_ok then -- Perform your transaction here.
session_control.commit end
else if session_control.is_ok then
session_control.rollback session_control.commit
end else
session_control.rollback
end
</code> </code>
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. 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.

View File

@@ -15,11 +15,13 @@ Template queries are parsed to replace each variable by its bound value. To crea
Variables syntax is simple: the ':' special character followed by the variable name. Variables syntax is simple: the ':' special character followed by the variable name.
<code> <code>
selection: DB_SELECTION selection: DB_SELECTION
Bind_var: STRING = "firstname" Bind_var: STRING = "firstname"
...
create selection.make ...
selection.set_query ("Select * from CONTACTS where Firstname = ':" + Bind_var + "'")
create selection.make
selection.set_query ("Select * from CONTACTS where Firstname = ':" + Bind_var + "'")
</code> </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. }}
@@ -28,16 +30,18 @@ Variables syntax is simple: the ':' special character followed by the variable n
Once you have created your query, you can map variable names to values and execute the query: Once you have created your query, you can map variable names to values and execute the query:
<code> <code>
selection: DB_SELECTION selection: DB_SELECTION
Bind_var: STRING is "firstname" Bind_var: STRING is "firstname"
...
loop ...
io.read_line
selection.set_map_name (io.laststring, Bind_var) loop
selection.execute_query io.read_line
... selection.set_map_name (io.laststring, Bind_var)
selection.unset_map_name (Bind_var) selection.execute_query
end ...
selection.unset_map_name (Bind_var)
end
</code> </code>
{{seealso|<br/> {{seealso|<br/>

View File

@@ -12,13 +12,15 @@ EiffelStore lets you use stored procedures with [[ref:/libraries/store/reference
To execute 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> <code>
procedure: DB_PROC procedure: DB_PROC
...
create procedure.make ("UPDATE") ...
procedure.load
if procedure.exists then create procedure.make ("UPDATE")
... procedure.load
end if procedure.exists then
...
end
</code> </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).
@@ -33,11 +35,13 @@ You can execute your request mostly like a basic one:
** Execute the query through the DB_PROC object. ** Execute the query through the DB_PROC object.
<code> <code>
procedure: DB_PROC procedure: DB_PROC
expr: DB_CHANGE expr: DB_CHANGE
...
procedure.execute (expr) ...
expr.clear_all
procedure.execute (expr)
expr.clear_all
</code> </code>
** Check for errors and load result if any. ** Check for errors and load result if any.
@@ -50,19 +54,20 @@ DB_PROC also enables you to create or drop stored procedures:
* Use drop to delete one. * Use drop to delete one.
The following example shows how to overwrite a procedure in the database: The following example shows how to overwrite a procedure in the database:
<code> <code>
procedure: DB_PROC procedure: DB_PROC
... ...
create procedure.make ("NEW_PROCEDURE")
procedure.load create procedure.make ("NEW_PROCEDURE")
if procedure.exists then procedure.load
procedure.drop if procedure.exists then
end procedure.drop
procedure.load end
if not procedure.exists then procedure.load
procedure.set_arguments (<<"one_arg">>, <<"">>) if not procedure.exists then
procedure.store ("update contacts set firstname = one_arg where contactid = 1") procedure.set_arguments (<<"one_arg">>, <<"">>)
end procedure.store ("update contacts set firstname = one_arg where contactid = 1")
end
</code> </code>

View File

@@ -2,6 +2,8 @@
[[Property:weight|0]] [[Property:weight|0]]
[[Property:uuid|e2b93aea-ec1b-5897-0b0a-adc5681a1dcb]] [[Property:uuid|e2b93aea-ec1b-5897-0b0a-adc5681a1dcb]]
The Common Gateway Interface (CGI) emerged as the first way to present dynamically generated information on the World Wide Web. It allows the computer to process forms filled by the user and return appropriate information. <br/> The Common Gateway Interface (CGI) emerged as the first way to present dynamically generated information on the World Wide Web. It allows the computer to process forms filled by the user and return appropriate information. <br/>
EiffelWeb was developed by Interactive Software Engineering to provide Eiffel developers access to the CGI technology. The library makes it possible to write Eiffel systems that interact directly with the WEB. EiffelWeb was developed by Interactive Software Engineering to provide Eiffel developers access to the CGI technology. The library makes it possible to write Eiffel systems that interact directly with the WEB.

View File

@@ -17,19 +17,19 @@ These variables are usually used for the following purposes:
===Accessing Input Values=== ===Accessing Input Values===
The browser sends in the ''In'' a stream containing the data relative to the user entry and selection at the applications starts. EiffelWeb stores each data element and its associated name within a Hash-Table, the feature form_data of class CGI_INTERFACE. You can access their values from your code with the interface defined in class CGI_FORMS, which allows you to retrieve text entries, to know whether a button was pressed or not, etc. The browser sends in the ''In'' a stream containing the data relative to the user entry and selection at the applications starts. EiffelWeb stores each data element and its associated name within a Hash-Table, the feature <eiffel>form_data</eiffel> of class <eiffel>CGI_INTERFACE</eiffel>. You can access their values from your code with the interface defined in class <eiffel>CGI_FORMS</eiffel>, which allows you to retrieve text entries, to know whether a button was pressed or not, etc.
===Sending answers to the browser=== ===Sending answers to the browser===
The response has to contain an HTTP header in order to be understood by the browser. Depending on the nature of the reply, an HTML page, a simple re-direction, an error notification, you will select different features and options. Your application must send at least a response header, indicating the status of the request if known. You may want to attach to it the text you wish to send back to the user. This text is usually written in HTML, so that it will display nicely on the user's browser; you can use for this purpose the class HTML_PAGE. You may then send the header followed by your text using the features send_to_browser of classes CGI_RESPONSE_HEADER and HTML_PAGE. The response has to contain an HTTP header in order to be understood by the browser. Depending on the nature of the reply, an HTML page, a simple re-direction, an error notification, you will select different features and options. Your application must send at least a response header, indicating the status of the request if known. You may want to attach to it the text you wish to send back to the user. This text is usually written in HTML, so that it will display nicely on the user's browser; you can use for this purpose the class <eiffel>HTML_PAGE</eiffel>. You may then send the header followed by your text using the features <eiffel>send_to_browser</eiffel> of classes <eiffel>CGI_RESPONSE_HEADER</eiffel> and <eiffel>HTML_PAGE</eiffel>.
{{note|You may not write into a file before you have sent the answer to the browser. }} {{note|You may not write into a file before you have sent the answer to the browser. }}
===Dealing with Cookies=== ===Dealing with Cookies===
You can access the cookies corresponding to a specific URL/domain thanks to the feature cookies, of class CGI_ENVIRONMENT. It is a hash-table, in which all the data with associated names as keys are stored. You can access the cookies corresponding to a specific URL/domain thanks to the feature <eiffel>cookies</eiffel>, of class <eiffel>CGI_ENVIRONMENT</eiffel>. It is a hash-table, in which all the data with associated names as keys are stored.
To store a cookie on a machine, you can use the feature set_cookies, of class CGI_RESPONSE_HEADER. To store a cookie on a machine, you can use the feature <eiffel>set_cookies</eiffel>, of class <eiffel>CGI_RESPONSE_HEADER</eiffel>.
==Advanced Topics== ==Advanced Topics==
@@ -38,16 +38,16 @@ To store a cookie on a machine, you can use the feature set_cookies, of class CG
The information the server sends back may be confidential. Follow these steps to protect the page content: The information the server sends back may be confidential. Follow these steps to protect the page content:
# Create an HTML page, for example by using class HTML_PAGE. # Create an HTML page, for example by using class HTML_PAGE.
# Store this page somewhere, with a random name. # Store this page somewhere, with a random name.
# Create an instance of class CGI_RESPONSE_HEADER and choose the secure redirect option. Then call send_to_browser. # Create an instance of class <eiffel>CGI_RESPONSE_HEADER</eiffel> and choose the secure redirect option. Then call <eiffel>send_to_browser</eiffel>.
===Complex Headers=== ===Complex Headers===
The Eiffel-Web application has the possibility to send a selection of different HTTP headers. They can be found in class CGI_RESPONSE_HEADER. In particular, it is advised to generate a status for each request, the value of the most common ones may be found in class CGI_ [[ref:/libraries/web/reference/cgi_common_status_types_chart|COMMON_STATUS_TYPE]] . The Eiffel-Web application has the possibility to send a selection of different HTTP headers. They can be found in class <eiffel>CGI_RESPONSE_HEADER</eiffel>. In particular, it is advised to generate a status for each request, the value of the most common ones may be found in class [[ref:/libraries/web/reference/cgi_common_status_types_chart|CGI_COMMON_STATUS_TYPES]] .
===Debugging facilities=== ===Debugging facilities===
Design by Contract is one of the greatest strengths of the Eiffel language. When you usually run your application from EiffelStudio, you are notified when an assertion is violated and the tool offers different options in order to be able to find out its sources (feature and class tools, object inspectors, etc). However this cannot be applied to an EiffelWeb application, since it has to be run on the server. <br/> Design by Contract is one of the greatest strengths of the Eiffel language. When you usually run your application from EiffelStudio, you are notified when an assertion is violated and the tool offers different options in order to be able to find out its sources (feature and class tools, object inspectors, etc). However this cannot be applied to an EiffelWeb application, since it has to be run on the server. <br/>
Therefore, EiffelWeb provides its own facilities for debugging. To test your classes at run-time, all you need to do is to set the Boolean feature is_debug_mode to <code> True </code> in your root class (which should inherit from CGI_INTERFACE). When your application crashes (because of an assertion ora bug), the exception trace will be displayed on the screen. Therefore, EiffelWeb provides its own facilities for debugging. To test your classes at run-time, all you need to do is to set the Boolean feature <eiffel>is_debug_mode</eiffel> to <code>True</code> in your root class (which should inherit from <eiffel>CGI_INTERFACE</eiffel>). When your application crashes (because of an assertion or a bug), the exception trace will be displayed on the screen.