Hi,

This is giving me a headache! I guess there's something I don't
understand about BEGIN TRANSACTION/END TRANSACTION.

Changes I make to two tables revert back.

Below is some code executed when the user wants to change the key field
in the Symbols table (the field name is Symbol). Referential integrity
requires that I also change any occurrence of the changed Symbol in the
Securities table.

When I step through the code I can see the changes are being made. The
comments in the code below indicate that. But when I exit the
application, they revert back to the old values.

Here are a few possibly significant factors.

1. Even though the field temporarily changes in the Symbols table, the
modified record appears at the bottom of the table even though the index
order is on that same field (Symbol). I expected the changed record to
take its normal place in the index order. It doesn't.

2. I'm using the buttonbar that is automatically placed on the form when
I use the Form Wizard. There is a lot of code in there (much of which I
don't understand) that may be screwing things up.

3. This is VFP9

4. I've tried using "automatic" referential integrity in the database but
when I omit the operations on the Securities table (in the code below);
the rows in that table don't change.

Any thoughts would be greatly appreciated.

Thanks, Frank

Code snipped begins here:


BEGIN TRANSACTION

SELECT Symbols
REPLACE Symbol WITH m.NewName
* The record does change
SEEK(m.NewName)

SELECT Securities
m.recno = RECNO()
m.OldFilt = FILTER()
SET FILTER TO Symbol = m.OldName
LOCATE
REPLACE ALL Symbol WITH m.NewName
* All records that match Oldname change to Newname.

SET FILTER TO &OldFilt
TRY
GO RECNO
CATCH
GO TOP
ENDTRY

END TRANSACTION

SELECT Symbols
SEEK(m.NewName)
ThisForm.pgefrmSYMBOLS.PgeSymbols.cmboSymbol.Requery
=ThisForm.PgeFrmSymbols.pgeSymbols.REFRESH()

end of code.

Re: Data changes but reverts. by trw7at

trw7at
Tue Jun 21 13:23:31 CDT 2005

Frank Dreyfus seemed to utter in
news:Xns967BBFB245D42adfslur0mdoaur03jadl@207.115.63.158:

> Hi,
>
> This is giving me a headache! I guess there's something I don't
> understand about BEGIN TRANSACTION/END TRANSACTION.
>
> Changes I make to two tables revert back.
>
> Below is some code executed when the user wants to change the key field
> in the Symbols table (the field name is Symbol). Referential integrity
> requires that I also change any occurrence of the changed Symbol in the
> Securities table.
>
> When I step through the code I can see the changes are being made. The
> comments in the code below indicate that. But when I exit the
> application, they revert back to the old values.
>
> Here are a few possibly significant factors.
>
> 1. Even though the field temporarily changes in the Symbols table, the
> modified record appears at the bottom of the table even though the
> index order is on that same field (Symbol). I expected the changed
> record to take its normal place in the index order. It doesn't.
>
> 2. I'm using the buttonbar that is automatically placed on the form
> when I use the Form Wizard. There is a lot of code in there (much of
> which I don't understand) that may be screwing things up.
>
> 3. This is VFP9
>
> 4. I've tried using "automatic" referential integrity in the database
> but when I omit the operations on the Securities table (in the code
> below); the rows in that table don't change.
>
> Any thoughts would be greatly appreciated.
>
> Thanks, Frank
>
> Code snipped begins here:
>
>
> BEGIN TRANSACTION
>
> SELECT Symbols
> REPLACE Symbol WITH m.NewName
> * The record does change
> SEEK(m.NewName)
>
> SELECT Securities
> m.recno = RECNO()
> m.OldFilt = FILTER()
> SET FILTER TO Symbol = m.OldName
> LOCATE
> REPLACE ALL Symbol WITH m.NewName
> * All records that match Oldname change to Newname.
>
> SET FILTER TO &OldFilt
> TRY
> GO RECNO
> CATCH
> GO TOP
> ENDTRY
>
> END TRANSACTION
>
> SELECT Symbols
> SEEK(m.NewName)
> ThisForm.pgefrmSYMBOLS.PgeSymbols.cmboSymbol.Requery
> =ThisForm.PgeFrmSymbols.pgeSymbols.REFRESH()
>
> end of code.

A couple of items that come to mind are:

1) Are any/all of the affected tables buffered? If so, you need to
issue a TABLEUPDATE() in there to commit the changes.

2) Wizard-built stuff is notoriously problematic. I would never
trust my data to a wizard-built form. It may or may not be
involved in your problem... but you've been warned.

3) What is the primary and foreign key in your relationship
between the symbols and securities tables? If it's the
"symbol" field, you've got a table design problem. The
primary and foreign key fields should not be "meaningful"
data and should not be changed. You're asking for trouble
if this is the case.

4) When you say you've "tried automatic RI", that implies that
you created a cascading update rule. Again, this indicates
that you are changing the value of a primary key and want
the RI code to change this in the child table. This is bad
mojo.

-- TRW
_______________________________________
t r w 7
at
i x dot n e t c o m dot c o m
_______________________________________

Re: Data changes but reverts. by Frank

Frank
Tue Jun 21 16:55:48 CDT 2005


trw7at@ixdot.netcomdotcom (Tim Witort) wrote in
news:Xns967C746ECBFB0timwitortwrotethis@207.217.125.201:

> A couple of items that come to mind are:
>
> 1) Are any/all of the affected tables buffered? If so, you need to
> issue a TABLEUPDATE() in there to commit the changes.
>
> 2) Wizard-built stuff is notoriously problematic. I would never
> trust my data to a wizard-built form. It may or may not be
> involved in your problem... but you've been warned.
>
> 3) What is the primary and foreign key in your relationship
> between the symbols and securities tables? If it's the
> "symbol" field, you've got a table design problem. The
> primary and foreign key fields should not be "meaningful"
> data and should not be changed. You're asking for trouble
> if this is the case.
>
> 4) When you say you've "tried automatic RI", that implies that
> you created a cascading update rule. Again, this indicates
> that you are changing the value of a primary key and want
> the RI code to change this in the child table. This is bad
> mojo.
>
> -- TRW


Hi and thanks for your help!

In response to your points...

1. Yes, they are buffered. I did a TABLEUPDATE() and it's now working!
Thanks!

2. I had seen some mention of this before, but I needed the navbar
(buttonbar) and didn't want to have to do it all myself.

3. The symbol field is the primary key in the Symbols table and it is
the field I need to change. I guess I could create a new, non-user-
visible field (maybe an autoinc field) as a proxy for the symbol field;
but it seem redundant.

4. I revisited the RI stuff and it's now working nicely.

There are several new features in VFP9 (I'm used to VFP6 and earlier) so
the learning curve is a bit steep. But I'm getting there ;>)

Thanks again,

Frank