2009-09-10

Create Sqlite Database by SQL Script.

Sqlite supports c/c++, Tcl and sql interfaces. Max wrote some sql scripts to create and initialize a single-table sqlite DB. Put the following three files in the same fold and execute createDB.sh.

1) createDB.sql (create a DB)

CREATE TABLE tb_master
(
Id integer PRIMARY KEY,
Name text NOT NULL UNIQUE,
Creator text,
Group_name varchar(20),
Time_stamp integer,
Snapshot blob,
Thumbnail blob,
Ingredient text,
Workflow text
);

2) demoData.sql (insert demo data)


INSERT INTO tb_master
VALUES
(
1,
'Applepipe',
'Max',
'Cake',
10,
'ddd',
'ddd',
'dddd',
'ssss'
);
INSERT INTO tb_master
VALUES
(
2,
'Chinaball',
'Jasmin',
'Soup',
11,
'ddd',
'ddd',
'dddd',
'ssss'
);



3) createDB.sh (main shell script)

#!/bin/sh
# This is a script to create a sqlite3 database "test.db"

#local variables
DB=test.db
CREATE_SCRIPT=createDB.sql
DATA_SCRIPT=demoData.sql

#remove database file if it exists.
if [ -f $DB ]
then
echo remove $DB
rm -rf $DB
fi


#create a database with sql script
echo create $DB
sqlite3 $DB < $CREATE_SCRIPT

#initialize with testing data
echo insert records
sqlite3 $DB < $DATA_SCRIPT

2009-09-09

Compile c/c++ code with sqlite3 library.

1) Install sqlite3 library.
  • >wget http://www.sqlite.org/sqlite-amalgamation-3.6.17.tar.gz
  • >tar xvfz qlite-amalgamation-3.6.17.tar.gz
  • >cd sqlite-3.6.17
  • >./configure
  • >make
  • >make install

The library libsqlite3.la now is installed to /usr/bin/...

2) Compile as following. Try the test code.
  • >gcc -o test test.c -lpthread -ldl -lsqlite3

2009-09-08

First impression of SQLite3

"SQLite is not designed to replace Oracle. It is designed to replace fopen()."

What a clear signal! SQLite's target is not a "enterprise database engine" but a samll, simple but smart database for applications.

Key features
  1. Embedded devices and applications
  2. Zero-Configuration
  3. Single Database File
  4. Stable Cross-Platform Database File
  5. C/C++ API
  6. SQL Compatibility
  7. 5 Datatypes In SQLite Version 3: NULL, INTEGER,REAL,TEXT,BLOB
  8. License in public domain (total free in product)
    References

    Putty in chinese

    A good article to configure Putty to see Chinese.

    Override assigment operators in C#

    A C++ class can implement assignment operators to
    1) assign itself, or
    2) convert the other class to itself.
    See the example.

    Unlike C++, C# does not support override of assignment operator. C# uses "implicit" key word to replace the assignment operator. See the example here.

    2009-09-07

    Program and Test Qt Embedded Code on PC - virtual framebuffer


    "Qt for Embedded Linux applications write directly to the framebuffer, eliminating the need for the X Window System and saving memory. For development and debugging purposes, a virtual framebuffer can be used, allowing Qt for Embedded Linux programs to be developed on a desktop machine, without switching between consoles and X11." (Source: http://doc.trolltech.com)

    0) You need a linux host, I have debian Lenny at home.
    1) Download Qt for X11. The Library source (*.tar.gz), not the SDK (*.bin).
    2) Installing Qt/X11. You may meet following error message during ./configure.

    You might need to modify the include and library search paths by editing QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11 in /home/lolveley/bin/qt-x11-opensource-src-4.5.1/mkspecs/linux-g++.

    The reason is the some dependencies are missing. Try this:
    • > apt-get build-dep qt4-qmake

    3) Qt for Embedded Linux library must be configured and compiled with the -qvfb option

    • > ./configure -qvfb
    • > make
    • >make install

    4) Compile and run tool qvfb (Qt virtual framebuffer) as a normal Qt for X11 application.
    • >cd path/to/Qt/tools/qvfb
    • >make
    • >make install
    If you encounter the error "/usr/bin/ld: cannot find -lXtst", you need install "libxtst-dev".

    5) Running embedded applications using the virtual framebuffer. Note: try the examples compiled with embedded Qt, not X11. Otherwise, you may encounter the error like "qvfb: cannot connect to X server". See example here.


    Reference .


    2009-09-04

    Create a ISO file in linux

    How to create a iso file?
    Forget about Nero, forget about MagicISO. These windows software just waste time and money. In Linux everything is just a line of command.

    >dd if=/dev/cdrom of=2440.iso
    5597332+0 records in
    5597332+0 records out
    2865833984 bytes (2.9 GB) copied, 430.944 s, 6.7 MB/s

    Maybe you want to mount this iso file
    > mkdir /dev/2440
    >mount -o loop 2440.iso /dev/2440/

    Or you want to mount the iso file at system startup, then add one line into /etc/fstab
    /$(yourpath)/2440.iso /mnt/2440 iso9660 ro,loop,auto 0 0