Author Archives: alwold

MySQL Feature Bingo

Using newish features in MySQL is kind of like playing bingo. Especially if you don’t control the version of the server you are working with. Here are some excerpts from the official manual that illustrate this point:

  • Support for triggers is included beginning with MySQL 5.0.2.
  • Before MySQL 5.0.10, triggers cannot contain direct references to tables by name.
  • The DEFINER clause specifies the MySQL account to be used when checking access privileges at trigger activation time. It was added in MySQL 5.0.17.
  • From MySQL 5.0.17 on, MySQL checks trigger privileges like this:
  • In MySQL Server 3.23.44 and up, the InnoDB storage engine supports checking of foreign key constraints
  • As of MySQL 4.1.1, mysqldump generates dump files that take advantage of this capability automatically when they are reloaded.
  • Views (including updatable views) are implemented beginning with MySQL Server 5.0.1.
  • Beginning with MySQL 5.0.3, the grant system takes stored routines into account as follows:
  • As of MySQL 5.0.1, a stored procedure or function is associated with a particular database.
  • Multiple SELECT statements generate multiple result sets, so the client must use a MySQL client library that supports multiple result sets. This means the client must use a client library from a version of MySQL at least as recent as 4.1.

…and the list goes on of course.

Online Learning Systems and Search

Back when I was a CS undergrad, Blackboard was not very popular yet (at least among the nerdy CS faculty).  Most classes had a class web site involving a tilde, the professor’s username and some quick and dirty HTML.  They were generally extremely simple, concise, and easy to navigate.  Additionally, they were open to the public either out of intention or lack of effort to secure them.  As a result, one could visit the ASU web site and search for a class like CSE 340 and find a collection of class web sites with syllabi, assignments, etc.  This was really useful for getting a feel for a class and/or professor’s style before actually registering for it.  You could read the syllabus and see what material would be covered, whether group work would be involved, how it would be graded, etc.  It was all very nice.

Now, everyone uses Blackboard and all of the course resources are on lockdown (perhaps for the reverse reasons as they were previously public).  You pretty much can’t find anything useful if you search for a class number on the ASU web site, based on my quick testing.  I suppose this is a good thing, because many professors consider such materials part of the intellectual property and don’t want them to be freely available, but I think quite a few wouldn’t mind if prospective enrollees were able to read through the course materials.  Perhaps an opencourseware system is the answer.

Sakai and the App Builder plugin


So, I am trying to jump into Sakai development by writing a tool that can keep a log of email conversations between instructors and students. Since I’m new to Sakai, I will probably end up starting over a few times before I figure out the best way to develop. I decided, at the advice of a coworker to start using RSF and the App Builder plugin. So far, it’s pretty intimidating. I started by doing a full CRUD framework, since that is one of the options for the plugin. I think digesting RSF and the way they set up their Hibernate stuff at the same time is a bit much, so I’ve gone backwards to starting with their hello world app, which I’m going to try to convert into a number guessing game to give me a handle on session management, RSF, etc. It seems like there is a pretty serious lack of any tutorials that go beyond modifying the hello world to say something different. The whole video tutorial thing is pretty cool, so maybe I’ll make one if I get far enough along. But for now, I can recommend starting with hello world if you don’t know RSF already. I can also say that RSF looks pretty nice so far. Much simpler than JSF but some of the same good ideas.

Leopard terminal color rotate

I used to use this trick to rotate colors between terminal windows. When I upgraded to Leopard, the windows stopped being transparent, which sucked. I have finally come up with a solution that uses a different technique. You will need to create several terminal profiles for different color schemes. The cool thing about this way of doing it is that you can use different transparency settings for different colors. You should call the new profiles “rotate X” where X is a number. Then you install this script as /Users/alwold/setcolor.sh or some such thing:

#!/bin/sh
if [ -e ~/.lastterm ]; then
LAST_PROFILE=`cat ~/.lastterm`
fi
if [ “$LAST_PROFILE” == “” ]; then
LAST_PROFILE=1
else
LAST_PROFILE=$(($LAST_PROFILE+1))
fi
if [ “$LAST_PROFILE” == “6” ]; then
LAST_PROFILE=1
fi
echo tell application \”Terminal\” to set current settings of first window to settings set \”rotate $LAST_PROFILE\” |osascript
echo $LAST_PROFILE > ~/.lastterm

Finally, you need to call that script from your .profile (or you can just put the whole script in your .profile). Also, the script assumes you have rotate 1 – rotate 5. If your number of profiles is different, change the 6 accordingly.

Drupal 5.7 on Resin 3.1.4

