Excited n00b

Discussion in 'Ruby' started by Mark Carter, Feb 15, 2005.

  1. Mark Carter

    Mark Carter Guest

    I jobby out VBA code for a living, although I use python wherever I can.
    I thought I'd try out Ruby to see what all the fuss was about.

    So far, I'm impressed. Here's a little proggy that I knocked out to dump
    the table structure of a database:

    require 'win32ole'

    def schema()
    @MDB_FILE_NAME = "C:\\mcarter\\srel\\2292-Stargate\\demo.mdb"

    # Create the object
    conn=WIN32OLE.new("ADODB.Connection")
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
    Source=\"#{@MDB_FILE_NAME}\""
    conn.open


    #http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthopenschema.asp

    #http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstschemaenum.asp
    adSchemaTables = 20 #constant
    rs = conn.OpenSchema(adSchemaTables)
    rs.MoveFirst if !rs.eof
    while !rs.eof
    yield rs
    rs.MoveNext
    end
    rs.close()
    conn.close
    end

    schema { | table |
    puts "NEW TABLE"
    for field in table.Fields
    puts "%-15s %10s" % [field.name, field.value]
    end
    puts
    }



    OK, it could do with some refactoring, but I was just trying to get
    something working. I think that impresses me about this block stuff is
    that it's a really neat way to hide messy implementation details. ADODB
    has a slightly strange way of iterating over records (the !rs.eof bit);
    but that doesn't matter because it's all hidden away. I just iterate
    over the recordset like it was a normal list.

    I'm tempted to stick around to see what other goodies Ruby has in store.

    What I'm actually trying to do is read a database, bump the date values
    of some of the fields, create some new records, and put the result into
    a new database. Before I completely re-invent the wheel, is there a ruby
    library that is likely to be of assistance?
     
    Mark Carter, Feb 15, 2005
    #1
    1. Advertising

  2. "Mark Carter" <> schrieb im Newsbeitrag
    news:...
    > I jobby out VBA code for a living, although I use python wherever I can.
    > I thought I'd try out Ruby to see what all the fuss was about.


    Welcome aboard!

    > So far, I'm impressed. Here's a little proggy that I knocked out to dump
    > the table structure of a database:
    >

    <snip/>

    > OK, it could do with some refactoring, but I was just trying to get
    > something working. I think that impresses me about this block stuff is
    > that it's a really neat way to hide messy implementation details. ADODB
    > has a slightly strange way of iterating over records (the !rs.eof bit);
    > but that doesn't matter because it's all hidden away. I just iterate
    > over the recordset like it was a normal list.
    >
    > I'm tempted to stick around to see what other goodies Ruby has in store.


    I'm nearly sure you'll stay longer... :)

    > What I'm actually trying to do is read a database, bump the date values
    > of some of the fields, create some new records, and put the result into
    > a new database. Before I completely re-invent the wheel, is there a ruby
    > library that is likely to be of assistance?


    Look at the Ruby DBI/DBD implementations. It typically comes preinstalled
    but if you need more, you can look in the RAA http://raa.ruby-lang.org/

    There's also other DB handling stuff:
    http://raa.ruby-lang.org/cat.rhtml?category_major=Library;category_minor=Database

    Kind regards

    robert
     
    Robert Klemme, Feb 15, 2005
    #2
    1. Advertising

  3. On Tue, 15 Feb 2005 21:54:53 +0900, Mark Carter <> wrote:
    > What I'm actually trying to do is read a database, bump the date values
    > of some of the fields, create some new records, and put the result into
    > a new database. Before I completely re-invent the wheel, is there a ruby
    > library that is likely to be of assistance?


    Check out Active Record (http://ar.rubyonrails.org)

    --
    Gavri
    ---------------------------------------------------
    I blog here: http://gavri.blogspot.com
     
    Gavri Fernandez, Feb 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Koncept
    Replies:
    3
    Views:
    1,978
    Nick Santos
    Dec 6, 2003
  2. newgenre
    Replies:
    1
    Views:
    319
    Curt_C [MVP]
    Apr 14, 2004
  3. newgenre

    n00b needs SQL Server

    newgenre, Apr 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    299
    Curt_C [MVP]
    Apr 15, 2004
  4. newgenre

    n00b Help Setting up MSDE SQL Server

    newgenre, Apr 18, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,364
  5. Sean Wolfe

    help me get excited about python 3

    Sean Wolfe, Jan 4, 2012, in forum: Python
    Replies:
    3
    Views:
    270
    peter
    Jan 6, 2012
Loading...

Share This Page