Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1418: 1455.patch

File 1455.patch, 55.4 kB (added by wishdev@gmail.com, 3 years ago)

Update to rev 1455 - Small change to add created_at and updated_at to the developers definition

  • test/deprecated_associations_test.rb

    old new  
    311311  end 
    312312 
    313313  def test_has_many_find_all 
    314     assert_equal 2, Firm.find_first.find_all_in_clients("type = 'Client'").length 
     314    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     315        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     316      assert_equal 2, Firm.find_first.find_all_in_clients("\"TYPE\" = 'Client'").length 
     317    else 
     318      assert_equal 2, Firm.find_first.find_all_in_clients("type = 'Client'").length 
     319    end 
    315320    assert_equal 1, Firm.find_first.find_all_in_clients("name = 'Summit'").length 
    316321  end 
    317322 
  • test/connections/native_firebird/connection.rb

    old new  
     1print "Using native Firebird\n" 
     2require 'fixtures/course' 
     3require 'logger' 
     4 
     5ActiveRecord::Base.logger = Logger.new("debug.log") 
     6 
     7db1 = '/db/activerecord_unittest.fdb' 
     8db2 = '/db/activerecord_unittest2.fdb' 
     9 
     10ActiveRecord::Base.establish_connection( 
     11  :adapter  => "firebird", 
     12  :host     => "localhost",  
     13  :username => "", 
     14  :password => "", 
     15  :database => db1 
     16) 
     17 
     18Course.establish_connection( 
     19  :adapter  => "firebird", 
     20  :host     => "localhost",  
     21  :username => "", 
     22  :password => "",  
     23  :database => db2 
     24) 
  • test/aaa_create_tables_test.rb

    old new  
    1212   
    1313  def each_statement() 
    1414    statement = '' 
    15     each_line { |line| 
    16       #The last character of each line is a line-feed, so we will check the next-to-last character 
    17       #to see if it is a semicolon.  A better way of doing this would be to look for a semicolon anywhere 
    18       #within the line in case multiple statements have been put on a single line. 
    19       #The last statement in the file must be followed by a line-feed. 
    20       if line.slice(-2,1)==';' then 
    21         statement = statement + line.slice(0,line.length-2) + "\n" 
    22         yield statement 
    23         statement = '' 
    24       else 
    25         statement = statement + line 
    26       end 
    27     } 
     15    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     16        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     17      term = ';' 
     18      termlen = 1 
     19      each_line { |line| 
     20        if line != "\n" 
     21          if line.slice(0, 8) == 'SET TERM' then 
     22            term = line.slice(8, line.length - 8).strip.slice(0..-2).slice(0..(-1 * termlen )) 
     23            termlen = term.length 
     24          else  
     25            if line.slice(-1 - termlen, termlen) == term then 
     26              statement = statement + line.slice(0,line.length - 1 - termlen) + "\n" 
     27              yield statement 
     28              statement = '' 
     29            else 
     30              statement = statement + line 
     31            end 
     32          end 
     33        end 
     34      } 
     35    else 
     36      each_line { |line| 
     37        #The last character of each line is a line-feed, so we will check the next-to-last character 
     38        #to see if it is a semicolon.  A better way of doing this would be to look for a semicolon anywhere 
     39        #within the line in case multiple statements have been put on a single line. 
     40        #The last statement in the file must be followed by a line-feed. 
     41        if line.slice(-2,1)==';' then 
     42          statement = statement + line.slice(0,line.length-2) + "\n" 
     43          yield statement 
     44          statement = '' 
     45        else 
     46          statement = statement + line 
     47        end 
     48      } 
     49    end 
    2850  end 
    2951end 
    3052 
     
    3658  def run_sql_file(connection, path) 
    3759    sql_file = SqlFile.new(path) 
    3860    sql_file.each_statement { |statement| 
    39     begin 
    40       #Skip errors.  If there is a problem creating the tables then it will show up in other tests. 
    41       connection.execute(statement) 
    42     rescue ActiveRecord::StatementInvalid 
    43     end } 
     61      begin 
     62        #Skip errors.  If there is a problem creating the tables then it will show up in other tests. 
     63        connection.execute(statement) 
     64        if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     65            ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     66          connection.commit_db_transaction() 
     67        end 
     68      rescue ActiveRecord::StatementInvalid 
     69      end 
     70    } 
    4471  end 
    4572 
    4673  def test_table_creation 
  • test/associations_test.rb

    old new  
    338338  def test_find_all 
    339339    firm = Firm.find_first 
    340340    assert_equal firm.clients, firm.clients.find_all 
    341     assert_equal 2, firm.clients.find(:all, :conditions => "type = 'Client'").length 
     341    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     342        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     343      assert_equal 2, firm.clients.find(:all, :conditions => "\"TYPE\" = 'Client'").length 
     344    else 
     345      assert_equal 2, firm.clients.find(:all, :conditions => "type = 'Client'").length 
     346    end 
    342347    assert_equal 1, firm.clients.find(:all, :conditions => "name = 'Summit'").length 
    343348  end 
    344349 
     
    354359    firm = Firm.find_first 
    355360    client2 = Client.find(2) 
    356361    assert_equal firm.clients.first, firm.clients.find_first 
    357     assert_equal client2, firm.clients.find_first("type = 'Client'") 
    358     assert_equal client2, firm.clients.find(:first, :conditions => "type = 'Client'") 
     362    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     363        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     364      assert_equal Client.find(2), firm.clients.find_first("\"TYPE\" = 'Client'") 
     365    else 
     366      assert_equal Client.find(2), firm.clients.find_first("type = 'Client'")  
     367    end 
    359368  end 
    360369 
    361370  def test_find_first_sanitized 
    362371    firm = Firm.find_first 
    363372    client2 = Client.find(2) 
    364     assert_equal client2, firm.clients.find_first(["type = ?", "Client"]) 
    365     assert_equal client2, firm.clients.find(:first, :conditions => ['type = ?', 'Client']) 
    366     assert_equal client2, firm.clients.find(:first, :conditions => ['type = :type', { :type => 'Client' }]) 
     373    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     374        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     375      assert_equal client2, firm.clients.find_first(["\"TYPE\" = ?", "Client"]) 
     376      assert_equal client2, firm.clients.find(:first, :conditions => ["\"TYPE\" = ?", 'Client']) 
     377      assert_equal client2, firm.clients.find(:first, :conditions => ["\"TYPE\" = :type", { :type => 'Client' }]) 
     378    else 
     379      assert_equal client2, firm.clients.find_first(["type = ?", "Client"]) 
     380      assert_equal client2, firm.clients.find(:first, :conditions => ['type = ?', 'Client']) 
     381      assert_equal client2, firm.clients.find(:first, :conditions => ['type = :type', { :type => 'Client' }]) 
     382    end 
    367383  end 
    368384 
    369385  def test_find_in_collection 
  • test/base_test.rb

    old new  
    817817  end 
    818818 
    819819  def test_count_with_join 
    820     res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.type = 'Post'" 
     820    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     821        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     822      res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id = comments.post_id WHERE posts.\"TYPE\" = 'Post'" 
     823    else 
     824      res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.type = 'Post'" 
     825    end 
    821826    res2 = res + 1 
    822827    assert_nothing_raised do 
    823       res2 = Post.count("posts.type = 'Post'", 
    824                         "LEFT JOIN comments ON posts.id=comments.post_id") 
     828      if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     829          ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     830        res2 = Post.count("posts.\"TYPE\" = 'Post'", "LEFT JOIN comments ON posts.id=comments.post_id") 
     831      else 
     832        res2 = Post.count("posts.type = 'Post'", "LEFT JOIN comments ON posts.id=comments.post_id") 
     833      end 
    825834    end 
    826835    assert_equal res, res2 
    827836  end 
  • test/binary_test.rb

    old new  
    1717    if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter 
    1818      return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter) 
    1919    end 
     20 
     21    if ActiveRecord::ConnectionAdapters.const_defined? :FirebirdAdapter 
     22      return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     23    end 
     24 
    2025    bin = Binary.new 
    2126    bin.data = @data 
    2227 
  • test/inheritance_test.rb

    old new  
    66  fixtures :companies, :projects 
    77 
    88  def test_a_bad_type_column 
    9     Company.connection.insert "INSERT INTO companies (id, type, name) VALUES(100, 'bad_class!', 'Not happening')" 
     9    if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     10        ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     11      Company.connection.insert "INSERT INTO companies (id, \"TYPE\", name) VALUES(100, 'bad_class!', 'Not happening')" 
     12    else 
     13      Company.connection.insert "INSERT INTO companies (id, type, name) VALUES(100, 'bad_class!', 'Not happening')" 
     14    end 
    1015    assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) } 
    1116  end 
    1217 
  • test/fixtures/db_definitions/firebird.sql

    old new  
     1CREATE DOMAIN BOOLEAN AS SMALLINT 
     2         default 0 
     3         check (value in (0,1)); 
     4CREATE DOMAIN SERIAL AS INTEGER NOT NULL; 
     5CREATE DOMAIN TEXT AS BLOB SUB_TYPE TEXT SEGMENT SIZE 80; 
     6 
     7CREATE GENERATOR GEN_ACCOUNTS_ID; 
     8CREATE GENERATOR GEN_AUTO_ID_TESTS_AUTO_ID; 
     9CREATE GENERATOR GEN_BINARIES_ID; 
     10CREATE GENERATOR GEN_BOOLEANTESTS_ID; 
     11CREATE GENERATOR GEN_COLNAMETESTS_ID; 
     12CREATE GENERATOR GEN_COMMENTS_ID; 
     13CREATE GENERATOR GEN_COMPANIES_ID; 
     14CREATE GENERATOR GEN_COMPUTERS_ID; 
     15CREATE GENERATOR GEN_CUSTOMERS_ID; 
     16CREATE GENERATOR GEN_DEVELOPERS_ID; 
     17CREATE GENERATOR GEN_ENTRANTS_ID; 
     18CREATE GENERATOR GEN_FK_TEST_HAS_FK_ID; 
     19CREATE GENERATOR GEN_FK_TEST_HAS_PK_ID; 
     20CREATE GENERATOR GEN_MIXINS_ID; 
     21CREATE GENERATOR GEN_MOVIES_MOVIEID; 
     22CREATE GENERATOR GEN_POSTS_ID; 
     23CREATE GENERATOR GEN_PROJECTS_ID; 
     24CREATE GENERATOR GEN_TASKS_ID; 
     25CREATE GENERATOR GEN_TOPICS_ID; 
     26 
     27CREATE TABLE ACCOUNTS (ID SERIAL, 
     28                FIRM_ID INTEGER, 
     29                CREDIT_LIMIT INTEGER, 
     30PRIMARY KEY (ID)); 
     31 
     32CREATE TABLE AUTO_ID_TESTS (AUTO_ID SERIAL, 
     33                "VALUE" INTEGER, 
     34PRIMARY KEY (AUTO_ID)); 
     35 
     36CREATE TABLE BINARIES (ID SERIAL, 
     37                DATA BLOB, 
     38PRIMARY KEY (ID)); 
     39 
     40CREATE TABLE BOOLEANTESTS (ID SERIAL, 
     41                "VALUE" BOOLEAN, 
     42PRIMARY KEY (ID)); 
     43 
     44CREATE TABLE COLNAMETESTS (ID SERIAL, 
     45                "REFERENCES" INTEGER NOT NULL, 
     46PRIMARY KEY (ID)); 
     47 
     48CREATE TABLE COMMENTS (ID SERIAL, 
     49                POST_ID INTEGER NOT NULL, 
     50                "TYPE" VARCHAR(255) NOT NULL, 
     51                BODY TEXT NOT NULL, 
     52PRIMARY KEY (ID)); 
     53 
     54CREATE TABLE COMPANIES (ID SERIAL, 
     55                "TYPE" VARCHAR(50), 
     56                RUBY_TYPE VARCHAR(50), 
     57                FIRM_ID INTEGER, 
     58                NAME VARCHAR(50) NOT NULL, 
     59                CLIENT_OF INTEGER, 
     60                RATING INTEGER DEFAULT 1, 
     61PRIMARY KEY (ID)); 
     62 
     63CREATE TABLE COMPUTERS (ID SERIAL, 
     64                DEVELOPER INTEGER NOT NULL, 
     65                EXTENDEDWARRANTY INTEGER NOT NULL, 
     66PRIMARY KEY (ID)); 
     67 
     68CREATE TABLE CUSTOMERS (ID SERIAL, 
     69                NAME VARCHAR(100), 
     70                BALANCE INTEGER DEFAULT 0, 
     71                ADDRESS_STREET VARCHAR(100), 
     72                ADDRESS_CITY VARCHAR(100), 
     73                ADDRESS_COUNTRY VARCHAR(100), 
     74                GPS_LOCATION VARCHAR(100), 
     75PRIMARY KEY (ID)); 
     76 
     77CREATE TABLE DEVELOPERS (ID SERIAL, 
     78                NAME VARCHAR(100), 
     79                SALARY INTEGER DEFAULT 70000, 
     80                CRTEATED_AT TIMESTAMP DEFAULT NULL, 
     81                UPDATED_AT TIMESTAMP DEFAULT NULL, 
     82PRIMARY KEY (ID)); 
     83 
     84CREATE TABLE DEVELOPERS_PROJECTS (DEVELOPER_ID INTEGER NOT NULL, 
     85                PROJECT_ID INTEGER NOT NULL, 
     86                JOINED_ON DATE); 
     87 
     88CREATE TABLE ENTRANTS (ID SERIAL, 
     89                NAME VARCHAR(255) NOT NULL, 
     90                COURSE_ID INTEGER NOT NULL, 
     91PRIMARY KEY (ID)); 
     92 
     93CREATE TABLE FK_TEST_HAS_FK (ID SERIAL, 
     94                FK_ID INTEGER NOT NULL, 
     95PRIMARY KEY (ID)); 
     96 
     97CREATE TABLE FK_TEST_HAS_PK (ID SERIAL, 
     98PRIMARY KEY (ID)); 
     99 
     100ALTER TABLE FK_TEST_HAS_FK ( 
     101FOREIGN KEY (FK_ID) REFERENCES FK_TEST_HAS_PK (ID)); 
     102 
     103CREATE TABLE MIXINS (ID SERIAL, 
     104                PARENT_ID INTEGER DEFAULT NULL, 
     105                POS INTEGER DEFAULT NULL, 
     106                CREATED_AT TIMESTAMP DEFAULT NULL, 
     107                UPDATED_AT TIMESTAMP DEFAULT NULL, 
     108                LFT INTEGER DEFAULT NULL, 
     109                RGT INTEGER DEFAULT NULL, 
     110                ROOT_ID INTEGER DEFAULT NULL, 
     111                "TYPE" VARCHAR(40) DEFAULT NULL, 
     112PRIMARY KEY (ID)); 
     113 
     114CREATE TABLE MOVIES (MOVIEID SERIAL, 
     115                NAME VARCHAR(100), 
     116PRIMARY KEY (MOVIEID)); 
     117 
     118CREATE TABLE PEOPLE (ID SERIAL, 
     119                FIRST_NAME VARCHAR(40) NOT NULL, 
     120                LOCK_VERSION INTEGER DEFAULT 0 NOT NULL, 
     121PRIMARY KEY (ID)); 
     122                 
     123CREATE TABLE POSTS (ID SERIAL, 
     124                AUTHOR_ID INTEGER, 
     125                TITLE VARCHAR(255) NOT NULL, 
     126                "TYPE" VARCHAR(255) NOT NULL, 
     127                BODY TEXT NOT NULL, 
     128PRIMARY KEY(ID)); 
     129 
     130CREATE TABLE PROJECTS (ID SERIAL, 
     131                NAME VARCHAR(100), 
     132PRIMARY KEY (ID)); 
     133 
     134CREATE TABLE SUBSCRIBERS (NICK VARCHAR(100) NOT NULL, 
     135                NAME VARCHAR(100), 
     136PRIMARY KEY (NICK)); 
     137 
     138CREATE TABLE TASKS (ID SERIAL, 
     139                "STARTING" TIMESTAMP DEFAULT NULL, 
     140                "ENDING" TIMESTAMP DEFAULT NULL, 
     141PRIMARY KEY (ID)); 
     142 
     143CREATE TABLE TOPICS (ID SERIAL, 
     144                TITLE VARCHAR(255) DEFAULT NULL, 
     145                AUTHOR_NAME VARCHAR(255) DEFAULT NULL, 
     146                AUTHOR_EMAIL_ADDRESS VARCHAR(255) DEFAULT NULL, 
     147                WRITTEN_ON TIMESTAMP DEFAULT NULL, 
     148                BONUS_TIME TIME DEFAULT NULL, 
     149                LAST_READ DATE DEFAULT NULL, 
     150                CONTENT TEXT, 
     151                APPROVED SMALLINT DEFAULT 1, 
     152                REPLIES_COUNT INTEGER default 0, 
     153                PARENT_ID INTEGER DEFAULT NULL, 
     154                "TYPE" VARCHAR(50) DEFAULT NULL, 
     155PRIMARY KEY (ID)); 
     156 
     157SET TERM !!; 
     158CREATE TRIGGER ACCOUNTS_INSERT FOR ACCOUNTS  
     159ACTIVE BEFORE INSERT POSITION 0  
     160as 
     161DECLARE VARIABLE curval INTEGER; 
     162begin 
     163  if (new.id is null) then 
     164    new.id = gen_id(gen_accounts_id, 1); 
     165  else 
     166    curval = gen_id(gen_accounts_id, 0); 
     167    begin 
     168      if (new.id > curval) then 
     169        curval = gen_id(gen_accounts_id, new.id - curval); 
     170    end 
     171end!! 
     172 
     173CREATE TRIGGER AUTO_ID_TESTS_INSERT FOR AUTO_ID_TESTS  
     174ACTIVE BEFORE INSERT POSITION 0  
     175as 
     176DECLARE VARIABLE curval INTEGER; 
     177begin 
     178  if (new.auto_id is null) then 
     179    new.auto_id = gen_id(gen_auto_id_tests_auto_id, 1); 
     180  else 
     181    curval = gen_id(gen_auto_id_tests_auto_id, 0); 
     182    begin 
     183      if (new.auto_id > curval) then 
     184        curval = gen_id(gen_auto_id_tests_auto_id, new.auto_id - curval); 
     185    end 
     186end!! 
     187  
     188CREATE TRIGGER BINARIES_INSERT FOR BINARIES 
     189ACTIVE BEFORE INSERT POSITION 0  
     190as 
     191DECLARE VARIABLE curval INTEGER; 
     192begin 
     193  if (new.id is null) then 
     194    new.id = gen_id(gen_binaries_id, 1); 
     195  else 
     196    curval = gen_id(gen_binaries_id, 0); 
     197    begin 
     198      if (new.id > curval) then 
     199        curval = gen_id(gen_binaries_id, new.id - curval); 
     200    end 
     201end!! 
     202  
     203CREATE TRIGGER BOOLEANTESTS_INSERT FOR BOOLEANTESTS  
     204ACTIVE BEFORE INSERT POSITION 0  
     205as 
     206DECLARE VARIABLE curval INTEGER; 
     207begin 
     208  if (new.id is null) then 
     209    new.id = gen_id(gen_booleantests_id, 1); 
     210  else 
     211    curval = gen_id(gen_booleantests_id, 0); 
     212    begin 
     213      if (new.id > curval) then 
     214        curval = gen_id(gen_booleantests_id, new.id - curval); 
     215    end 
     216end!! 
     217  
     218CREATE TRIGGER COLNAMETESTS_INSERT FOR COLNAMETESTS  
     219ACTIVE BEFORE INSERT POSITION 0  
     220as 
     221DECLARE VARIABLE curval INTEGER; 
     222begin 
     223  if (new.id is null) then 
     224    new.id = gen_id(gen_colnametests_id, 1); 
     225  else 
     226    curval = gen_id(gen_colnametests_id, 0); 
     227    begin 
     228      if (new.id > curval) then 
     229        curval = gen_id(gen_colnametests_id, new.id - curval); 
     230    end 
     231end!! 
     232  
     233CREATE TRIGGER COMMENTS_INSERT FOR COMMENTS  
     234ACTIVE BEFORE INSERT POSITION 0  
     235as 
     236DECLARE VARIABLE curval INTEGER; 
     237begin 
     238  if (new.id is null) then 
     239    new.id = gen_id(gen_comments_id, 1); 
     240  else 
     241    curval = gen_id(gen_comments_id, 0); 
     242    begin 
     243      if (new.id > curval) then 
     244        curval = gen_id(gen_comments_id, new.id - curval); 
     245    end 
     246end!! 
     247  
     248CREATE TRIGGER COMPANIES_INSERT FOR COMPANIES  
     249ACTIVE BEFORE INSERT POSITION 0  
     250as 
     251DECLARE VARIABLE curval INTEGER; 
     252begin 
     253  if (new.id is null) then 
     254    new.id = gen_id(gen_companies_id, 1); 
     255  else 
     256    curval = gen_id(gen_companies_id, 0); 
     257    begin 
     258      if (new.id > curval) then 
     259        curval = gen_id(gen_companies_id, new.id - curval); 
     260    end 
     261end!! 
     262  
     263CREATE TRIGGER COMPUTERS_INSERT FOR COMPUTERS  
     264ACTIVE BEFORE INSERT POSITION 0  
     265as 
     266DECLARE VARIABLE curval INTEGER; 
     267begin 
     268  if (new.id is null) then 
     269    new.id = gen_id(gen_computers_id, 1); 
     270  else 
     271    curval = gen_id(gen_computers_id, 0); 
     272    begin 
     273      if (new.id > curval) then 
     274        curval = gen_id(gen_computers_id, new.id - curval); 
     275    end 
     276end!! 
     277  
     278CREATE TRIGGER CUSTOMERS_INSERT FOR CUSTOMERS 
     279ACTIVE BEFORE INSERT POSITION 0  
     280as 
     281DECLARE VARIABLE curval INTEGER; 
     282begin 
     283  if (new.id is null) then 
     284    new.id = gen_id(gen_customers_id, 1); 
     285  else 
     286    curval = gen_id(gen_customers_id, 0); 
     287    begin 
     288      if (new.id > curval) then 
     289        curval = gen_id(gen_customers_id, new.id - curval); 
     290    end 
     291end!! 
     292  
     293CREATE TRIGGER DEVELOPERS_INSERT FOR DEVELOPERS 
     294ACTIVE BEFORE INSERT POSITION 0  
     295as 
     296DECLARE VARIABLE curval INTEGER; 
     297begin 
     298  if (new.id is null) then 
     299    new.id = gen_id(gen_developers_id, 1); 
     300  else 
     301      curval = gen_id(gen_developers_id, 0); 
     302    begin 
     303      if (new.id > curval) then 
     304        curval = gen_id(gen_developers_id, new.id - curval); 
     305    end 
     306end!! 
     307  
     308CREATE TRIGGER ENTRANTS_INSERT FOR ENTRANTS 
     309ACTIVE BEFORE INSERT POSITION 0  
     310as 
     311DECLARE VARIABLE curval INTEGER; 
     312begin 
     313  if (new.id is null) then 
     314    new.id = gen_id(gen_entrants_id, 1); 
     315  else 
     316      curval = gen_id(gen_entrants_id, 0); 
     317    begin 
     318      if (new.id > curval) then 
     319        curval = gen_id(gen_entrants_id, new.id - curval); 
     320    end 
     321end!! 
     322  
     323CREATE TRIGGER FK_TEST_HAS_FK_INSERT FOR FK_TEST_HAS_FK 
     324ACTIVE BEFORE INSERT POSITION 0  
     325as 
     326DECLARE VARIABLE curval INTEGER; 
     327begin 
     328  if (new.id is null) then 
     329    new.id = gen_id(gen_fk_test_has_fk_id, 1); 
     330  else 
     331      curval = gen_id(gen_fk_test_has_fk_id, 0); 
     332    begin 
     333      if (new.id > curval) then 
     334        curval = gen_id(gen_fk_test_has_fk_id, new.id - curval); 
     335    end 
     336end!! 
     337 
     338CREATE TRIGGER FK_TEST_HAS_PK_INSERT FOR FK_TEST_HAS_PK 
     339ACTIVE BEFORE INSERT POSITION 0  
     340as 
     341DECLARE VARIABLE curval INTEGER; 
     342begin 
     343  if (new.id is null) then 
     344    new.id = gen_id(gen_fk_test_has_pk_id, 1); 
     345  else 
     346      curval = gen_id(gen_fk_test_has_pk_id, 0); 
     347    begin 
     348      if (new.id > curval) then 
     349        curval = gen_id(gen_fk_test_has_pk_id, new.id - curval); 
     350    end 
     351end!! 
     352  
     353CREATE TRIGGER MIXINS_INSERT FOR MIXINS 
     354ACTIVE BEFORE INSERT POSITION 0  
     355as 
     356DECLARE VARIABLE curval INTEGER; 
     357begin 
     358  if (new.id is null) then 
     359    new.id = gen_id(gen_mixins_id, 1); 
     360  else 
     361      curval = gen_id(gen_mixins_id, 0); 
     362    begin 
     363      if (new.id > curval) then 
     364        curval = gen_id(gen_mixins_id, new.id - curval); 
     365    end 
     366end!! 
     367  
     368CREATE TRIGGER MOVIES_INSERT FOR MOVIES 
     369ACTIVE BEFORE INSERT POSITION 0  
     370as 
     371DECLARE VARIABLE curval INTEGER; 
     372begin 
     373  if (new.id is null) then 
     374    new.id = gen_id(gen_movies_movieid, 1); 
     375  else 
     376      curval = gen_id(gen_movies_movieid, 0); 
     377    begin 
     378      if (new.id > curval) then 
     379        curval = gen_id(gen_movies_movieid, new.id - curval); 
     380    end 
     381end!! 
     382  
     383CREATE TRIGGER PEOPLE_INSERT FOR PEOPLE 
     384ACTIVE BEFORE INSERT POSITION 0  
     385as 
     386DECLARE VARIABLE curval INTEGER; 
     387begin 
     388  if (new.id is null) then 
     389    new.id = gen_id(gen_people_id, 1); 
     390  else 
     391      curval = gen_id(gen_people_id, 0); 
     392    begin 
     393      if (new.id > curval) then 
     394        curval = gen_id(gen_people_id, new.id - curval); 
     395    end 
     396end!! 
     397  
     398CREATE TRIGGER POSTS_INSERT FOR POSTS 
     399ACTIVE BEFORE INSERT POSITION 0  
     400as 
     401DECLARE VARIABLE curval INTEGER; 
     402begin 
     403  if (new.id is null) then 
     404    new.id = gen_id(gen_posts_id, 1); 
     405  else 
     406      curval = gen_id(gen_posts_id, 0); 
     407    begin 
     408      if (new.id > curval) then 
     409        curval = gen_id(gen_posts_id, new.id - curval); 
     410    end 
     411end!! 
     412  
     413CREATE TRIGGER PROJECTS_INSERT FOR PROJECTS  
     414ACTIVE BEFORE INSERT POSITION 0  
     415as 
     416DECLARE VARIABLE curval INTEGER; 
     417begin 
     418  if (new.id is null) then 
     419    new.id = gen_id(gen_projects_id, 1); 
     420  else 
     421    curval = gen_id(gen_projects_id, 0); 
     422    begin 
     423      if (new.id > curval) then 
     424        curval = gen_id(gen_projects_id, new.id - curval); 
     425    end 
     426end!! 
     427  
     428CREATE TRIGGER TASKS_INSERT FOR TASKS  
     429ACTIVE BEFORE INSERT POSITION 0  
     430as 
     431DECLARE VARIABLE curval INTEGER; 
     432begin 
     433  if (new.id is null) then 
     434    new.id = gen_id(gen_tasks_id, 1); 
     435  else 
     436    curval = gen_id(gen_tasks_id, 0); 
     437    begin 
     438      if (new.id > curval) then 
     439        curval = gen_id(gen_tasks_id, new.id - curval); 
     440    end 
     441end!! 
     442  
     443CREATE TRIGGER TOPICS_INSERT FOR TOPICS  
     444ACTIVE BEFORE INSERT POSITION 0  
     445as 
     446DECLARE VARIABLE curval INTEGER; 
     447begin 
     448  if (new.id is null) then 
     449    new.id = gen_id(gen_topics_id, 1); 
     450  else 
     451    curval = gen_id(gen_topics_id, 0); 
     452    begin 
     453      if (new.id > curval) then 
     454        curval = gen_id(gen_topics_id, new.id - curval); 
     455    end 
     456end!! 
     457  
     458COMMIT!! 
     459SET TERM ;!! 
  • test/fixtures/db_definitions/firebird.drop.sql

    old new  
     1DROP TABLE accounts; 
     2DROP TABLE auto_id_tests; 
     3DROP TABLE binaries; 
     4DROP TABLE booleantests; 
     5DROP TABLE colnametests; 
     6DROP TABLE comments; 
     7DROP TABLE companies; 
     8DROP TABLE computers; 
     9DROP TABLE customers; 
     10DROP TABLE developers; 
     11DROP TABLE developers_projects; 
     12DROP TABLE entrants; 
     13DROP TABLE fk_test_has_fk_id; 
     14DROP TABLE fk_test_has_pk_id; 
     15DROP TABLE mixins; 
     16DROP TABLE movies; 
     17DROP TABLE people; 
     18DROP TABLE posts; 
     19DROP TABLE projects; 
     20DROP TABLE subscribers; 
     21DROP TABLE tasks; 
     22DROP TABLE topics; 
     23 
     24DROP GENERATOR GEN_ACCOUNTS_ID; 
     25DROP GENERATOR GEN_AUTO_ID_TESTS_AUTO_ID; 
     26DROP GENERATOR GEN_BINARIES_ID; 
     27DROP GENERATOR GEN_BOOLEANTESTS_ID; 
     28DROP GENERATOR GEN_COLNAMETESTS_ID; 
     29DROP GENERATOR GEN_COMMENTS_ID; 
     30DROP GENERATOR GEN_COMPANIES_ID; 
     31DROP GENERATOR GEN_COMPUTERS_ID; 
     32DROP GENERATOR GEN_CUSTOMERS_ID; 
     33DROP GENERATOR GEN_DEVELOPERS_ID; 
     34DROP GENERATOR GEN_ENTRANTS_ID; 
     35DROP GENERATOR GEN_MIXINS_ID; 
     36DROP GENERATOR GEN_MOVIES_MOVIEID; 
     37DROP GENERATOR GEN_POSTS_ID; 
     38DROP GENERATOR GEN_PROJECTS_ID; 
     39DROP GENERATOR GEN_TOPICS_ID; 
     40 
  • test/fixtures/db_definitions/firebird2.sql

    old new  
     1CREATE DOMAIN BOOLEAN AS SMALLINT 
     2         default 0 
     3         check (value in (0,1)); 
     4CREATE DOMAIN SERIAL AS INTEGER NOT NULL; 
     5CREATE DOMAIN TEXT AS BLOB SUB_TYPE TEXT SEGMENT SIZE 80; 
     6 
     7CREATE GENERATOR GEN_COURSES_ID; 
     8 
     9CREATE TABLE COURSES (ID SERIAL, 
     10                NAME VARCHAR(255), 
     11PRIMARY KEY (ID)); 
     12 
     13SET TERM !!; 
     14CREATE TRIGGER COURSES_INSERT FOR COURSES 
     15ACTIVE BEFORE INSERT POSITION 0  
     16as 
     17DECLARE VARIABLE curval INTEGER; 
     18begin 
     19  if (new.id is null) then 
     20    new.id = gen_id(gen_courses_id, 1); 
     21  else 
     22    curval = gen_id(gen_courses_id, 0); 
     23    begin 
     24      if (new.id > curval) then 
     25        curval = gen_id(gen_courses_id, new.id - curval); 
     26    end 
     27end!! 
     28 
     29COMMIT!! 
     30SET TERM ;!! 
  • test/fixtures/db_definitions/firebird2.drop.sql

    old new  
     1DROP TABLE courses; 
     2 
     3DROP GENERATOR GEN_COURSES_ID; 
     4 
  • test/fixtures/company.rb

    old new  
    66 
    77 
    88class Firm < Company 
    9   has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 AND (type = 'Client' OR type = 'SpecialClient' OR type = 'VerySpecialClient' )" 
     9  if ActiveRecord::ConnectionAdapters.const_defined?(:FirebirdAdapter) && 
     10      ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 
     11    has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE \"FIRM_ID\" = 1 AND (\"TYPE\" = 'Client' OR \"TYPE\" = 'SpecialClient' OR \"TYPE\" = 'VerySpecialClient' )" 
     12  else 
     13    has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 AND (type = 'Client' OR type = 'SpecialClient' OR type = 'VerySpecialClient' )" 
     14  end 
    1015  has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" 
    1116  has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" 
    1217  has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" 
  • Rakefile

    old new  
    2222 
    2323 
    2424desc "Default Task" 
    25 task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_sqlite3, :test_postgresql
     25task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_sqlite3, :test_postgresql, :test_firebird
    2626 
    2727# Run the unit tests 
    2828 
     
    3838  t.verbose = true 
    3939} 
    4040 
    41 for adapter in %w( postgresql sqlite sqlite3 sqlserver db2 oci
     41for adapter in %w( postgresql sqlite sqlite3 sqlserver db2 oci firebird
    4242  Rake::TestTask.new("test_#{adapter}") { |t| 
    4343    t.libs << "test" << "test/connections/native_#{adapter}" 
    4444    t.pattern = "test/*_test{,_#{adapter}}.rb" 
  • lib/active_record/validations.rb

    old new  
    469469 
    470470        if scope = configuration[:scope] 
    471471          validates_each(attr_names,configuration) do |record, attr_name, value| 
    472             record.errors.add(attr_name, configuration[:message]) if record.class.find_first(record.new_record? ? ["#{attr_name} = ? AND #{scope} = ?", record.send(attr_name), record.send(scope)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ? AND #{scope} = ?", record.send(attr_name), record.send(:id), record.send(scope)]) 
    473           end 
     472              if record.class.find_first(record.new_record? ?  
     473                                         ["#{attr_name} " + 
     474                                           (record.send(attr_name).nil? ? "IS" : "=") + 
     475                                           " ? AND #{scope} " + 
     476                                           (record.send(scope).nil? ? "IS" : "=") + 
     477                                           " ?", 
     478                                           record.send(attr_name), record.send(scope)] : 
     479                                         ["#{attr_name} " + 
     480                                           (record.send(attr_name).nil? ? "IS" : "=") + 
     481                                           " ? AND #{record.class.primary_key} " + 
     482                                           (record.send(:id).nil? ? "IS NOT" : "<>") + 
     483                                           " ? AND #{scope} " + 
     484                                           (record.send(scope).nil? ? "IS" : "=") + 
     485                                           " ?", 
     486                                           record.send(attr_name), record.send(:id), record.send(scope)]) 
     487                record.errors.add(attr_name, configuration[:message]) 
     488            end 
     489          end 
    474490        else 
    475491          validates_each(attr_names,configuration) do |record, attr_name, value| 
    476492            record.errors.add(attr_name, configuration[:message]) if record.class.find_first(record.new_record? ? ["#{attr_name} = ?", record.send(attr_name)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ?", record.send(attr_name), record.send(:id) ] ) 
  • lib/active_record/connection_adapters/abstract_adapter.rb

    old new  
    349349        'Abstract' 
    350350      end 
    351351 
     352      def parameterized_primary_key() 
     353        nil 
     354      end 
     355 
    352356      # Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database. 
    353357      def structure_dump() end 
    354358 
  • lib/active_record/connection_adapters/firebird_adapter.rb

    old new  
     1# firebird_adapter.rb 
     2# author: John W Higgins <develop@wishdev.com> 
     3# based on the interbase adapter work of Kazuhiro Yoshida <moriq@moriq.com> 
     4# some parts "borrowed" from Luke Holden's <lholden@cablelan.net> postgresql_adaptor.rb 
     5 
     6require 'active_record/connection_adapters/abstract_adapter' 
     7require 'parsedate' 
     8require 'active_record/vendor/firebird' 
     9require 'time' 
     10 
     11module ActiveRecord 
     12  class Base 
     13    def self.firebird_connection(config) # :nodoc: 
     14      require 'redbird' 
     15      symbolize_strings_in_hash(config) 
     16      if config.has_key?(:database) 
     17        database = config[:database] 
     18      else 
     19        raise ArgumentError, "No database specified. Missing argument: database." 
     20      end 
     21      username = config[:username] ? config[:username].to_s : 'SYSDBA' 
     22      password = config[:password] ? config[:password].to_s : 'masterkey' 
     23      charset  = config[:charset] 
     24      conn = Redbird::connect(database, username, password, charset) 
     25      ConnectionAdapters::FirebirdAdapter.new( 
     26        conn, logger 
     27      ) 
     28    end 
     29  end 
     30 
     31  module ConnectionAdapters 
     32    class FirebirdAdapter < AbstractAdapter # :nodoc: 
     33      class FirebirdColumn < Column #:nodoc: 
     34 
     35        def initialize(name, default, sql_type, subtype, scale, precision, length) 
     36          @name, @scale, @precision, @limit = name, scale, precision, length 
     37          @sql_type = Firebird::blr_type(sql_type, subtype) 
     38          @type = Firebird::ruby_type(@sql_type) 
     39          @default = type_cast default 
     40          @parms = Array.new() 
     41        end 
     42 
     43        def type_cast(value) 
     44          return nil if value.nil? || value =~ /^\s*null\s*$/i 
     45          case @type 
     46          when :integer  
     47            case value 
     48            when FalseClass 
     49              0 
     50            when TrueClass 
     51              1 
     52            else 
     53              value.to_i 
     54            end 
     55          when :float 
     56            value.to_f 
     57          when :timestamp 
     58            cast_to_time(value) 
     59          when :time 
     60            cast_to_time(value) 
     61          when :date 
     62            cast_to_date(value) 
     63          else 
     64            value 
     65          end 
     66        end 
     67 
     68        def cast_to_date(value) 
     69          return value if value.is_a? Date 
     70          return Date.new(value.year, value.month, value.day) if value.is_a? Time 
     71          return Date.parse(value) if value.is_a? String 
     72        end 
     73 
     74        def cast_to_time(value) 
     75          return value if value.is_a? Time 
     76          time_array = ParseDate.parsedate value 
     77          time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1; 
     78          Time.send Base.default_timezone, *time_array 
     79        end 
     80      end 
     81    end 
     82 
     83    class FirebirdAdapter < AbstractAdapter # :nodoc: 
     84      attr_accessor :parms 
     85 
     86      @@keywords = ['type', 'starting', 'ending'] 
     87       
     88      def select_all(sql, name = nil) 
     89        select(sql, name) 
     90      end 
     91       
     92      def select_one(sql, name = nil) 
     93        result = select(sql, name) 
     94        result.nil? ? nil : result.first 
     95      end 
     96 
     97      def columns(table_name, name = nil) 
     98        table_structure(table_name, name).inject([]) do |columns, (field_name, type, default, length,  
     99                                                                   precision, scale, subtype)| 
     100          columns << FirebirdColumn.new(field_name, default, type, subtype, scale, precision, length) 
     101          columns 
     102        end 
     103      end 
     104 
     105      def execute(sql, name = nil, parms = nil) 
     106        log(sql, name, @connection) { |connection| connection.execute(sql, parms) } 
     107      end 
     108 
     109      def insert(sql, name = nil, pk = nil, id_value = nil) 
     110        if pk.nil? # Who called us? What does the sql look like? No idea! 
     111          execute sql, name 
     112        elsif id_value # Pre-assigned id 
     113          log(sql, name, @connection) { @connection.execute sql } 
     114        else # Assume the sql contains a bind-variable for the id 
     115          table = sql.split(" ", 4)[2] 
     116          id_value = insert_id(table, pk) 
     117          log(sql, name, @connection) { @connection.execute(sql, id_value) } 
     118          id_value 
     119        end 
     120      end 
     121 
     122      def update(sql, name = nil) 
     123        log(sql, name, @connection) { @connection.execute(sql, @parms) } 
     124        @connection.rows_affected 
     125      end 
     126 
     127      def delete(sql, name = nil) 
     128        execute(sql, name) 
     129        @connection.rows_affected 
     130      end 
     131 
     132      def begin_db_transaction() 
     133        # auto-start 
     134      end 
     135 
     136      def commit_db_transaction 
     137        @connection.commit 
     138      end 
     139 
     140      def rollback_db_transaction 
     141        @connection.rollback 
     142      end 
     143 
     144      def quote(value, column = nil) 
     145        case value 
     146        when String 
     147          if column 
     148            case column.type 
     149            when :date 
     150              value, timestr = value.split(/ /, 2) 
     151            when :time 
     152              datestr, value = value.split(/ /, 2) 
     153            when :binary 
     154              value = '' 
     155            end 
     156          end 
     157          "'#{quote_string(value)}'" # ' (for ruby-mode) 
     158        when NilClass 
     159          "NULL" 
     160        when TrueClass 
     161          (column && column.class == :boolean) ? "'t'" : "1" 
     162        when FalseClass 
     163          (column && column.class == :boolean) ? "'f'" : "0" 
     164        when Float, Fixnum, Bignum 
     165          "#{value.to_s}" 
     166        when Date 
     167          format =  
     168            if column && column.type == :timestamp 
     169              "%Y-%m-%d %H:%M:%S" 
     170            else 
     171              "%Y-%m-%d" 
     172            end 
     173          "'#{value.strftime(format)}'" 
     174        when Time 
     175          format =  
     176            if column && column.type == :time 
     177              "%H:%M:%S" 
     178            elsif column && column.type == :timestamp 
     179              "%Y-%m-%d %H:%M:%S" 
     180            else 
     181              "%Y-%m-%d %H:%M:%S" 
     182            end 
     183          "'#{value.strftime(format)}'" 
     184        when DateTime 
     185          format = 
     186            if column 
     187              case column.class 
     188              when :date 
     189                "%Y-%m-%d" 
     190              when :time 
     191                "%H:%M:%S" 
     192              else 
     193                "%Y-%m-%d %H:%M:%S" 
     194              end 
     195            else 
     196              "%Y-%m-%d %H:%M:%S" 
     197            end 
     198          "'#{value.strftime(format)}'" 
     199        else  
     200          "'#{quote_string(value.to_yaml)}'" 
     201        end 
     202      end 
     203 
     204      def quote_string(s) 
     205        s.gsub(/'/, "''") # ' (for ruby-mode) 
     206      end 
     207 
     208      def quote_column_name(name) 
     209        %Q("#{name.upcase}") 
     210      end 
     211 
     212      def add_limit_with_offset!(sql, limit, offset) 
     213        if /\A\s*SELECT\s+/i=~sql  
     214          sql[$~.end(0), 0] = "FIRST #{limit} SKIP #{offset} " 
     215        end  
     216      end 
     217 
     218      def add_limit_without_offset!(sql, limit) 
     219        if /\A\s*SELECT\s+/i=~sql  
     220          sql[$~.end(0), 0] = "FIRST #{limit} " 
     221        end  
     222      end 
     223 
     224      def adapter_name() 
     225        "Firebird" 
     226      end 
     227 
     228      def parameterized_primary_key() 
     229        "?" 
     230      end 
     231 
     232      def quote_keywords(colname) 
     233        @@keywords.include?(colname.downcase) ? "\"" + colname.upcase + "\"" : colname.upcase 
     234      end 
     235 
     236      def unquote_keywords(colname) 
     237        colname.gsub(/\"/, '').downcase 
     238      end 
     239 
     240