Archive auto Primary Keys?

Anything QL Software or Programming Related.
User avatar
BSJR
Trump Card
Posts: 186
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: Archive auto Primary Keys?

Post by BSJR »

The Quanta archives hold some family tree programs running in Archive. There was also a version published in the QL-World exchange series. Several _dbf's were linked together. For that each person is identified by a unique number that is generated automatically in field one when a new individual is inserted.
The same way Marriages and Families records are numbered. This famarch.zip (18KB) - Family Archive database - might be worth a look.

https://dilwyn.qlforum.co.uk/database/index.html

BSJR


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Archive auto Primary Keys?

Post by dilwyn »

Code: Select all

proc addEntry
cls 
rem if count()=0: let RefNo=0: endif 
display 
last 
let RefNo=RefNo+1
let dataval1$=""
append 
display 
alter 
endproc 

proc CreateDB
create "ram1_test_dbf"
RefNo
dataval1$
endcreate 
endproc 

proc openFile
open "ram1_test_dbf"
endproc 
Aha, the light bulb got switched on.

The secret lies in not using the INSERT command, rather ALTER.

In the routine above, the procedure CreateDB creates a database with two fields to play with - the first field is the Reference Number (RefNo) field, which increments by one for each entry added. The second is any old text field (dataval1$).

The routine assumes the database is held in order sorted by the reference number. Or could be assigned as the number of records already in the file possibly, if not already in order: let RefNo=count()

We jump to the end of the file, the displayed fields take the values of that record. We increment the value of the RefNo field and blank the data field and DISPLAY it with the new reference number token and blank text field. Now we APPEND that as the next new record in the database. Then ALTER it. Effectively an insert with a new system-generated auto-incrementing field value.

Now this may not necessarily be exactly what Sparrowhawk was trying to achieve, but it may give an idea for further developing as he required. Hope it's of some help.


User avatar
Sparrowhawk
Super Gold Card
Posts: 652
Joined: Wed Dec 15, 2010 12:33 pm
Location: @131072
Contact:

Re: Archive auto Primary Keys?

Post by Sparrowhawk »

Many thanks to everyone. This all looks rather promising Dilwyn, I'll certainly have a play, and look at the family tree one too.
I keep meaning to take a further look at dbas - I did skim the code examples very briefly over lockdown and also played around with it a few years back. Seems impressive. Will definitely look again.

SQLite (or even a more modest SQL engine) would be amazing though. Obviously lots of issues (quite apart from the porting ones) - for example, I've always wondered how one would map NULLs to S*BASIC. Probably have any SELECT query return both an array of results as strings, and also a binary string of which fields (based on ordinal position) are NULL, eg '0000010001' - 6th and 10th field is NULL?

Anyway, again, thanks for all he replies.


PS. I'd forgotten that Firebird was Interbase. Am I imagining it or would I have used Interbase with early Delphi for local dev? Seems to ring a vague bell.
Last edited by Sparrowhawk on Mon Nov 06, 2023 9:54 am, edited 1 time in total.


a.k.a. Jean-Yves
User avatar
Sparrowhawk
Super Gold Card
Posts: 652
Joined: Wed Dec 15, 2010 12:33 pm
Location: @131072
Contact:

Re: Archive auto Primary Keys?

Post by Sparrowhawk »

Ahah! I say I'll look at the family tree one, but of course I forgot that I am not currently a QUANTA member and so alas cannot access the library. But that's a whole other conversation of course :D


a.k.a. Jean-Yves
User avatar
BSJR
Trump Card
Posts: 186
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: Archive auto Primary Keys?

Post by BSJR »

Sparrowhawk wrote: Mon Nov 06, 2023 9:53 am Ahah! I say I'll look at the family tree one, but of course I forgot that I am not currently a QUANTA member and so alas cannot access the library. But that's a whole other conversation of course :D
The link I gave to Dilwyn's site is a program by Andy Carmichael who also wrote the one in QL-World's MDV Exchange so it's most likely the same program.
Having looked at the Quanta entries, these are based on many of the same Archive Procedures including the record numbering.

BSJR


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Archive auto Primary Keys?

Post by dilwyn »

Sparrowhawk wrote: Mon Nov 06, 2023 9:50 am Many thanks to everyone. This all looks rather promising Dilwyn, I'll certainly have a play, and look at the family tree one too.
Don't know how well it'd tie into what you wish to do in Archive, but it was the best I could come up with.


User avatar
Sparrowhawk
Super Gold Card
Posts: 652
Joined: Wed Dec 15, 2010 12:33 pm
Location: @131072
Contact:

Re: Archive auto Primary Keys?

Post by Sparrowhawk »

BSJR wrote: Mon Nov 06, 2023 11:26 am The link I gave to Dilwyn's site is a program by Andy Carmichael who also wrote the one in QL-World's MDV Exchange so it's most likely the same program.
Having looked at the Quanta entries, these are based on many of the same Archive Procedures including the record numbering.

BSJR
Thanks, will investigate.


a.k.a. Jean-Yves
Derek_Stewart
Font of All Knowledge
Posts: 3975
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Archive auto Primary Keys?

Post by Derek_Stewart »

Hi,

With regards to sqlite, the main source code is merged into a single file, with is over 1mb in size, on compiling with C68, the source code is too large for the compilef to handle.

I supple QDOS-GCC would solve this, but I have got this to run, maybe the Docker version would do it, I will investigate this.

However, there is sqlite source code in a standard C format with all the fucyions as separate files, which I have managed fo compile most of the to an objecft format ready to be linked into an executable, this where a Make will help. So just got write makefile and it should compile.

There is an issue with the compiling of the FTS functions, which is FullText Search. I just need to see if this can be disabled.


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Archive auto Primary Keys?

Post by NormanDunbar »

Sparrowhawk wrote:vPS. I'd forgotten that Firebird was Interbase. Am I imagining it or would I have used Interbase with early Delphi for local dev? Seems to ring a vague bell.
Yes, all the Delphi releases came with, and still do AFAIK, Interbase.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply