Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code not working inside a transaction as expected

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
I have a tendancy to reuse records

So a typical peice of code to amalgamate a cursor with the original table would be

BEGIN TRANSACTION

select <parent table>

change flag field to 0 for matching records

select <cursor>

scan
locate or seek the flagged field
transfer the info
endscan

end transaction

since it is possible to be returning less records than it started with it just leaves the flagged field at 0

The computer just leaves loads of flagged fields and keeps on creating new records
take away the transaction processing and it works

it failed to find flagged fields from a previous test

Obviously it is a lot more complex than the psudo code above.

I thought the transaction processing might have been suppressing the changes to the flag field, but the second run should find the changes on the first run


Any Ideas (Please)






 
Yes the table is buffered and I am doing a Tableupdate during the transaction processing
 
OK, it was a bit of a long shot.

I don't know if this is relevant, but looking at your SCAN loop, you have:

scan
locate or seek the flagged field
transfer the info
endscan

Are you locating or seeking in the same alias that you are scanning? If so, that really sounds like trouble. Then again, I'm not sure that alone would explain the behaviour you are seeing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I derived a cursor from this table _cursor

so I scan _cursor for !deleted()
and the records are put into a flagged record in the table
I see what you mean Mike but it works without the transaction processing.

I am not too worried but the code isn't as bomb proof as I would like, in this instance we are only looking at 5 records, it would take a genius to hit control alt del at the precise instant of saving.

A lot of my tables only have a couple of hundred records so I use locate & if Found(). I have a problem adding indexes as I rarely go to site.

I am always a bit reluctant to post code as it probably not up to your standard
Code:
*BEGIN TRANSACTION
*-* clean out every relevant record in sOrderbatch
	SELECT sOrderbatch
	REPLACE ALL sOrderbatch.ifk_sorderline WITH 0 ;
		FOR THISFORM.orderline = ifk_sorderline AND lDone = .F. AND !DELETED()

	SELECT _tmporderbatch
	SCAN FOR !DELETED()
		SELECT sOrderbatch
		LOCATE FOR sOrderbatch.ifk_sorderline = 0

		IF !FOUND()
			APPEND BLANK
		ENDIF

		SELECT _tmporderbatch
		SCATTER MEMVAR FIELDS EXCEPT ipk_batch
		SELECT sOrderbatch
		GATHER MEMVAR
	ENDSCAN

	SELECT sOrderbatch

	TABLEUPDATE(.T.)
*END TRANSACTION







 
What WAIT WINDOW SET([Exact]) said?
I asked because of this:
FOR THISFORM.orderline = ifk_sorderline

Second thought: ALWAYS and I mean ALWAYS check what TableUpdate returns and ALWAYS use ALL parameters:
Code:
IF NOT TABLEUPDATE(.t.,.t., [sOrderbatch])
   AERROR(laError)
   LIST MEMORY LIKE laError
ENDIF


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Couple of thoughts.

First, in these days of enormous drives, recycling records seems like way more work than necessary.

Second, this whole thing seems like a home-grown variant of local views. Why not just use views? They'll handle insertion and deletion automatically.

In fact, just using buffering will take care of that for you.

Tamar
 
[&nbsp;]

I am always a bit reluctant to post code as it probably not up to your standard

First, I doubt that any two FoxPro programmers can fully agree on what is standard and what is not. We can usually agree on basic things like readability and such, but usually not for things more complex.

Second, FP is such a diverse language that there are often a dozen or more perfectly legitimate ways of accomplishing any given task.

Third, the immensity and variety of possible jobs that FP can do generally precludes trying to define a standard that would encompass all possible jobs.

Fourth, all of us at various times have tunnel vision and cannot see the forest for the trees. Putting your code out there gives all of us a chance to help you find problems that you might not ever see. Why would you want to spend hours, days, weeks, etc over some small simple thing we can spot immediately and that you can't see?

We frequent forums to help and to give help. In the process you learn from us and we learn from you. No one can help anyone else unless enough is known about the problem. On this forum the code giving you fits is the most important part of finding the solution quickly and correctly, so put it out there. We are not here to put you down - We are here to help solve your problems.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Thanks everybody for your comments, I am a bit old fashioned & I like to have all the code in the exe as well as the problem of changing a dbc on a system that I will never have direct access to. (without a long drive).

I am due to make a few table changes this week & I have been trying to organise it since last Friday. Unfortunatly some of the non technical problems have perverse technical answers.

Hope that makes sense

Richard



 
mmerlinn


I used to program in 2.6 as an IT contractor and regularly had my code assesed,

SinceI started on vfp6 I have been a lone programmer or working from home. I havn't had my vfp code assesed ever, when you are self taught your thoughts and techniques tend to be limited. For instance trying to create an object is completly alien although I must tackle this asap.

Taking over this job has helped enormously, it has a copy of navtools which seems to be unstable to keep life interesting


Richard
Preston Lancs
 
[&nbsp;]

when you are self taught your thoughts and techniques tend to be limited

All the more reason to post your code. By doing so you get the experience and resources from many different programmers worldwide.

As a self-taught programmer myselt, starting with Apple Basic and Apple Assembly Language in 1980, I full well understand how limited are the techniques that I use. I also understand how valuable the help is that I have received since I started frequenting this forum. Many times before coming here I struggled for months over problems that turned to have a simple solution.

I still struggle over problems, but now if I can't find the solution in what I consider a reasonable time, I come here and post my code so others can look at it. And all of my code, even today, is based on standards I defined while using Apple Basic, long before FP was even a dream, and long before there were any real programming standards for desktop computers. In today's modern VFP environment the standards I adhere to do not match the standards of any other VFP programmer.

As a result, I sometimes find it very hard to understand the code other programmers post. And I am sure the reverse is also true regarding the code I post.

Regardless, in all of the times I have posted code, no one has ever even hinted that I should change my standards to match theirs. As long as I made a good faith attempt to solve the problem before coming here, everyone has been more than willing to help me find the solution. I try to do the same for others when I can.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Got it

Though a little surprised
I somehow had a filter set, but I thought a replace all respected filters

Anyway emergeny over and thanks to everyone who has helped me


Richard
Preston Lancs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top