0

I have a function which is invoked from looping over selected rows in the selection table. The stored proc is invoked & everything works well for the first record in the selection however after the selection table is edited by the stored proc the selection in MapInfo becomes Null. Is there any way to keep the selection alive after the first edit so I can go on & run the stored proc for the next row in the selection? (ps. I know I'm refreshing the tables in the code however this isn't being hit at run time as the code enters an 'else' before this is invoked due to the null selection:

*****************************************************
' Create Historical BidBlock
'
' Add selected Region from mpBidBlocks to mpHistoricalBidBlocks
'*****************************************************
sub BidBlock(i_blockID as integer)
dim SelCount as integer
dim SelTableName as string
dim i_lstCountry,i_contractid,i_type,i_stage,i_MIPRINX as integer
dim i_RelinqDate as integer
dim s_CurrentRelinqComments as string
dim s_RelinqSchComments as string
dim s_CurrentRelinqArea as string
dim res as string
dim returnResult as string
dim returnResultStatus as integer
dim process as string
process="moveBidBlock"
print chr$(12)
'
'
' Make sure supporting tables are open

if getSelectionInfo(SelCount, SelTableName) then
    if SelCount > 0 then
        if SelTableName = vwBidBlocks then
            'Have one Contract selected
            'move to Relinquishments and update Historical Contracts
            if isTableOpen(vwHistoricalBidBlocks) then
                'tables are open
                'does it need save
                if doesTableNeedSave(vwHistoricalBidBlocks) or doesTableNeedSave(vwBidBlocks) then
                    note "You must save edits before using this function!"
                    exit sub
                end if

                'is it a polygon
                if ObjectInfo(Selection.obj, OBJ_INFO_TYPE) = OBJ_TYPE_REGION then
                    'finally - does the user have this country locked
                    if userHasSelectedCountryLocked() then
                        'everything is ready
                        res = logFile(dataroot+debugfile,"Historical Bid Block BlockId:" +i_BlockID,"INF")
                            '
                            ' Now we can complete historical bid block move

                            if executeSPReturnResult(process,"declare @out varchar(200),@Return int exec dbo.pr_moveBidBlock @BLOCKID="+i_blockId+", @MI12='MapInfo', @NewMI_PRINX=@Return output, @Message=@out output select @out,@Return",returnResult , returnResultStatus ) then
                                res = logFile(dataroot+debugfile,"Historical BidBlock returnResult:" +returnResult+" "+returnResultstatus,"INF")
                                '
                                ' Check result is good
                                '
                                if returnresultstatus >= 0 then
                                    'refresh the tables
                                    call RefreshServerTable(vwBidBlocks, false)
                                    call RefreshServerTable(vwHistoricalBidBlocks, false)
                                    res = logFile(dataroot+debugfile,"finished "+process,"INF")
                                    note "Historical BidBlock completed for BlockId:" +i_BlockID
                                else
                                   note "Historical BidBlock failed for BlockId:" +i_BlockID+" possible validation error?"
                                end if
                            else
                                note "Error trying to run "+process+", returned error: "+returnresult
                                exit sub
                            end if

                    else
                        note "Sorry you don't have " + Selection.Country + " locked out"
                    end if
                else
                    note "You must select a BidBlock polygon"
                end if
            else
                note vwHistoricalBidBlocks + " must be open"
            end if
        else
            note "Your selection must be of a BidBlock to perform a historical bidblock"
        end if
    else
        note "You must select one BidBlock object to perform a historical bidblock"
    end if
else
    note "You need to select a BidBlock before you can use this function"
end if
end sub
2

Yes, you need to store the name of the selection table and reference it by name rather than using the special name 'Selection'. You can get the selection table's name using SelectionInfo(SEL_INFO_SELNAME). Once you've got that, you'll need to use Alias variables to reference the fields of that table. Also, you need to make sure that you use Fetch to retrieve each record or the cursor will never move to the next row. For example:

Dim mySelection as String
Dim alRowIDColumn as Alias

mySelection = SelectionInfo(SEL_INFO_SELNAME)
alRowIDColumn = mySelection & ".RowID"

Fetch first from mySelection     '// get the first record in the selection
Do While not EOT(mySelection)
    Print "Current row: " & alRowIDColumn
    '// do stuff with this record...
    Fetch next from mySelection    '// get the next record in the selection
Loop
  • Also remember to use the NoSelect keyword if you are using SQL Select statements in your loop – Peter Horsbøll Møller Jul 13 '15 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.