From: blue orchid Date: 2011-10-09T13:13:47+09:00 Subject: Ruby and MySQl UI.menu("Plugins").add_item('Condition Ratingjhj') { Jeny.paint } module Jeny def self.paint require 'mysql' dbh = Mysql.real_connect("localhost", "root", "***", "test",3306) dbh.query("drop table if exists condition_rating") dbh.query("create table condition_rating(component varchar(20), ID int(4), rating int(1))") dbh.query("insert into condition_rating values('deck',2345,1),('Substructure',2349,2),('Superstructure',2353,3)") #printf "%d rows were inserted\n",dbh.affected_rows res = dbh.query("SELECT component, ID, rating FROM condition_rating where rating IN (1,2,3)") while row = res.fetch_row do row.collect! { |v| v.nil? ? "NULL" : v } x=row[0] b=row[1] c=row[2] printf "%s,%s, %s\n", row[0], row[1], row[2] end Sketchup.active_model.entities.each {|entity| if entity.entityID == 2349 and c=='2' entity.material = "green" break end } end end I am using this script for Google Sketchup. My problem is that whenever I tried to execute the script, it is successful only for the last column i.e. ('Superstructure',2353,3). The execution fails for other columns. I know there is a problem in this part. res = dbh.query("SELECT component, ID, rating FROM condition_rating where rating IN (1,2,3)") while row = res.fetch_row do I would like to know what is the appropriate code to be get successful result. -- Posted via http://www.ruby-forum.com/.