Tag: sqlite

Rails数据库布尔值

代码优先: create_table :users do |t| … t.boolean :is_active, :default => true … end 现在,这是我的问题 – 我正在创建一个rake任务来导入大量的记录(10,000+)。 我已经做了大量的测试和基准测试,并确定执行此任务的最快和最有效的方法是创建一个巨大的原始SQL语句。 (我正在从CSV读取数据)。 举个例子: inserts = Array.new FasterCSV.foreach(…) do |row| inserts.push “(row[0], row[1]…)” end User.connection.execute “INSERT INTO users (…) VALUES #{inserts.join(“, “)}” 一切都很好。 整个过程在(字面上)秒内完成,而不是使用ActiveRecord完成1.5小时。 但是,我的问题在于布尔字段。 我在SQLite上本地开发,但在生产中使用MySQL。 当使用ActiveRecord时,Rails确定要在“布尔”字段中放置什么(因为几乎所有数据库都不同)。 我正在编写自定义SQL,我想知道是否有办法可以做类似…… INSERT INTO users(…, is_active, …) VALUES (…, ActiveRecord::Base.connection.boolean.true, …) …正确返回特定于数据库的布尔值。 任何回答“只使用ActiveRecord”的人都将被拒绝投票。 在这种情况下,这根本不可行。 […]

由于缺少sqlite3 gem,Rails 4.0rc1应用程序未运行

我第一次尝试安装Rails 4.0。 在带有Ruby 2.0 x64的Windows 8上。 冉: gem install rails –version 4.0.0.rc1 –no-ri –no-rdoc 然后我跑: rails new test_app cd test_app rails s 但localhost:3000的网页报告以下错误: 为数据库适配器指定’sqlite3’,但未加载gem。 将gem’sqlite3 gem ‘sqlite3’添加到您的Gemfile中。 它在我的Gemfile中: gem ‘sqlite3’ 我尝试多次运行bundle install ,它甚至没有在所有其他gem中列出它。 更新 :我尝试以两种不同的方式安装sqlite3 gem,两者都使用从DevKit的msys.bat文件打开的终端。 @szines下面提到的方式给了我以下错误: $ gem install sqlite3 –platform=ruby — –with-opt-dir=c:/sqlite-amalgamation-3071602 Temporarily enhancing PATH to include DevKit… Building native extensions with: ‘–with-opt-dir=c:/sqlite-amalgamation-3071602’ […]

如何从SQLite迁移到PostgreSQL(Rails)

我是一个DB菜鸟,所以请和我好心。 我有一些问题通过点击gem将我的SQLite DB推送到Heroku。 与他们交谈,他们告诉我其中一个解决方案可能是将我的数据库从SQLite转换为PostgreSQL。 有一个简单的方法吗? 谢谢 更多信息: – 来自Rails应用程序的数据库 – 我在Mac OS X上 – 刚刚通过macports安装了PostgreSQL

Rails 3.1。 Heroku PGError:运算符不存在:字符变化=整数

