The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Cranking on the DBI rewrite

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Cranking on the DBI rewrite Posted: Jan 6, 2006 2:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Cranking on the DBI rewrite
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Kirk, Francis and I have gotten rolling on the DBI rewrite. Well, at this point it's just a major refactoring. The "next gen" DBI is going to wait until we refactor the existing DBI package and apply patches for known bugs.

Last night I decided to take a whack at row.rb and see what I could improve on. It was quite the learning process. You see, DBI::Row is a delegate of Array, and stores a hash internally. This is why it behaves as both an Array and a Hash to allow you access column data by index or name.
row = DBI::Row.new(['first','last','age'], ['daniel','berger','36'])
row[0]      # 'daniel'
row[:first] # 'daniel'

That's handy, though I almost always reference by name rather than index, since you never know when an index just might change on you. Mind you, a column name could change to, but it's less likely.

What I didn't know was that you could actually get data using regular expressions, ranges and arrays as well. So, all of these are legal:
row[/first/]        # 'daniel'
row[0..1]           # ['daniel','berger']
row[[:last,:first]] # ['berger','daniel']

You can also do multiple arg references. This was a little goofy because in the case of 2 args (and only 2 args) it was decided to act like the second form of Array#[], i.e. the first value is the starting point and the second value is the length. If it's 3 or more arguments, it's more like a slice.
row[0,1]              # ['daniel']
row[2,1,0]            # ['36', 'berger', 'daniel']
row[:age, /first/, 1] # ['36', 'daniel', 'berger']

Cool, eh?

Of course, I just realized while I was writing this that I broke Range support somehow. Forget to test one little thing, and blam!

Update: Fixed the Range handling :)

Read: Cranking on the DBI rewrite

Topic: Using SwitchTower with multiple deployment stages Previous Topic   Next Topic Topic: Makefile issues on Solaris - the workaround

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use