return result
end
+ def gen_db()
+ case @db_dsn
+ when /^SQLite3:/ then puts "SQLite3 DB#{@db_dsn.split(':')[1]} generating"
+ when /^Mysql:/ then
+ name = nil
+ host = nil
+ port = nil
+ socket = nil
+ flag = nil
+ dsn = @db_dsn.split(':')
+ if dsn[2].nil? then
+ dsn[1].split(';').each do |attr|
+ case attr.split('=')[0].strip.eql? "database"
+ when /database/i then
+ name = attr.split('=')[1].strip
+ when /host/i then
+ host = attr.split('=')[1].strip
+ when /port/i then
+ port = attr.split('=')[1].strip
+ when /socket/i then
+ socket = attr.split('=')[1].strip
+ when /flag/i then
+ flag = attr.split('=')[1].strip
+ else
+ etc = attr.split('=')[1].strip
+ end
+ end
+ else
+ name = dsn[1].strip
+ host = dsn[2].strip
+ end
+ if host.eql? "localhost" or host.eql? "127.0.0.1" then
+ File.open("create_db.txt","w") do |f|
+ f.puts "GRANT ALL ON #{name}.* TO '#{@db_user}'@'#{host}' IDENTIFIED BY '#{@db_passwd}';"
+ f.puts "CREATE DATABASE #{name};"
+ end
+ socket_str = ""
+ socket_str = "--socket=#{socket}" if not socket.nil?
+ puts "Mysql DB #{name} generating"
+ system("mysql -h #{host} #{socket_str} -u #{@db_user} --password=#{@db_passwd} < create_db.txt")
+ end
+ else puts "not support DB #{@db_dsn}"
+ end
+ end
def create_db()
+ gen_db()
result = get_db_connection() do |db|
case @db_dsn
when /^SQLite3:/ then inc="AUTOINCREMENT"