ruby - 如何使用建立连接创建类以建立数据库连接 - RUBY
问题描述
我对Ruby语言了解不多。我正在尝试创建一个类来建立 oracle 数据库连接。此类将接收要在其他类中重用的连接。我正在从事一个自动化项目,需要建立这种连接,以便为自动化测试准备大量数据。下面我将提供我的代码,以便有人可以指导我如何创建这个类。在这种情况下,无法访问连接类。
require "rubygems"
require "active_record"
class Connection
attr_accessor :connection
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "dboraclehomolog.com.br:1521/homolog",
:username => "USER",
:password => "password",
)
def initialize
connection = ActiveRecord::Base.connection
end
def execute_select(sql)
results = ActiveRecord::Base.connection.execute(sql)
if results.nil?
return results
else
return false
end
end
def exec(sql)
begin
ActiveRecord::Base.connection.execute(sql)
rescue => e
puts e.message
end
end
end
错误:未初始化的常量 Repactuar::Conexao (NameError)
解决方案
推荐阅读
- reactjs - 同一页面上的多个反应下拉列表为每个下拉列表获取相同的值
- java - android:RecyclerView set adapter
- azure - Xamarin iOS 在 Azure 中是否可以为同一个 Web API 提供两个通知中心,一个处于生产模式,另一个处于开发模式?
- java - 从 Web SRC URL 生成文件
- excel - Excel 将一维数组转置为多维数组
- python - 检查是否包含字符串时获得完全匹配是行
- android-uiautomator - 如何计算 UiAutomator 中所有 RecyclerView 项目的不同项目
- python - 唯一约束失败:“app”_customuser.username
- javascript - 强制将块拆分为某个包
- django - 多个附件django电子邮件