0
貌似EI Capitan和以前的版本的安装有些差别,记录一下。大体来说,你需要安装下面3个部分。
- Oracle Instant Client
- ruby-oci8 gem
- activerecord-oracle_enhanced-adapter gem
安装Oracle Instant Client
去Oracle官网下载下面几个包,并按照 http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
- instantclient-basic-macos.x64-12.1.0.2.0.zip
- instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
- instantclient-sdk-macos.x64-12.1.0.2.0.zip
解压到/opt/oracle/instantclient_12_1
cd ~
unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
unzip instantclient-sdk-macos.x64-12.1.0.2.0.zip
3. 创建link
cd /opt/oracle/instantclient_12_1
ln -s libclntsh.dylib.12.1 libclntsh.dylib
Note: OCCI programs will additionally need:
ln -s libocci.dylib.12.1 libocci.dylib
4. 配置PATH
export ORACLE_HOME=/opt/oracle/instantclient_12_1
export OCI_DIR=/opt/oracle/instantclient_12_1
export PATH=$ORACLE_HOME:$PATH
export TNS_ADMIN=$HOME
export NLS_LANG="AMERICAN_AMERICA.UTF8"
安装Gem
gem install 'ruby-oci8' -v '~> 2.1.0'
gem install 'activerecord-oracle_enhanced-adapter' -v '~> 1.5.0'
测试
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "database",
:username => "username",
:password => "password")
cursor = ActiveRecord::Base.connection.execute("SELECT 1 n FROM table")
# query data
result_data = []
result_data << cursor.column_metadata.map { |e| e.name }
while row = cursor.fetch
result_data << row
end
引用
- http://stackoverflow.com/questions/36811473/ruby-oci8-installation-error-in-mac-el-capitan
- https://craig.io/setting-up-a-rails-development-environment-with-oracle/
0
Posted on
Thursday, November 17, 2016
by
醉·醉·鱼
and labeled under
sql
- ODBC。Open Database Connectivity,是很老的一个数据库连接API。现在基本上没有用了。
- 微软后来开发了OLE DB,算是ODBC的替代品,同时支持更多的数据源,比如spreadsheets
- ADO.NET是基于.NET framework来连接关系型和非关系型数据库。看上去像ADO的进化版,实际上完全是全新的东西。
- JDBC。同ODBC,不过是给JAVA用的。
- JDBC有两款driver,一个是微软自己开发的sqljdbc4,另外一个是jtds。前者不支持NamedPipe。
- 可以通过
jdbc:jtds:sqlserver://./DatabaseName;instance=LOCALDB#88893A09;namedPipe=true 连接namedPipe
- jtds是基于FreeTds。
- ruby下面tiny_tds也是基于FreeTds的。