Thursday, July 5, 2018

invalid vector subscript on MoneyManagerEx

I do my budgeting and income/expense analysis using this software package called MoneyManagerEx. Open-source and easy to use. Best of all, it's free.

So I was in the process of entering a "buy" share transaction. Being the lazy guy that I am, I duplicated a previous "buy" entry, instead of creating a new transaction. After making the necessary edits, the system came up with an error message saying "invalid vector<T> subscript". Cannot edit or delete the new entry because the system keeps throwing up this error message.

Searched the interwebs high and low and found only one reference regarding this. Basically, creating duplicates of stock transactions was never implemented in the software, yet was not specifically disabled. This is fixed in v1.4 where the Duplicate button is disabled for stock transactions.

To remove the offending transaction (if you know which one), you simply run a delete batch file via Tools --> Database --> Database-Debug:

-- MMEX Debug SQL - Update --
delete from CHECKINGACCOUNT_V1 where TRANSID = x;

In general, we first need to list out the account ID of the shares:
select ACCOUNTNAME, ACCOUNTID from ACCOUNTLIST_V1
where ACCOUNTTYPE = "Shares";

This tells us the correct linkages:
select ca.TRANSID, ca.ACCOUNTID, ca.TOACCOUNTID
from CHECKINGACCOUNT_V1 ca, SHAREINFO_V1 si
where ca.TRANSID = si.CHECKINGACCOUNTID;

With this we can determine the extra transaction that needs to be deleted:
select ACCOUNTID, TRANSID, TOACCOUNTID from CHECKINGACCOUNT_V1
where ACCOUNTID = x;

And this is how the debug file looks like (assuming 30 is the account ID of the share with the bad transaction:
-- MMEX Debug SQL - Read --
select ACCOUNTNAME, ACCOUNTID from ACCOUNTLIST_V1 where ACCOUNTTYPE = "Shares";
select ca.TRANSID, ca.ACCOUNTID, ca.TOACCOUNTID from CHECKINGACCOUNT_V1 ca, SHAREINFO_V1 si where ca.TRANSID = si.CHECKINGACCOUNTID and ca.ACCOUNTID = 30;
select TRANSID, ACCOUNTID, TOACCOUNTID from CHECKINGACCOUNT_V1 where ACCOUNTID = 30;

Problem solved.