[Gambas-user] A request for SQLRequest
bb
adamnt42 at gmail.com
Wed Feb 2 10:48:45 CET 2022
On Mon, 2022-01-31 at 17:58 +1030, bb wrote:
> Could we have a "DISTINCT" option in the Select() function please?
>
> b
>
Upon reflection and a bit of searching I see that the SQLRequest class
is written in pure Gambas :-)
So I cloned the Select() function into SelectDistinct() and that now
works fine in postgresql, mariadb and sqlite3, all of which support the
DISTINCT call. I had to do it that way because the Select() function
already has optional parameters and in fact variant parameters, so
adding another parameter to the function is not trivial and cloning the
function was so simple. For anyone interested, here is the function.
Public Sub SelectDistinct(Optional Fields As Variant, ...) As SQLRequest
Dim aField As String[]
$sType = "SELECT DISTINCT"
If Fields Then
Try aField = Fields
If Error Then
aField = [CStr(Fields)]
aField.Insert(Param.All)
Else
aField = aField.Copy()
Endif
Else
aField = ["*"]
Endif
$aField = aField
Return Me
End
Note that I also "completed" the If Fields block, I don't know whether
that is really necessary, but as the Irish say "To be sure, to be sure,
to be sure."
@Benoit,
Feel free, in fact I'd appreciate it if you would, include this in the
product. I'd submit a merge but I'll be damned if I know how to push a
clean bit of code like this without all our other local tweaks.
regards
b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220202/2e225555/attachment.htm>
More information about the User
mailing list