hey glenn, i'm not doing anything with prepare(), but i think the urls are different because they are different packages. namely, the first one is the pure mysql library.
-n On Aug 23, 2010, at 4:38 PM, Glenn Little wrote: > I should mention that by "currently at v2.7" I meant that I'm on a > host that is currently running mysql gem v2.7 and it cannot easily be > upgraded at the moment due to some critical legacy apps running on > there that I can't take a chance on breaking. > > -glenn > > On Mon, Aug 23, 2010 at 4:30 PM, Glenn Little <[email protected]> wrote: >> I'm trying to use the mysql gem directly (currently at v2.7). The >> documentation is at these two places: >> >> http://www.tmtm.org/en/ruby/mysql/ >> http://www.tmtm.org/en/mysql/ruby/ >> >> And the second one seems more up to date (mentions prepare()). Not >> sure what the deal is with those two urls being sort of the same but >> not, but whatever. >> >> My question is, is anyone using the above gem and doing prepared >> queries? If so, how are you parsing the results? I'd like to get >> hash results like I can when not using prepared queries. Simplified: >> >> ------------------------------------------ >> db = Mysql::real_connect(host, user, password, db) >> result = db.query("SELECT * FROM users WHERE lname = 'Smith'") >> result.each_hash do |row| >> do stuff with row["fieldname1"] and row["fieldname2"] etc... >> end >> ------------------------------------------ >> >> >> But the way I'm doing prepared queries: >> ------------------------------------------ >> db = Mysql::real_connect(host, user, password, db) >> lname = "Smith" >> query = "SELECT * FROM users WHERE lname=?" >> stmt = db.prepare(query) >> result = stmt.execute(lname) >> ------------------------------------------ >> >> Basically, it seems the return value of db.query() is not the same as >> stmt.execute(). The first returns a Result object, the second returns >> a Statement object. And it seems that the Result object gives me >> each_hash(), but the Statement object (modeling the query results, >> grrr) gives me only each(), which just gives me a bunch of big arrays >> that are a nightmare to manage as tables are modified (have to work >> out the indices as things change). >> >> >> Two questions: >> >> 1) Is there a reason for the (what appears to be) inconsistency? >> >> 2) I'd love to hear from anyone who has some experience with this gem >> to know who you've dealt with this situation (if it even is a >> "situation" rather than me just misunderstanding something) >> >> Thanks much... >> >> -glenn >> > > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
