Posts

[Level 3] Using vim to replace ^M with newline

I searched it on net Under unix, inside vim, ^V + gives me a ^M which is the \r character. Wish this helps. regards, Stanley Huang

[Level 1] vim settings.

set nu set ic set nolist set tabstop=4 Wish this helps. regards, Stanley Huang

[Level 3] Schema management tips for MySQL

{Database management tips} [in source save] 4 files in source save. 1. schema: => by release version. => only create table/procedure, no alter, no insert, no drop ...etc. => use mysqldump -d. 2. schema change log: => by date. => split into two parts. one is schema(except foreign key), and put it on the top. Another is foreign key, and put it on the tail. => must add drop tabele before create, and must be sequencial by date. => modify manually. 3. data: => by release version. => only insert, no update, no delete...etc. => use mysqldump. 4. data change log: => by date. => could use insert/update/delete, but delete(truncate) must before update than insert, and must be sequencial by date. => modify manually. [use case] how to create patch: a: use schema comparision. => takes time, but more efficacy. b: use changelog comparision. => esay way, but suffer performance. so, use a to build patch, but use b to verify result....

[Level 3] Rownum/auto_increment, substring, reverse index, case and mutli-table update for MySQL

-- [rownum] -- set initial equipment_id select max(equipment_id) from device into @rownum;   -- insert into equipment insert into device select @rownum:=ifnull(@rownum,-1)+1 from device; -- [multi-table update] update event inner join device using (deviceid) inner join equipment on device.macaddress = equipment.mac_address set event.equipment_id = equipment.equipment_id where event.eventtypeid < 400 ; -- [reverse index] select instr(c,','), substring(c,1,instr(c,',')-1), reverse(substring(c,1,instr(c,',')-1)), reverse(substring(reverse(substring(c,1,instr(c,',')-1)),1,instr(reverse(substring(c,1,instr(c,',')-1)),'@')-1)) from ( select 'a@1:2:3:4,x,y,z' as c union all select '1:2:3:4,x,y,z' as c union all select 'a@b@1:2:3:4,x,y,z' as c ) as t -- [case] update types set id =   ( select case types.id when 1 then 10001 when 2 then 10002 when 3 then 10003 when 4 then 10004 else types.id...

[Level 2] Use mkisofs to backup your filesystem.

You can use mkisofs to backup your filesystem. # mkisofs --allow-lowercase --allow-multidot -r -o ./stanley.iso ./stanley # mount -F hsfs `pwd`/stanley.iso /tmp/t Wish this helps. regards, Stanley Huang

[Level 3] MySQL Stored Procedure Template.

This is my stored procedure template: -- myparent_block:BEGIN   -- declare variables   DECLARE fetch_id INT DEFAULT NULL;   DECLARE loop_done BOOLEAN DEFAULT FALSE;   -- declare conditions   DECLARE condition_not_found CONDITION FOR SQLSTATE '02000';   -- declare cursors   DECLARE cursor_myparent CURSOR FOR     SELECT id FROM myparent WHERE serialnumber=sn;   -- declare handlers   DECLARE continue HANDLER FOR condition_not_found     SET loop_done := TRUE;   OPEN cursor_myparent;   REPEAT     FETCH cursor_myparent into fetch_id;     DELETE FROM mychild WHERE pid=fetch_id;   UNTIL loop_done END REPEAT;   CLOSE cursor_device;   DELETE FROM myparent WHERE fkid=fetchfkid; END myparent_block; -- Wish this helps. regards, Stanley Huang

[Level 3] South for Django 1.2

in south project: http://south.aeracode.org/docs/databaseapi.html#database-specific-issues South automatically exposes the correct set of database API operations as south.db.db ; it detects which database backend you’re using from your Django settings file. It’s usually imported using: from south.db import db If you’re using multiple database support (Django 1.2 and higher), there’s a corresponding south.db.dbs dictionary which contains a DatabaseOperations object (the object which has the methods defined above) for each database alias in your configuration file: from south.db import dbs dbs [ 'users' ] . create_table ( ... ) You can tell which backend you’re talking to inside of a migration by examining db.backend_name - it will be one of postgres , mysql , sqlite3 , pyodbc or oracle . It should worth to try~ Wish this helps. regards, Stanley Huang