-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pistos Christou wrote:
> unknown wrote:
> 
>>I'm working on a program that manipulates and stores a lot of data in
>>a database via ActiveRecord. I'm having a heck of a time trying to
>>
>>Anyone have experience with this type of work? Care to share any tips
>>on getting this to work?
> 
> 
> A bit away from your original topic (and perhaps this belongs on the 
> Rails mailing list), but: I'd be interested to hear if you run into any 
> problems using AR outside of Rails.  I have been writing an application 
> (IRC game) which uses AR with PostgreSQL, and I have had uncountable 
> problems due to the way AR connects to the database.  I am constantly 
> hitting the maximum connection limit, and stray PostgreSQL child 
> processes are always being left around.
> 
> What DB are you using?
> 

Let me guess, your IRC game is multi-threaded? AR stores connections based on the Thread.current_thread.id (or at least it does in
1.13.2, things changed slightly in 1.14.2). I ran into this problem as well. If you are using AR 1.13.2 I can give you a fix,
otherwise you'll have to do it yourself or wait about a week for me to patch 1.14.2 (if it needs it).

Here is the code:
- -------------------
# Attempt to load active-record version, but if this dies, then don't complain
# Newer versions of rails seem to include VERSION by default, however activerecord-1.13.2 doesn't.
begin ; require 'active_record/version' ; rescue LoadError; end

# This includes changes to ActiveRecord 1.13.2
class ActiveRecord::Base

        # This is overridden because ActiveRecord 1.13.2 stores database connections based on the
        # Thread id. The processor uses a new thread for each new set of files to process.
        # We want the same connection to be used.
        #
        # Version 1.14.2 no longer has the class variable @@connection_cache, so we should
        # not redefine this method if we are at or above that version.
		if ActiveRecord::VERSION::STRING < '1.14.2'
    	    def self.connection
                @@connection_cache[123456][name] ||= retrieve_connection
	        end
		end
end
- ---------------------

How this helps,

Zach

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEffr/Myx0fW1d8G0RAkJLAJ9YeHhrlNCce4HwQGC+StwhAv4xEgCeLMX9
LgMa1ecsMSCxynmCRs0BOYc=
=Igay
-----END PGP SIGNATURE-----