Since the great computer outage1, my capabilities of developing Delphi programs has dropped to minimal. I've been able to work on the Prolog interpreter primarily because this uses no database and no Hebrew, so I can develop it with Delphi 7 using a virtual computer on my laptop. I used to say that I would convert the Occupational Therapist's programs to Unicode only if someone put a gun to my head - well, I've reached that stage and have to start converting her programs. I find it rather ironic to see that the 'This day in blog history' has two blogs from five years ago about porting an application to Windows 10/Delphi 10.2! The applications may have been ported but the databases certainly weren't.
As working in Delphi 10.2 on my laptop computer (with 8 GB memory) is painful, I've taken the step of ordering a new desktop computer - this will have 16 GB memory, a much faster processor, a 1 TB disc and a larger screen. To think that my first ever computer had 512 KB memory and that adding a further 128 KB was considered a huge win! This new computer is due to be delivered later today.
In the mean time, I decided to convert one of the OP's programs that she's been having problems with recently. This program has "only" 15 tables, two of which are not being used any more (for licensing purposes) and a few have only integer fields. It's the tables with the character data - like the People table - that cause all the problems in converting data. Last night, I created the new database using 'SQL Manager Lite'; I defined the default character set for the database as UTF8, as necessary for Unicode. I defined all the tables using the DDL data, modifying this only when there were character fields.
Today I started work on the conversion tool. Some time ago, I worked on a similar tool for converting the Manager database - this has slightly over 100 tables, many of which contain character data; I wrote code that converted about half of the tables. The first table that I worked on this morning had only integer fields so that wasn't a problem, but the second had a character field, and this is where the problems began.
Simply reading from one database and saving to another is not good enough when the data has to be changed. I tried various methods, such as reading the old data by means of a conversion to AnsiString then trying to convert it to utf8 via the AnsiToUtf8 function but this didn't work either. I wasn't even sure that the field in the new database was defined as utf8 because the 'column character set' was empty.
After lengthy consultation with CoPilot, I ended up using the following obscure to read the old data then save it as unicode.
for i:= 8 to 15 do begin raw:= qGetPeople.fields[i].AsBytes; s:= TEncoding.GetEncoding(1255).GetString(raw); utf8:= TEncoding.Utf8.getbytes (s); p:= qInsPeople.Params[i]; if Length(utf8) > 0 then p.SetBlobData(@utf8[0], Length(utf8)) else p.Clear; end;
CoPilot tells me that there's a bug in the database driver and there might be one in the SQL manager as well, so using a very low level method of writing the data as a blob should overcome these bugs. CP also gave me the code for checking the character set of the appropriate fields; I discovered that fortunately they are defined as UTF8. When I look at the character fields in the Unicode database, they are in Hebrew and not some form of gibberish.
Today I'll finish converting the entire database (fortunately not too large) then tomorrow I'll start on converting the program itself. Who knows what problems await me.
Internal links
[1] 2041
| Title | Tags | ||
|---|---|---|---|
| 328 | Sumptuous Sunday 4 | Cooking | |
| 541 | The simplest ideas are normally the best | ERP, Problem solving | |
| 920 | Vinyl log 27 - 23 January | Vinyl log, 10cc | |
| 1371 | Porting an application to Windows 10/Delphi 10.2 (part 3) | Programming, Delphi, Unicode | |
| 1372 | Porting an application to Windows 10/Delphi 10.2 (part 4) | Programming, Delphi, Unicode | |
| 1576 | More David Crosby: Guinnevere | CSN | |
| 1892 | Garth Hudson RIP | Obituary, The Band |