Bug 378676 - 4.8.0 creates invalid mysql statements on windows
Summary: 4.8.0 creates invalid mysql statements on windows
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: database (show other bugs)
Version: unspecified
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-11 21:20 UTC by Gary
Modified: 2019-08-29 00:44 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.8.1,5.0.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary 2017-04-11 21:20:41 UTC
Been using 4.7.2 on Windows, trying to install 4.8.0 on Windows (via http://sourceforge.net/projects/kmymoney2/files/KMyMoney-Windows/4.8.0/kmymoney-x86-setup-4.8.0.exe/download) using MySQL.

After program is installed, File -> Save as Database results in multiple errors:
1) CREATE TABLE kmmAccountsPayeeIdentifier (accountId varchar(32) NOT NULL, "order" smallint unsigned NOT NULL, identifierId varchar(32) NOT NULL, PRIMARY KEY (accountId, "order")) ENGINE = InnoDB;

dies due to using "order", per bug #365615.  I changed 4 instances in the SQL calls (2 each in creating tables kmmAccountsPayeeIdentifier  and kmmPayeesPayeeIdentifier ) from order to userOrder

2) What appears to be a typo in INSERT INTO kmmFileInfo row, hiPayeeIdentifierId data is NULLentifierId when I'm guessing it should be NULL?

After making the above changes, the SQL tables create successfully, but the program dies when using File -> Open database.  Another instance of Bug 365615, hardcoded "order" instead of userOrder in the query ORDER BY, here is error text:


Cannot open file as requested. Error was: Error in function const class QMap<class QString,class MyMoneyPayee> __thiscall MyMoneyStorageSql::fetchPayees(const class QStringList &,bool) const : reading Payee
Driver = QMYSQL, Host = localhost, User = root, Database = kmymoney2
Driver Error: 
Database Error No -1: 
Text:  
Error type 0
Executed: SELECT kmmPayees.id AS id, kmmPayees.name AS name, kmmPayees.reference AS reference,  kmmPayees.email AS email, kmmPayees.addressStreet AS addressStreet, kmmPayees.addressCity AS addressCity, kmmPayees.addressZipcode AS addressZipcode,  kmmPayees.addressState AS addressState, kmmPayees.telephone AS  telephone, kmmPayees.notes AS notes,  kmmPayees.defaultAccountId AS defaultAccountId, kmmPayees.matchData AS matchData, kmmPayees.matchIgnoreCase AS matchIgnoreCase,  kmmPayees.matchKeys AS matchKeys,  kmmPayeesPayeeIdentifier.identifierId AS identId  FROM ( SELECT * FROM kmmPayees  ) kmmPayees  LEFT OUTER JOIN kmmPayeesPayeeIdentifier ON kmmPayees.Id = kmmPayeesPayeeIdentifier.payeeId  ORDER BY kmmPayees.id, kmmPayeesPayeeIdentifier."order";
Query error No 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"order"' at line 1 QMYSQL: Unable to execute query
Error type 2


Is there a way to modify the SQL code given that I'm running it using the Windows .exe installer?
Comment 1 Gary 2017-04-11 21:26:42 UTC
Here is the exact SQL in my 2), error is in 4th from last field:

INSERT INTO kmmFileInfo (version, created, lastModified, baseCurrency, institutions, accounts, payees, tags, transactions, splits, securities, prices, currencies, schedules, reports, kvps, dateRangeStart, dateRangeEnd, hiInstitutionId, hiPayeeId, hiTagId, hiAccountId, hiTransactionId, hiScheduleId, hiSecurityId, hiReportId, encryptData, updateInProgress, budgets, hiBudgetId, hiOnlineJobId, hiPayeeIdentifierId, logonUser, logonAt, fixLevel) VALUES (8, '2017-04-11', '2017-04-11', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'N', NULL, NULL, NULL, NULLentifierId, NULL, NULL, 4);
Comment 2 Ralf Habacker 2017-06-29 18:35:07 UTC
(In reply to Gary from comment #1)
> Here is the exact SQL in my 2), error is in 4th from last field:
The problem here is that the implementation of creating the statements
creates a template first similar to the constructed line below:

INSERT INTO kmmFileInfo (hiPayeeId, hiPayeeIdentifierId) VALUES (:hiPayeeId, :hiPayeeIdentifierId);

and then replace the variable name :hiPayeeId' with 'NULL' which results into

INSERT INTO kmmFileInfo (hiPayeeId, hiPayeeIdentifierId) VALUES (NULL, NULLIdentifierId);

and let the remain replace of ':hiPayeeIdentifierId' unfinished.
Comment 3 Ralf Habacker 2017-06-29 18:47:59 UTC
Git commit f0caa56bd8af0d7939b64f63294c2a60ca7b4e8b by Ralf Habacker.
Committed on 29/06/2017 at 18:47.
Pushed by habacker into branch '4.8'.

Fix '4.8.0 creates invalid mysql statements on windows'.

The performed replace was too simple.
FIXED-IN:4.8.1

M  +3    -0    kmymoney/mymoney/storage/mymoneydbdef.cpp

https://commits.kde.org/kmymoney/f0caa56bd8af0d7939b64f63294c2a60ca7b4e8b
Comment 4 Ralf Habacker 2017-07-01 13:38:24 UTC
Git commit 64fa0cd4b58790324eaab18674e82de28e5cafaa by Ralf Habacker.
Committed on 01/07/2017 at 13:38.
Pushed by habacker into branch '4.8'.

Fix SQL DDL generation

Query parameters are being matched only based on their name. If one
parameter starts with the name of another, this leads to conflicts, e.g.
:payeeId and :payeeIdentifier --> if both matches are replaced by NULL,
this results in the second match being replaced to NULLentifier, which
is obviously not intended.

This commit superseeds commit f0caa56bd8af0d7939b64f63294c2a60ca7b4e8b.

(cherry-picked from commit b4061d79fd6d205dcd1f85ec5528c1027f7fe1ad)

REVIEW: 129796
FIXED-IN:4.8.1

# Conflicts:
#	kmymoney/mymoney/storage/mymoneydbdef.cpp

M  +4    -4    kmymoney/mymoney/storage/mymoneydbdef.cpp

https://commits.kde.org/kmymoney/64fa0cd4b58790324eaab18674e82de28e5cafaa