Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Sqlite3, AR and Quoting issue

#2387

this concerns AR 2.2.2 and likely 2.3.

I have noticed that if I create using a migration a table like the following: (note that the name or type does not seem to matter for the timestamp)

create_table :mytable do |t| t.integer id t.date timestamp1 t.string timestamp2 end

When I use a model like

class Mytable < ActiveRecord::Base end

The following code causes to save the date in YAML for timestamp.. m = Mytable.new(:timestamp1 => "2009-03-31 11:13:24", :timestamp2 => "2009-03-31 11:13:24") m.save

when looking in the database, both of the fields looks like --- \n - 2009-03-31 11:13:24 \n

which now makes querying against timestamp impossible... I think this is a bug. If not, then it needs to be documented or have a way to change the behavior...

The problem is in the connection_adapters/abstract/quoting.rb, in the quote method

Reported by manu · March 31st, 2009 @ 11:30 PM

State: invalid
Milestone: 2.x
Assigned to: DHH DHH
Importance: none

Activity

  1. qoobaa
    qoobaa

    Migration:

    
    class CreateMyModels < ActiveRecord::Migration
      def self.up
        create_table :my_models do |t|
          t.string :first_timestamp
          t.date :second_timestamp
          t.datetime :third_timestamp
    
          t.timestamps
        end
      end
    end
    

    Model:

    
    class MyModel < ActiveRecord::Base
    end
    

    Creating:

    
    MyModel.create(:first_timestamp => "2009-05-06 20:38:00", :second_timestamp => "2009-05-06 20:38:00", :third_timestamp => "2009-05-06 20:38:00")
    

    Let's see database:

    
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> .d
    BEGIN TRANSACTION;
    CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
    INSERT INTO "schema_migrations" VALUES('20090506183730');
    CREATE TABLE "my_models" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_timestamp" varchar(255), "second_timestamp" date, "third_timestamp" datetime, "created_at" datetime, "updated_at" datetime);
    INSERT INTO "my_models" VALUES(1,'2009-05-06 20:38:00','2009-05-06','2009-05-06 20:38:00','2009-05-06 18:38:51','2009-05-06 18:38:51');
    DELETE FROM sqlite_sequence;
    INSERT INTO "sqlite_sequence" VALUES('my_models',1);
    CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
    COMMIT;
    sqlite> select * from my_models;
    1|2009-05-06 20:38:00|2009-05-06|2009-05-06 20:38:00|2009-05-06 18:38:51|2009-05-06 18:38:51
    
    
    About your application's environment
    Ruby version              1.9.1 (x86_64-linux)
    RubyGems version          1.3.3
    Rack version              1.0 bundled
    Rails version             2.3.2
    Active Record version     2.3.2
    Action Pack version       2.3.2
    Active Resource version   2.3.2
    Action Mailer version     2.3.2
    Active Support version    2.3.2
    Environment               development
    Database adapter          sqlite3
    

    Everything works perfectly using sqlite3-ruby (1.2.4).

    May 6th, 2009 @ 07:50 PM

  2. Prem Sichanugrist (sikachu)