<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BKeeney Briefs &#187; recordset</title>
	<atom:link href="http://www.bkeeneybriefs.com/tag/recordset/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bkeeneybriefs.com</link>
	<description>Software Development Using REAL Studio</description>
	<lastBuildDate>Sat, 04 Feb 2012 19:36:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Recordset.idxField vs Recordset.Field</title>
		<link>http://www.bkeeneybriefs.com/2012/02/recordset-idxfield-vs-recordset-field/</link>
		<comments>http://www.bkeeneybriefs.com/2012/02/recordset-idxfield-vs-recordset-field/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 19:36:40 +0000</pubDate>
		<dc:creator>Bob Keeney</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[REALbasic]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[REAL Studio]]></category>
		<category><![CDATA[recordset]]></category>
		<category><![CDATA[Speed]]></category>

		<guid isPermaLink="false">http://www.bkeeneybriefs.com/?p=1037</guid>
		<description><![CDATA[Yesterday I was complaining about my OPC project and I&#8217;ve added a few more bullet points in the comments section.  This morning I added a comment about how the idiot developer used Recordset.idxField(index) rather than Recordset.Field(&#8220;FieldName&#8221;).  I hate it when developers use idxField because it makes it tough to read and I constantly have to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.bkeeneybriefs.com/2012/02/dear-idiotic-developer/" target="_blank">Yesterday</a> I was complaining about my OPC project and I&#8217;ve added a few more bullet points in the comments section.  This morning I added a comment about how the idiot developer used Recordset.idxField(index) rather than Recordset.Field(&#8220;FieldName&#8221;).  I hate it when developers use idxField because it makes it tough to read and I constantly have to go back and look at the query and count fields.  In the short term I modify the query string in the IDE and put index comments in the in string.  Something like this:</p>
<p>s = &#8220;Select field1, &#8221; _ //1</p>
<p>+ &#8220;field2, &#8221; _ //2</p>
<p>and so on but it&#8217;s still a pain.</p>
<p>Anyway, Christian S. posted a comment that got me thinking.  He said:</p>
<blockquote><p>idxField is good. It can speedup applications a lot.</p></blockquote>
<p>Is that really true?  I have never tested it so I created a little test application using an actual query from the project I&#8217;m working on.  I run the same query twice.  The first time I loop through the recordset using nothing but idxField and the second time I use nothing but field which uses the field name.  The results are interesting and confirmed my suspicions.</p>
<p>If I run my two functions just once and bring back only 1 record and do one read in the function the idx field is indeed faster by about 50%.  However my testing differences range from 6 to 300 microseconds faster and while I didn&#8217;t average out all the results, I&#8217;d say most times it was around 60 microseconds faster.  I ran this test a lot to see if I would see a wider variation but did not.  My 300 microseconds difference happened just once out of about 25 runs.</p>
<p>I changed my query so that instead of bringing back 1 record it brings back over 700 and I loop through the recordset and then do the same same test.  IdxField comes back about 15% faster.  When I loop through the same row 10,000 times there is no statistical difference which means that while Field is slower it&#8217;s a one time hit since my tests show that even doing the same pull 10,000 times the total difference between the two functions is still only about a 10-15% difference in overall speed.</p>
<p>My conclusion is that yes, idxField <em>IS</em> faster than using Field but to say it speeds up an application &#8220;a lot&#8221; is an exaggeration.  In 10 years of Real Studio consulting work I have rarely done an application that requires that much speed from the queries.  If you have any sort of graphical user interface I think it safe to say that updates to the controls on screen are significantly slower than pulling data out of the recordset.  That&#8217;s NOT to say that the query itself is fast because often times that is the most limiting factor.</p>
<p>I won&#8217;t discourage you from using idxField.  If you do, though, I really encourage you to use constants named after your fields.  So perhaps you create a constant named kField1 and the value is 1 for the first field in your recordset.  The only drawback to this approach is that you (or the developer after you) will change the SQL query and all the code using idxfield no longer works because your field order is different.</p>
<p>I much prefer the explicitness of using Field because I never have to worry if I change my field order.  It&#8217;s very readable.  It&#8217;s not perfect and there are plenty of reasons why it&#8217;s not the best (there&#8217;s a reason why we use <a href="https://www.bkeeney.com/realbasic/activerecord" target="_blank">ActiveRecord</a> in a lot of projects).  Use what&#8217;s best for you and what&#8217;s best for the five years from now.</p>
<p>What say you, RB developers?</p>
            <script type="text/javascript">  linkscolor = "000000";  highlightscolor = "888888";  backgroundcolor = "FFFFFF";  channel = "none";   </script><script type="text/javascript" src="http://www.addmarx.com/dynamicbookmark_compressed.php"></script><span><a onClick="clickDynamic1(this); return false;" href="http://www.addmarx.com"><img style="padding:0px; margin:0px" src="http://www.bkeeneybriefs.com/wp-content/plugins/addmarx/sharebookmarx.png" border="0"></a></span><span style="position:absolute; z-index:1000001; margin-top:24px; margin-left:-127px; visibility:hidden;"><iframe id="addmarx_empty" scrolling="no" frameborder="0"></iframe></span><p class="addmarx_spacer"></p><!-- Please place the above code into your site where you want to have a bookmark/share/publicize link. Please do not change any of the code aside from the link text or image, or else the code may not work properly.  -->                  ]]></content:encoded>
			<wfw:commentRss>http://www.bkeeneybriefs.com/2012/02/recordset-idxfield-vs-recordset-field/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why Is My Recordset Nil?</title>
		<link>http://www.bkeeneybriefs.com/2009/05/why-is-my-recordset-nil/</link>
		<comments>http://www.bkeeneybriefs.com/2009/05/why-is-my-recordset-nil/#comments</comments>
		<pubDate>Wed, 27 May 2009 20:15:02 +0000</pubDate>
		<dc:creator>Bob Keeney</dc:creator>
				<category><![CDATA[REALbasic]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[recordset]]></category>

		<guid isPermaLink="false">http://www.bkeeneybriefs.com/?p=25</guid>
		<description><![CDATA[This one comes up on the RB Forums a lot.  The post generally goes something like this:  &#8220;I have a database and everything works fine until here &#60;insert code snippet&#62; and I get a Nil Object Exception because rs is nil.&#8221; If everything else is working fine then it must be the recordset.  If you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>This one comes up on the RB Forums a lot.  The post generally goes something like this:  &#8220;I have a database and everything works fine until here &lt;insert code snippet&gt; and I get a Nil Object Exception because rs is nil.&#8221;</p>
<p>If everything else is working fine then it must be the recordset.  If you&#8217;re not checking the database for an error you&#8217;ll never know!  The db.error property tells you that you had an error and the db.errormessage property does a pretty good job of telling you what the error is.</p>
<p style="padding-left: 30px;">dim rs as recordset<br />
rs = db.SQLSelect(&#8220;SELECT * FROM sometable WHERE somefield=avalue&#8221;)<br />
if db.error then<br />
msgbox &#8220;Error!&#8221; + db.ErrorMessage<br />
return<br />
end</p>
<p style="padding-left: 30px;">//do something with the recordset here.</p>
<p>I find this happens a lot with developers that came from Visual Basic 6 where database errors throw an exception.  REALbasic doesn&#8217;t work the same way.  Get over it and start checking for database errors.</p>
<p>If you want to capture database errors you can do something like what we&#8217;ve done:</p>
<p style="padding-left: 30px;">if gDB.Error then Raise new BK_Debug.BK_DatabaseException(gDB.ErrorMessage, s)</p>
<p>Where BK_DatabaseException is a RuntimeException subclass defined like this:</p>
<p style="padding-left: 30px;">Sub Constructor(sMessage as string, sSQL as string)<br />
If sMessage &lt;&gt; &#8220;&#8221; Then<br />
Me.Message = sMessage<br />
End If</p>
<p style="padding-left: 30px;">If sSQL &lt;&gt; &#8220;&#8221; Then<br />
Me.Message = Me.Message + EndOfLine +  EndOfLine + sSQL<br />
End<br />
End Sub</p>
<p>This can be useful if you have automated error handling and can receive this information.  Of course, if you&#8217;re creating a runtime exception you had better be handling them in the app.unhandledexception event otherwise your app will shutdown and you&#8217;ll have pissed off users.</p>
            <script type="text/javascript">  linkscolor = "000000";  highlightscolor = "888888";  backgroundcolor = "FFFFFF";  channel = "none";   </script><script type="text/javascript" src="http://www.addmarx.com/dynamicbookmark_compressed.php"></script><span><a onClick="clickDynamic1(this); return false;" href="http://www.addmarx.com"><img style="padding:0px; margin:0px" src="http://www.bkeeneybriefs.com/wp-content/plugins/addmarx/sharebookmarx.png" border="0"></a></span><span style="position:absolute; z-index:1000001; margin-top:24px; margin-left:-127px; visibility:hidden;"><iframe id="addmarx_empty" scrolling="no" frameborder="0"></iframe></span><p class="addmarx_spacer"></p><!-- Please place the above code into your site where you want to have a bookmark/share/publicize link. Please do not change any of the code aside from the link text or image, or else the code may not work properly.  -->                  ]]></content:encoded>
			<wfw:commentRss>http://www.bkeeneybriefs.com/2009/05/why-is-my-recordset-nil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

