KBD

Keith Devens .com

Saturday, July 5, 2008 Flag waving
"It's no trick for talented people to be interesting, but it's a gift to be interested. We want... – Randy S. Nelson (dean of Pixar University)
← Sequel: Lightweight ORM library for RubyWoW Forums -> Feral PvP is fine, L2P... →

Daily link icon Monday, September 17, 2007

jamtronix: Example of connecting to SQL Server via Ruby

jamtronix: Example of connecting to SQL Server via Ruby.

← Sequel: Lightweight ORM library for RubyWoW Forums -> Feral PvP is fine, L2P... →

Comments XML gif

Revence (http://freeshells.ch/~revence) wrote:

I use ADODB when on Windows (for 'tis fast and tried and true). And it goes for my PostgreSQL and Access and MS SQL Server ... just provide the conn string and you're rolling.

∴ Revence | 18-Sep-2007 12:01am est | http://freeshells.ch/~revence | #10306

Keith (http://keithdevens.com/) wrote:

ADODB is for PHP :-P

just provide the conn string and you're rolling.

Same for Ruby's DBI. I'll post the code later. Super easy.

Keith | 18-Sep-2007 6:35am est | http://keithdevens.com/ | #10307

Keith (http://keithdevens.com/) wrote:

Here's a modified snippit of some code I wrote recently. Like I said, super easy:

require 'dbi'

connstr = "DBI:ADO:Provider=SQLOLEDB;Data Source=IP_ADDRESS;"+
  "Initial Catalog=YOURDB;Persist Security Info=True;"+
  "User ID=USER;Password=PASS"
DBI.connect(connstr) do |db|
    db.select_all("SELECT * FROM Tasks WHERE Enabled = 1") do |row|
        name = row["Name"].gsub(/[^\w]/,"_") # replace invalid characters
        File.open("./data/#{name}.txt", 'w') do |file|
            puts "Writing command to file #{name}"
            file.write(row["Command"])
        end
    end
end

(Had to word wrap some to make it fit.) Note that Ruby's do ... end blocks ensure proper resource closure.

Keith | 18-Sep-2007 9:15am est | http://keithdevens.com/ | #10308

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Terminator 3 was awful

I think the biggest reason why T3​totally blew was because Edward​Furlong g...

76.167.172.64: Jun 29, 3:06am

Generated in about 0.117s.

(Used 8 db queries)

mobile phone