transaction commit

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
christoforosKor
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 112
Joined: Mon Aug 27, 2012 2:22 pm

transaction commit

Post by christoforosKor » Thu Jan 29, 2015 9:53 am

Hello, I am trying to make insert and update to my database and if an error occurs to rollback the transaction.
The code I use is

Code: Select all

try {
            $db->transactionStart();
            $query->setQuery("update bst_elg_bst_stats st inner join bst_elg_bst_calcnewstats nst
                        on st.idPredictor = nst.idPredictor and st.idBetType = nst.idBetType and st.idMatchType = nst.idMatchType
                        set st.predictWin = st.predictWin + nst.predictWin,
                        st.predictSum = st.predictSum + nst.predictSum,
                        st.oddWin = st.oddWin + nst.oddWin,
                        st.oddSum = st.oddSum + nst.oddSum,
                        st.riskSum = st.riskSum + nst.riskSum"
                        );
            $db->execute();
            $query->setQuery("insert into bst_elg_bst_stats
                        (idPredictor, idBetType, idMatchType, predictWin, predictSum, oddWin, oddSum, riskSum)
                        select cp.idPredictor, cp.idBetType, m.idMatchType, count(*) as predictWin, sum(cs.predictSum), sum(cp.odd) as oddWin, sum(cs.oddSum),  sum(cs.maxOdd) 
                        from bst_elg_bst_calcpredictor cp
                        inner join bst_elg_bst_match m on cp.idMatch = m.idMatch 
                        inner join bst_elg_bst_calcsums cs on cp.idPredictor = cs.idPredictor and cp.idMatch = cs.idMatch and cp.idBetType = cs.idBetType
                        left join bst_elg_bst_stats bs on cs.idPredictor = bs.idPredictor and m.idMatchType = bs.idMatchType and cs.idBetType = bs.idBetType
                        where bs.idPredictor is null and bs.idBetType is null and bs.idMatchType is null and cp.idBetOptionStatus = 4
                        group by cp.idPredictor, cp.idBetType, m.idMatchType, cp.idBetOptionStatus");
            $db->execute();
            $db->transactionCommit();
        }
        catch (Exception $ex)
       {
            JLog::add($ex->getCode() . ' ' . $ex->File() . ' ' . $ex->getMessage(), JLog::ERROR);
            $db->transactionRollback();
        }
       
    }
When I run the same code without the $db->transactionStart() and $db->transactionCommit(), It works fine.
I have read the example https://docs.joomla.org/Using_transactions_in_Joomla and I can't see something wrong.

thanks for any help.

gws
Joomla! Champion
Joomla! Champion
Posts: 5952
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: transaction commit

Post by gws » Thu Jan 29, 2015 1:57 pm

I am no coder but is the table of the correct type to use transactions?

christoforosKor
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 112
Joined: Mon Aug 27, 2012 2:22 pm

Re: transaction commit

Post by christoforosKor » Wed Feb 04, 2015 6:40 pm

gws wrote:I am no coder but is the table of the correct type to use transactions?
It;s an InnoDb table, the abstraction is standard joomla JTable class, I don't see why there is any problem with the transaction


Locked

Return to “General Questions/New to Joomla! 3.x”