修复错误有点麻烦。 一切都适用于本地机器。 在PG上,heroku是错误的。 这是日志: ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m ActionView::Template::Error (PGEr ror: ERROR: operator does not exist: character varying = integer ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m LINE 1: …T “reviews”.* FROM “re views” WHERE “reviews”.”trip_id” = 32 ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m : SELECT “reviews”.* FROM “review s” WHERE “reviews”.”trip_id” = 32): ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m 31: ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m 33: ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m 34: ←[32m2012-01-09T19:52:24+00:00 app[web.1]:←[0m 32: […]

bundle exec rake test:模型抛出Errno :: EACCES:权限被拒绝

我正在做railsstutorial的草稿版本,当我尝试运行bundle exec rake test:models我收到此错误消息: rake aborted! Errno::EACCES: Permission denied – C:/Users/Alex/Desktop/Workspace/Rails/sample_ app/db/test.sqlite3 C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/test_helper.rb:3:in `’ C:/Users/Alex/Desktop/Workspace/Rails/sample_app/test/helpers/application_helper _test.rb:1:in `’ Tasks: TOP => test:run => test:units (See full trace by running task with –trace) 使用–trace: ** Invoke test (first_time) ** Execute test ** Invoke test:run (first_time) ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Execute test:prepare ** […]

SQLite在开发中,PostgreSQL在生产中 – 为什么不呢?

由于可能的问题,Heroku建议不要这样做。 我是一个SQL菜鸟,你能解释一下使用不同数据库可能遇到的问题类型吗?

使用Rails将外部JSON保存到DB

我正在使用gem“httparty”对外部源进行GET调用; 这是我的Controller.rb: def show response = HTTParty.get(‘URI’) user = JSON.parse(response) user.each {|line| puts line[‘user’][‘id’]} #the “[‘user’][‘id’]” is because of the nested JSON object that is returned after the parse. end 这会在我的rails控制台中返回正确的输出,但现在的问题是如何将[‘id’]保存到我的数据库中? 目前,我的用户模型有:id和:name; 来自外部API的JSON对象发送:id和:name以及一些我不需要的其他信息。 class User < ActiveRecord::Base attr_accessor :id, :name end 任何帮助表示赞赏,谢谢!

SQLite3错误 – 无法回滚 – 没有事务处于活动状态

已解决(见下文) 当我试图在我的Ruby on Rails应用程序(或在控制台中)创建或销毁记录(在SQLite3上运行)时,我得到一个SQLexception: irb(main):014:0> ApiCache.all => [] irb(main):015:0> ApiCache.create(:hash => ‘qwe’, :contents => ‘asd’) SQLite3::SQLException: cannot rollback – no transaction is active from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:97:in `close’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:97:in `prepare’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:134:in `execute’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:517:in `rollback’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /connection_adapters/sqlite_adapter.rb:168:in `rollback_db_transaction’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /connection_adapters/abstract/database_statements.rb:176:in `transaction’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:207:in `transaction’ from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:290:in `with_transaction_returning_status’ […]

Rails:部署到Heroku,有很多问题

我第一次尝试将我的rails应用程序部署到Heroku,遇到了很多问题。 该应用程序崩溃,您可以查看图像中的日志: http : //i.stack.imgur.com/bsx1b.png 更糟糕的是,当我试图在本地查看我的应用程序时,它无法在postgreSQL环境中工作。当我回到在database.yml中使用sqLite3时工作正常。 我认为问题可能是我实际上必须安装postgreSQL,除了添加pg gem和运行bundle install。 我继续使用一键安装程序(Windows 7 64位)安装PostgreSQL。 重启后,一个简单的rails服务器或bundle install命令开始失败,所以我重新安装了整个ruby和rails。 现在rails server命令工作正常,当我尝试在本地环境中查看我的应用程序时,它会提示不同的错误。 所以现在我有pgAdmin III和Rails PG::Error fe_sendauth: no password supplied 我试着遵循这个 ,但我找不到“pg_hba.conf”。 我想答案是基于不同的操作系统。 现在再次,捆绑器不工作,给我错误…… 问题: 1)使用一键安装程序安装postgreSQL是否正确? 因为这导致我的ROR以某种方式“崩溃”,我不得不重新安装rails。 2)我想我将删除与postgreSQL相关的所有内容,重新安装Rails,并从头开始。 我必须采取哪些步骤? 我看过的所有参考文献似乎都不适合Windows环境。 在我的gemfile中,我有 gem ‘pg’ gem ‘thin’ 在我的数据库中,我有 # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is […]

Ruby on Rails – 无法加载这样的文件 – mysql2 / 2.2 / mysql2(LoadError)

我在我的Rails项目中使用SQLite,但当我听说Heroku不支持SQLite时,我转而使用MYSQL。 切换我的数据库后,我启动了我的rails服务器“rails s”,但它给了我以下错误: C:\Sites\simple_cms>rails server C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require’ : cannot load such file — mysql2/2.2/mysql2 (LoadError) from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2 :in `’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `r equire’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:76:in `requ ire’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:76:in `bloc k (2 levels) in require’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:72:in `each ‘ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:72:in `bloc k in require’ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:61:in `each ‘ from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.8.4/lib/bundler/runtime.rb:61:in `requ […]