Mr. Simpson,

The problem isn't with Fetch Rec either. Basically, the problem is a side
effect of the insert command and an event sent to the Info Tool.

The Fetch you are doing does work but then the current record value is
updated by the Info Tool during the insert command. The tool gets an event
sent by the transaction code that tells it so save any changes (the user
could have been in the process of editing a value in the Info tool window).
In processing the event , the Info tool does a fetch for its remembered
record which affects the current record used by insert. It looks like this
behavior has been around for a very long time. I checked version 2.12 and
it did the same thing!

The only difference this should make in your code is that if, after doing
the fetch, you gather the value of the column into a variable and use the
variable in the insert statement, everything should work as expected.

Hope this helps!

Eric Blasenheim
Software Architect
MapInfo Corporation







Mail List:
       [EMAIL PROTECTED]
                                                                           
 From:      on 02/06/2004 11:48 AM                                         
                                                                           
                                                                           
 To:       <[EMAIL PROTECTED]>                             
                                                                           
 cc:                                                                       
                                                                           
 Subject:  MI-L Dechiphered: Odd behavior of FETCH                         
                                                                           



OK, folks, after a little experimentation,
I found that the problem doesn't appear to be with
FETCH LAST, but with FETCH REC n.

More specifically, if the Info Tool window is open,
showing a record from the table in question, then

Run Command "FETCH REC"+str$(n)+" From "+t

doesn't appear to have any effect!  Instead, the
table's "current row" is the one showing in the
Info window.

There are three workarounds, depending upon what you want
to do:

1. Close the Info window before any invocation of the code.
2. Set the Info window's current row to the row you're duplicating.
3. Avoid the issue and use the slower SELECT method.

Oh well, at least I hope you found this entertaining.

Best regards
Spencer

- - - - - - - - - - Code - - - - - - - - - -

function DuplicateRow (ByVal t as string,
                             col (0) as string,
                       ByVal cols as smallint,
                       ByVal r as integer) as integer

dim a as alias
dim icols as string
dim qcols as string

qcols = t + "." + col (1)
icols = col(1)
if cols > 1
   then for i = 2 to cols
            qcols = qcols + "," + t + "." + col (i)
            icols = icols + "." + col (i)
        next
end if
a = t + ".rowid"

run command "fetch rec "+str$(r)+" from "+str$(t)
'
' BAD NEWS if the Info window is open!
'
run command "insert into "+t+" ("+icols+") values ("+qcols+")"

fetch last from t
DuplicateRow = a
end function


---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10309








---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10319

Reply via email to