It seems there are three strategies I can choose among, or indeed four if I include the zero option of continuing to copy/paste from Calc.
-
Load into Calc using the various options when opening a .csv file there: paying particular attention to getting the separators and date formats recognised correctly. Select all, copy/paste into Base creating a new table or appending to a suitable existing one
-
Create a suitable folder to contain the .csv file or files and then create a âdatabse connectorâ file to that folder by using the options in the dialog when opening Base. That makes LO regard that folder as a read-only text database. This works best when the locale set for LO matches (or is close enough) to that of the organisation that generated the .csv file/s â then use copy/paste to move that data from the intermediate database to the destination one.
-
Start as in option 1, but then write suitable macros in the destination database to do the transfer at the touch of a button from within forms. Thanks to @RobertG for this suggestion and the further details given in other comments he has made
-
Use the HSQLDB non-standard SQL âCREATE TEXT TABLE âŚâ to create a text table based on a .csv file that is placed in the same folder as the .odb file of the destination database. Then use a View to do any necessary transmogrification of the data, and the standard SQL "INSERT INTO (<columns) SELECT * FROM ". Big thanks to @Villeroy for this suggestion and the very helpful links to some Macro code to do this which you will find in his comments on my question
Each of the options has its merits, in my opinion, and corresponding disadvantages.
-
The spreadsheet option gives a more flexible interface to importing .csv files if the user actually uses it instead of just taking the default options. In contrast there are far fewer options when creating a connector database in options 1 and 2; and even fewer in option 3 unless you are a real SQL wizard and can write the workarounds in an SQL view.
-
Is by far the easiest conceptually for someone not interested in the inside details of SQL let alone LO and the Java of HSQLDB. You can still create a view on the imported data if it needs further massaging once it arrives in the destination database, and if you create that view using the LO GUI then you can be confident that it will survive future upgrades of LO. This option leaves the door open to future migration to option 2 once you get other parts of your software working. It also also works for copy/pasting data into a connected MariaDB engine and presumably any other external database (though that is beyond the scope of my question). I have tested this using LO 6.4 on LinuxMint copy/pasting data into both the embedded HSQLDB engine and into an external Mariadb (Ver 15.1 Distrib 10.3.37-MariaDB).
-
Is only straightforward if you are already at least partly familiar with LO Macro. If/when I attempt this my preference would be to write the code in Python and hook it in from a very simple Macro command to run the Python code. Or even Perl! Although I am fluent in both Perl and Python, one look at Macro sends me back to the 1970âs and Basic. Perhaps that is merely prejudice on my part; but a language looking good is personally important to me when I have the choice. Your preferences may vary of course: Libre means âfree as in speechâ
-
Is only straightforward if you are an SQL wizard and can use that to workaround the limitation that this method only recognises dates if they are in ISO format (2022-12-25 rather than either 25/12/2022 or 12/25/2022). If you write that wizardry within the Edit as SQL option of Views then you can be reasonably confident it will survive future migration. Alternatively if you stick to Standard SQL only then CREATE View will work from Tools->SQL and by saving the SQL code elsewhere you should survive any future migration of LO. For those sufficiently knowledgeable about writing SQL and about .csv complexities this option offers by far the best degree of resliience against one other potential migration issuie: what happens if the idiots at the data provider later change some pernickety detail of their .csv format? Long experience suggests they will make it work in MS Office and one or two other MS packages, but leave free software users drowning. @Villeroy has used this method âfor yearsâ so it is well tested, and he is also quite an active volunteer here and I am sure he would answer new questions if you canât make it work yorself
A request from me I want this question and answer to remain at the strategic level, to help other users choose a strategy. Feel free to comment here if you want to add another option, or a major advantage or disadvantage of any of the above. PLEASE do not ask detailed questions of implementation here â to keep this thread tidy start a new question. By all means link back to these options if you do that.
Almost my final point: you may be interested to know why I am so concerned about future migration. That is because I have been a user of OO Base and later LO Base for years. I survived the migration from LO using embedded Firefox to embedded HSQLDB and the migration was a nightmare for me. The end result is well worth the trouble, but I do not want a similar nighmare again. As I have no control over what the lovely LO devs will do in future I want to do everything I can to make any future transition as seamless as possible.
If you want to use the software you are writing for longer than the expected lifetime of your operating system and for longer than the expected lifetime of your current version of LO then you need to think about this.
For me the issue is that some of the accounts I prepare have to be kept for six or seven years. If the HMRC (our tax people) ask for details within that time I am legally obliged to help them understand why the summary figures I gave them are vaild. I therefore want to be sure that my accounts database will still work in seven years from the day I start work on a particular yearâs data.
If you are doing something that you know you will not need to use past your next OS upgrade then that is not such an issue for you. Answer the following questions for yourself first: What is the long-term support promise from your OS provider? From LO for the version you are using?
And finally: please regard this post as CC_BY_ATTRIB This means you are very welcome to copy this answer but if you use a substantial amount of it please acknowledge me as Ask LibreOffice: @trueriver.