gb.db2 Order by

Post your Gambas programming questions here.
Poly
Newbie
Posts: 41
Joined: Sat Nov 02, 2024 11:10 am

Re: gb.db2 Order by

Post by Poly »

Have a look here, it has already been fixed.

https://lists.gambas-basic.org/archive/ ... 00064.html

That was quick. I am impressed. :D
BruceSteers
Legend
Posts: 2081
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: gb.db2 Order by

Post by BruceSteers »

Poly wrote: Tue Mar 25, 2025 11:21 am Have a look here, it has already been fixed.

https://lists.gambas-basic.org/archive/ ... 00064.html

That was quick. I am impressed. :D
Welcome to the cutting edge of gambas where any problems you find get fixed quickly :)

Thanks to Benoit for fixing and thanks to you for reporting, Gambas is now a little bit better :)
8-)
User avatar
grayghost4
Regular
Posts: 215
Joined: Wed Dec 05, 2018 5:00 am
Location: Marengo, Illinois usa

Re: gb.db2 Order by

Post by grayghost4 »

Do I have to reinstall Gambas to get it ... or just wait for the next release ?
BruceSteers
Legend
Posts: 2081
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: gb.db2 Order by

Post by BruceSteers »

it is fixed in master (development branch) right now.

then bug fixes will add to stable in the next release.
Poly
Newbie
Posts: 41
Joined: Sat Nov 02, 2024 11:10 am

Re: gb.db2 Order by

Post by Poly »

BruceSteers wrote: Tue Mar 25, 2025 12:04 pm
Thanks to Benoit for fixing and thanks to you for reporting, Gambas is now a little bit better :)
8-)
Thank you for your kind words. :D

I can't thank Benoit and the community enough when I see how quickly the bug was fixed.
Now I'm waiting impatiently for the new release.
But thanks to Grayghost4 I now know how I can do the whole thing alternatively by using Quote. :)
User avatar
grayghost4
Regular
Posts: 215
Joined: Wed Dec 05, 2018 5:00 am
Location: Marengo, Illinois usa

Re: gb.db2 Order by

Post by grayghost4 »

BruceSteers wrote: Tue Mar 25, 2025 3:17 pm it is fixed in master (development branch) right now.
I installed the development and can verify that it works properly with sqlite database :D
User avatar
gbWilly
Site Admin
Posts: 151
Joined: Fri Sep 23, 2016 11:41 am
Location: Netherlands
Contact:

Re: gb.db2 Order by

Post by gbWilly »

Poly wrote: Wed Mar 26, 2025 8:35 am Now I'm waiting impatiently for the new release.
But thanks to Grayghost4 I now know how I can do the whole thing alternatively by using Quote. :)
There is no need to wait for gb.db2 Subst to be in a new release.
You can use gb Subst as well. I been working like that for over 10 years and it never failed me.

Simple function as example using Subst (not the db2 Subst).
Public Function RemoveBasedOnDate(hConn As Connection, sTableName As String, iDaysBack As Integer, bUseDateTime As Boolean) As Boolean

  Dim rResult As Result
  Dim sQuery As String
  Dim sDateBackShort, sDateBackLong As String
  
  sDateBackShort = Format(Date(Now - iDaysBack), "yyyy-mm-dd")
  sDateBackLong = Subst("&1 00:00:00", sDateBackShort) 
  
  If bUseDateTime Then 
    sQuery = Subst("DELETE FROM `&1` WHERE Date < '&2'", sTableName, sDateBackLong)
  Else 
    sQuery = Subst("DELETE FROM `&1` WHERE Date < '&2'", sTableName, sDateBackShort)
  Endif
  Debug sQuery

  '--make it a transaction that can be rolled back--
  hConn.Begin
  rResult = hConn.Exec(sQuery)
  hConn.Commit
  
  Return True
  
  Catch
    Debug Subst("&1 (&2): &3", Error.Where, Error.Code, Error.Text)
    hConn.Rollback
    Error.Clear
    Return False
    
End

I threw in the
Debug sQuery
so you can see the actual query that will be executed.
Exampe on how to use:
If RemoveBasedOnDate(MyConn, "LogTable", 2, True) Then
 Message.Info(" Removed records older than 2 days from LogTable")
Else
  Message.Error("Something went wrong!!")
Endif

Note that the table needs a field named Date and the date content in a certain format
Either yyyy-mm-dd
OR yyyy-mm-dd hh:nn:ss
Screenshot below is from a mariadb table taken in phpMyAdmin to show a longdate example:
TableExample.png
This is the table structure for the Date field:
TableStructure.png
Code is a simplified routine I use in logging tables that have one of both date formats in a field named 'Date'. Wrote it right here without testing, so might be typo's in it.

Enjoy...
You do not have the required permissions to view the files attached to this post.
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- Gambas3 Debian/Ubuntu repositories

- GambOS

... there is always a Catch if things go wrong!
Poly
Newbie
Posts: 41
Joined: Sat Nov 02, 2024 11:10 am

Re: gb.db2 Order by

Post by Poly »

gbWilly wrote: Thu Mar 27, 2025 12:28 am
There is no need to wait for gb.db2 Subst to be in a new release.
You can use gb Subst as well. I been working like that for over 10 years and it never failed me.
Many thanks for the tip and your code examples.
I am really still a beginner without a project or a specific intention. I've just been playing with databases a bit.
But I think Gambas is great and I'm happy if I can perhaps help some beginners to try Gambas more by discovering errors or ambiguities and eliminating them.
My first introduction to Gambas was quickly ended by the fact that an array was read only. Because I thought I was too stupid, but that was a bug in the version at the time.

I will try to understand your examples and I am really pleased that you have added them here.
I like to learn :D

gbWilly wrote: Thu Mar 27, 2025 12:28 am
Enjoy...
I have a lot of fun with gambas. I just need more time. :lol:
User avatar
gbWilly
Site Admin
Posts: 151
Joined: Fri Sep 23, 2016 11:41 am
Location: Netherlands
Contact:

Re: gb.db2 Order by

Post by gbWilly »

Poly wrote: Thu Mar 27, 2025 6:38 pm Many thanks for the tip and your code examples.
I am really still a beginner without a project or a specific intention. I've just been playing with databases a bit.
Many moons ago I wrote a small thing aimed at people completely new to Gambas3 and programming in general. It never really got finished (personal circumstances) but it is still valid and more important usable introduction to GUI programming in Gambas3 and best of all downloadable as a pdf. Mail address in there is no longer valid and maybe some here on the forum contributed to grammar corrections and more. Check it out and discover...

In those days, I had big plans on a whole series (this was part 2, part 1 was on installing and compiling gambas and no longer valid as we moved from subversion to git). I like writing training manuals as I have worked as IT trainer for a good 5 to 6 years back in the 90ies (also developing training materials now and then).
Poly wrote: Thu Mar 27, 2025 6:38 pm But I think Gambas is great and I'm happy if I can perhaps help some beginners to try Gambas more by discovering errors or ambiguities and eliminating them.
My first introduction to Gambas was quickly ended by the fact that an array was read only. Because I thought I was too stupid, but that was a bug in the version at the time.
I learned a lot a long time ago on a Gambas forum before this one (White Islands software) and learned just by trying to solve the problems people reported on the forum. Try to replicate them in a vm and see what was causing it. Kind of what I see Bruce doing on this forum, getting smarter by the day, while helping others ;)

I discovered a lot in those days merely by doing that (and reading the wiki over and over again many, many, many, many times... ;) ) I had some open source projects in those day on the old forum all about supporting Gambas somehow or discovering it's possibilities.

Then, in 2013, I started migrating (read code it all completely new) the software (databases and front ends) I wrote 10 yeras before, in a Windows XP and Windows 2003 server environment for the corporation I worked for to gambas3 front ends (and eventually way more), mysql (later mariadb backend) on debian servers. Never going back, the servers never had problems, software (read gambas and all underlying) stable as one wished for without having to figure out work arounds. Complete migration took me about 4 years at about 20 hours a week, running a dual environment for that period (windows/Linux). Migration period was not just that, but also improvements and new additions as Gambas offered way more freedom of doing. And developed a set of management tools in Gambas3 as well, including daemons running on the servers reporting back to me.

Gambas is great for so many things, I really love programming in Gambas and have several private projects (for my own use).
Poly wrote: Thu Mar 27, 2025 6:38 pm I will try to understand your examples and I am really pleased that you have added them here.
I like to learn :D
Well, enjoy it some more...
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- Gambas3 Debian/Ubuntu repositories

- GambOS

... there is always a Catch if things go wrong!
Poly
Newbie
Posts: 41
Joined: Sat Nov 02, 2024 11:10 am

Re: gb.db2 Order by

Post by Poly »

gbWilly wrote: Thu Mar 27, 2025 9:27 pm Many moons ago I wrote a small thing aimed at people completely new to Gambas3 and programming in general.
This is from you? :o
I've already worked through it completely. It was what got me started with Gambas3 in the first place. :)
I think I know pretty much all the Gambas docs and I'm in the process of reading the wiki over and over again.
I can also highly recommend the Greek Gambas book https://github.com/demosthenesk/the_gambas3_book
I have translated it completely into German and think that your ‘How to Gambas’, the ‘Gambas from Zip’ and this book give you enough tools to get a good understanding of Gambas.
At least enough so that people are able to read the wiki better and dare to ask questions in a forum like this. ;)

I feel really honoured to be in contact with such important people from Gambas.
Thank you very much for this great "How to...."
For the work you have put into the creation and thus for the support for Gambas. :)

It's good to know that such cracks are reading along here.

With the very best regards
Poly
Post Reply