So, in case you didn’t hear, Caucho has a component called Quercus built into their Resin product which is a pure Java PHP interpreter. With this product, it is claimed that one can achieve 4x performance gains with Drupal (phew…that was a lot of links). The concept of being able to call into Java code as well seems appealing to me. Although Drupal is now at version 6.0, I tried it with 5.7, since I know most modules work with 5.x, but I’m not sure about 6. Here’s a quick guide…

  1. Download Caucho Resin 3.1.4 (open source)
  2. Download Drupal 5.7
  3. Unzip Resin
  4. Put a copy of mysql JDBC driver in the lib directory under resin
  5. Put a copy of JavaMail mail.jar in the lib directory also
  6. Create mysql database for drupal and a user to access it
  7. Go into webapps under the resin directory
  8. Unzip drupal here
  9. Rename drupal-5.7 to drupal
  10. Create WEB-INF/resin-web.xml under the drupal directory:



    jdbc:mysql://localhost:3306/databasename
    username
    password








    index.php








  11. Modify drupal/sites/default/settings.php
    • Change database name
    • Change username/password
  12. Start resin (java -jar lib/resin.jar)
  13. Go to http://localhost:8080/drupal/install.php (you need to explicitly go to install.php, since drupal gets confused about the modified settings.php, but no data in the db)
  14. Your drupal should now be functional

MySQL FTW

This little gem I encountered today speaks for itself…

mysql> select count(*) from Principal where status = ‘ ‘ and status = ”;
+———-+
| count(*) |
+———-+
| 39021 |
+———-+
1 row in set (0.35 sec)

Xen, HVM, and running out of memory

I think I’m in an uncommon situation, but I needed to set up lots of HVM (full virtualization) hosts on my Xen install, since the dom0 is a different distribution (debian) than the domU hosts (Fedora). With paravirtualization, the “balloon driver” takes care of memory allocation, I think. But in HVM mode, you actually have to have the amount of memory required by your VM available outside of dom0. If you don’t have enough, you get an error like this:

Error: Error creating domain: (12, ‘Cannot allocate memory’)

It took forever to figure this out, but the key is to limit dom0’s memory, so that you have enough for your VMs. The machine I’m working with has 16 gigs, so I limited dom0 to 1 gig by using this line in the menu.lst for grub:

kernel /xen-3.0.3-1-amd64.gz dom0_mem=1024M

Yours will probably look different, but the key is the dom0_mem parameter. Once you add that, you will have 15 gig left for allocating virtual machines.

Pictures

I think my blog is really boring because it doesn’t have any pictures.  I’m jealous of those people that get themselves to carry their camera and take random pictures of interesting stuff during their day.  My brother Bob was doing a picture a day project, but that seems to have died.  What I’d like to do, though, is capture a photo that complements whatever I happen to be writing about, as opposed to the picture being the star of the show.  I have a really nice camera, but it is too big to carry around all the time.  If you feel like getting me a smaller one, have a visit to my Amazon wish list and pick one up :).

Taking photos in Java with the Blackberry

According to this press release, RIM has released the APIs needed to take photos with the Blackberry camera in Java apps.  As far as I have figured out, they have enabled the API to start the camera app, but not an API to listen for new photos.  That isn’t particularly horrible, because you can use the File Connection API to open the Blackberry filesystem and monitor for new photos.  The only tricky part is knowing when the camera app has relinquished control back to your app, so you can start looking for the new photos.

Another post about my favorite database

Relational databases are really cool. When you get experienced with them, you can leverage all sorts of features to make sure your data is solid. A good database schema will provide a good check against buggy code trying to mess up your data. One of my favorite ways to enforce integrity is the usage of NOT NULL constraints. I recently added some to a MySQL database I’m working on, and I noticed something unusual…

mysql> alter table SERVICES add SERVICE_KEY varchar(64) NOT NULL UNIQUE;
Query OK, 1 row affected (0.16 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> describe SERVICES;
+------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+----------------+
| SERVICE_ID | bigint(20) | NO | PRI | NULL | auto_increment |
| DESCRIPTION | varchar(128) | YES | | NULL | |
| COMMENTS | varchar(64) | YES | | NULL | |
| ACTIVE | varchar(3) | YES | | NULL | |
| CREATED_BY | varchar(128) | YES | | NULL | |
| CREATED_DATE | datetime | YES | | NULL | |
| UPDATED_BY | varchar(128) | YES | | NULL | |
| UPDATED_DATE | datetime | YES | | NULL | |
| TYPE | varchar(4) | YES | | NULL | |
| URL | varchar(1024) | YES | | NULL | |
| MAX_TRAN_THREADS | smallint(6) | YES | | NULL | |
| MAX_SYNC_THREADS | smallint(6) | YES | | NULL | |
| SERVICE_KEY | varchar(64) | NO | UNI | | |
+------------------+---------------+------+-----+---------+----------------+

As you may notice, the default value is somewhat nebulous on this new column. Normally the default will show NULL, which is good. In this case, it looks like it is either “nothing” which I would equate to NULL, or ”, which is horrible because it breaks the whole purpose of having the constraint. Since I trust MySQL to generally do the wrong thing, I test it:

mysql> insert into SERVICES (SERVICE_ID) values (NULL);
Query OK, 1 row affected, 1 warning (0.00 sec)

And of course, it is taking my null SERVICE_KEY value and turning it into ”. So now, if my app is broken and trying to insert null into SERVICE_KEY, MySQL will save the day and “fix” the data, completely eliminating any errors from being produced that would have revealed the bug in my code.

To quote the famous fashion designer Mugatu, I feel like I’m taking crazy pills! Everyone seems to love MySQL, but it seems completely obvious to me that it is not even a candidate to be considered when writing anything moderately serious.