我试图弄清楚如何在将其交给执行之前对SQL字符串进行参数化,但遗憾的是我在互联网上发现了很多这样的信息:
sql = "SELECT * FROM table_name WHERE thing LIKE '%#{input}%'"
Run Code Online (Sandbox Code Playgroud)
这是一件坏事......但是,参数化sql查询可以在底层的Sequel库中找到,这就是TinyTDS的基础.所以我知道这是可能的.我只是很难搞清楚.
我真的想这可能是简单,只需这样:
@client = TinyTds::Client.new(
:adapter => 'sqlserver',
:host => host,
:database => db,
:username => username,
:password => password)
sql = "SELECT * FROM table_name WHERE thing LIKE ?"
safe_sql = @client.prepare(sql, input)
result = @client.execute(safe_sql)
Run Code Online (Sandbox Code Playgroud)
我似乎Dataset在源代码中找到了一个叫做类的东西,它有一个prepare方法.问题是,我该如何使用它?在将其交给对象中的execute()方法之前,是否需要创建另一个@client对象?我找不到一个initialize或一个new方法,所以简单的实例化似乎是错误的方法.
我的问题
我可以采取哪些可靠的步骤来100%使这个工作?我需要真正的指示,而不是一个班轮答案或过程的模糊概念描述.
让我们来看看它的底部.似乎某些地方存在冲突,而且我在GitHub上的宝石开发者得到了与我在Ruby/Rails/Bundler/Homebrew上的经验相关的低级辅助,所以这不完全是他们的错:P但是我需要弄清楚如何尽快得到这个工作,所以这里是我目前的这个问题的状态.
更新:2/25/2013
更新了GCC/XCODE版本4.6(4H127)并下载了最新版本的XCODE COMMAND-LINE TOOLS,现在iconv_open()显示在extconf检查器中.现在我收到这些错误:
我相信它们现在是tiny_tds的问题,并且与最新的xcode路径兼容.
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... yes
checking for ct_bind() in -lct... yes
creating Makefile
make
xcrun cc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I. -DHAVE_ICONV_OPEN -DHAVE_SYBFRONT_H -DHAVE_SYBDB_H -I-I/usr/local/php5/include -I-I/usr/include -I-I/usr/local/include -I-I/opt/local/include -I-I/usr/local/MacGPG2/include -I-I/opt/sm/pkg/active/include -I/usr/local/php5/include -I/usr/include -I/usr/local/include -I/opt/local/include -I/usr/local/MacGPG2/include -I/opt/sm/pkg/active/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -c …Run Code Online (Sandbox Code Playgroud) 这是我用来连接SQL Server 2012 express的代码.我的文件名是Connect.rb.
require "rubygems"
require "tiny_tds"
client = TinyTds::Client.new(
:username => 'sa',
:password => 'sapassword',
:dataserver => 'localhost\SQLEXPRESS',
:database => 'ContactsDB')
result = client.execute("SELECT * FROM [Contacts]")
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我收到以下错误:
在'execute'中:来自Connect.rb的关闭连接(TinyTds :: Error):在'main'中
当我用以下代码替换上面的代码时,
client = TinyTds::Client.new(
:username => 'sa',
:password => 'sapassword',
:host => 'localhost',
:port => 1433,
:database => 'ContactsDB')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
在'connect'中:无法连接:Adaptive Server不可用或不存在
是什么导致了这个错误以及如何修复它?
我一直在尝试使用OSX 10.6在Macbook上安装TinyTDS gem.我成功安装了免费TDS - 确认它的工作原理是:
tsql -H SERVER -p 1433 -U username.
Run Code Online (Sandbox Code Playgroud)
我从gem install tiny_tds得到的错误是:
Building native extensions. This could take a while...
ERROR: Error installing tiny_tds:
ERROR: Failed to build gem native extension.
/Users/jason/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... no
-----
freetds is missing.
-----
*** extconf.rb failed ***
Could not create Makefile due to some …Run Code Online (Sandbox Code Playgroud) 我用homebrew(linux端口)来安装freeTDS,我正在尝试使用gem tinytds部署/捆绑安装我的应用程序.在进行bundle安装时我得到了这个错误输出
Installing tiny_tds (0.5.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/deployer/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
/usr/bin/ld: /opt/homebrew/lib/libsybdb.a(dblib.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/homebrew/lib/libsybdb.a: could not read symbols: Bad value
Run Code Online (Sandbox Code Playgroud)
非常类似于此修复程序,但我没有在我的文件夹中引用的文件:https://stackoverflow.com/a/7119224/1130736
自制lib文件夹的内容:
/opt/homebrew/lib$ ls
libct.a libsybdb.a
Run Code Online (Sandbox Code Playgroud)
完全错误转储:
full error dump:
Installing tiny_tds (0.5.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/deployer/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... yes
checking for …Run Code Online (Sandbox Code Playgroud) 我正在寻找一步一步的指南,如何在Heroku上安装freetds.我需要从ruby脚本访问Sql Server,不幸的是Cedar不支持tinytds gem.我已经阅读了互联网上可用的任何信息,包括关于heroku buildpacks但无法成功的信息.
我非常感谢能帮助在heroku上部署freetds的人.
提前谢谢, - 杰克
我的脚本使用mysql,tiny_tds,fileutils和net/ftp.在ruby 1.9.3上运行.当我从文件夹内部运行它时,它工作得很好.
但是,当我将它添加到cron选项卡时,tiny_tds经常失败.我不知道是否有任何其他宝石失败,因为我无法通过此错误:
require':没有要加载的文件 - tiny_tds(LoadError)
我尝试从crontab使用的同一个shell执行它,我得到了那个错误.
整个脚本只有一个文件.
我是红宝石的新手,所以我的知识在以正确的方式设置环境方面是有限的.
在我的文件的头部
#!/usr/bin/ruby
require "mysql"
require "fileutils";
require "tiny_tds"
require "net/ftp"
Run Code Online (Sandbox Code Playgroud)
简而言之,我从mysql获取了一个Jobs列表,将其与MsSQL进行比较,将FTP文件与之相比较,并在作业完成时再次更新mysql.
我需要从cron运行它.
经过一段时间的研究,我试图将宝石设置为全局,但是,我认为这可能没有用.
在此先感谢您的帮助!
:我已经使用了两个不同的数据库为我的Rails应用程序MongoDB和MsSQL使用Mongoid,并activerecord-sqlserver-adapter分别适配器.一切都很好,但生成模型时出现问题.
问题是"我怎样才能生成与之相关MongoDB或MsSQL不同的模型?"
例如:我要生成People新型涉及MongoID并Animal与模型MsSQL.当我用命令生成时:rails g model Animal name:string它生成与mongoid相关的模型.如何使用与MsSQL相关的ActiveRecord生成模型Animal.
请帮我.谢谢
我必须使用我的Rails 4.2.3中的"Tiny TDS"宝石,当然还有Heroku的cedar-14,我不能,因为FreeTDS已不再使用了.
如何在Heroku cedar-14上使用FreeTDS?
我正在网上看,我发现了这个:
https://github.com/foraker/heroku-buildpack-freetds
他说使用"heroku-buildpack-multi",这个:https://github.com/ddollar/heroku-buildpack-multi
但我不明白怎么做!
我必须在我的本地电脑上创建".buildpacks"文件?
然后我必须"git push heroku master"?
这个程序今天仍然有效吗?
或者我必须使用它:https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app
请帮帮我,谢谢.
更新:
我发现如何使用以下方法在Heroku上安装FreeTDS:
https://github.com/eltiare/heroku-buildpack-freetds
Run Code Online (Sandbox Code Playgroud)
有了这个:
https://github.com/ddollar/heroku-buildpack-multi
Run Code Online (Sandbox Code Playgroud)
用这个.buildpacks:
https://github.com/eltiare/heroku-buildpack-freetds.git#master
https://github.com/heroku/heroku-buildpack-ruby.git#master
Run Code Online (Sandbox Code Playgroud)
但是现在,在部署之后,我收到了一个错误:
/app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require': libsybdb.so.5: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/tiny_tds-0.6.2/tiny_tds/tiny_tds.so (LoadError)
Run Code Online (Sandbox Code Playgroud)
和应用程序崩溃.
怎么修?
这些是日志:
部署:
Deleting 2 files matching .slugignore patterns.
Fetching custom git buildpack... done
Multipack app detected
Downloading Buildpack: https://github.com/eltiare/heroku-buildpack-freetds.git
=====> Detected Framework: FreeTDS
Installing freetds into /tmp/build_5e53a70f18da19be7f6defafbfad826b/vendor/freetds
% Total …Run Code Online (Sandbox Code Playgroud) 我一直看到此错误,并且无法连接到远程服务器上的数据库。
给我一个到数据库的连接字符串,如下所示:
data source=qsss.gar.de\SQL2012,3000;initial catalog=City;persist security info=True;user id=user_me;password=user_me##2009;
Run Code Online (Sandbox Code Playgroud)
现在,我database.yml基于该连接字符串创建了一个文件,如下所示:
development:
adapter: 'sqlserver'
host: 'qsss.gar.de\SQL2012,3000'
port: 1433
database: 'City'
username: 'user_me'
password: 'user_me##2009'
Run Code Online (Sandbox Code Playgroud)
当我尝试运行服务器时,它总是以配置文件中找不到的服务器名称打我。
opts[:port] ||= 1433
opts[:dataserver] = "#{opts[:host]}:#{opts[:port]}" if opts[:dataserver].to_s.empty?
connect(opts) // ERROR AT THIS LINE
end
def tds_73?
Run Code Online (Sandbox Code Playgroud)
请尝试帮助我弄清楚这是什么问题?
更新:
我可以使用SQLPro for MSSQL向导使用完全相同的连接参数连接到服务器:
它可以通过向导运行,但不能通过TinyTDS的代码运行!