如何在带有unixodbc和freetds的Mac上安装RODBC? [英] How do I install RODBC on Mac with unixodbc and freetds?

查看:177
本文介绍了如何在带有unixodbc和freetds的Mac上安装RODBC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行了相当广泛的搜索之后,我注意到许多人都很难找到可以回答这个问题的从入门到精通的指南. (至少一个问题指出存在一种解决方案,但建议的解决方案无法绕开默认情况下的事实, RODBC尝试针对iODBC(优胜美地不包含的iODBC)进行编译.)我刚刚经历了此过程,所以我想在此进行记录,以希望对其他人有好处.我正在连接到SQL Server数据库.

After a fairly extensive search, I noticed that a number of people are having a hard time finding a start-to-finish guide that answers this question. (At least one question notes that a solution exists, but the proposed solution does not get around the fact that, by default, RODBC attempts to compile against iODBC, which is not included with Yosemite.) I just went through this process, so I thought I would document it here in the hope that it will benefit others. I am connecting to a SQL Server database.

推荐答案

使用 Homebrew 作为我的OS X软件包管理器,我可以按照以下步骤安装RODBC(假设我已经安装了 R ).

Using Homebrew as my OS X package manager, I can install RODBC with the following steps (assuming I have already installed R).

  1. 安装unixodbc:

$ brew install unixodbc

  • 安装freetds(如有必要,将/usr/local/Cellar/unixodbc/2.3.2_1替换为unixodbc目录)

  • Install freetds (replacing /usr/local/Cellar/unixodbc/2.3.2_1 with your unixodbc directory, if necessary):

    $ brew install --with-tdsver=8.0 --with-msdblib --with-unixodbc=/usr/local/Cellar/unixodbc/2.3.2_1 freetds
    

  • 配置您的freetds安装(以下是最小配置文件):

  • Configure your freetds installation (the following is a minimal configuration file):

    # server specific section
    [global]
    ;       tds version = 8.0
    ;       dump file = /tmp/freetds.log
    ;       debug flags = 0xffff
    ;       timeout = 10
    ;       connect timeout = 10
            text size = 64512
    
    [TESTSQL]
            # insert the actual host below
            host = <xxx.xx.x.xx>
            port = 1433
            tds version = 8.0
    

  • 测试freetds配置:

    $ tsql -H `<xxx.xx.x.xx>` -p 1433 -U `<username>` -P `<password>`
    

    locale is "en_US.UTF-8"
    locale charset is "UTF-8"
    using default charset "UTF-8"
    1> exit
    

  • 配置您的unixodbc安装(以下是最小配置文件):

  • Configure your unixodbc installation (the following is a minimal configuration file):

    $ sudo vim /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini
    

    odbcinst.ini

    [MSSQL]
    Description   = Microsoft SQL Server driver
    Driver        = /usr/local/Cellar/freetds/0.95.18/lib/libtdsodbc.so
    

    (和另一个最小安装文件):

    (and another minimal installation file):

    $ sudo vim /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini
    

    odbc.ini

    [ODBC Data Sources]
    TESTSQL     = Test database
    
    [TESTSQL]
    Driver      = MSSQL
    Servername  = TESTSQL
    Port        = 1433
    Database    = TMSEPRD
    TDS_Version = 8.0
    

  • 使用isql测试新配置:

  • Test the new configuration with isql:

    $ isql TESTSQL `<username>` `<password>`
    

    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> quit
    

  • 创建指向您主目录中文件的符号链接:

  • Create a symbolic link to the files in your home directory:

    $ ln -vs /usr/local/Cellar/freetds/0.95.18/etc/freetds.conf ~/.freetds.conf
    $ ln -vs /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbc.ini ~/.odbc.ini
    $ ln -vs /usr/local/Cellar/unixodbc/2.3.2_1/etc/odbcinst.ini ~/.odbcinst.ini
    

  • 通过将以下代码行添加到文件中来查找和修改您的RProfile文件(用包含sql.hsqlext.h文件的include目录替换/usr/local/include;第二个如果目录不存在,则该行可能是不必要的):

  • Find and modify your RProfile file by appending the following line(s) of code to the file (replacing /usr/local/include with the include directory that contains your sql.h and sqlext.h files; the second line may be unnecessary if the directory does not exist):

    $ vim /Library/Frameworks/R.framework/Versions/3.2/Resources/library/base/R/Rprofile
    Sys.setenv(ODBC_INCLUDE="/usr/local/include")
    Sys.setenv(ODBC_LIBS="/usr/local/lib")
    

  • 现在下载RODBC程序包源(您可以下载

  • Now download the RODBC package source (which you an download here) to your Downloads folder.

    打开一个新的R控制台会话并安装软件包(将RODBC_1.3-12.tar.gz替换为软件包源的名称):

    Open a new R console session and install the package (replacing RODBC_1.3-12.tar.gz with the name of your package source):

    install.packages(〜/Downloads/RODBC_1.3-12.tar.gz",repos = NULL,键入="source")

    install.packages("~/Downloads/RODBC_1.3-12.tar.gz", repos=NULL, type="source")

  • 该软件包现在应该可以工作了:

    The package should now work:

    > library(RODBC)
    > myconn <- odbcConnect("TESTSQL", uid="<userid>", pwd="<password>")
    

    感谢

    Thanks to Jared Folkins and Gabi Huiber for help with figuring out what directories R looks in by default for the requisite files for RODBC.

    这篇关于如何在带有unixodbc和freetds的Mac上安装RODBC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