Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Jun 22, 2018 2:06 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: SQL Question
PostPosted: Sat Mar 30, 2013 8:24 pm 
Offline
User avatar

Joined: Fri Oct 10, 2008 7:14 pm
Posts: 94
I have a RecordSet that I want to move to particular row based on the key value.

The select would be "SELECT * from Contacts where pkContactID = " + iContactID

Problem is I don't want to execute a new select and create a new RecordSet, I want to move to the row in existing record set.

Instead of .MoveNext or .MovePrevious I want to .MoveTo...

How would I do this?

thanks much in advance,
bill


Top
 Profile  
Reply with quote  
 Post subject: Re: SQL Question
PostPosted: Sun Mar 31, 2013 1:31 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Copy the data from each row of the recordset into some other data structure, such as a class you create just for this purpose. Instantiate a new object for each row, load it, and store it in a Dictionary keyed by ID.


Top
 Profile  
Reply with quote  
 Post subject: Re: SQL Question
PostPosted: Sun Mar 31, 2013 6:30 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
dim rs as recordset
rs = myDatabase.SQLSelect("SELECT * FROM myTable;")

if (rs IsNil) or (rs.BoF and rs.EoF) then
//the record set is invalid
return
else
rs.MoveFirst
end if

Do
if rs.Field("pkContactID").IntegerValue = iContactID then
Exit
else
rs.MoveNext
end if
Loop Until rs.EoF

if rs.EoF then
//iContactID is not present in the table
return
end if

//rs is positioned at the iContactID record

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: SQL Question
PostPosted: Mon Apr 01, 2013 9:21 am 
Offline
User avatar

Joined: Fri Oct 10, 2008 7:14 pm
Posts: 94
Thanks to both responses.

Both solutions seem like they may take some CPU cycles unless the table is fairly small - which in this case it will be.

Thanks again,
b


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group