Kishore and I are working on. It’s been quite a remarkable …">

Jason Bosco

Full Stack Web Developer ; Generalist

Two Timestamp Columns in MySQL

CREATE TABLE `test_table` (
`id` INT( 10 ) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE = INNODB;

That should be simple right? Apparently not:

Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

I can use CURRENT_TIMESTAMP in only one place in the table. So I can’t have MySQL do what I intended it to do - maintain two timestamps, one to store the record creation timestamp and another to store record update timestamp. So I thought I’ll maintain those two timestamps by myself in the app. Give me two simple TIMESTAMP fields:

CREATE TABLE `test_table` (
`id` INT( 10 ) NOT NULL,
`created_at` TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP NOT NULL
) ENGINE = INNODB;

MySQL automatically set the first timestamp field to DEFAULT to CURRENT_TIMESTAMP and ON UPDATE to CURRENT_TIMESTAMP. The second timestamp field was set to DEFAULT to 0. That was indeed strange.

I thought I found a bug in MySQL. But no, it turns out it is actually a feature! Actually, it’s a result of a combination of features:

  • With neither DEFAULT CURRENT_TIMESTAMP nor ON UPDATE CURRENT_TIMESTAMP, it is the same as specifying both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP.
  • It need not be the first TIMESTAMP column in a table that is automatically initialized or updated to the current timestamp. However, to specify automatic initialization or updating for a different TIMESTAMP column, you must suppress the automatic properties for the first one. Then, for the other TIMESTAMP column, the rules for the DEFAULT and ON UPDATE clauses are the same as for the first TIMESTAMP column, except that if you omit both clauses, no automatic initialization or updating occurs.

Infering from the above two points from the MySQL manual, if there are two (or more) TIMESTAMP fileds in a table with no DEFAULT and ON UPDATE clauses specified, MySQL automatically defaults the first timestamp field to have a DEFAULT CURRENT_TIMESTAMP and an ON UPDATE CURRENT_TIMESTAMP field and the rest of the timestamp fields to have a DEFAULT 0. 

Now coming back to the problem at hand, I need to track the creation and update timestamps of a record. This can be achieved using another feature:

  • By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values, and assigning NULL assigns the current timestamp.

So if I assign a NULL value to a NOT NULL TIMESTAMP field, it uses the current timestamp value instead! And that’ll be my created_at field. The updated_at TIMESTAMP field can have DEFAULT CURRENT_TIMESTAMP and an ON UPDATE CURRENT_TIMESTAMP to track the update time. So just to keep it a little more obvious I now use the following CREATE TABLE:

CREATE TABLE `test_table` (
`id` INT( 10 ) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT 0,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE = INNODB;

The corresponding INSERT statment will be:

References:

INSERT INTO test_table (id, created_at, updated_at) VALUES (1, NULL, NULL);

Solution: ‘NSInternalInconsistencyException’, Reason: ‘Invalid Nib Registered for Identifier ((Null)) - Nib Must Contain Exactly One Top Level Object Which Must Be a UITableViewCell Instance’

This seems pretty obvious now that I know it but my Google fu failed me on this one, so I thought I’ll add a note about it should someone encounterthis issue. I was working with the TableViewController and my app would crash with this error:

2012-08-15 19:59:43.706 transcribe-ios[42544:10703] Missing proxy for identifier UpstreamPlaceholder-13
2012-08-15 19:59:43.707 transcribe-ios[42544:10703] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:4118
2012-08-15 19:59:43.707 transcribe-ios[42544:10703] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier ((null)) - nib must contain exactly one top level object which must be a UITableViewCell instance'
*** First throw call stack:
(0x1990022 0x2990cd6 0x1938a48 0xc132cb 0x30f316 0x12191 0x316c54 0x3173ce 0x302cbd 0x3116f1 0x2bad42 0x1991e42 0x24e5679 0x24ef579 0x24744f7 0x24763f6 0x2503160 0x28cf30 0x196499e 0x18fb640 0x18c74c6 0x18c6d84 0x18c6c9b 0x2f297d8 0x2f2988a 0x27c626 0x1e9d 0x1e05 0x1)
terminate called throwing an exception(lldb)

I’m using a StoryBoard and the issue is that I had more than one prototype cell visible in the table view. The error says that there is more than 1 cell with the same Identifier:

The solution is to set the number of Prototype Cells to the actual number of different types of cells you have (the ‘type’ being identified by the ‘identifier’). In my case, I just had 1 type of cell and so I set the number of Prototype Cells to 1.

Our Tool “Transcribe” Is Featured on TheNextWeb

Aimed at journalists, students or anyone with a need to convert interviews and such like to the written from, Transcribe does exactly as it says on the tin. And it’s so incredibly simple to use. … 

I used this app for the first time this week and, well, it was a godsend.

Source: http://thenextweb.com/apps/2012/08/04/transcribe-an-awesome-audio-transcripti…

Facebook Login With Only Email and Html7magic?

I happened to stumble on Carl’s Jr.’s Facebook page today and particularly on this post (for no particular reason, I should add): 

http://www.facebook.com/91702965455/posts/10151579104835456

and I quickly noticed the login area on the top right. It only had an email field and a login button. (I was not signed into Facebook when I visited the page.) For a brief moment I thought Facebook had finally done away with the concept of passwords somehow!

So I clicked on the login button and it took to me the standard Facebook login page. Oh well, passwords are here to stay.

But here’s the question: why would Facebook do this? Why would they place only an email field on that page and not a password field? Isn’t it an extra step for users to click on the login button and then be directed to another page to enter their password?

And then I wondered if this was a CSS issue, and looked at the source code: 

And I was able to confirm that it wasn’t a CSS issue causing the password field to be hidden. There wasn’t any input field for a password on that page. 

And now I found something else that’s interesting. A class named “html7magic”. What am I to expect?! Is FB out there using HTML 7 secretely and somehow translating their HTML7 code to HTML5 to work with current browsers?! 

Scribble Joins the Ranks of Evernote and Springpad on the Chrome Web Store!

I was curious how people casually browsing through the Chrome web store would discover Scribble. And so I opened up the Chrome Web Store and browsed through the first few tile sets of apps on the home page. I didn’t find Scribble there. Oh well, I told myself, referals from news sitesblogs and other sites are our primary traffic source I guess.

Then I went to the Utilities section since we had posted Scribble under the Utilities category and there it was - Scribble featured right on top of the Utilties section with the biggest banner we had uploaded. There were three apps featured on the top in rotation:

  • Evernote - A major player in the note-taking app category
  • Springpad
  • and SCRIBBLE

So that’s how people find out about Scribble! 

Scribble Featured on PCWorld!

Exciting times as the number of Scribble users increases to 27,000! I wonder how many of those 27,000 users would pay for a pro-version of Scribble.

5 Business-Savvy Chrome Apps

Still using Windows’ notepad to preserve thoughts and ideas? The horror. Scribble brings sticky notes to your browser, complete with alarms if you have time-sensitive notes.

Even better, it works offline, so your notes are accessible even when the Internet is not.

Source: http://www.pcworld.com/businesscenter/article/253433/5_businesssavvy_chrome_a…

Job Posting for Building Pixza

And so I was looking at the analytics for Pixza. There was a referral from gamedev.net. I was curious to find out where Pixza was mentioned on gamedev.net. And I found this post: http://www.gamedev.net/classifieds/item/306-looking-for-html5-programmer/.

Someone wants to hire a person to build a game similar to Pixza! I wonder why he mentions that we didn’t respond to his attempts to get in touch with us.

I need someone to partner with for a small project that  should not take more than 1-2 weeks  (it might take longer idk)

- How about a year and a half in the midst of undergrad college work? 

Here’s wishing our dear friend all the best in his endaevor. May be, given the availability of platforms like node.js, socket.ioPusher and Meteor today, building Pixza from scratch might not take such a long time. We didn’t have these luxuries when we started working on Pixza. All we had was this Richard Jones’ article to start out with.