This class consists of a number of features that simplify the use of SQL queries making the source code more compact, understandable and elegant. Especially, this class is useful when you have extensive use of typical SQL statements: SELECT, INSERT, UPDATE and DELETE. It is supposed, that you inherit this class in those your classes where the use of SQL queries is intended.
The example below demonstrates how to use this class to create SQL queries for various purposes:
inherit QUERY_COMPOSER ... query: QUERY ins : SQL_INSERT sel : SQL_SELECT del : SQL_DELETE upd : SQL_UPDATE s : STRING r : REAL n : INTEGER ... ------------------------------------------------------------- -- Query 1a: select names of all the products from -- the Products table whose IDs are greater than 100: query := sql ("select Prodname from Products where ProdId >") & 100 ------------------------------------------------------------- -- Query 1b: same but using the SQL_SELECT class: sel := select_ ("ProdName", "Products", sql ("ProdID >") & 100) ------------------------------------------------------------- -- Query 1c: modify the last query to provide sorting -- of products by unit prices: sel.order_by ("UnitPrice") ------------------------------------------------------------- -- Query 1d: modify the last query making the selection -- criteria strictler: now all selected products should -- be cheaper than $10 for a unit: sel.and_where (sql ("UnitPrice <") & 10) ------------------------------------------------------------- -- Query 2a: insert into the table Cities a record about -- the city "Moscow" having approximately 10M citizens: s := "Moscow" n := 10000000 query := sql ("insert into Cities (City_Name, Total_Citizens) values(") & s &, n + ')' ------------------------------------------------------------- -- Query 2b: same but using the SQL_INSERT class: s := "Moscow" n := 10000000 ins := insert ("Cities", "City_Name, Total_Citizen", <<s, n>>) ------------------------------------------------------------- -- Query 3a: physically delete all the records marked -- as deleted from the table whose name become known -- in runtime: s := "Hardware" query := sql ("delete from") & s + " where Deleted_Flag = 'D'" ------------------------------------------------------------- -- Query 3b: same but using the SQL_DELETE class: s := "Hardware" query := delete (s, "Deleted_Flag = 'D'") ------------------------------------------------------------- -- Query 4: update the position and salary of a person -- having the name Joe Donovan: s := "Joe Donovan" upd := update ( "Employees", <<"position", "salary">>, <<"programmer", 35000>>, sql ("Employee_Name =") & s)