Gordon P. Hemsley

Linguist by day. Web developer by night.

Posts Tagged ‘SASHA’

PHP, MySQL, and the BIT field type

Posted by Gordon P. Hemsley on February 8, 2010

As Dave Humphrey once taught me:

When you do a search, and it comes back with no results, it’s a sign that you need to write something.

This is an issue that I came across while testing SASHA (which is available for you to try out, by the way), and I didn’t know if it was a bug or a feature. I could find no mention of it anywhere, and the people in the #mysql IRC channel on FreeNode weren’t especially helpful in helping me get to the bottom of it.

What is the issue, you ask? Well, even that in and of itself is a question, because I don’t know whether it’s a bug (or feature) in PHP or MySQL. However, I’m inclined to think it’s the latter, and I’ll get to why in a moment.

But first, some background. The table that SASHA uses to store schedules uses the BIT field type for keeping track of which days of the week a schedule occurs on. I figured it’d be easiest to use a 7-bit field and just flip a bit for each day of the week. And that worked fine for me on my local test server. But then I had a colleague test SASHA out on his test server, and things went a little wacky.

It took a little while to figure out what was causing our problem, and we finally got to the bottom of it: I was using MySQL 5.0 and he was using MySQL 5.1! Apparently, between 5.0 and 5.1, the return format of a BIT field changed from the literal binary data (output in the browser as a character, because the browser didn’t know it wasn’t) to a decimal representation of that data.

The first problem with that was that I had no idea there was a possibility of getting anything but the raw binary data I was getting on my server. The second problem was coming up with a straight-forward solution to detecting whether the database was feeding us raw binary data or converted decimal data. There was no direct way to do this, but I figured out the next best thing. A simple way to check what kind of data we’re getting is to find out whether it converts cleanly to an actual character. Here’s an excerpt from SASHA that demonstrates:

// MySQL 5.0 returns bit as binary, while MySQL 5.1 returns decimal
if( $days == chr( ord( $days ) ) )
	$input = 'binary';
	$input = 'decimal';

That seems to do the trick when it comes to handling unpredictable BIT field data.

(Again, I can’t guarantee that this isn’t actually a PHP issue, but I seem to recall us both being around the same version of PHP.)

If you have any insight into the matter, please do leave a comment.

Posted in Mozilla, Open Source, SourceForge | Tagged: , , , , , , , , , , , , , , , | 4 Comments »

SASHA 0.1.0-RC1 Released

Posted by Gordon P. Hemsley on July 12, 2009

It’s been a while since I’ve updated here, but I’d like to take the opportunity now to announce the first ever release of the Student Assignment, Scheduling, and Homework Assistant. SASHA 0.1.0-RC1 was released a few weeks ago for testing purposes, before 0.1.0 final is released.

Here is the official announcement:

This marks the first ever release of the Student Assignment, Scheduling, and Homework Assistant. SASHA is a tool designed to help students keep track of their assignments, tests, and other time-sensitive items. This release candidate includes features related to courses in educational institutions, including schedule items, assignments, and tests.

This release candidate is also a call for testers to help ensure that the release is relatively bug-free, and in a usable state. If no major defects are found, then the 0.1.0-RC1 code will be re-released as 0.1.0; else, another release candidate will be forthcoming.

Since SASHA requires institution-specific packages to operate efficiently, this release is mostly geared towards students at the University of Vermont (UVM), as that is the only package that is currently available. Packages must be downloaded separately.

SASHA Website: http://sasha.sourceforge.net/
SASHA Project Page: https://sourceforge.net/projects/sasha/
SASHA 0.1.0-RC1 Files: https://sourceforge.net/project/showfiles.php?group_id=163392&release_id=632770
SASHA 0.1.0-RC1 Release Notes: https://sourceforge.net/project/shownotes.php?group_id=163392&release_id=632770
SASHA Institution Packages: https://sourceforge.net/projects/sasha-pkg/

(This announcement was also submitted to the Slashdot Firehose.)

I’m currently looking for testers to give SASHA a beating to ensure that I haven’t missed any bugs. I’ve been using everything personally (i.e. dogfooding it) since I began writing it, but that also means that I may be too close to it to find the kinks. You may attempt to set up your own instance of SASHA, if you’d like, but be sure to read the instructions set forth in docs/INSTALL. You’ll be lost otherwise.

If you’re worried about setting SASHA up yourself, but are willing to try to help anyway, I’ve also set up a demo at YourSASHA.com for testing (and demonstration) purposes. If you have any comments, questions, suggestions, or any other feedback at all, please do not hesitate to join me in #SASHA-dev on Freenode. I’ll help you out.

Please forgive me for tagging this with Mozilla. While it’s not directly Mozilla-related, it is education-related, so I hope you’ll let it slide. More importantly, I hope SASHA will be able to help you at some point in the future.

Posted in Mozilla, Open Source, SourceForge | Tagged: | Leave a Comment »