Online Eiffel Documentation |
Documentation Home > Class Libraries > EiffelStore > EiffelStore Content > EiffelStore Interface Layer |
EiffelStudio |
Selection Access |
Once you haveselected 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 theDatabase/Eiffel objects Coupling to learn advanced data handling features.
To use DB_RESULT, process in 2 steps:
DB_SELECTION class provides different ways to customize result loading:
selection: DB_SELECTION my_result: DB_RESULT ... selection.query ("...") if selection.is_ok then selection.load_result my_result := selection.cursor end
selection: DB_SELECTION container: ARRAYED_LIST [DB_RESULT] create container.make (Max_results) ... selection.set_container (container) ... from container.start until container.after loop ... end
Tip: Provide DB_SELECTION with the LIST structure convenient for what you need to do with the results.
class MY_ACTION inherit ACTION redefine execute, found end ... execute is do i := i + 1 end ... found: BOOLEAN is do Result := i >= Max_result end
selection: DB_SELECTION action: MY_ACTION ... selection.set_action (action) selection.query ("...") if selection.is_ok then selection.load_result end
A DB_RESULT object merely carries data retrieved from the database. You have to convert it to a DB_TUPLE to access data within the retrieved row conveniently, i.e. mostly the column values:
selection: DB_SELECTION tuple: DB_TUPLE ... create tuple tuple.copy (selection.cursor) if tuple.count >= 2 and then tuple.column_name (2).is_equal ("Firstname") then io.putstring (tuple.item (2).out) end
See Also
Performing a database selection.
Coupling database data and Eiffel objects.
Copyright 1993-2006 Eiffel Software. All rights reserved. |