Tag: sqlite3

在OS X Lion上与sqlite3 gem挣扎

我是Mac和Ruby on Rails的新手,我正在尝试设置我的环境。 我一直在研究这个教程,并试图在Mac OS X Lion上安装sqlite3 gem。 Xcode 4.2.1 git版本1.7.5.4 Ruby 1.9.3p0 gem -v结果为1.8.11 sqlite版本3.7.5 当我尝试运行gem install sqlite3或gem install sqlite3 — –with-sqlite3-dir=/usr/bin我得到下面的错误文本,有没有人有任何建议? Building native extensions. This could take a while… ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension. /Users/mikehking/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb –with-sqlite3-dir=/usr/bin checking for sqlite3.h… *** extconf.rb failed *** Could not create […]

SQLite3 :: SQLException:没有这样的表:messages:SELECT“messages”。* FROM“messages”

我正在制作一个基于此railscast的简单聊天应用程序。 我发布了另一个关于此的问题,但我愚蠢地没有添加模型,然后我将其命名为错误。 但是,现在已经修复了。 问题是,我甚至不确定我是否需要数据库。 我本来打算完成这个,然后将它上传到heroku上就可以玩了。 我不想存储消息,但如果有必要,那么我会。 这是我的代码。 index.html.erb Hack Chat 控制器; class MessagesController < ApplicationController def index @messages = Message.all end def create @message = Message.create!(params[:message]) PrivatePub.publish_to("/messages/new", "alert('#{@message.content}');") end end 模型; class Message < ActiveRecord::Base end 航线; Hackchat::Application.routes.draw do root to: ‘messages#index’ resources :messages end 的Gemfile; source ‘https://rubygems.org’ gem ‘rails’, ‘4.0.0’ gem “rake”, “~> 10.1.1” […]

使用ruby中的数组进行数据库查询

我正在尝试在数组中查找所有具有值的行,这是我的代码 require ‘sqlite3’ db = SQLite3::Database.new(‘test.sqlite’) res = db.query(“SELECT w1.synsetid FROM words w1 WHERE w1.wordid IN (?)”, arr) arr:字符串数组 我得到了这个错误 SQLite3::RangeException: bind or column index out of range 任何帮助?

不能种子数据库; 因为拒绝连接而无法工作?

当我尝试播种我的应用程序时,我收到错误: 无法建立连接,因为 – 目标机器主动拒绝它。 – 连接(2) 我相信原因是因为我遇到了mysql2的问题,所以我将它与MySQL 5.5服务器一起卸载,然后切换到sqlite3。 我认为mysql2的服务器在后台运行,所以这可能是问题所在。 我该如何解决这个问题? 我如何关闭Mysql2本地主机服务器或导致此问题的服务器? 我在Windows 7 64位上运行。 Rails 3.0.9 SQLite3 1.3.4 谢谢。 注意:我可以迁移并丢弃。 编辑: 配置/ database.yml的 # SQLite version 3.x # gem install sqlite3 development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: […]

有关从mysql源填充sqlite数据库的ruby解决方案的任何建议

我有一个使用MySQL的Rails应用程序。 应用程序需要填充sqlite数据库,以便从主mysql数据库分发到客户端应用程序。 sqlite数据库的模式与mysql数据库非常相似,但不完全相同。 将使用存储在主mysql数据库中的模式子集和数据来填充sqlite数据库。 数据子集将由http请求中传递的参数确定。 这不是作为维护操作,而是作为sqlite db将mysql数据库的子集交付给客户端应用程序。 我正在考虑尝试修改点击或使用续集来编写金属应用程序以连接到两个数据库以传输数据。 任何其他建议将不胜感激?

为什么ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:near“)”:语法错误:INSERT INTO“user_friendships”()VALUES()

为什么ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:near“)”:语法错误:INSERT INTO“user_friendships”()VALUES() 试图测试时: $ ruby​​ -I test test / unit / user_friendships_test.rb require ‘test_helper’ class UserFriendshipsTest < ActiveSupport::TestCase should belong_to (:user) should belong_to (:friend) test "that creating a frinedship works without raising an exception" do assert_nothing_raised do UserFriendship.create user: users(:a), friend: friends(:b) end end end 任何的想法? 更新:他是Schema.rb的一部分 create_table “user_friendships”, :force => […]

返回sqlite3 gem的#execute和#query方法的值

我在sqlite3 gem的帮助下使用ruby中的sqlite3数据库(我试图更好地理解使用sqlite3 gem而不使用ActiveRecords)。 我有一个SQL查询如下: SELECT id FROM contacts WHERE first_name = ‘Charles’ 从中我期望它返回值’5′ 执行 $db.execute(‘SELECT id FROM contacts WHERE first_name = ?’, ‘Charles’) do |result| puts result end 上面将打印’5’,但会返回一个sqlite3对象。 我似乎无法让execute方法返回值’5’。 询问 $db.query(‘SELECT id FROM contacts WHERE first_name = ?’, ‘Charles’) do |result| result.first.first end 我能得到的最接近的是使用query方法返回值’5’(上图),但这需要.first.first ,这似乎是错综复杂的。 有没有更好的方法让我获得我需要的价值? 即也许通过访问sqlite3对象?

如何在iframe中显示网站

我正在使用ruby和sinatra。 我需要创建一个网站,允许用户上传其他网站的zipfile,并在页面上的多个iframe中显示所有网站,但我不知道如何开始这个。 到目前为止,我已经建立了可以上传zip文件并将其放在上传文件夹中的网站,我可以通过这样做在网站上显示 Your browser does not support iframes. post ‘/upload’ do File.open(‘uploads/’ + params[‘file’][:filename], ‘w’) do |f| f.write(params[‘file’][:tempfile].read) end end 问题是我不一定知道html文件的名称,或者只是放置它的名称有多少

无法安装sqlite3 gem

我正在尝试运行bundle命令来安装todo应用程序的所有gem。 所有gem下载没有问题,但sqlite3gem没有。 我不知道以下哪些方法可以解释一下发生了什么以及如何解决? 使用本机扩展安装sqlite3 1.3.8 Gem :: Ext :: BuildError:错误:无法构建gem原生扩展。 /Users/tomfinet/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151208- 2023-1esrcfp.rb extconf.rb checking for sqlite3.h… yes checking for sqlite3_libversion_number() in -lsqlite3… yes checking for rb_proc_arity()… yes checking for sqlite3_initialize()… yes checking for sqlite3_backup_init()… yes checking for sqlite3_column_database_name()… no checking for sqlite3_enable_load_extension()… no checking for sqlite3_load_extension()… no checking for sqlite3_open_v2()… yes checking for […]

Fresh rails app默认为Postgres而不是SQLite3

我刚刚在这台机器上安装了rbenv,ruby 2.2.3和rails 4.2.4。 我已经启动了我的rails应用程序而没有更改任何代码,只使用rails new .的默认生成文档rails new . 然后我用rails server启动了rails server 。 当命中http://localhost:3000我收到以下错误: “为数据库适配器指定’postgresql’,但未加载gem ‘pg’ 。将gem’pg gem ‘pg’添加到您的Gemfile中(并确保其版本达到ActiveRecord所需的最小值)。” 我从之前的Node项目中安装了postgres,但是我的database.yml仍然按照你对新应用程序的期望进行读取: # SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem ‘sqlite3’ # default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: […]