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
订阅:
博文 (Atom)