From: "Berger, Daniel" Date: 2002-07-09T03:20:50+09:00 Subject: RE: Ruby.DBI -- select where ... > -----Original Message----- > From: Michael Neumann [mailto:uu9r@rz.uni-karlsruhe.de] > Sent: Monday, July 08, 2002 1:17 PM > To: ruby-talk@ruby-lang.org > Subject: Re: Ruby.DBI -- select where ... > > > On Tue, Jul 09, 2002 at 01:10:36AM +0900, Mark Probert wrote: > > Hi. > > > > This is a Ruby-DBI question. I am using 0.0.15 under ruby > 1.6.6 (cygwin). > > I am using ODBC to connect to a SQL 7 database. The connection and > > test programs work fine. > > > > However, when I do: > > > > require 'dbi' > > > > dbh = DBI.connect('DBI:ODBC:pubs', 'bob', 'bob') > > state = "CA" > > sth = dbh.prepare("select au_lname, au_fname from authors > where state = #{state}") > > sth.execute > > Better write: > > sth = dbh.prepare("select au_lname, au_fname from authors > where state = ?") > sth.execute(state) > > or even shorter: > > dbh.execute("select au_lname, au_fname from authors where > state = ?", state) Just to follow-up, this is actually the "better" way of doing it Mark. Using interpolated strings creates a new execution plan every time you execute the query, whereas the placeholder method uses the same execution plan. This may not only improve your speed, but use less IO. At least, that's what the Perl DBI book says. Regards, Dan