VIM and Mysql integration

I use VIM with additional configuration instead of IDE. That configuration includes code explorer using ctag, syntax checking for PHP and Perl and run Perl scripts (syntax highlighting is not a subject of discussion ;)). Also I should run Mysql queries often. So, I decided to add integration with Mysql to VIM. I managed to do that thanks to that simple solution. Just add this code to your .vimrc:
to select database:
map <C-d> :call SwitchDB()<CR>
:function SwitchDB()
: let g:current_db = input("Database > ")

to run query:

map <C-m> :call Doquery()<CR>
:function Doquery()
: if !exists("g:current_db")
: call SwitchDB()
: endif
: let query_string = input(g:current_db . " > " )
: if query_string != ""
: exe "!mysql " . g:current_db . " -e \"" . escape(query_string, '"') . "\""
: endif

So, when you press Ctrl-d the VIM gives you a prompt to type database name, Ctrl-m will run query. Sure you can use the your preferable combinations of keys. Also you may extend the login functionality by adding prompt for database host and user or hardcoded that information in the SwitchDB() function.

Using VIM to construct queries in the Mysql shell even much easier. Just specify VIM as default editor:
export EDITOR=vim
After that type \e in the Mysql shell. It’ll bring you VIM window where you’ll able to type your query. To finish with editing just type ZZ as usual. To run built query type ; and press Enter.

As result we’ll have possibility to run Mysql queries directly from VIM and using VIM to create queries in the Mysql shell.

Perl, C++, mysql and UTF8

Recently I finished with Russian translation of LinuxMCE UI. But as I know now it was the easiest part. After addition Russian descriptions in the database I faced with problem of displaying them. I made a research and found following. To have UTF8 data in the mysql database a few steps should be done:

  • default charset for server should be set to utf8 in the /etc/mysql/my.cnf:
  • default charset for client should be set to utf8 in the /etc/mysql/my.cnf:

    After that the charset for mysql shell will be UTF8 but not latin1 as in the stock version.
  • default charset for desired database should be set to utf8:
    alter database pluto_main charset=utf8;
  • default charset for desire table should be set to utf8:
    alter table Text_LS charset=utf8;
  • default charset for all text fields in the table should be also set to utf8:
    alter table Text_LS modify column Description longtext CHARACTER SET utf8 COLLATE utf8_general_ci
  • the client application should pass UTF8 flag to tell mysql about charset for connection. Here is a Perl example:
    my $dbh = DBI->connect("dbi:mysql:pluto_main;host=localhost", "root") or die "Cannot connect to database: $DBI::err!";
    $dbh->{'mysql_enable_utf8'} = 1;
    $dbh->do('SET NAMES utf8');

To display UTF8 text in the Perl script just set UTF8 charset for STDOUT:
binmode STDOUT, ":utf8";

But with LinuxMCE the situation is more complicate. Its UI is developed on C++. So, After a googling I found the way to set UTF8 for connection. There is a function mysql_options() in the Mysql C API. It should be called after mysql_init() but before mysql_connect() or mysql_real_connect() and allows to set desire charset:
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, 'utf8');
and run some SQL statement when connecting to the MySQL server:
mysql_options(&mysql, MYSQL_INIT_COMMAND, 'SET NAMES utf8');
But it didn’t help. The Russian text is still displayed as question mark. So, have to dig LinuxMCE code to solve that. Otherwise the Russian translation won’t be added.

IMDB::Film v0.42 is out!

I just released a new version of IMDB::Film – 0.42. Following changes were done since previous version:

  • added retrieving of plot keywords for the film;
  • fixed issue with retrieving of movie’s plot contained links;
  • fixed issue with displaying special HTML symbols;
  • added test for the plot keywords;
  • fixed POD documentation.

To implement correct displaying of special HTML symbols two new modules were added into dependencies list – use Text::Unidecode and HTML::Entities.

You can send bugs or ideas to improve the module via CPAN RT.

Maemo CTags package

VIM and Ctags
VIM and Ctags

Recently I built Exuberant Ctags package for OS2008. It might be useful for all who develop directly under Scratchbox using VIM. Ctags offers a possibility to explore methods from the opened files similar way as IDE (see screen-shot).

The CTag package can be found on the download page under section Packages for Nokia770/N800/N810. The config file for VIM with supporting of CTags can be downloaded there as well.

Eclipse plugins for Maemo Development

Maemo Team recently released a set of plug-ins for Maemo Eclipse integration. It allows developers to use Eclipse IDE to develop and test Maemo applications. Actually, the set contains following parts: maemo PC Connectivity, maemo ESBox plugin for Eclipse IDE and maemo Pluthon plugin for Eclipse IDE.

Maemo PC connectivity makes connection between developer PC and Internet Tablet. Maemo ESBox plugin for Eclipse IDE integrates maemo SDK Scratchbox based development environment to the Eclipse development environment. So, developers can do all their work from Eclipse IDE. Maemo Pluthon plugin for Eclipse IDE allows to develop and test Python application directly on Internet Tablet without using maemo SDK and Scratchbox.

As I see that set of plug-ins will make the process of Maemo development easier and more suitable. I’m going to install Eclipse IDE on my fresh Kubuntu 7.10 and use Maemo PC connectivity with Maemo ESBox plugin for LinuxMCE Orbiter for Nokia770/N800/N810.

[via MaemoGeek]

Perl on Rails

BBC developers has announced its own Perl MVC framework – Perl on Rails. As you can understand from its name the new framework is similar to Ruby on Rails. The BBC Programmes was developed using the Perl on Rails.

Actually, there is a few Perl MVC frameworks like Catalyst, Ganty, Maypole or Jifty. If Perl on Rails will be released as open source it’ll make the popular program language more attractive to develop enterprise applications.

Accessing the Nokia N800 camera

Linux-based Internet Tablet Nokia N800 is very popular. Even coming N810 is not going to replace it completely (I’m not talking about windows-based Origami). Using Maemo SDK it’s fairly simple develop new applications or porting existing ones. For sure to be success you need a right documentation. Following article from explains obviously how to use N800 camera API.

P. S. The easiest way IMHO to setup Maemo development environment is downloading the Maemo SDK VMware Appliance. It can be run with free VMwave Player which available for both: Linux and Windows.

Qtopia Greenphone

The well-known company Trolltech, which develops Qt, has announced his Qtopia Greenphone. This smartphone is unique because it’s open for development and upload new mobile applications. The specification is quit similar to others: quad band GSM/EDGE handset that boasts a QVGA touch screen display, 1.3-megapixel camera, 317MHz XScale processor, 128MB ROM, 64MB RAM, Bluetooth, and a miniSD card slot.

Greenphone will ship with source code for all the native phone applications in addition to development tools and the phone itself

It’s cool and geek smartphone but the price is also cool – $700! So, if you have this money and want to develop for mobile Linux phones go ahead! The Greenphone is expexted to sell on the middle of this September.


Updated: Trolltech announces pricing for Greenphone kits: from $695 to $890