Why oh why won’t CakePHP store my tinyint(1) data?

CakePHPOK, I actually know the answer to the question posed in the subject line. Despite the palpable suspense, I am sure 99.9% of my audience can tune out now. That leaves the remaining 0.001 readers to dive into this problem with me.

I’m doing a lot of CakePHP development these days, and I’m loving it. (What? The McDonald’s legal team is on its way over here? Damn. Fine, McDonalds. Have it your way. What, Burger King too? I guess I better make a run for the border. OK, joke’s over.)

Of course, plunging into a sea of someone else’s code is always fraught with a little peril, and today I found some. Here’s the scenario:

MySQL is a pretty cool database. I’m very loyal to it. But there are some things it should do, but it just doesn’t. One of those things is support a boolean data type. So, we make do. A common way to make do, and the way preferred by CakePHP, is to use a tinyint(1) field and just store 0 or 1 in it. In fact, CakePHP loves this approach so much that whenever it sees a data field that’s a tinyint(1), it “automagically” refuses to accept any values for that field other than 0 or 1.

That’s super-dee-duper. If that’s what you want. But I have a data table, my users table, as it happens, and in that table I used to have a field called admin, a boolean value. Either the user’s an admin or not. Great. But I decided to upgrade this to allow more access levels than just 0 or 1 (and while I was at it, changing the field name, shockingly, to access_level). I wanted to be able to support up to ten levels. Well, great! A tinyint(1) will nicely store values from 0 through 9, so I’m set!

Except… it didn’t work. Every time I tried to save a value greater than 1, I’d find that it had saved 1 as the value. I could change it to 0 just fine, but anything else became 1.

I checked the documentation and found ample evidence for the “automagic” behavior, so I figured there were a couple of possible changes I could make that would fix the problem: I could change it to a tinyint(2), or I could change it to a char(1). Since I decided I’d rather (in theory) allow letters in the field than double-digit numbers, I went with char(1).

Only it still didn’t work.

I did some more research, found that I seemed to be on the right track, but I was still confounded.

Then it occurred to me. I knew I had seen a cache directory somewhere in the labyrinth of directories and subdirectories and sub-sub-sub-sub-subdirectories in the CakePHP package. And I also knew that a framework as developed as CakePHP probably wouldn’t hit up the database for schema information constantly, so maybe… just maybe… it was cached.

I burrowed down in my application to the app/tmp/cache/models directory, and sure enough… there’s a cache file for each data table, with the schema in a serialized form. Well, it’s a cache, right? Nothin’ to lose. Trash can, here we come! I refreshed my page, and voilà! Success!

So… word to the wise (or, not so wise, like me… otherwise you’d probably already know):

  1. CakePHP will only store 0 or 1 in a tinyint(1) field. Period.
  2. If you change the schema for any of your data tables, and CakePHP acts like you didn’t… dump that cache!

We now return you to our regular, slightly less geeky programming.

The last word on concept albums… for now

The last thing I’ll say about concept albums, and I’ll try not to go on for 47 paragraphs this time, is that I think it’s easier (and maybe more necessary) to do a concept album when your music is more abstract and/or experimental.

I think my approach would be a lot different if:

a) I could sing
b) I could adhere to a recognizable song structure
c) I could write lyrics about something other than science and man-made disasters

In other words, if I were a better songwriter, I would probably focus on crafting songs. As it is, my music is more sprawling and chaotic, and the only way I can rein it in at all for the purpose of producing an album is by coming up with an overarching concept.

The art of the concept album

A concept albumI love concept albums. They’re self-indulgent and pompous… two of the best traits a musician can have! (And anyone who thinks punk’s ascension in the late ’70s killed off pomposity in rock music is deluding themselves. Punk is as pompous as it can get!)

Anyway… the topic of concept albums came up in the RPM forums today, and I wrote such a self-indulgent and pompous post on the matter that I just felt I had to cross-post it here. To wit:

I don’t think I’m capable of making an album that’s not a concept album… although the nature of what constitutes a concept album can vary a lot. Let’s see… here’s a complete chronology of my solo albums and EPs since I really got into doing this in 2001.

THE DEWEY ‘JONE’ McNUKKLE STORY: SOUNDTRACK TO AN UNMADE FILM (September 2001)
Concept: All track titles are nicknames a particular friend of mine has had at some point in his life; music on each track corresponds to characteristics of the nickname.

