<div>Interesting; I would never have imagined that DataRow doesn't implement any interfaces.</div>
<div> </div>
<div>ItemArray doesn't look very expensive at all -- just a single allocation for the array, then the references are all copied over into it from an underlying ArrayList.</div>
<div><br> </div>
<div class="gmail_quote">On Mon, Jun 23, 2008 at 9:13 AM, Dino Viehland <<a href="mailto:dinov@exchange.microsoft.com">dinov@exchange.microsoft.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div lang="EN-US" vlink="purple" link="blue">
<div>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">Actually it's not related to the interfaces – DataRow implements no interfaces! Instead what it has is a default member which we of course map into __getitem__. And Python says that all things with __getitem__ can be enumerated by going from 0 until you get an exception.</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d"> </span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">In 2.0 we apparently support this conversion on user defined types but not on built-in .NET types. I'm actually doing some work now which will unify the .NET vs User-Defined type code paths so this will go away but I've opened bug #17142 to track this (<a href="http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=17142" target="_blank">http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=17142</a>). That way afterwards we'll make sure we've got a test in place and it won't regress in the future.</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d"> </span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">Now that being said you probably don't actually want to be doing this for performance reasons </span><span style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: Wingdings">J</span><span style="FONT-SIZE: 11pt; COLOR: #1f497d">. The way we know this iteration is complete is when an exception is thrown which is going to be bad for perf. Calling row.ItemArray is going to give you a real enumerable object which terminates w/o an exception so you may see better perf that way - of course that seems to make a copy of all the rows, so there's a trade-off to be made here…</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d"> </span></p>
<div style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<p><b><span style="FONT-SIZE: 10pt">From:</span></b><span style="FONT-SIZE: 10pt"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Curt Hagenlocher<br>
<b>Sent:</b> Monday, June 23, 2008 8:37 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] DataRows and IronPython 2.0 B3</span></p></div>
<div>
<div></div>
<div class="Wj3C7c">
<p> </p>
<div>
<p>It's very unlikely that this was intentional. I suspect that it's related to a change in the way we handle interfaces -- this wouldn't be the first unanticipated consequence of that change. :/</p></div>
<div>
<p><br> </p></div>
<div>
<p>On Mon, Jun 23, 2008 at 8:30 AM, Michael Foord <<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>> wrote:</p>
<p>Note that we can fix it by iterating over 'row.ItemArray' instead, I just wondered if the breakage was intentional.<br><span style="COLOR: #888888"><br>Michael Foord</span> </p>
<div>
<div>
<p><br><br>Michael Foord wrote:</p>
<p>Hello all,<br><br>I'm further investigating potential compatibility issues with moving Resolver One to IronPython 2, and I've encountered a change in behaviour with respect to iterating over DataRows.<br><br>The script below works in IronPython 1, printing all the data in the rows. In IronPython 2.0 B3 it raises an exception.<br>
<br>IronPython 1:<br>C:\compile>c:\Binaries\ironpython\ipy.exe test_data.py<br>0 System.Data.DataRow<br> 0 A Big Boy Did It and Ran Away<br>1 System.Data.DataRow<br> 0 Affective Computing<br>2 System.Data.DataRow<br>
0 Clear and Present Danger<br><br>IronPython 2:<br>C:\compile>c:\Binaries\ironpython2\ipy.exe test_data.py<br>0 <System.Data.DataRow object at 0x000000000000002B [System.Data.DataRow]><br>Traceback (most recent call last):<br>
File "test_data.py", line 29, in test_data.py<br>TypeError: expected IEnumerator, got DataRow<br><br><br>Test script:<br><br>import clr<br>clr.AddReference('System.Data')<br><br>from System.Data import DataSet<br>
from System.Data.Odbc import OdbcConnection, OdbcDataAdapter<br><br><br>connectString = (<br> "DRIVER={MySQL ODBC 3.51 Driver};"<br> "blah blah blah"<br> "OPTION=3;"<br>)<br><br>query = "SELECT title FROM books WHERE price > 2 ORDER BY title"<br>
<br>connection = OdbcConnection(connectString)<br>adaptor = OdbcDataAdapter(query, connection)<br>dataSet = DataSet()<br>connection.Open()<br>adaptor.Fill(dataSet)<br>connection.Close()<br><br>for rowIndex, row in enumerate(dataSet.Tables[0].Rows):<br>
print rowIndex, row<br> for colIndex, data in enumerate(row):<br> print ' ', colIndex, data<br><br>Michael Foord<br><a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>
<p><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>
</div></div></div>
<p> </p></div></div></div></div><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>