Yesterday I spent several hours working on the blog manager program (BMP);
this time can be divided into three sections: (a) adding functionality for
which I had an idea before programming; (b) fixing the startup code once
again; (c) improving something that occurred to me whilst I was working.
Way way back, just over two years ago, I
wrote1 it occurred to me that I could make a useful extension, and
allow my program to execute the Internet browser and display a given blog. So
I added an 'address' field both to the 'entries' table and to the form that
allows me to enter or edit an entry. In writing/copying that quote, I
utilised the 'address' field in order to find the link to that blog - it's
much faster to do so in the BMP that via the online blogger site.
Since then, I've been adding the address to every blog that I've written, and
in an informal way I've been adding addresses to older blogs. Again, because
the online blogger site's interface doesn't make this easy, I would request to
display a tag then iterate over all the blogs with that tag, adding addresses
to those that lack them.
This was somewhat ad hoc, so yesterday I had the idea of first creating
a list of all tags that have entries without addresses, sorted by descending
count; double clicking on a line should bring up the actual entries for that
tag that lack an address. Then I can iterate over these blogs and add their
addresses.
At first I tried to use the existing ShowTags form, as this already has a
certain amount of functionality built-in (or rather, I've already added this).
But it seemed that I was fighting the existing code all the way, and that the
advantages that would accrue from using the existing form were overshadowed by
the overhead. So I decided to create a new and much simpler form (NoAddress) to show the
tags that lack addresses.
For some currently unknown reason, I was not able to display this list sorted
in descending order. After banging my head against the computer screen for a
while, eventually I hit upon a solution that will technically sort in
ascending order but will display in descending order.
select tags.id, tags.name, count (*), 200 - count (*) as final
from tags
inner join tag2entry on tag2entry.tag = tags.id
inner join entries on entries.id = tag2entry.entry
where entries.address is null
group by 1, 2
order by 4, 2
This is a kludge but it works. Once I had this out of the way, I could write the query to collect all the entries that lack an address by a given tag in order to pass this to a new instance of the ShowEntries form. I also added the code to graph the top ten tags, should I be so inclined to see this.
Then it occurred to me that if I had added all the addresses lacking in the ShowEntries form, that form should somehow update the tags shown in the NoAddress form, reflecting that some entries now had addresses. At first I thought to do this by passing some form of parameter to ShowEntries, but this would change (not necessarily break) a certain amount of code. It would be much easier for the ShowEntries form when it was about to close to send a message to the main form that would look for child forms of type TNoAddress and tell them to refresh. This is more complicated to write in English than it is to program! I also added a 'secret' flag that will cause the entries to be shown in reverse order - this saves a key press. Displaying the entries in reverse order causes them to be in the same order as shown on the web site.
To my chagrin, I discovered that 90 of the 174 blogs tagged 'DBA' were lacking an address. So I toiled to add the addresses of all the blogs. This will also have reduced the number of entries lacking addresses for other tags, as there are the BMP informs me that 41 tags are paired with tag=DBA.
Having got all of that out of the way, I then discovered that once again2 the program would not work on my mobile computer. Instead of the usual error message that I had seen before, I was now getting a message that the database connection was missing (or similar). Eventually I realised that the code was blanking the location of the database file but was not providing a new location. The solution to this follows, moving code that was previously in the OpenDatabase procedure to BeforeConnect. A few hours later, it occurred to me that this code will prevent me from accessing the 'other' blog on my development machine and will also not set the 'fileprefix' variable, but this won't matter very much.
procedure TDm.OpenDatabase (index: word);
begin
dbnum:= index;
datadir:= IncludeTrailingPathDelimiter
(ExtractFileDir (application.exename))
+ 'data\';
mutex:= TILMutex.Create (progname);
end;
procedure TDm.SQLConnection1BeforeConnect(Sender: TObject);
var
pname, dir: string;
begin
if not fileexists (dm.SQLConnection1.Params.values['database']) then
begin
case dbnum of
0: begin
pname:= 'Perceptions';
fileprefix:= pname;
end;
1: begin
pname:= 'PPP';
fileprefix:= 'Programming pitfalls in Priority';
end;
end;
fileprefix:= fileprefix + ' ';
with TRegIniFile.create (regpath) do
begin
dir:= ReadString ('firebird', pname, '');
free
end;
with sqlconnection1 do
begin
close;
params.values['database']:= dir;
loginprompt:= false;
end;
end;
end;
I checked this code by running it on my mobile computer and trying to access the second database; this worked, but when I tried to run the 'show singleton query' (i.e. tags that have been used precisely once), I received a syntax error in the query. This was easily dealt with, and then I saw that in order to show the singleton entry, I was using code that had since been refactored into a procedure in the data module. So I replaced the duplicate code with a simple procedure call.
Now I can spend my idle time by adding addresses to entries - the next tag on the list is 'Holiday' with 53 entries. I imagine that I will kill two birds with one stone, as slightly further down the list is 'Italy' with 43 entries; I doubt that there are many - if any - old entries about Italy that are not connected to holidays.
Internal links
[1] 1538
[2] 1846
This day in history:
Blog # | Date |
Title | Tags |
648 | 17/11/2013 | TV series update | TV series, DCI Banks |
1273 | 17/11/2019 | Song festival 2019 | Kibbutz, Song writing |