Archive for the ‘General’ Category

How To: Send SQL commands to a database in VIM

Thursday, March 29th, 2007

A simple way of sending SQL to your database from everyone’s favourite editor Vim, without any plugins or macros.

Firstly we need to add a custom command to our .vimrc, open it up and add the following line, where:

  • CommandName - The name of your command
  • Username - The username for this database
  • Password - The password for this database
  • Database - The name of the database
:command -range=% CommandName :<line1>,<line2>w !mysql -uUsername -pPassword Database -t

For example:

:command -range=% SendDB :<line1>,<line2>w !mysql -utest -ptest test -t

That’s all the setting up we need. As you can see, after the exclamation mark is just the regular MySQL Command line tool and various options.

Fire up vim and start editing your sql.

# vim test.sql

As an example, here’s some simple SQL.

-- Drop existing table
DROP TABLE IF EXISTS `test`;

-- Create table
CREATE TABLE IF NOT EXISTS `test` (
    `test_id` INT(11) NOT NULL auto_increment,
    `name` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`test_id`)
);

-- Add our data
INSERT INTO `test`(`name`) VALUES('dave');

-- Get it back out again
SELECT * FROM `test`;

If we’re happy with what we’ve written, while in command mode, type :SendDB, or whatever you called your command and hit enter. If it works, you’ll see something like this.

~/test.sql[+][sql] unix
:SendDB
+---------+------+
| test_id | name |
+---------+------+
|       1 | dave |
+---------+------+

Press ENTER or type command to continue

You can always add to the custom command, in particular piping the output to less can be effective for larger result sets.

Related Searches, Web Pages and Videos on Adsense

Friday, February 23rd, 2007

I’ve just seen the following Adsense block on the Ubuntu Forums, not seen one before. Click the thumb to see the full size image.
Related Searches, Web Pages and Videos on Adsense

Get paid to search the web with SlashMySearch

Friday, February 16th, 2007

SlashMySearch is a internet search engine that pays it uses as they search. An interesting thought, I’m sure there are plenty of sites like this out there, but I thought I’d give it a try. I came across it at CJCM and IT via ProBlogger.

Simply signup and set your unique URL as your homepage. I don’t think it’s everybodies cup of tea and it might get a little annoying but it’s got to be worth a try. They also run a referral program, so tell your friends!.

DaveWP Wordpress Theme

Tuesday, February 6th, 2007

DaveWP screenshotI figure it’s about time I updated my blog and designed a new theme, but before I do I thought I would tidy this one up and release it. just like I told ‘Big John’ from Position is Everything I would do well over a year ago. It’s far from perfect, but I kind of like it and it made a good project for me to experiment with some new design technologies.

The layout is based on the The Jello Mold Piefecta Layout, being a 3 column, source ordered, fixed width, equal height column layout. The template also uses sIfr ( to produce rich and accessable headings.

Looking back I was clearly influenced by Mike Davidsons Blog design, for which I apologise to him and in no way take credit for the ‘look’ of the theme.

Get the zip or gzipped tarball. Feedback and comments would be appreciated, but not quite as much as bug reports and fixes.

PHP Conference London 2007

Tuesday, January 23rd, 2007

A couple of days behind with this one, but I thought I’d post to help out. As alot of the PHP community have mentioned, The PHP London user group are running the UK’s second dedicated PHP conference on Friday, 23rd February. Confirmed speakers thus far are, Cal Evans, Simon Laws, Kevlin Henney and Rasmus Lerdorf.

I didn’t make it last year but will see what I can sort out this year.