Bug 462833 - For database tables created with generated SQL, database storage layer doesn't correctly save and retrieve base currency
Summary: For database tables created with generated SQL, database storage layer doesn'...
Status: REPORTED
Alias: None
Product: kmymoney
Classification: Applications
Component: database (show other bugs)
Version: 5.1.2
Platform: Fedora RPMs Linux
: NOR minor
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-10 02:01 UTC by Bob Pesner
Modified: 2022-12-10 02:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Pesner 2022-12-10 02:01:47 UTC
SUMMARY
When working with database tables created by manually issuing the generated SQL, as opposed to letting kmymoney itself create the tables, the database storage layer doesn't correctly save and retrieve base currency, so that whenever such an SQL-based kmymoney file is opened, the user is prompted to re-choose the base currency.

STEPS TO REPRODUCE
1.  Start kmymoney with the -n option
2. Choose Tools->Generate Database SQL
3. Save the generated SQL into a file
4. Creating a new database or using an existing one, run the commands in the generated SQL file
5. In kmymoney, open the database
6. In the Currencies dialog that appears, add a currency and select it as the base currency
7. Save the kmymoney data to the database
8. Re-open the database by either closing and restarting kmymoney or choosing File->Open database

OBSERVED RESULT
kmymoney again prompts for selecting the base currency.
There is no row in the kmmKeyValuePairs table with kvpType='STORAGE', kvpKey='kmm-baseCurrency' and kvpData= <the 3 character base currency id>
The baseCurrency column in the single row in the kmmFileInfo table is empty

EXPECTED RESULT
File should open without prompt for base currency.
A row should be present in the kmmKeyValuePairs table with kvpType='STORAGE', kvpKey='kmm-baseCurrency' and kvpData= <the 3 character base currency id>
The baseCurrency column in the single row in the kmmFileInfo table should have the 3 character base currency id

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Reading the MyMoneyStorageSqlPrivate::readFileInfo method indicates that while there is a column called baseCurrency in the kmmFileInfo table, that's not where the base currency is retrieved from. Instead, it is retrieved from the kmmKeyValuePairs table, from a row with kvpType='STORAGE' and kvpId=''. If you manually issue the command 'insert into kmmkeyvaluepairs values('STORAGE','','kmm-baseCurrency','USD');' (or some other currency id), the problem goes away.

However, in the scenario described above, MyMoneyStorageSqlPrivate::writeFileInfo doesn't write such a record after choosing a base currency and saving to the database in the GUI. There is a call to writeKeyValuePairs("STORAGE", kvpList, pairs); around line 683 of kmymoney/plugins/sql/mymoneystoragesql_p.h, but at that point the pairs parameter has no entry with the key "kmm-baseCurrency". I haven't been able to determine why. 

I'm running kmymoney on Fedora 35 (close to EOL) and I have seen that Qt library updates do break some things, including kmymoney. I know nothing about Qt, but I am wondering if this is a Qt problem.