[[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:
*  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 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. 

Once you have handled your error, for instance by displaying the error_message on screen, you can call reset to perform new database transactions.

==Managing database connection==

[[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>
    session_control: DB_CONTROL

                ...

            session_control.connect
            if session_control.is_connected then
                    -- Perform your transactions here.
                session_control.disconnect
            end
</code>

==Committing changes in the database==

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 to its state after the most recent commit. 

The following example illustrates the use of these commands:
<code>
    session_control: DB_CONTROL

                ...

    from
    until
            transaction_completed or else not session_control.is_ok
    loop
            -- Perform your transaction here.
    end
    if session_control.is_ok then
            session_control.commit
    else
            session_control.rollback
    end
</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.

{{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/>
[[EiffelStore Implementation Layer|Implementation]]  <br/>
}}




