Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TRANSACTION loosing my data. Why?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00322762
Message ID:
00323502
Views:
21
Thanks Jim. Here is the code. It works now since the BEGIN TRANSACTION and END TRANSACTION are commented. Nothing saves, even if I see that the insert executes, if I uncomment the transaction command.
Strange? Could it be because the table where I insert are not into the datasession and then not buffered maybe?


* Basically, after the save of the main table (appur), we have to update all
* the related files (journals)

LOCAL cur_area, i, lident, lcurr,;
lnogl_ap, lnogl_tps_ach, lnogl_tvq_ach, a_amount, lnogl_bq, lnogl_ap_disc,;
l_ident
THISFORM.BtnRCost.visible = .T.
THISFORM.calctotal()

DIMENSION a_amount(2)

IF TYPE("oSession") = "O" AND NOT ISNULL(oSession)
oSession.Refresh_param()
STORE oSession.nogl_bq TO lnogl_bq
STORE oSession.nogl_ap_disc TO lnogl_ap_disc
STORE oSession.nogl_ap TO lnogl_ap
STORE oSession.nogl_tps_ach TO lnogl_tps_ach
STORE oSession.nogl_tvq_ach TO lnogl_tvq_ach
ELSE
STORE 1 TO lnogl_ap && Test mode
STORE 1 TO lnogl_tps_ach && Test mode
STORE 1 TO lnogl_tvq_ach && Test mode
STORE 1 TO lnogl_bq && Test mode
STORE 1 TO lnogl_ap_disc && Test mode
ENDIF

STORE SELECT() TO cur_area

*BEGIN TRANSACTION

STORE appur.ident TO lident

* We (re)create the purchases + purch. journal details
SELECT vmappur
GO TOP
STORE 1 TO i
DO WHILE !EOF()
IF vmappur.glaccnt <> 0 AND vmappur.amount <> 0
* Purchase Details
UPDATE appurd;
SET appurd.glaccnt = vmappur.glaccnt,;
appurd.amount = vmappur.amount ;
WHERE appurd.ident = lident AND;
appurd.seq = i
IF _TALLY = 0
INSERT INTO appurd (ident, seq,;
glaccnt,;
amount);
VALUES (lident, i,;
vmappur.glaccnt,;
vmappur.amount)
ENDIF
* Purchase Journal details (DEBIT)
UPDATE appurjd;
SET appurjd.glaccnt = vmappur.glaccnt,;
appurjd.curr = appur.curr,;
appurjd.mnt_db = vmappur.amount * appur.cur_rate,;
appurjd.mnt_cr = 0,;
appurjd.mnt_db_cur = vmappur.amount,;
appurjd.mnt_cr_cur = 0;
WHERE appurjd.ident = lident AND;
appurjd.seq = i
IF _TALLY = 0
INSERT INTO appurjd (ident, seq,;
glaccnt,;
curr,;
mnt_db, mnt_cr,;
mnt_db_cur, mnt_cr_cur);
VALUES (lident, i,;
vmappur.glaccnt,;
appur.curr,;
vmappur.amount * appur.cur_rate, 0,;
vmappur.amount, 0)
ENDIF
*
i = i + 1
ENDIF
SELECT vmappur
SKIP
ENDDO
GO TOP
DELETE FROM appurd WHERE ident = lident AND seq >= i

