[Gambas-user] Using dates in Gambas

Cedron Dawg cedron at exede.net
Sun Jun 2 13:52:57 CEST 2019


Hi David,

Finding good example code in whole programs is what is motivating me to write my FarmDB programs.  You might find my latest output helpful in this regard.  You'll want to download the second example in this thread:

https://forum.gambas.one/viewtopic.php?f=4&t=718

FarmInfoHtml_20190530.zip

As part of that process, I created a table via Gambas instead of a CREATE statement for the first time:

---------------------------------------

'---- Create the Table

        Dim theTable As Table
        
        theTable = theCon.Tables.Add("Load_Info")
        
        With theTable.Fields
           .Add("Id", gb.String)
           .Add("Name", gb.String)
           .Add("Version", gb.String)
           .Add("LastVersion", gb.String)
           .Add("Vendor", gb.String)
           .Add("Release", gb.String)
           .Add("UploadDate", gb.String)
           .Add("Description", gb.String)
           .Add("URL", gb.String)
           .Add("Size", gb.String)
           .Add("Checksum", gb.String)
           .Add("DownloadCount", gb.String)
           .Add("FullDownloadCount", gb.String)
           .Add("VoteCount", gb.String)
           .Add("Owner", gb.String)
           .Add("Tags", gb.String)
        End With
        
        theTable.Update
        
---------------------------------------

I have yet to try a "Find".

Here is the part of the code where I take a file downloaded from a Farm Info query and load it into my table.  Note that I first load the data into a collection called "theValueOf", then use the collection to stuff the record as I am not sure that all the fields are going to be there or in the same order.   Notice the use of ".Begin" and ".Commit" making this a transaction.  It speeds up the process tremendously.

-------------------------------


'---- Loop thought the files adding records to the load table

        Dim theCreateRS As Result

        theCon.Begin
        theCreateRS = theCon.Create("Load_Info")
        
        For Each theFilename In theFilenames
          Print theFilename  
          GoSub ProcessFile
        Next
        
        theCreateRS = Null
        theCon.Commit
.
.
.

'-----------------------------------------------------------------------------
ProcessFile:

        Dim theLine As String, theLines As String[], p As Integer
        
        theLines = Split(File.Load(theTxtDir & theFilename), "\r\n")
        
        theValueOf.Clear
        
        For Each theLine In theLines
          p = InStr(theLine, "=")
          If p > 0 Then
             theValueOf[Left(theLine, p - 1)] = DeQuote(Trim(Mid(theLine, p + 1)))
          Endif
        Next
   
        theCreateRS!Id = theValueOf["Id"]
        theCreateRS!Name = theValueOf["Name"]
        theCreateRS!Version = theValueOf["Version"]
        theCreateRS!LastVersion = theValueOf["LastVersion"]
        theCreateRS!Vendor = theValueOf["Vendor"]
        theCreateRS!Release = theValueOf["Release"]
        theCreateRS!UploadDate = theValueOf["UploadDate"]
        theCreateRS!Description = theValueOf["Description"]
        theCreateRS!URL = theValueOf["URL"]
        theCreateRS!Size = theValueOf["Size"]
        theCreateRS!Checksum = theValueOf["Checksum"]
        theCreateRS!DownloadCount = theValueOf["DownloadCount"]
        theCreateRS!FullDownloadCount = theValueOf["FullDownloadCount"]
        theCreateRS!VoteCount = theValueOf["VoteCount"]
        theCreateRS!Owner = theValueOf["Owner"]
        theCreateRS!Tags = theValueOf["Tags"]

        theCreateRS.Update

        Return

-------------------------------

I need to clean the code up a bit before I post it.  This was a rough draft for research purposes.  What will change is the field names.  Here I used the names used in the info files for consistency, and SQLite seems to do fine with mixed case.  MySQL and others don't, so I have been using all lower case with underscore separators for all my database projects.  Thus "FullDownloadCount" will become "full_download_count" in the revised version.

These reports will tell you which projects use which components according to the tags.  I have yet to parse the project files or the code.  However, there is no guarantee that the Software Farm projects are doing things correctly.  There does seem to be an "admin" dude that knows what they are doing.


I have a similar process for a different region of my database concerning Gambas' Components and Classes.  You can find the zip file, download it, run it, then have the code, the database, and the reports.

https://forum.gambas.one/viewtopic.php?f=4&t=709

Hope this helps you and others.  I know I have found it helpful for myself.

Ced



----- Original Message -----
From: "user" <user at lists.gambas-basic.org>
To: "user" <user at lists.gambas-basic.org>
Cc: "David Silverwood" <the_watchmann at yahoo.com>
Sent: Sunday, June 2, 2019 4:12:50 AM
Subject: Re: [Gambas-user] Using dates in Gambas

Hi Benoit 

I must admit that is easier said than done. Nowhere have I found anything pertaining to using the find etc methods and as you can see my attempt at using it failed and it was this request that sparked all the replies, though not one really pertaining to my question. In C I used to do it like that using sqlite3_exec / sqlite3_prepare_v2 etc and I basically moved towards familiar grounds first due to lack of documentation or examples. 

So, looking at my second example again, and going back to my question... what am I missing? 

Probably, my question should be 
When do you use db.Find() and under what circumstances would you use db.Edit() and how do they tie together. As Ced stated, a 'realworld example' would be a plus... 

open database 
create table 
new record 
update record 
delete record 
close db 

Regards 

David 



More information about the User mailing list