Archive for April, 2007
Hello MATE !
Saturday, April 21st, 2007While browsing thought the TextMate bundles I saw that the editor supports SQL .. not only the syntax but you can run queries from within TextMate. Currently it supports mysql, postgres and sqlite, I only tested mysql and it’s quite nice. I used to write the sql statements in TextMate because of the syntax highlighting and code completion copy the resulted sql query and run it in the mysql client but now I run it straight from the editor. There is one thing that TextMate lacks and that’s the display of the query execution time but that can be easily fixed by adding a simple command in the bundle editor.
For a simple configuration of the mysql client you have to add some shell variables in the TextMate preferences window shown below:

That’s all that you need to configure in order to use the mysql functionality in the editor. Of course you also need the mysql client tools installed on the local machine because TextMate uses the mysql command to connect and execute the query. By default mysql places the client tools in “/usr/local/mysql/bin/” which by default is not in the $PATH so you either add the path in the variable or just create a symbolic link to it in “/usr/bin/” using this command “ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql”. Then you need to create new document set the language to SQL create/paste the query select it and press ctrl+shift+q, this executes the current line/current selected block. Here’s an example:
As I said before…the problem is that we don’t see the total execution time of the query, but the problem can be easily solved by editing the command in the Bundle editor, the script for the command is actually a bash script so if you are familiar with bash scripting you can add all the stuff you want there. But we are interested in placing the “time” command in front of the mysql command.
The time command placed in the bundle editor will display the execution time of the mysql command, but for more information just type “man time” in the console. Now if you re-run the sql you will see some strange numbers at the end of the result.
The main reasons that made TextMate famous is the fact that it uses the shebang line which makes it possible to write the commands in any scripting language supported by the current machine (Perl, Python, Ruby …), but for more information on TextMate you can check out Macromates.
Space. The final frontier …
Friday, April 13th, 2007For a few days now I started working with MySql spatial functions and I discovered some stuff that you don’t find in the official documentation regarding indexes. In Mysql there is a special type of index that should be used when you have Geometric based types like points, polygons and other shapes, the index type is called SPATIAL INDEX. Now there is a problem with this type of index, let’s say that we create a simple table for testing:
CREATE TABLE `tbl_city_locations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) );
INSERT INTO tbl_city_locations(name) VALUES ('Place 1'); INSERT INTO tbl_city_locations(name) VALUES ('Place 2');
Let’s put in the location column
ALTER TABLE tbl_city_locations ADD COLUMN location POINT;
Now let’s say that we realized we are missing an index on the location column. No problem we go ahead and add it:
ALTER TABLE tbl_city_locations ADD SPATIAL INDEX (location);
at this point you will receive an error message stating that the column must be NOT NULL. No problem so far, we just add that too
ALTER TABLE tbl_city_locations MODIFY COLUMN location point NOT NULL;
now we can re-run the previous query … the index query but instead we get a very strange error message that says: “Unknown error”. So what happens here, although the column is not null the value for that column is empty and Mysql can’t add an spatial index on an empty geometric type, first we need to specify some values for that column :
UPDATE tbl_city_locations SET location = GeomFromText('POINT(0 0)');
this way we ensure that the columns have a value and we can safely add the index.
Ok, I simplified the example but imagine working on an existing table with a large set of rows (around 24 million) in which you have to compute the coordinates from other columns, receiving the “Unknown error” gets pretty frustrating. Anyway .. problem solved
Eye on iPod
Tuesday, April 10th, 2007Apple just announced that they sold 100 Million iPods since 2001, this makes the company the biggest seller of digital players in all the history. Since it’s been launched iPod won several awards for excellence and best product.

Application
Wednesday, April 4th, 2007After my little incident a few weeks ago I decided to create an application that will back-up my local svn data. Said and done, the application is written in Perl and so far it does a pretty good job. I set it up do to a back-up every hour, maybe that’s a bit to often but for now it’s ok. Feel free to download it, for assistance and bugs post a comment on this article.



