From: Brian Candler Date: 2010-02-15T18:46:03+09:00 Subject: Re: Square brackets Andreu wrote: > I'm using Ruby 1.9.1 and sqlite3 with sqlite3-Ruby (1.2.5) > > Doing the following query: > pc1 = db.execute("select count(*) from mytab where(n2=n1)") > I get say: pc1 = [["123"]] A SQL select in general returns multiple rows, each of which has multiple columns. So it's returning an array of rows, with one member, which is an array of columns, with one member. > and when using: > pc1 = db.get_first_row("select count(*) from mytab where(n2=n1)") > I get say: pc1 = ["123"] Here you explicitly asked only for the first row, so you get an array of columns, with one member. > What I really want is the numeric value alone without the > square brackets, quotes, and the like, as several queries are > 'chained' and this gets really annoying. Pull it out, using pc1 = db.execute(...)[0][0].to_i or pc1 = db.execute(...).first.first.to_i Note this will raise an exception if you get zero rows returned for some reason, but in this particular query you shouldn't. to_i is required because sqlite only implements text types. > Ruby 1.8.7 doesn't exibit that behaviour and work as expected. You need to show exactly what code you are running under both 1.9.1 and 1.8.7, and exactly what return values you get in both cases (p pc1, or puts pc1.inspect), and also show exactly what versions of the sqlite3 gem you have in both cases. -- Posted via http://www.ruby-forum.com/.