require 'win32ole'
conn = WIN32OLE.new('ADODB.Connection')
strCnxn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\\My Documents\\db1.mdb;Persist Security Info=False"
conn.Open strCnxn
rsCustomers = WIN32OLE.new("ADODB.Recordset")
strSQLCustomers = "select * from test1"
rsCustomers =conn.execute(strSQLCustomers)
rsCustomers.MoveFirst()
print "test#{rsCustomers.Fields}"
puts rsCustomers.Fields.item('test').value # field value
puts rsCustomers.Fields.item('test').name #field name
puts rsCustomers.Fields.Count
2009年1月20日星期二
ruby module include , class send
in rails's codes there is a wondful use of ruby module,just see following codes:
Notes:
A couple of points about the include statement before we go on. First, it has nothing to do with files. C programmers use a preprocessor directive called #include to insert the contents of one file into another during compilation. The Ruby include statement simply makes a reference to a named module. If that module is in a separate file, you must use require to drag that file in before using include. Second, a Ruby include does not simply copy the module's instance methods into the class. Instead, it makes a reference from the class to the included module. If multiple classes include that module, they'll all point to the same thing. If you change the definition of a method within a module, even while your program is running, all classes that include that module will exhibit the new behavior.[Of course, we're speaking only of methods here. Instance variables are always per-object, for example.]
References : http://www.rubycentral.com/pickaxe/tut_modules.html
another words:
The extend method will mix a module’s methods at the class level. The method defined in the Math module can be used as a class/static method.
The include method will mix a module’s methods at the instance level, meaning that the methods will become instance methods.
http://www.juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/
module MyTools
def run(*args)
puts "let #{args.join(' ')} run"
end
end
class Klass
def hello(*args)
"Hello " + args.join(' ')
end
end
class TryTools
#include MyTools
def initialize()
self.class.send :include,MyTools
end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
c=TryTools.new
c.run("me")
Notes:
A couple of points about the include statement before we go on. First, it has nothing to do with files. C programmers use a preprocessor directive called #include to insert the contents of one file into another during compilation. The Ruby include statement simply makes a reference to a named module. If that module is in a separate file, you must use require to drag that file in before using include. Second, a Ruby include does not simply copy the module's instance methods into the class. Instead, it makes a reference from the class to the included module. If multiple classes include that module, they'll all point to the same thing. If you change the definition of a method within a module, even while your program is running, all classes that include that module will exhibit the new behavior.[Of course, we're speaking only of methods here. Instance variables are always per-object, for example.]
References : http://www.rubycentral.com/pickaxe/tut_modules.html
another words:
The extend method will mix a module’s methods at the class level. The method defined in the Math module can be used as a class/static method.
The include method will mix a module’s methods at the instance level, meaning that the methods will become instance methods.
http://www.juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/
2009年1月5日星期一
Debugging Ruby and ROR
1,install rdebug, sudo gem install ruby-debug
2,command line for debugging ruby file , rdebug rubyscript.rb
3,tips for debugging rails app , insert 'debugger' statement into your code where the code you want to check
4,run ./script/server --debugger,then the app will trap into rdebug when execution flow encounters the 'debugger' statement.
2,command line for debugging ruby file , rdebug rubyscript.rb
3,tips for debugging rails app , insert 'debugger' statement into your code where the code you want to check
4,run ./script/server --debugger,then the app will trap into rdebug when execution flow encounters the 'debugger' statement.
2008年12月30日星期二
Ruby dynamic syntax checking
From the file sample/test.rb in the Ruby source code distribution:
def valid_syntax?(code, fname)
eval("BEGIN {return true}\n#{code}", nil, fname, 0)
rescue Exception
puts $!.message
false
end
original post: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/1efc85a01ab278f4?pli=1
def valid_syntax?(code, fname)
eval("BEGIN {return true}\n#{code}", nil, fname, 0)
rescue Exception
puts $!.message
false
end
original post: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/1efc85a01ab278f4?pli=1
Ruby syntax checking
Ruby -T way for checking ruby script like perl stict mode( maybe like ^_^)
sorry,it's wrong .
sorry,it's wrong .
2008年12月25日星期四
Set MySQL Connection Count On The Fly
Occasionally you'll run into a situation in which the connection count you've configured for MySQL is too low. This often happens on load balanced applications. You can use the following commands to view and set the connection limit on the fly:
original url : https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Set_MySQL_Connection_Count_On_The_Fly
mysql> select @@global.max_connections;
+--------------------------+
| @@global.max_connections |
+--------------------------+
| 1000 |
+--------------------------+
1 row in set (0.00 sec)
mysql> set @@global.max_connections = 3000;
Query OK, 0 rows affected (0.00 sec)
original url : https://boxpanel.blueboxgrp.com/public/the_vault/index.php/Set_MySQL_Connection_Count_On_The_Fly
2008年12月24日星期三
how to execute mutli-statements In Ruby/Mysql
there is a tip when you need to execute multi-statements in Ruby/Mysql.
the wrong version:
require 'mysql'
dbh=Mysql.real_connect('localhost','root','pass','db')
dbh.set_server_option( Mysql::OPTION_MULTI_STATEMENTS_ON )
stmt="select * from contents limit 1;\n" *10
puts stmt
dbh.query( stmt )
puts dbh.stat # got the
the correct version:
require 'mysql'
dbh=Mysql.real_connect('localhost','root','pass','db')
dbh.set_server_option( Mysql::OPTION_MULTI_STATEMENTS_ON )
stmt="select * from contents limit 1;\n" *10
puts stmt
dbh.query( stmt ) { |res|
puts "number of rows is #{res.num_rows()}"
}
puts dbh.stat
what 's the differents?
Wow,
dbh.query( stmt ) { |res|
puts "number of rows is #{res.num_rows()}"
}
and
dbh.query( stmt )
when multi-statements was executed , a group of result set were present ,
even we need not the the data in the result set .
so we should iterate the result sets and clear it before the next mysql-related statement .
References :
1,http://www.tmtm.org/en/mysql/ruby/ , offical site of Ruby/Mysql
2,http://dev.mysql.com/doc/refman/5.0/en/c-api-multiple-queries.html , one query multiple statment using C API on Mysql.
3,http://www.kitebird.com/articles/ruby-mysql.html , a goog tutorial for ruby/Mysql
the wrong version:
require 'mysql'
dbh=Mysql.real_connect('localhost','root','pass','db')
dbh.set_server_option( Mysql::OPTION_MULTI_STATEMENTS_ON )
stmt="select * from contents limit 1;\n" *10
puts stmt
dbh.query( stmt )
puts dbh.stat # got the
CR_COMMANDS_OUT_OF_SYNC error.
....
the correct version:
require 'mysql'
dbh=Mysql.real_connect('localhost','root','pass','db')
dbh.set_server_option( Mysql::OPTION_MULTI_STATEMENTS_ON )
stmt="select * from contents limit 1;\n" *10
puts stmt
dbh.query( stmt ) { |res|
puts "number of rows is #{res.num_rows()}"
}
puts dbh.stat
what 's the differents?
Wow,
dbh.query( stmt ) { |res|
puts "number of rows is #{res.num_rows()}"
}
and
dbh.query( stmt )
when multi-statements was executed , a group of result set were present ,
even we need not the the data in the result set .
so we should iterate the result sets and clear it before the next mysql-related statement .
References :
1,http://www.tmtm.org/en/mysql/ruby/ , offical site of Ruby/Mysql
2,http://dev.mysql.com/doc/refman/5.0/en/c-api-multiple-queries.html , one query multiple statment using C API on Mysql.
3,http://www.kitebird.com/articles/ruby-mysql.html , a goog tutorial for ruby/Mysql
2007年9月4日星期二
a English programming tech blog
a chance for practising english.
if my word or syntax is wrong please comment and correct me .
if my word or syntax is wrong please comment and correct me .
订阅:
博文 (Atom)