Object Pointer Info

Steve Kump lists at jskump.com
Fri Mar 7 12:38:57 CST 2003


Hi Charles,

I think I took that approach - I'm trying to write a script that updates the
ObjectPTR field in my Listings table to the RecID of the Dealer table record
that matches on the DealerID field.

It half works right now. Here's what I've done:
-------
    tell application "Valentina PPC"
        activate
        set DB to database "Temp"
        set Dealers to base object "Dealers" of DB
        set Listings to base object "Listings" of DB
        
        tell database "Temp"
            set theCursor to SQL Select "SELECT RecID,* FROM Dealers"
            set theCount to count of records of theCursor
        end tell
        
        repeat with i from 1 to theCount
            set current record of Dealers to record i of Dealers
            set position of theCursor to i
            set theDealerID to field "DealerID" of theCursor
            set theDealerName to field "DealerName" of theCursor
            set theDealerRecID to field "RecID" of theCursor
            display dialog theDealerRecID
            display dialog theDealerName
            
            set ResultSet to (select records of Listings where {field
"DealerID" of Listings, theDealerID})
            set theListingCount to (count of records of ResultSet)
            display dialog theDealerRecID
            
            tell Listings
                set field "DealerPTR" to current record of Dealers
                replace value for field "DealerPTR" in ResultSet
            end tell
            delete ResultSet -- free memory
            
        end repeat
        delete theCursor
        
    end tell
-------

The only problem is that ALL records get updated with the RecID from the
first record in the Dealers table. Currently, I have only 2 Dealers in the
Dealers table for testing. The dialogs display the correct values for the
repeat loop, but the current record of the Dealers table does not seem to be
updating.

It updates 1000 records every quickly with the replace value command, which
is nice, but I'm stuck on getting the correct RecID so far.

Steve



On 3/7/03 11:52 AM, "Charles Yeomans" <yeomans at desuetude.com> wrote:

> 
> On Friday, March 7, 2003, at 01:59  PM, Steve Kump wrote:
> 
>> Hi Ruslan,
>> 
>> I read the document and found the paragraph you were talking about.
>> 
>> So, if I have 2 tables, Dealer and Listings, I create the ObjectPtr in
>> the
>> Listings table to point to RecID of the Dealer record I want to relate
>> it
>> to. This makes sense...when I add a new Listings records, I first get
>> the
>> related Dealer record RecID, and add it to the ObjectPtr field in the
>> Listing record.
>> 
>> But here is my situation:
>> 
>> I want to import several hundred records from a text file into the
>> Listings
>> table. How do I create the relationship for these records now? Do I
>> have to
>> update each one of them with the RecID for the dealer?
>> 
>> 
> 
> First, import the existing primary and foreign keys to define
> relationships.  Then if you decide that you want to switch to ObjectPtr
> fields, you can write a script that maps the relationships to ObjectPtr
> fields.
> 
> Charles Yeomans
> 
> _______________________________________________
> Valentina mailing list
> Valentina at lists.macserve.net
> http://lists.macserve.net/mailman/listinfo/valentina



More information about the Valentina mailing list