Ticket #1418: 1455.patch
| File 1455.patch, 55.4 kB (added by wishdev@gmail.com, 3 years ago) |
|---|
-
test/deprecated_associations_test.rb
old new 311 311 end 312 312 313 313 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 315 320 assert_equal 1, Firm.find_first.find_all_in_clients("name = 'Summit'").length 316 321 end 317 322 -
test/connections/native_firebird/connection.rb
old new 1 print "Using native Firebird\n" 2 require 'fixtures/course' 3 require 'logger' 4 5 ActiveRecord::Base.logger = Logger.new("debug.log") 6 7 db1 = '/db/activerecord_unittest.fdb' 8 db2 = '/db/activerecord_unittest2.fdb' 9 10 ActiveRecord::Base.establish_connection( 11 :adapter => "firebird", 12 :host => "localhost", 13 :username => "", 14 :password => "", 15 :database => db1 16 ) 17 18 Course.establish_connection( 19 :adapter => "firebird", 20 :host => "localhost", 21 :username => "", 22 :password => "", 23 :database => db2 24 ) -
test/aaa_create_tables_test.rb
old new 12 12 13 13 def each_statement() 14 14 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 28 50 end 29 51 end 30 52 … … 36 58 def run_sql_file(connection, path) 37 59 sql_file = SqlFile.new(path) 38 60 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 } 44 71 end 45 72 46 73 def test_table_creation -
test/associations_test.rb
old new 338 338 def test_find_all 339 339 firm = Firm.find_first 340 340 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 342 347 assert_equal 1, firm.clients.find(:all, :conditions => "name = 'Summit'").length 343 348 end 344 349 … … 354 359 firm = Firm.find_first 355 360 client2 = Client.find(2) 356 361 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 359 368 end 360 369 361 370 def test_find_first_sanitized 362 371 firm = Firm.find_first 363 372 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 367 383 end 368 384 369 385 def test_find_in_collection -
test/base_test.rb
old new 817 817 end 818 818 819 819 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 821 826 res2 = res + 1 822 827 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 825 834 end 826 835 assert_equal res, res2 827 836 end -
test/binary_test.rb
old new 17 17 if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter 18 18 return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter) 19 19 end 20 21 if ActiveRecord::ConnectionAdapters.const_defined? :FirebirdAdapter 22 return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::FirebirdAdapter) 23 end 24 20 25 bin = Binary.new 21 26 bin.data = @data 22 27 -
test/inheritance_test.rb
old new 6 6 fixtures :companies, :projects 7 7 8 8 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 10 15 assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) } 11 16 end 12 17 -
test/fixtures/db_definitions/firebird.sql
old new 1 CREATE DOMAIN BOOLEAN AS SMALLINT 2 default 0 3 check (value in (0,1)); 4 CREATE DOMAIN SERIAL AS INTEGER NOT NULL; 5 CREATE DOMAIN TEXT AS BLOB SUB_TYPE TEXT SEGMENT SIZE 80; 6 7 CREATE GENERATOR GEN_ACCOUNTS_ID; 8 CREATE GENERATOR GEN_AUTO_ID_TESTS_AUTO_ID; 9 CREATE GENERATOR GEN_BINARIES_ID; 10 CREATE GENERATOR GEN_BOOLEANTESTS_ID; 11 CREATE GENERATOR GEN_COLNAMETESTS_ID; 12 CREATE GENERATOR GEN_COMMENTS_ID; 13 CREATE GENERATOR GEN_COMPANIES_ID; 14 CREATE GENERATOR GEN_COMPUTERS_ID; 15 CREATE GENERATOR GEN_CUSTOMERS_ID; 16 CREATE GENERATOR GEN_DEVELOPERS_ID; 17 CREATE GENERATOR GEN_ENTRANTS_ID; 18 CREATE GENERATOR GEN_FK_TEST_HAS_FK_ID; 19 CREATE GENERATOR GEN_FK_TEST_HAS_PK_ID; 20 CREATE GENERATOR GEN_MIXINS_ID; 21 CREATE GENERATOR GEN_MOVIES_MOVIEID; 22 CREATE GENERATOR GEN_POSTS_ID; 23 CREATE GENERATOR GEN_PROJECTS_ID; 24 CREATE GENERATOR GEN_TASKS_ID; 25 CREATE GENERATOR GEN_TOPICS_ID; 26 27 CREATE TABLE ACCOUNTS (ID SERIAL, 28 FIRM_ID INTEGER, 29 CREDIT_LIMIT INTEGER, 30 PRIMARY KEY (ID)); 31 32 CREATE TABLE AUTO_ID_TESTS (AUTO_ID SERIAL, 33 "VALUE" INTEGER, 34 PRIMARY KEY (AUTO_ID)); 35 36 CREATE TABLE BINARIES (ID SERIAL, 37 DATA BLOB, 38 PRIMARY KEY (ID)); 39 40 CREATE TABLE BOOLEANTESTS (ID SERIAL, 41 "VALUE" BOOLEAN, 42 PRIMARY KEY (ID)); 43 44 CREATE TABLE COLNAMETESTS (ID SERIAL, 45 "REFERENCES" INTEGER NOT NULL, 46 PRIMARY KEY (ID)); 47 48 CREATE TABLE COMMENTS (ID SERIAL, 49 POST_ID INTEGER NOT NULL, 50 "TYPE" VARCHAR(255) NOT NULL, 51 BODY TEXT NOT NULL, 52 PRIMARY KEY (ID)); 53 54 CREATE 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, 61 PRIMARY KEY (ID)); 62 63 CREATE TABLE COMPUTERS (ID SERIAL, 64 DEVELOPER INTEGER NOT NULL, 65 EXTENDEDWARRANTY INTEGER NOT NULL, 66 PRIMARY KEY (ID)); 67 68 CREATE 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), 75 PRIMARY KEY (ID)); 76 77 CREATE 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, 82 PRIMARY KEY (ID)); 83 84 CREATE TABLE DEVELOPERS_PROJECTS (DEVELOPER_ID INTEGER NOT NULL, 85 PROJECT_ID INTEGER NOT NULL, 86 JOINED_ON DATE); 87 88 CREATE TABLE ENTRANTS (ID SERIAL, 89 NAME VARCHAR(255) NOT NULL, 90 COURSE_ID INTEGER NOT NULL, 91 PRIMARY KEY (ID)); 92 93 CREATE TABLE FK_TEST_HAS_FK (ID SERIAL, 94 FK_ID INTEGER NOT NULL, 95 PRIMARY KEY (ID)); 96 97 CREATE TABLE FK_TEST_HAS_PK (ID SERIAL, 98 PRIMARY KEY (ID)); 99 100 ALTER TABLE FK_TEST_HAS_FK ( 101 FOREIGN KEY (FK_ID) REFERENCES FK_TEST_HAS_PK (ID)); 102 103 CREATE 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, 112 PRIMARY KEY (ID)); 113 114 CREATE TABLE MOVIES (MOVIEID SERIAL, 115 NAME VARCHAR(100), 116 PRIMARY KEY (MOVIEID)); 117 118 CREATE TABLE PEOPLE (ID SERIAL, 119 FIRST_NAME VARCHAR(40) NOT NULL, 120 LOCK_VERSION INTEGER DEFAULT 0 NOT NULL, 121 PRIMARY KEY (ID)); 122 123 CREATE 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, 128 PRIMARY KEY(ID)); 129 130 CREATE TABLE PROJECTS (ID SERIAL, 131 NAME VARCHAR(100), 132 PRIMARY KEY (ID)); 133 134 CREATE TABLE SUBSCRIBERS (NICK VARCHAR(100) NOT NULL, 135 NAME VARCHAR(100), 136 PRIMARY KEY (NICK)); 137 138 CREATE TABLE TASKS (ID SERIAL, 139 "STARTING" TIMESTAMP DEFAULT NULL, 140 "ENDING" TIMESTAMP DEFAULT NULL, 141 PRIMARY KEY (ID)); 142 143 CREATE 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, 155 PRIMARY KEY (ID)); 156 157 SET TERM !!; 158 CREATE TRIGGER ACCOUNTS_INSERT FOR ACCOUNTS 159 ACTIVE BEFORE INSERT POSITION 0 160 as 161 DECLARE VARIABLE curval INTEGER; 162 begin 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 171 end!! 172 173 CREATE TRIGGER AUTO_ID_TESTS_INSERT FOR AUTO_ID_TESTS 174 ACTIVE BEFORE INSERT POSITION 0 175 as 176 DECLARE VARIABLE curval INTEGER; 177 begin 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 186 end!! 187 188 CREATE TRIGGER BINARIES_INSERT FOR BINARIES 189 ACTIVE BEFORE INSERT POSITION 0 190 as 191 DECLARE VARIABLE curval INTEGER; 192 begin 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 201 end!! 202 203 CREATE TRIGGER BOOLEANTESTS_INSERT FOR BOOLEANTESTS 204 ACTIVE BEFORE INSERT POSITION 0 205 as 206 DECLARE VARIABLE curval INTEGER; 207 begin 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 216 end!! 217 218 CREATE TRIGGER COLNAMETESTS_INSERT FOR COLNAMETESTS 219 ACTIVE BEFORE INSERT POSITION 0 220 as 221 DECLARE VARIABLE curval INTEGER; 222 begin 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 231 end!! 232 233 CREATE TRIGGER COMMENTS_INSERT FOR COMMENTS 234 ACTIVE BEFORE INSERT POSITION 0 235 as 236 DECLARE VARIABLE curval INTEGER; 237 begin 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 246 end!! 247 248 CREATE TRIGGER COMPANIES_INSERT FOR COMPANIES 249 ACTIVE BEFORE INSERT POSITION 0 250 as 251 DECLARE VARIABLE curval INTEGER; 252 begin 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 261 end!! 262 263 CREATE TRIGGER COMPUTERS_INSERT FOR COMPUTERS 264 ACTIVE BEFORE INSERT POSITION 0 265 as 266 DECLARE VARIABLE curval INTEGER; 267 begin 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 276 end!! 277 278 CREATE TRIGGER CUSTOMERS_INSERT FOR CUSTOMERS 279 ACTIVE BEFORE INSERT POSITION 0 280 as 281 DECLARE VARIABLE curval INTEGER; 282 begin 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 291 end!! 292 293 CREATE TRIGGER DEVELOPERS_INSERT FOR DEVELOPERS 294 ACTIVE BEFORE INSERT POSITION 0 295 as 296 DECLARE VARIABLE curval INTEGER; 297 begin 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 306 end!! 307 308 CREATE TRIGGER ENTRANTS_INSERT FOR ENTRANTS 309 ACTIVE BEFORE INSERT POSITION 0 310 as 311 DECLARE VARIABLE curval INTEGER; 312 begin 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 321 end!! 322 323 CREATE TRIGGER FK_TEST_HAS_FK_INSERT FOR FK_TEST_HAS_FK 324 ACTIVE BEFORE INSERT POSITION 0 325 as 326 DECLARE VARIABLE curval INTEGER; 327 begin 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 336 end!! 337 338 CREATE TRIGGER FK_TEST_HAS_PK_INSERT FOR FK_TEST_HAS_PK 339 ACTIVE BEFORE INSERT POSITION 0 340 as 341 DECLARE VARIABLE curval INTEGER; 342 begin 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 351 end!! 352 353 CREATE TRIGGER MIXINS_INSERT FOR MIXINS 354 ACTIVE BEFORE INSERT POSITION 0 355 as 356 DECLARE VARIABLE curval INTEGER; 357 begin 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 366 end!! 367 368 CREATE TRIGGER MOVIES_INSERT FOR MOVIES 369 ACTIVE BEFORE INSERT POSITION 0 370 as 371 DECLARE VARIABLE curval INTEGER; 372 begin 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 381 end!! 382 383 CREATE TRIGGER PEOPLE_INSERT FOR PEOPLE 384 ACTIVE BEFORE INSERT POSITION 0 385 as 386 DECLARE VARIABLE curval INTEGER; 387 begin 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 396 end!! 397 398 CREATE TRIGGER POSTS_INSERT FOR POSTS 399 ACTIVE BEFORE INSERT POSITION 0 400 as 401 DECLARE VARIABLE curval INTEGER; 402 begin 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 411 end!! 412 413 CREATE TRIGGER PROJECTS_INSERT FOR PROJECTS 414 ACTIVE BEFORE INSERT POSITION 0 415 as 416 DECLARE VARIABLE curval INTEGER; 417 begin 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 426 end!! 427 428 CREATE TRIGGER TASKS_INSERT FOR TASKS 429 ACTIVE BEFORE INSERT POSITION 0 430 as 431 DECLARE VARIABLE curval INTEGER; 432 begin 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 441 end!! 442 443 CREATE TRIGGER TOPICS_INSERT FOR TOPICS 444 ACTIVE BEFORE INSERT POSITION 0 445 as 446 DECLARE VARIABLE curval INTEGER; 447 begin 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 456 end!! 457 458 COMMIT!! 459 SET TERM ;!! -
test/fixtures/db_definitions/firebird.drop.sql
old new 1 DROP TABLE accounts; 2 DROP TABLE auto_id_tests; 3 DROP TABLE binaries; 4 DROP TABLE booleantests; 5 DROP TABLE colnametests; 6 DROP TABLE comments; 7 DROP TABLE companies; 8 DROP TABLE computers; 9 DROP TABLE customers; 10 DROP TABLE developers; 11 DROP TABLE developers_projects; 12 DROP TABLE entrants; 13 DROP TABLE fk_test_has_fk_id; 14 DROP TABLE fk_test_has_pk_id; 15 DROP TABLE mixins; 16 DROP TABLE movies; 17 DROP TABLE people; 18 DROP TABLE posts; 19 DROP TABLE projects; 20 DROP TABLE subscribers; 21 DROP TABLE tasks; 22 DROP TABLE topics; 23 24 DROP GENERATOR GEN_ACCOUNTS_ID; 25 DROP GENERATOR GEN_AUTO_ID_TESTS_AUTO_ID; 26 DROP GENERATOR GEN_BINARIES_ID; 27 DROP GENERATOR GEN_BOOLEANTESTS_ID; 28 DROP GENERATOR GEN_COLNAMETESTS_ID; 29 DROP GENERATOR GEN_COMMENTS_ID; 30 DROP GENERATOR GEN_COMPANIES_ID; 31 DROP GENERATOR GEN_COMPUTERS_ID; 32 DROP GENERATOR GEN_CUSTOMERS_ID; 33 DROP GENERATOR GEN_DEVELOPERS_ID; 34 DROP GENERATOR GEN_ENTRANTS_ID; 35 DROP GENERATOR GEN_MIXINS_ID; 36 DROP GENERATOR GEN_MOVIES_MOVIEID; 37 DROP GENERATOR GEN_POSTS_ID; 38 DROP GENERATOR GEN_PROJECTS_ID; 39 DROP GENERATOR GEN_TOPICS_ID; 40 -
test/fixtures/db_definitions/firebird2.sql
old new 1 CREATE DOMAIN BOOLEAN AS SMALLINT 2 default 0 3 check (value in (0,1)); 4 CREATE DOMAIN SERIAL AS INTEGER NOT NULL; 5 CREATE DOMAIN TEXT AS BLOB SUB_TYPE TEXT SEGMENT SIZE 80; 6 7 CREATE GENERATOR GEN_COURSES_ID; 8 9 CREATE TABLE COURSES (ID SERIAL, 10 NAME VARCHAR(255), 11 PRIMARY KEY (ID)); 12 13 SET TERM !!; 14 CREATE TRIGGER COURSES_INSERT FOR COURSES 15 ACTIVE BEFORE INSERT POSITION 0 16 as 17 DECLARE VARIABLE curval INTEGER; 18 begin 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 27 end!! 28 29 COMMIT!! 30 SET TERM ;!! -
test/fixtures/db_definitions/firebird2.drop.sql
old new 1 DROP TABLE courses; 2 3 DROP GENERATOR GEN_COURSES_ID; 4 -
test/fixtures/company.rb
old new 6 6 7 7 8 8 class 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 10 15 has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" 11 16 has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" 12 17 has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" -
Rakefile
old new 22 22 23 23 24 24 desc "Default Task" 25 task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_sqlite3, :test_postgresql ]25 task :default => [ :test_ruby_mysql, :test_mysql_ruby, :test_sqlite, :test_sqlite3, :test_postgresql, :test_firebird ] 26 26 27 27 # Run the unit tests 28 28 … … 38 38 t.verbose = true 39 39 } 40 40 41 for adapter in %w( postgresql sqlite sqlite3 sqlserver db2 oci )41 for adapter in %w( postgresql sqlite sqlite3 sqlserver db2 oci firebird ) 42 42 Rake::TestTask.new("test_#{adapter}") { |t| 43 43 t.libs << "test" << "test/connections/native_#{adapter}" 44 44 t.pattern = "test/*_test{,_#{adapter}}.rb" -
lib/active_record/validations.rb
old new 469 469 470 470 if scope = configuration[:scope] 471 471 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 474 490 else 475 491 validates_each(attr_names,configuration) do |record, attr_name, value| 476 492 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 349 349 'Abstract' 350 350 end 351 351 352 def parameterized_primary_key() 353 nil 354 end 355 352 356 # Returns a string of the CREATE TABLE SQL statements for recreating the entire structure of the database. 353 357 def structure_dump() end 354 358 -
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 6 require 'active_record/connection_adapters/abstract_adapter' 7 require 'parsedate' 8 require 'active_record/vendor/firebird' 9 require 'time' 10 11 module 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