ruby数据库
Ⅰ rails on ruby,如何缓存数据库到本地
可以采用cookie来保存数据,想要提交信息的时候在对服务器发出请求
Ⅱ ruby(rails) 程序如何 连接 各种远程数据库
在使用Cookie.find等操作的时候,就会连接到database.yml中monitor_spider配置的数据库上操作。以前一直都这么用,没发现什么不妥。最近一个项目,由于启动的进程比较多,老是碰到数据库连接池链接获取超时的错误。
通过MySQL Client用命令:show processlist; 发现数据库连接数量一直居高不下,轻轻松松就上2k+的连接。通过读Rails框架的connection_pool.rb文件代码,发现在各模型中用establish_connection连接数据库会造成很大的问题。文件中类ConnectionHandler的establish_connection方法代码如下:Ruby代码 def establish_connection(name, spec) @connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec) end def establish_connection(name, spec)
@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
Ⅲ 如何用ruby操作sql数据库
可以看一下这个网页
http://www.cnblogs.com/wangyuyu/p/3242611.html
详细讲了
用ruby操作sql数据库
Ⅳ 如何使用Ruby on Rails连接Oracle数据库
今天学习了一下最近流行的Ruby on Rails,感觉:就是一个代码生成器
链接Oracle数据库的时候,查了半天的资料。终于找到办法了
http://blog.csdn.net/OwenLiu/article/details/576715
Ⅳ ruby 可以连hana 数据库吗
可以的,具体步骤如下,以及例子代码,用ODBC
Install Sinatra on Ruby
gem install sinatra
Install DevKit forRuby
rubydk.rb init rubydk.rb install
3.Install RDBIgem install rdbi-driver-odbc
4.Creating an 32bit ODBCGo to C: –> Windows –> SysWOW64 –> odbcad32.exe
5.
Ruby_SAP_HANA.rb
require ‘sinatra’
require ‘rdbi-driver-odbc’
get ‘/’ do
body do
<<-eos
<div align=’center’>
<h1>Ruby/Sinatra and SAPHANA– Table Browser</h1>
<form action=’/login’ method=’post’>
<label for=’dsn’>DSN</label><br/>
<input type=’text’ name=’dsn’ /><br />
<label for=’user’>User</label><br />
<input type=’text’ name=’user’ /><br />
<label for=’password’>Password</label><br />
<input type=’password’ name=’password’ /><br />
<input type=’submit’ name=’submit’ value=’Login’ />
</form>
</div>
eos
end
end
get ‘/login_view’ do
$output = “<div align=’center’><form action=’/table_view’ method=’post’>”
$output += “Choose Table <SELECT NAME=’tab’>”
for i in 0…$Tables_Len
$output += “<option value=#{$Tables[i]}>#{$Tables[i]}</option>”
end
$output += “</option>”
$output += “<input type=’submit’ name=’submit’ value=’Show Table’ />”
$output += “</form></div>”
body $output
end
get ‘/show_table’ do
$output = “<div align=’center’><table border=’1′><tr>”
for i in 0…$Fields_Len
$Fields_Fields = $Fields[i].to_s
$output += “<th> #{$Fields_Fields} </th>”
end
$output += “</tr>”
for i in 0…$Data_Len
$output += “<tr>”
for j in 0…$Fields_Len
$output += “<td> #{$Data[i][j].to_s} </td>”
end
$output += “</tr>”
end
$output += “</table></div>”
body $output
end
post ‘/login’ do
$dsn,$user,$password = params[:dsn],params[:user],params[:password]
“#{do_login}”
“#{get_tables}”
redirect ‘/login_view’
end
post ‘/table_view’ do
$tab = params[:tab]
“#{get_data}”
redirect ‘/show_table’
end
helpers do
def do_login
$dbh = RDBI.connect :ODBC, :db => $dsn, :user => $user,:password => $password
end
def get_tables
$rs = $dbh.execute “SELECT table_name from SYS.CS_TABLES_ where schema_name = ‘SFLIGHT'”
$ary = $rs.as(:Array).fetch(:all)
$Tables = Array.new
for i in 0…$ary.length
$Tables.push($ary[i][0])
end
$Tables_Len = $Tables.length
end
def get_data
$query = “SELECT COLUMN_NAME FROM SYS.CS_COLUMNS_ AS A INNER JOIN SYS.CS_TABLES_ AS B “
$query += “ON A.TABLE_REF = B.REF_ID WHERE TABLE_NAME = ‘”
$query += $tab
$query += “‘ AND ABAP_TYPE_ID > 0”
$rs = $dbh.execute $query
$ary = $rs.as(:Array).fetch(:all)
$Fields = Array.new
$Data = Array.new
for i in 0…$ary.length
$Fields.push($ary[i][0])
end
$Fields_Len = $Fields.length
$query = “SELECT * FROM SFLIGHT.” + $tab
$rs = $dbh.execute $query
$ary = $rs.as(:Array).fetch(:all)
for i in 0…$ary.length
$Data.push($ary[i])
end
$Data_Len = $Data.length
end
end
Ⅵ ruby连接sqlite,ruby中创建数据库sample,往表格student中插数据,update方法,键盘输入,修改对应值
每个方法都加参数 db
然后各个方法里面对db进行连接,然后才是每个方法相应的操作
Ⅶ Ruby on Rails 查询数据库 where 和 find 的区别
在写LINQ语句的时候,往往会看到版.AsEnumerable() 和 .AsQueryable() 。
例如:权
[csharp] view plain
string strcon = "Data Source=.\\SQLEXPRESS;Initial Catalog=Db_Example;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection con = new SqlConnection(strcon);
con.Open();
Ⅷ ruby 连接数据库mysql 报错~~~
require 'mysql'
class MysqlDb
# attr_accessor :host, :user, :pass, :database
def open(host=nil, user=nil, pass=nil, database=nil,port=3306)
@host =host
@user = user
@pass = pass
@database = database
@port = port
begin
@connection = Mysql.new(@host, @user, @pass, @database, @port)
rescue
puts "connect faild! an error has occurred: #{$!}" # 错误信息保存在特殊变量$!中。
try_again
end
end
def try_again
puts '------------------try again, if not modify, leave a blank---------------'
print "host: "
host=STDIN.gets.strip
@host = check_value(host,@host)
puts "---------------current host: #{@host}"
print "user: "
user =STDIN.gets.strip
@user = check_value(user,@user)
puts "---------------current user: #{@user}"
print "password: "
pass =STDIN.gets.strip
@pass = check_value(pass,@pass)
puts "---------------current password: #{@pass}"
print "database: "
database =STDIN.gets.strip
@database = check_value(database,@database)
puts "---------------current database: #{@database}"
print "port: "
port =STDIN.gets.strip
@port = check_value(port,@port)
open(@host, @user, @pass, @database, @port)
puts "---------------current port: #{@port}"
end
def check_value(value,returnvalue)
if value == ""
nil
else
returnvalue = value
end
return returnvalue
end
def iquery(sql)
field = []
@connection.query(sql).each do |data|
field << data
end
field.to_a
end
def iexecute(sql)
@connection.query(sql)
end
def close
@connection.close
end
end
# useages
adb = MysqlDb.new
adb.open('127.0.0.1','root','zyq001122','hello_z','3307')
# result = db.query "insert into user value(7,\"lilY\",\"256y42\",\"#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\" )" # 插入记录
# result.each {|row| puts row}
num_of_records = adb.iquery ('select count(*) from user') #查询
puts num_of_records
#sql = "insert into user value(10,\"Hello-Kitty\",\"256y42\",\"#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\" )" # 数据操作
# sql = 'update user set name=\'jackjhons\' where uid=5 ' # 更新一条记录
#adb.iexecute(sql)
# adb.close
Ⅸ ruby on rails 可否将一个form中的数据提交给3数据库
表单跟数据库没关系, 看你在controller里怎么处理. 在controller里操作就可以了.
Ⅹ 安装ruby环境,用mysql数据库,总是报错,调了一下午,网上方法都用了也不管事
make的时候需要调用ruby很多编译前的参数.一些信息make不知道的话会不知道如何建库.
我个人的建议是根据你安装的ruby路径和版本信息把配置选项补充全.下面是我电脑上面的配置,你可以借鉴一下.据我分析应该能解决你的问题.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/usr/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/ruby-2.1.2/rubies/ruby-2.1.2/bin/ruby