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

Ticket #5940 (assigned defect)

Opened 2 years ago

Last modified 11 months ago

[PATCH] Rails update_attributes does not work on a SQL Server table that contains a Timestamp.

Reported by: steven@mdlogix.com Assigned to: tomafro (accepted)
Priority: high Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: blocker Keywords: Timestamp, SQL Server sqlserver
Cc: bryanl

Description

Attempting to update an underlying active_record that is populated from a SQL Server table that contains a timestamp column will give the following DBI error:

DBI::DatabaseError: 23000 (272) [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update a timestamp column

Attachments

sql_server_adapter_timestamp_fix.diff (6.6 kB) - added by steven@mdlogix.com on 08/28/06 18:56:03.
readonly_timestamp_columns_for_sqlserver.diff (6.0 kB) - added by tomafro on 07/04/07 16:06:40.
Experimental timestamp patch, for comment

Change History

08/28/06 18:56:03 changed by steven@mdlogix.com

  • attachment sql_server_adapter_timestamp_fix.diff added.

08/28/06 21:54:51 changed by tomafro

  • keywords changed from Timestamp, SQL Server to Timestamp, SQL Server sqlserver.
  • owner changed from David to tom@popdog.net.

I'm not sure hiding the column from ActiveRecord is the best solution for this. Also, the attached patch looks like it's missing a new test. I'll try and look at this in more detail later this week.

09/19/06 10:30:19 changed by tomafro

  • owner changed from tom@popdog.net to tomafro.

03/02/07 19:41:03 changed by tomafro

Having thought about this for some time now, I think the best approach would be to mark columns such as timestamp as read only, and prevent active record from including them in insert/update statements. I'm in the process of clearing a large backlog of SQL Server issues, and will hopefully get around to this soon.

04/24/07 13:58:58 changed by bryanl

  • cc set to bryanl.

07/04/07 16:05:33 changed by tomafro

I've written an experimental patch for the approach I outlined above. It allows reading/writing data from tables with timestamp columns, as well as access to the timestamp itself (if really required).

One note of caution:

It's necessary to reload a recently saved/updated object to get the latest timestamp. This patch also changes the mapping of the :timestamp columns in migrations from datetime to timestamp. I'm not sure what I think of this. Maybe a special datatype, :sqlserver_timestamp might be better for cross-db compatability.

07/04/07 16:05:41 changed by tomafro

  • status changed from new to assigned.

07/04/07 16:06:40 changed by tomafro

  • attachment readonly_timestamp_columns_for_sqlserver.diff added.

Experimental timestamp patch, for comment

08/22/07 11:12:38 changed by neilrickards

This patch appears to be working well against activerecord 1.15.3