Beeld advertenties

# -->

July 06, 2009

Some simple user defined variables in MySQL

You can use simple user defined variables in MySQL (command line). Expressions involving variables are evaluated for each row of a query result, a property that you can use to provide a column of row numbers in the output. It's a simple procedure:
set @var_name := whatever_you_want

Tax

set @vat := 1/100*119;
example: the price of a product is 45.50 USD excl. VAT. The VAT is 19%. You want to know the total price, the query is
select 45.50 * @vat;
output: 54.14

set @exvat := 1/119*100;
example: the total price of a product is 66. USD. The VAT is 19%. You want to know the price without the VAT, the query is
select 66 * @exvat;
output: 55.46

Numbered results

set @n = 0;
select @n := @n+1 as no, col1 from table1 where col1 like '%this%';

All records in the output of your query are numbered now. Nice!

Make your own user defined variable and let me know what you've achieved :-)

More information: http://dev.mysql.com/doc/refman/5.0/en/user-variables.html

PDF split and merge

I have found a great open source tool to split or merge PDF documents: PDFSAM.

PDF Split and Merge is an easy to use tool to merge and split pdf documents. Console and GUI versions are available. The GUI is written in Java Swing and it provides functions to select files and set options.

July 04, 2009

Indexes in MySQL

You can create an index on a database table:

create index index_name on table_name (field(5));

You can check your index with this command:

show index from table_name;

or

show index from dbase_name.table_name;
show index from table_name from dbase_name;

Show_index

Continue reading "Indexes in MySQL" »

July 01, 2009

MySQL File formats and headers

MySQL uses a number of different file formats for the storage of information. Regardless of the storage engine, every MySQL table in an existing database is represented, on disk, by a .frm file, which describes the definition of the table. The .frm file is named after the table. The .frm format is the same on all platforms.

Continue reading "MySQL File formats and headers" »

June 30, 2009

Find MAC addresses with ARP

Today, I had to make a list of all items in my local network. Just to be sure I had all the important details, I wanted to note the MAC addresses too. This was easy, as Linux and Windows both understand the ARP command:

arp -a

More information

June 26, 2009

Hoffmann Advanced Interrogation and Lie Detection Sessions

Hoffmann Investigations organizes the Advanced Interrogation and Lie Detection Sessions from 23rd to 25th November 2009 in Almere, The Netherlands. Hoffmann Advanced Interrogation and Lie Detection Sessions will be given by the well-known expert Stan B. Walters.

More information (only when you're on LinkedIn).

Regular Expressions Cookbook

The Regular Expressions Cookbook is in stock at Amazon.com. The book covers the regular expression flavors .NET, Java, JavaScript, Perl, PCRE, Python, and Ruby, and the programming languages C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET. After a quick introduction, the book starts with a detailed regular expression tutorial which equally covers all 7 regex flavors. That chapter is followed by a detailed guide how to implement regular expressions in your source code, again covering the 8 programming languages equally. These chapters too are presented in cookbook format.

USA:    http://www.amazon.com/exec/obidos/ASIN/0596520689/jgsbookselection
UK:     http://www.amazon.co.uk/exec/obidos/ASIN/0596520689/jgsbookselect
Canada: http://www.amazon.ca/exec/obidos/ASIN/0596520689

June 17, 2009

Pipe MySQL to stdin

Today I was playing with MySQL command line under Windows (I use XAMPP for this). Thanks to the MySQL cookbook I learned about the -e option. This is great, because with this -e option you can pipe MySQL to stdin, so I have learned.

For example:

c:\xampp\mysql\bin>mysql -u root -p your_password -e "select * from dbase_name.table_name" | logparser "select * from stdin" -i:tsv -o:datagrid

By default, results generated by queries that are specified with -e are displayed in tabular format if output goes to the terminal, and in tab-delimited format otherwise. This can come in handy especially when you combine MySQL with MS logparser !

Of course, you can use the -e option also for more common tasks, such as storing the output of the query in a file which you can open with Microsoft Excel, for example:

c:\xampp\mysql\bin>mysql -u root -p your_password -e "select * from dbase_name.table_name" > c:\my_files\my_output.csv

One more cool thing about the -e option is that you can use multiple queries in one line,  as long as you delimited them with ;

for example:

C:\xampp\mysql\bin>mysql -u root -p -e "use dbase_name; show tables; desc table_name; select * from table_name where col_name = 'test'"

By the way, if you let the -e precede by a -H, a nice HTML page with the results of your query will be created ! Do you prefer to create an XML page, no problemo, just let the -e precede by a -X

MySQL shortcuts

You can use several shortcuts with MySQL (command line), such as:

\? = help
\c = clear command
\C = switch to another charset (might be needed for processing multi-byte charsets)
\d = set delimiter (use something else after a statement instead of ;)
\g = send command to server
\G = send command to server
With \g and \G you can generate "vertical" output with each column value on a separate line. This makes large outputs far more readable !
\h = help
\p = print current command
\q = quit MySQL
\r = reconnect (or see which database you're in)
\R = change your mysql prompt (personalize your prompt, which can be funny :-))
\s = show status (which can be very informative)
\t = don't write to into outfile
\T = write into outfile
\u = use database
\w = don't show warnings after every statement
\W = show warnings after every statement
\# = rebuild completion hash
\. = execute an SQL scriptfile

'Maak downloaden strafbaar'

Bron: AD.nl multimedia

"DEN HAAG - Het gratis downloaden van muziek, films en computerspelletjes moet strafbaar worden. Een Kamercommissie is het zat dat het auteursrecht vooral door jongeren massaal wordt omzeild, door nieuwe cd's en films gratis van het internet te plukken. Dat blijkt uit de initiatiefnota auteursrecht, die een werkgroep met leden van de CDA, PvdA, SP en VVD vandaag presenteert. De Kamercommissie constateert dat vele internetters op internet films kijken die nog niet uit zijn of nieuwe muziek in het bezit te krijgen zonder daar een cent voor te betalen. De commissie roept de ministers Hirsch Ballin (Justitie) en Van der Hoeven (Economische Zaken) op tegen op te treden. Wanneer minderjarigen de fout ingaan, moeten hun ouders aansprakelijk worden gesteld."