Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 07, 2019 3:05 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Nil Check for Recordset Not Working As Expected
PostPosted: Mon Apr 05, 2010 6:23 pm 
Offline

Joined: Sun Feb 19, 2006 7:06 pm
Posts: 65
I have a RecordSet checked to see if it pulled any information. Here is the code (boss told me to change the variable names to protect the innocent)

dim rs as recordset
dim SearchString as string

SearchString = "Select * from database_table WHERE column1 = 'info'"

rs = app.db.SQLSelect(SearchString)

if rs <> nil then
' Match - Do something here

else
' No Match - Do something else here

end if


rs will ALWAYS return Non-Nil, even if there is not a match to the query. The values in the RecordSet are Nil but the RecordSet itself isn't Nil

What would cause this behavior? I haven't run into this before.

Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: Nil Check for Recordset Not Working As Expected
PostPosted: Mon Apr 05, 2010 7:23 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
The only time the recordset will be nil is if there was an error in the query. Finding zero records is not an error. It will return an empty recordset, where rs<> nil and rs.EOF is already true.


Top
 Profile  
Reply with quote  
 Post subject: Re: Nil Check for Recordset Not Working As Expected
PostPosted: Mon Apr 05, 2010 10:20 pm 
Offline
User avatar

Joined: Sat Apr 04, 2009 5:10 pm
Posts: 954
I agree with Mr. expert. rs=Nil or rs<>Nil will tell you if the database is accessible. Meanwhile, the following is what I happened to write to find out if there are data matches.

If rs.RecordCount>0 Then
// There's at least one match
Else
// There's no match
End if

_________________
Mac OS X 10.5.8/REALBasic 2008 R5.1 ~ REALBasic 2009 R4
--------------------------------------------------
Please don't use my topics in order to advertise your plug-ins.
Watch out for European spammers who try to sell plug-ins you don't even need.


Top
 Profile  
Reply with quote  
 Post subject: Re: Nil Check for Recordset Not Working As Expected
PostPosted: Mon Apr 05, 2010 10:53 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
While RecordCount works well enough for RealSQLDatabase, it is hit or miss for the other databases. Testing EOF always works on all db's. Just fyi.


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group