TAI CHI AND CHAI TEA (October 2003)
Concept: Not so much, really, although I did structure the CD as if it were two sides, with a “Tai Chi” side and a “Chai Tea” side, and the track sequence was designed around that. Oh, and there’s a 13-minute, 5-“movement” suite about the Iraq war, to make up for the lack of an overall concept.

LIMITATIONS OF THE SYSTEM (EP, August 2004)
Concept: Atari. All of the tracks have Atari 2600 sounds incorporated in them.

INFLATIONARY COSMOLOGY (May 2005)
Concept: Can it get any more grandiose? The album represents the entire arc of the existence of the universe, from Big Bang to Heat Death. A suite in the middle also represents the entire arc of human existence from cavemen to the present day, in case it wasn’t pretentious enough already. I was so spent by the concept on this album that I went two years without recording anything after it was completed.

HIGHWAY 34 REVISITED (May 2007)
Concept: Probably the only thing I’ve ever done without a real concept, but I guess I was trying to capture the essence of all of my musical influences, right down to the second-hand nature of the album’s title.

DIVISION BY ZERO [VOL. I] (EP, August 2007)
Concept: The beginning of an extended autobiographical project. Each track has a year in the title and corresponds to some significant event in my life from that year. This 3-song EP features events from 1973 (my conception), 1976 (not sure, but it involves a new bed, vomit and hospitalization) and 1978 (pizza).

UNNATURAL DISASTERS (February 2008)
Concept: This was my RPM submission last year. The concept is strange places, or more accurately, places made strange by human activity. Each track is a sonic representation of some of my favorite made-weird-by-people places on earth.

TECHNETIUM (EP, February 2008)
Concept: A one-track, 38-minute “EP”; the characteristics of this minimalist techno track were determined based on properties of the technetium atom. Yeah… I forgot to mention “nerd alert.”

MELLOTRONIC (EP, July 2008)
Concept: The Mellotron. Oh, how I love it.

THE BEE LP! (October 2008)
Concept: Bees. All tracks represent something about bees and their behavior.

ANAGRAMMATIC PSEUDONYMS (February 2009)
Concept: This is going to be my RPM submission for this year. Each track title is an anagram of my name. The first letters of each of the 13 tracks, in order, spell out my name. How’s that for establishing some parameters for yourself.

Anyway… my reason for going on at such length here (besides extreme narcissism) is to perhaps give some ideas as to how broad the idea of a “concept album” can be — and how inspiring it can be to dive into a project like this with a specific concept in mind. I find I can be most creative when I have a set of parameters to work within. It gives me a starting point… and a destination.

I knew my tunnel through the center of the Earth wouldn’t have ended up in China!

GlobeAs a kid I often wondered if the whole “dig a hole to China” idea really held water. I was suspicious that my hole through the center of the Earth wouldn’t actually come out within the boundaries of Asia’s most populous nation.

Of course, at the time I was probably so young that I wasn’t aware that China was Asia’s most populous nation, considering that I also somehow thought such a hole would actually be possible to dig. Oh yeah, and I never just, you know, looked at a globe to prove that it was a ridiculous proposition.

For a long time now, I’ve realized that line drawn from Minnesota through the center of the planet would emerge on the other side somewhere in the remote vastness of the southern Indian Ocean, but I never knew where until antipodr came along. Now I know that it would be roughly midway between Perth, Western Australia and the Kerguelen Islands, a place I have known about for approximately 5 minutes now, and which is apparently populated predominantly by feral cats, rabbits and sheep introduced by human visitors over the past couple of centuries. Sweet.

Well… I’m off to the garage for my shovel. Gotta start digging sometime!

Hilarious Portal Video (NSFWOK: Not Safe For Work Or Kids)

I had to put that “or kids” in there because my kids like watching me play the “shooting holes” game, a.k.a. Portal. It is awesome. I’ve talked about it before, but it is worth mentioning again since I just found this video, and I had been playing it again earlier tonight.

I kind of suck at it though. I haven’t even gotten to the turrets that star in the video. But I since already know about the “Rosebud”-esque ending, this video doesn’t spoil it. Beware, it’s drenched in profanity and 1337-speak so it’s not for everyone. And it probably makes little sense if you’re not familiar with Portal. But I found it absolutely hilarious.