Friday, August 10, 2007

SQL Server Timestamp Field

It's been so long since I've had a decent Microsoft rant, I guess it must just be time. A while back, in a SQL Server database (don't laugh, the client insisted), I needed to have a timestamp for when a row is created. Silly me, I actually looked through the data type list, saw "timestamp", and thought, "Hey, that must be a timestamp!". Yeah, silly me.

The timestamp type? It isn't even a usable type. It gets set whenever the row gets updated, is binary data, and has nothing to do with dates or times. What I really wanted was a Datetime field with a default value of getdate(). Not a timestamp.

I'm so glad that the REST of my coding life, I get to be in Postgres. In Ubuntu. On Linux. Away from Microsoft. Harumph!


Thursday, August 02, 2007

A Minor Rails Hiccup, With Solution

As mentioned, I've been working through Agile Web Development With Rails, 2E. I got to p. 88, which talks about adding data via a migration. So I download the data for 003_add_test_data.rb, and run rake on it. Nothing. All of my rows get deleted, but no new ones get added. I add some print lines, which get displayed when rake runs, so I know the code is getting executed. But no data gets added. Harumph!

Well, let's back up a bit. A few pages prior, I added validation to the model. Pretty cool stuff, being able to throw in some regular expressions and have a pretty error message show up on the page. So I did a little extra-curricular playing around, and life was good.

After looking around a bit, I discovered that the data that the book wants me to add wasn't passing my validation tests. Okay, fine. So why wasn't rake showing any of the validation exceptions?

Well, a quick post to the Rails forum later, it turns out that create() won't throw exceptions, it just adds entries into the 'errors' list and continues. create!() will throw an exception with the same error text that the Rails app shows, and stops the migration. Problem solved.