comp • gb.db • sqlrequest

SQLRequest (gb.db)

Since 3.8

This class provides a facility to generate a basic SQL request on a single table.

This class is
Create a new SQL request object.
creatable
.
This class can be used as a
Return the SQL request corresponding to the SQLRequest object.
function
.

Methods

Specify that the next WHERE clause will be concatenated with the AND operator.
And  
Tells that the request is a DELETE request.
Delete  
Specify the table of the request.
From  
Return the SQL request corresponding to the SQLRequest object.
Get  
Specify that the next WHERE clause will be concatenated with the OR operator.
Or  
Describe the ORDER BY clause of the request.
OrderBy  
Tells that the request is a SELECT request.
Select  
Specify one criterion of the WHERE clause.
Where  

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