[[Property:modification_date|Thu, 04 Jan 2024 11:06:50 GMT]]
[[Property:publication_date|Thu, 04 Jan 2024 11:06:50 GMT]]
[[Property:title|Selector Sample]]
[[Property:weight|1]]
[[Property:uuid|3d608710-5537-04e4-fa89-a608ee6864cd]]
This sample creates a DB_BOOK table in your database, enters sample data in it and lets you select rows from this table with author's name.
==Compiling==
To compile the example:
* Launch EiffelStudio.
* Click '''Add project'''
* Browse to ''$ISE_EIFFEL\examples\store\select\''.
* Clicking open loads the selected project
* Choose select.ecf
* Select the target according to the installed DBMS
* Choose the location where the project will be compiled, by default the same directory containing the configuration file.
* Click '''OK'''.
==Running==
In order to run this example, you must first create a file named data.sql
from one of the files in the select
example directory. You will see that the data.sql
files in the example directory have names which include the names of the available DBMS handles. This is because the SQL can differ from one DBMS to another. For example, you'll see data.sql.oracle
and data.sql.odbc
. If you are using the Oracle DBMS, you should rename or make a copy of data.sql.oracle
as data.sql
and make sure it's in your execution directory before running the example.
{{note|The data.sql
file must be available in the sample application current directory. If you run the sample from EiffelStudio, this directory should be the ''EIFGENs/target/W_CODE/'' directory of your project (where target is one of the installed DBMS). }}
This sample lets you interact with your database through a console.
First you have to enter the database connection information:
* For ODBC:
Database user authentication:
Data Source Name: handson
Name: smith
Password: mypass
{{note|''Name'' and ''Password'' are not required with ODBC. If you don't need ''Name'' and ''Password'', you can simply hit ''Return'' when prompted. }}
* For Oracle:
Database user authentication:
Name: smith@HANDSON
Password: mypass
{{note|You must specify the Oracle User Name and Net Service Name with the syntax `@` where `` stands for the User Name and `` stands for the Net Service Name. }}
Then you can select rows from this table with author's name, for instance:
Author? ('exit' to terminate):Bertrand Meyer
Seeking for books whose author's name match: Bertrand Meyer
Author:Bertrand Meyer
Title:Eiffel The Libraries
Quantity:11
Price:20
double_value:435.60000610351562
First publication:07/01/1994 12:00:00.0 AM
Author:Bertrand Meyer
Title:Eiffel The Language
Quantity:9
Price:51
double_value:775.22998046875
First publication:07/01/1992 12:00:00.0 AM
Author? ('exit' to terminate):
{{note|Enter `exit` to quit the application. }}
==Under the Hood==
This sample showcases the use of the [[ref:libraries/store/reference/db_selection_chart|DB_SELECTION]] class to perform smart ''select'' queries, using:
* [[Data Object Coupling|Database data and Eiffel objects Coupling]] .
* [[Query variables|Variables Binding]] .
The whole sample code is contained in the root class:
* SELECTOR for Oracle.
* SELECTOR_ODBC for ODBC.