SQLite is a lightweight SQL-compliant database. The download is about 244kb (command-line client + DLL). SQLite implements most of the SQL92 and needs no configuration. SQLite is a client-only solution that does not require a separate server process. For best results, use SQLite 3.3.7. Later versions (3.3.8) introduce an incompatibility, see here Step 1 – Install SQLiteWindowsTo use SQLite for windows you need two files:
These can be downloaded as precompiled binaries at SQLite’s homepage Once you’ve unzipped your downloads, copy the three files to your Ruby bin directory (typically C:\ruby\bin). Add Watch this screencast for a step-by-step demonstration. UnixMost package managers put an sqlite or sqlite3 binary in your path. If you have not built from source install the sqlite3-dev package as well. It might be called libsqlite3-dev on your system. If you need to store UTF-8 data in your database make sure to supply—enable-utf8 to the ./configure script” Mac OS X (up till version 10.3.9)with DarwinPorts
Mac OS X 10.4 (aka Tiger) and beyondsqlite3 is part of Mac OS X 10.4. Its path is ’/usr/bin/sqlite3’. You do not need to install it. Note: this version of SQLite doesn’t support the “drop table if exists foo;” syntax, but this is only a minor problem. Step 2 – Get the sqlite ruby gemUse gem to install sqlite for Ruby. Windows
Select option 2. When using SQLite 3:
Select option 1. UNIX and Mac OS XNote: SWIG used to be required for the sqlite3-ruby gem, however as of version 1.20.0 it is no longer required Install the gem as follows:
Unless you get this (because you typed sqlite3 instead of sqlite3-ruby):
You will see the following:
Choose the highest-numbered “(ruby)” version, in this case option 1. Also if this fails make sure you have the Ruby dev package as ‘mkmf’ is needed from it. Creating a databaseSQLite stores databases in files. To create a new database, run the Windows
Unix and Mac OS XIn a UNIX system, and provided that you have a file consisting of the SQL creation statements for this database (for example from an application you are deploying), you can shortcut the creation operation:
Configure database.yml to use sqliteSQLite does not use authentication and needs only a pointer to the database file.
Please note: If you are using SQLite3 use “sqlite3” instead of “sqlite” for the value of the And you are done! Possible GotchasQ: I get errors when trying to install the gem… sudo gem install sqlite Attempting local installation of ‘sqlite‘ Local gem file not found: sqlite*.gem Attempting remote installation of ‘sqlite‘ Building native extensions. This could take a while... ERROR: While executing gem ... (RuntimeError) ERROR: Failed to build gem native extension. Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite-2.0.1 for inspection. ruby extconf.rb install sqlite checking for main() in -lsqlite... no checking for sqlite.h... noAny clues? I did install swig as well as sqlite via DarwinPorts already, which puts stuff in /opt/...
I had the same problem. Use A: There are several possible reasons; if you don’t have Xcode installed the ruby.h header file won’t be found. If you have Xcode 2.2 on Tiger 10.4.3 you’ll find the ruby.h header file has moved from /usr/lib/ruby/1.8/powerpc-darwin8.0/ruby.h to /usr/lib/ruby/1.8/universal-darwin8.0/ruby.h. As a result it isn’t being found by gem. Some people have found symlinks fix the problem, but many readers of comp.lang.ruby advocate installing ruby from source as the install of ruby that comes with Tiger is deemed to be slightly broken. —GrahamAshton In Linux (SUSE 10), install ruby-devel (to get ruby.h) if not installed—Alberto B: I had two versions of Ruby installed via DarwinPorts. Unfortunately rb-rubygems was linked to the older (1.8.2) one. My solution was to uninstall ruby (1.8.2 and 1.8.4) and rb-rubygems and reinstall them after swig. —Michael I got the exact same error, but it turned out that Ubuntu Breezy doesn’t install gcc by default, a quick
I have also received the same error (Ubuntu Breezy), but it was because the sqlite3.h was missing. You need libsqlite3-dev:
Q: I am experiencing strange database errors on Linux/Unix
A: On Mac OS X 10.4 Tiger, try uninstalling the gem ( Q: Windows version gives an error message like “Application failed to start because A: Make sure the Q: SQLite::Exceptions::\DatabaseException file is encrypted or is not a database. A: It seems that sqlite databases created with version 2 do not work with sqlite version 3 and vice versa. Q: SQLite returns “0.0” for values from database views. A: Looks like Rails thinks the field is a float? You can put numbers in the fields, but strings show up as 0.0. Try adding the field specifier (ex. TEXT) in the database definition. Q: Using SQLite in Rails terminates the webrick server by throwing segfaults such as “deadlock 0xb781a95c: run:-/usr/lib/ruby/1.8/drb/drb.rb:932: [BUG] Segmentation fault”. Any hints? A: This is likely to be a problem with sqlite-ruby. Maybe you didn’t install it properly. See the question above about strange database errors. On Mac OS X 10.4 Tiger, try uninstalling the gem ( Q: It seems is that ActiveRecord’s save method doesn’t set the id of the inserted row after saving the record to a SQLite database. Is this an issue with SQLite or with ActiveRecord? A: Make sure you have swig installed before installing sqlite3-ruby! See the question immediately above this one for instructions. I’ve had the exact problem and installing swig then re-install sqlite3-ruby did fix it. One note: I believe sqlite3-ruby is the preferred module ( Q: I am using Migrations and am having the same issue. ActiveRecord doesn’t set the id after a save. Checking the database schema, I have: “id” INTEGER PRIMARY KEY NOT NULL. Any suggestions? Q: Same here – I’m using migrations to create a table and the id is not set after an insert. Migrations is creating the id column as INTEGER PRIMARY KEY NOT NULL. Is there a workaround? A: The “id” field should be INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL - the database will then set it automagically. This is probably what ActiveRecord is expecting. See also SQLite create table and SQLite autoincrement Q: WEBrick is complaining about ”\ArgumentError: No database file specified. Missing argument: dbfile” A: sqlite3 uses the parameter “dbfile:” in place of “database:”, which is easy to visually gloss over when editing a database.yml that is preconfigured for MySQL. Q: Does ActiveRecord::Migration support SQLite? A: Migrations appear to work fine with SQLite in Rails 0.14.0 and later. SQLite migrations are not supported in prior versions of Rails. Q: I am a newbie so excuse this question. Do I have to use the gem version of Ruby-Sqlite, or will a non-gem installed ruby-sqlite work too? (I am on _nix) A: On Ubuntu Here’s what worked for me: sudo apt-get install libsqlite3-0 sqlite3 swig libsqlite3-ruby
Pre Ubuntu 6.06LTS: sudo apt-get install libsqlite3-0 libsqlite3-dev sqlite3 swig sudo gem install sqlite3-ruby # Select the highest Ruby version (ususally 1.) If you don’t install the libsqlite3-dev package, then you won’t have the header files you need to compile the native extension when you install the Rubygem.
Hope that helps. Debian sid To install Ruby on Rails in Debian sid do: apt-get install rails sqlite3 sqlite3-ruby Note: you’ll probably need to add libsqlite3 and libsqlite3-dev to that—Phillip You need to use sqlite3 as adapter in config/database.yml file. If you get other weird errors, perhaps you are using MySQL syntax (instead of “standard” SQL) for creating the tables. The example in this page worked for me on Rails. – Max Example of weird error: SQLite3::SQLException: SQL logic error or missing database: INSERT INTO An alternative possible solution to this kind of error is to check the ownership of your database file, it appears that at least sometimes (i.e. rails 1.1 sqlite 3.2.8) that the writing process (i.e. apache/webbrick) must own the database file (i.e. write permission is not sufficient) I suppose this has something to do with locking – occ Q: Please excuse my newbie question ! My yaml.rb returns argument error for “adapter: sqlite3”. I have both sqlite3 and sqlite installed. And the database.yml is configured as: development:adapter: sqlite3 dbfile: db/temp.db A: I had similar problems with yaml – it turned out to be a tab in the file, make sure you only have spaces and no tabs Q: I’m getting deadlocks and application error exceptions when using SQLite. How can I fix this? Q: I’m getting this error: “libsqlite3.so: cannot open shared object file: No such file or directory” A: On our Fedora server, we resolved that error by doing > sudo yum install ruby-sqlite3 Apparently it wasn’t enough just to have this package installed (it had already been installed): sqlite.i386 3.3.3-1.2
|
|
来自: 昵称34752 > 《ruby,rails》