ActiveRecord Save is not saving

I am having a strange problem. I am trying to update a bunch of records
like this

a.each do |a|
b = Company.find_by_id(a.company_id)
b.col_name = Time.now
b.save
end

after I run this, I check the DB and the column “col_name” is indeed
updated. However, if I check the DB 5-10 minutes later, all changes are
gone. I’ve tried update_attribute, same problem.

Any idea what I am doing wrong?

thanks,

after I run this, I check the DB and the column “col_name” is indeed
updated. However, if I check the DB 5-10 minutes later, all changes are
gone. I’ve tried update_attribute, same problem.

Try checking your configuration and verify that database auto-commit is
turned on.

hth,

Long

Long,

I checked, my autommit is set to 1. I am using MySQL. Any idea what
else
might be wrong?

Thanks for your help,
e

Does anone know what else can be wrong with my DB? Every once in a
while my
Updates don’t get committed. The application was working fine all
morning,
but just now one update got rolled back again. My @@autocommit is
enabled,
I am not using any transactions, it’s a simple update.

Thanks,

On 8/29/06, eduard [email protected] wrote:

Does anone know what else can be wrong with my DB? Every once in a while
my Updates don’t get committed. The application was working fine all
morning, but just now one update got rolled back again. My @@autocommit is
enabled, I am not using any transactions, it’s a simple update.

It appears your code is not checking the result of .save to see whether
validation failed.

jeremy

I check save and it works fine. I check the DB after I run update and
the
records are updated (most of the time). However, every once in a while,
if
I check the table that was updated 5 minutes later, all changes are
rolled
back. I realized that it’s the issue with MySQL, not Rails. Is my
MySQL
missing some crucial configuration that I am not aware of?. I am using
MySQL 5, InnoDB and my @@autocommit is enabled. I posted a question on
mysql.com several days ago but never got a single response.

Any help would be greately appreciated.

thanks

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

eduard wrote:

I check save and it works fine. I check the DB after I run update and
the records are updated (most of the time). However, every once in a
while, if I check the table that was updated 5 minutes later, all
changes are rolled back. I realized that it’s the issue with MySQL, not
Rails. Is my MySQL missing some crucial configuration that I am not
aware of?. I am using MySQL 5, InnoDB and my @@autocommit is enabled.
I posted a question on mysql.com http://mysql.com several days ago but
never got a single response.

Any help would be greately appreciated.

I use MySQL 4.1 and 5, and I have never seen anything like you suggest.
Have you checked your rails logs to see if there are any
explicit rollbacks being called?

If you think it is MySQL you should reproduce the issue outside of
Rails/ActiveRecord and within MySQL client.

Also, what version of MySQL 5 are you running? Can you paste your MySQL
config also?

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

iD8DBQFE+kbbMyx0fW1d8G0RAmvCAJ0ehXpOL4d4LM3g3NrqOwM0ipfHqQCfSC0/
s0d3lnwKBNg2WM62dp715Rs=
=YaFu
-----END PGP SIGNATURE-----

Zach,

Yes, I can reproduce this error within MySQL client. So, it’s defintely
not
a Rails issue. I can only reproduce this error a few times a day,
usually
it works fine. I am running Version: ‘5.0.22’ on FC 5 and my
@@autocommit
is enabled.

here’s my my.cnf file

innodb_data_home_dir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

Set buffer pool size to 50-80% of your computer’s memory,

but make sure on Linux x86 total memory usage is < 2GB

innodb_buffer_pool_size=1G
innodb_additional_mem_pool_size=50MB

innodb_log_buffer_size=8MB

skip-external-locking
max_connections=200
read_buffer_size=1M
sort_buffer_size=1M

Default to using old password format for compatibility with mysql 3.x

clients (those using the mysqlclient10 compatibility package).

#old_passwords=1 #original, in my SQL 4.1 this didn’t work with Rails
old_passwords=0

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid