トップ «前の日記(2005-04-04) 最新 次の日記(2005-04-06)» 編集

3 日坊主日記


2005-04-05 [長年日記]

_ [Rails] ActiveRecord: count の後 find_all したら select * が2回呼ばれる

結局

  • association_proxy.rb (-r 1036):
        def respond_to?(symbol, include_priv = false)
 -        load_target
 -        proxy_respond_to?(symbol, include_priv) || @target.respond_to?(symbol, include_priv)
 +        proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
        end

なわけだけど svn HEAD では直っていました。orz

_ [qmail] ハイフン

learn-ruby-in-kansai ML に送れないYo!

" " で囲んだら送れた。

_ [Rails] SQLite win32

 C:\>gem list sqlite --remote
 sqlite
 sqlite-ruby
 sqlite3-ruby

2.0.2 以降は sqlite-ruby になったんだね。

とりあえず SQLite3 じゃないほうを gem で入れてみる。

 C:\>gem install sqlite-ruby
 Select which gem to install for your platform (i386-mswin32)
  1. sqlite-ruby 2.2.3 (ruby)
  2. sqlite-ruby 2.2.3 (mswin32)
 ...
 > 2

http://www.sqlite.org/download.html

  • sqlitedll-2_8_16.zip
  • sqlite-2_8_16.zip

入れておく。

test/tests.rb は

 system "ruby extconf.rb > /dev/null"

とかしやがるので、そのままではうまくいかない。

 # LOAD THE TEST CASES

以降をこぴぺして、

 require 'rubygems'
 require_gem 'sqlite-ruby'
 require 'fileutils'

と書いておく (test_loader.rb として保存)。

 C:\usr\lib\ruby\gems\1.8\gems\sqlite-ruby-2.2.3-mswin32\test>ruby test_loader.rb
 'arrayfields' does not appear to exist... skipping arrayfields integration test
 Loaded suite All SQLite/Ruby Unit Tests
 Started
 ........................................................................
 Finished in 1.613 seconds.

 72 tests, 186 assertions, 0 failures, 0 errors
 C:/usr/lib/ruby/1.8/fileutils.rb:687:in `unlink': Permission denied - db/fixtures.db (Errno::EACCES)

rm_f に失敗してるのはキニシナイ。 'arrayfields' は気にしなくていいのかなあ。

ActiveRecord 側でテストしてみる。

 C:\usr\lib\ruby\gems\1.8\gems\activerecord-1.9.1\test>ruby -I connections\native_sqlite base_test.rb
 ./../lib/active_record/base.rb:221: uninitialized constant ActiveRecord::Base::ClassInheritableAttributes (NameError)

はあ? active_support がちゃんと load されてないなあ。

  • active_record.rb:
   begin
     require 'active_support'
   rescue LoadError
     require 'rubygems'
     require_gem 'activesupport'
 +   require 'active_support'
   end

としておく。

追記 (2005-06-03): よりよい解法。-rubygems を使いなさい。

 ruby -rubygems -I connections\native_sqlite base_test.rb
 C:\usr\lib\ruby\gems\1.8\gems\activerecord-1.9.1\test>ruby -I connections\native_sqlite base_test.rb
 Using native SQlite
 SQLite database not found at C:/usr/lib/ruby/gems/1.8/gems/activerecord-1.9.1/test/fixtures/fixture_database.sqlite. Rebuilding it.
 Executing 'sqlite C:/usr/lib/ruby/gems/1.8/gems/activerecord-1.9.1/test/fixtures/fixture_database.sqlite "create table a (a integer); drop table a;"'
 SQLite database not found at C:/usr/lib/ruby/gems/1.8/gems/activerecord-1.9.1/test/fixtures/fixture_database_2.sqlite. Rebuilding it.
 Executing 'sqlite C:/usr/lib/ruby/gems/1.8/gems/activerecord-1.9.1/test/fixtures/fixture_database_2.sqlite "create table a (a integer); drop table a;"'
 Loaded suite base_test
 Started
 ...............................................................................
 Finished in 82.279 seconds.

 79 tests, 169 assertions, 0 failures, 0 errors

_ [qmail] ハイフン(2)

learn-ruby-in-kansai ML に送れないYo!

今度は送れた。向こうの設定なんだろうか。

_ [Firebird] GetRowsAffected

Ed さんに教えてもらいました!

 long int GetRowsAffected(long * status, isc_stmt_handle * stmt)
 {
 	int insertCount = 0;
 	int updateCount = 0;
 	int deleteCount = 0;
 	int selectCount = 0;
 	int l			= 0;
 	int count		= 0;
 	char *ptr;
 	char count_type;
 	char strBuffer[64] = "";
 	char itemsReq[] = {isc_info_sql_records};

 	(void) isc_dsql_sql_info(status, stmt, 1, itemsReq, sizeof(strBuffer),
 strBuffer);

 	// *** Must add test for errors in the status vector here ***

 	for (ptr = strBuffer + 3; *ptr != isc_info_end; )
 	{
 		count_type = *ptr++;
 		l = isc_vax_integer (ptr, 2);
 		ptr += 2;
 		count = isc_vax_integer (ptr, l);
 		ptr += l;
 		switch (count_type)   {

 			case isc_info_req_update_count:
 				updateCount = count;
 				break;

 			case isc_info_req_delete_count:
 				deleteCount = count;
 				break;

 			case isc_info_req_select_count:
 				selectCount = count;
 				break;

 			case isc_info_req_insert_count:
 				insertCount = count;
 				break;
 		}
 	}

 	return insertCount + updateCount + deleteCount;
 }
[]