Jul 31, 2009

Extracting all possible info about MySQL database

We need a tool which can extract all possible info about MySQL database to have it as a source for another tool which compares extracted info to an existing database and executes necessary changes. Works goes all around very well. Here is just a link to some useful information: http://code.openark.org/blog/mysql/useful-database-analysis-queries-with-information_schema

Jul 29, 2009

Debugging of MySQL stored procedures

I ran into problem earlier today with an SP. I had no clue how to find out what was wrong. I started to search for some debugger for MySQL's SPs, but found ones for a Windows only. Then I found following post. I found it most helpful: http://gilfster.blogspot.com/2006/03/debugging-stored-procedures-in-mysql.html

Jul 28, 2009

Distutils

Looking at distutils to publish some of the code I've written. So far so good. Here are my leads:
http://docs.python.org/distutils/
http://linux.com/archive/feature/118439
http://wiki.python.org/moin/Distutils/Tutorial

Jul 27, 2009

Mac OS and bluetooth proximity automatization

The colleague of mine started to look around on how to lock screen of Mac when he has to leave the computer. It is sad that there is no such easy solution for Mac as there is for WinTels. However among many interesting solutions there is one which is very intriguing - to use bluetooth enabled device to lock/unlock computer for you.
Here is a link describing the solution for Ubuntu:
http://technogra.ph/20080309/sections/downloads/blueproximity-walking-away-to-lock-your-computer/
And here are an articles focusing on Mac OS:
http://hollington.ca/technocrat/?p=44
http://www.makeuseof.com/tag/automate-your-mac-your-home-with-proximity-mac-only/
http://theappleblog.com/2009/06/11/how-to-proximity-automation/
http://mathamlin.com/speak/proximity-jacksms-applescript-mac-fun/

Jul 21, 2009

Frustrated from Lightroom

Lightroom keeps crashing on me. Whenever it is to do anything with Nikon D70 NEF format. Damn.... I dunno what to do....

Jul 20, 2009

More stored procedures in MySQL

Recently I had to do some maintenance on MySQL database for a customer. It is all for his e-commerce web site. The issue was that all brands are stored separately in a table. However there is several synchronization tools that update site's content. So it happened that we have plenty of the brand names with different casing (e.g. Panasonic and PANASONIC).

As there is few different programs talking to the database written in different programing languages I decided to centralize the functionality in the DB itself. The issue is that we are using UTF-8 names of brands and depending on a language and its version the eastern european characters are being lowercased differently.

So I made another column for storing the hash. The issue here is to have a central code for lowercasing and then hashing string (the brand name) before it is stored to the DB. For this I created following function:

CREATE FUNCTION get_brand_id (s VARCHAR(255)) RETURNS BIGINT (20)
DETERMINISTIC
BEGIN
DECLARE my_hash VARCHAR(255);
DECLARE out1 BIGINT(20);
SET my_hash = md5(lower(s));
INSERT IGNORE INTO brands SET name=s, hash=my_hash;
SELECT brand_id INTO out1 FROM brands WHERE hash=my_hash;
RETURN out1;
END


Then I needed to create hash for all existing brands. So I made following procedure:
CREATE PROCEDURE hash_brands()
BEGIN
DECLARE my_hash, my_name VARCHAR(255);
DECLARE my_brand_id BIGINT(20);
DECLARE is_done INT DEFAULT 0;

DECLARE cur CURSOR FOR
SELECT brand_id, name FROM BRANDS;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET is_done = 1;

OPEN cur;
WHILE NOT is_done DO
FETCH cur INTO my_brand_id, my_name;
SET my_hash = md5(lower(my_name));
UPDATE brands SET
hash=my_hash
WHERE brand_id=my_brand_id;
END WHILE;
CLOSE cur;
END
Then I just neede to change unique key from name to hash field. Now I need to change couple of scripts to use my function or better to trigger insert on the brands table to use my function. Will see about that.