gb.db2 Order by

Post your Gambas programming questions here.
Andreas_K
Newbie
Posts: 20
Joined: Wed Sep 13, 2023 6:04 pm
Location: Italy - South Tyrol

gb.db2 Order by

Post by Andreas_K »

Hello, since i updatet from gb.db to db.db2 the order by in the sql statement dont work anymore, what i have to change?
I have also the problem, when i have a combobox and i open the popup (in the combobox), select a entry and then i enter in the field a text, the keypress event is not working, until i put the focus to another control and then i go back. The same problem i have in the IDE, from time to time, i need to select again the module or class, otherwise the keyboard is not working. I have this issue on Ubuntu 24.04 and on Ubuntu 24.10 (x86_64 and arm64). Anyone a idea what is the problem?
Thanks
User avatar
cogier
Site Admin
Posts: 1197
Joined: Wed Sep 21, 2016 2:22 pm
Location: Guernsey, Channel Islands

Re: gb.db2 Order by

Post by cogier »

I'll leave the database problem to those with better knowledge on that subject.

Regarding your "Click" problem, try Public Sub ComboBox1_Activate() not Public Sub ComboBox1_Click(). I think that will help you.
Andreas_K
Newbie
Posts: 20
Joined: Wed Sep 13, 2023 6:04 pm
Location: Italy - South Tyrol

Re: gb.db2 Order by

Post by Andreas_K »

Thanks, sorry i wrote wrong, key_release is not working, key_press works.
User avatar
thatbruce
Regular
Posts: 295
Joined: Sat Sep 04, 2021 11:29 pm

Re: gb.db2 Order by

Post by thatbruce »

give us an example of how you are doing the order by query.
I have had no problems at all with db2,
b
BruceSteers
Legend
Posts: 2110
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: gb.db2 Order by

Post by BruceSteers »

I do not get any key_release issues with combobox

But I often find i have typed something in a class/module but it did not appear because the editor was not focused and i have to click on the document to use the keyboard.

This happens sometimes after hitting the "run" button to test a program. (and possibly other IDE forms opening then closing)
It's simply (annoyingly) after a test run the editor does not regain focus and needs to be clicked.

It maybe a toolkit issue , try the IDE (and your program) with QT and see if it still happens.
env GB_GUI=gb.gui.qt gambas3
Andreas_K
Newbie
Posts: 20
Joined: Wed Sep 13, 2023 6:04 pm
Location: Italy - South Tyrol

Re: gb.db2 Order by

Post by Andreas_K »

Public Function ImportDB(sTable As String, sField1 As String, sField2 As String, Optional sWhere As String) As Boolean

   Dim Res As Result
   Dim sSql As String = DB.Subst("SELECT * FROM &1 ORDER BY '&2' ", sTable, sField1)
 
   If sWhere <> "" Then
      ssql = db.Subst("SELECT * FROM &1 " & sWhere & " ORDER BY '&2' ", sTable, sField1)
   Endif


With gb.db works, but with gb.db2 not.
Andreas_K
Newbie
Posts: 20
Joined: Wed Sep 13, 2023 6:04 pm
Location: Italy - South Tyrol

Re: gb.db2 Order by

Post by Andreas_K »

Today Key_Press don't work with Key.UP and Key.DOWN, i need to put the code in Key_Release to work? after Key_Release is worked out the Click Event is fired??.
I have a combobox with there i search in a gridlist the data, with up and down i scroll the gridlist.

Public Sub cbosearch_KeyRelease()
   ' Message(Key.Code)

   If mGridlist.aList.Count = 0 Then Return

   Dim iIndex As Integer

   For i As Integer = 0 To GridList.Rows.Count - 1
      If GridList.Rows[i].Selected Then
         iindex = i
         i = GridList.Rows.Count - 1
      Endif
   Next

   Select Case Key.Code
      Case Key.Enter, Key.Return 'Enter
         iIndex = mGridlist.FindIndexofText(cboSearch.Text)

         If iindex = -1 Then Return
         GridList.Scroll(0, GridList.Current.Y)
         Dim Result As String = GridList.Current.Text
         cbosearch.Text = Result
         'Show Record
         If GridList.Row = -1 Then Return
         GridSelected(GridList[GridList.Row, 0].Text)
         Return
      Case Key.Up
         If iindex > 1 Then
            iindex = iindex - 1
            GridList.Row = iindex
            GridList.Scroll(0, GridList.Current.Y)
            Result = GridList.Current.Text
            cbosearch.Text = Result
            Return
Poly
Newbie
Posts: 42
Joined: Sat Nov 02, 2024 11:10 am

Re: gb.db2 Order by

Post by Poly »

Andreas_K wrote: Mon Mar 17, 2025 5:37 pm
Public Function ImportDB(sTable As String, sField1 As String, sField2 As String, Optional sWhere As String) As Boolean

      ssql = db.Subst("SELECT * FROM &1 " & sWhere & " ORDER BY '&2' ", sTable, sField1)
   Endif


With gb.db works, but with gb.db2 not.
Hello, I am not an expert, but I am currently experimenting with an SQL database.
So far I have no problems with gb.db2
But I immediately notice something in your code.
You have not quoted correctly in db.Subst.
If you want to substitute a table name, you have to put it in square brackets.

See https://gambaswiki.org/wiki/doc/db-quoting

"If a substitution pattern in enclosed with square brackets, then the argument is supposed to be a table name, and the Connection.Quote method is used to correctly quote the table name into the result string. "

so you have to write

Code: Select all

 ssql = db.Subst("SELECT * FROM [&1]"  & sWhere &  "ORDER BY '&2' ", sTable, sField1)
Try it out to see if this fixes the error.

Best regards
Poly
User avatar
Quincunxian
Regular
Posts: 199
Joined: Sun Jun 25, 2017 12:14 am
Location: Western Australia
Contact:

Re: gb.db2 Order by

Post by Quincunxian »

Hi Poly,
Just a best practice thing - I'd recommend NOT using the name 'sWHERE' as a variable as it's a SQL key word and it makes it somewhat confusing when you look at the statement.

Can you give me an example of what you would pass in sWhere please, as I can't quite make sense of your SQL statement.

I'm not an expert but I do write a lot of MySql / SQLite based applications in Gambas.
Cheers - Quin.
I code therefore I am
User avatar
thatbruce
Regular
Posts: 295
Joined: Sat Sep 04, 2021 11:29 pm

Re: gb.db2 Order by

Post by thatbruce »

This is a perfect example of what happens when the original post contains two questions!
Post Reply