* Purchase Journal Details (Next part: taxes and account payable)
*** TAXES (DEBIT)
IF appur.mnt_gst <> 0
UPDATE appurjd;
SET appurjd.glaccnt = lnogl_tps_ach,;
appurjd.curr = appur.curr,;
appurjd.mnt_db = appur.mnt_gst * appur.cur_rate,;
appurjd.mnt_cr = 0,;
appurjd.mnt_db_cur = appur.mnt_gst,;
appurjd.mnt_cr_cur = 0;
WHERE appurjd.ident = lident AND;
appurjd.seq = i
IF _TALLY = 0
INSERT INTO appurjd (ident, seq,;
glaccnt,;
curr,;
mnt_db, mnt_cr,;
mnt_db_cur, mnt_cr_cur);
VALUES (lident, i,;
lnogl_tps_ach,;
appur.curr,;
appur.mnt_gst * appur.cur_rate, 0,;
appur.mnt_gst, 0)
ENDIF
i = i + 1
ENDIF
IF appur.mnt_pst <> 0
UPDATE appurjd;
SET appurjd.glaccnt = lnogl_tvq_ach,;
appurjd.curr = appur.curr,;
appurjd.mnt_db = appur.mnt_pst * appur.cur_rate,;
appurjd.mnt_cr = 0,;
appurjd.mnt_db_cur = appur.mnt_pst,;
appurjd.mnt_cr_cur = 0;
WHERE appurjd.ident = lident AND;
appurjd.seq = i
IF _TALLY = 0
INSERT INTO appurjd (ident, seq,;
glaccnt,;
curr,;
mnt_db, mnt_cr,;
mnt_db_cur, mnt_cr_cur);
VALUES (lident, i,;
lnogl_tvq_ach,;
appur.curr,;
appur.mnt_pst * appur.cur_rate, 0,;
appur.mnt_pst, 0)
ENDIF
i = i + 1
ENDIF
*** ACCOUNT PAYABLE (CREDIT)
IF ApPur.mnt_inv <> 0
UPDATE appurjd;
SET appurjd.glaccnt = lnogl_ap,;
appurjd.curr = appur.curr,;
appurjd.mnt_db = 0,;
appurjd.mnt_cr = ApPur.mnt_inv * appur.cur_rate,;
appurjd.mnt_db_cur = 0,;
appurjd.mnt_cr_cur = ApPur.mnt_inv;
WHERE appurjd.ident = lident AND;
appurjd.seq = i
IF _TALLY = 0
INSERT INTO appurjd (ident, seq,;
glaccnt,;
curr,;
mnt_db, mnt_cr,;
mnt_db_cur, mnt_cr_cur);
VALUES (lident, i,;
lnogl_ap,;
appur.curr,;
0, ApPur.mnt_inv * appur.cur_rate,;
0, ApPur.mnt_inv)
ENDIF
i = i + 1

ENDIF
DELETE FROM appurjd WHERE ident = lident AND seq >= i

* PURCHASE JOURNAL (HEADER)
UPDATE appurj SET appurj.acc_year = appur.acc_year,;
appurj.acc_period = appur.acc_period,;
appurj.descr = appur.descr,;
appurj.mnt_inv = appur.mnt_inv,;
appurj.mnt_gst = appur.mnt_gst,;
appurj.mnt_pst = appur.mnt_pst,;
appurj.inv_date = appur.inv_date,;
appurj.due_date = appur.due_date,;
appurj.cr_by = appur.cr_by,;
appurj.cr_date = appur.cr_date,;
appurj.curr = appur.curr,;
appurj.cur_rate = appur.cur_rate,;
appurj.inv_no = appur.inv_no,;
appurj.supp_id = appur.supp_id,;
appurj.supp_name = appur.supp_name;
WHERE appurj.ident = appur.ident
IF _TALLY = 0
INSERT INTO appurj (ident,;
acc_year, acc_period,;
descr,;
mnt_inv,;
mnt_gst, mnt_pst,;
inv_date, due_date,;
cr_by, cr_date,;
curr, cur_rate,;
inv_no,;
supp_id, supp_name);
VALUES (appur.ident,;
appur.acc_year, appur.acc_period,;
appur.descr,;
appur.mnt_inv,;
appur.mnt_gst, appur.mnt_pst,;
appur.inv_date, appur.due_date,;
appur.cr_by, appur.cr_date,;
appur.curr, appur.cur_rate,;
appur.inv_no,;
appur.supp_id, appur.supp_name)
ENDIF

*END TRANSACTION

SELECT vmappur
=TABLEREVERT(.T.)

STORE appur.ident TO l_ident
=REQUERY("vmappur")
SELECT vmappur
GO TOP

THISFORM.ScnADistribuertxt.visible = .F.
THISFORM.ScnADistribuer.visible = .F.
THISFORM.ScnPayer.visible = .F.
THISFORM.ScnPayertxt.visible = .F.

THISFORM.WsGrid1.Refresh
THISFORM.refresh()
SELECT (cur_area)

>>I have a TRANSACTION (BEGIN...END) with SQL inserts and updates in it. Strange enought, it executes it but nothing is in my data after the end. I took out the TRANSACTION command and it works fine.
>>Is it because these tables are not in my form dataenvironment ?
>>
>>Thanks
>
>Eric,
>
>Sounds like the code doesn't hit the end transaction at all. Could you show the code?
>
>A TRANSACTION does not update anything until the END TRANSACTION is encountered. So if you are seeing no changes after the transaction then it is likely that the END TRANSACTION has not been executed.
Eric Crespin
Consultant
PC PLUS Software Inc.
www.pcplus.ca
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform