This project is archived and is in readonly mode.

#2387 ✓invalid
manu

Sqlite3, AR and Quoting issue

Reported by manu | March 31st, 2009 @ 11:30 PM | in 2.x

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

Comments and changes to this ticket

  • qoobaa

    qoobaa May 6th, 2009 @ 07:50 PM

    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).

  • Prem Sichanugrist (sikachu)

    Prem Sichanugrist (sikachu) January 20th, 2010 @ 05:58 PM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages