SQLRequest (gb.db)
Since 3.8
This class provides a facility to generate a basic SQL request on a single
table.
Methods
And
|
Specify that the next WHERE clause will be concatenated with the AND operator.
|
Delete
|
Tells that the request is a DELETE request.
|
From
|
Specify the table of the request.
|
Get
|
Return the SQL request corresponding to the SQLRequest object.
|
Or
|
Specify that the next WHERE clause will be concatenated with the OR operator.
|
OrderBy
|
Describe the ORDER BY clause of the request.
|
Select
|
Tells that the request is a SELECT request.
|
Where
|
Specify one criterion of the WHERE clause.
|
The class preserves Gambas DBMS independence. In other words the same code will produce a request that is syntactically correct for the dialect of the underlying database.
Example
Dim hConn As Connection
Dim iAgeMin As Integer = 18
Dim iAgeMax As Integer = 30
Dim hSqlRequest As SqlRequest
' ... Initializing the connection
hSqlRequest = New SqlRequest(hConn)
Print hSqlRequest.Select("id", "name", "age").From("people").Where("age >= &1", iAgeMin).And().Where("age <= &1", iAgeMax).OrderBy("name", "age DESC").Get()
will result in an SQL DML sentence that is correct for the database type specified by the hConn
Connection:
SELECT id, name, age FROM people WHERE age >= 18 AND age <= 30 ORDER BY name,age DESC