28 September 2013

An Intro on SQLite

SQLite is a Relational Database Management System (RDMS). but unlike other RDMS, it does not require a ceentral server to be run or client to access the process. and lightweight. due to its small size it is use in various application, Operating System, Embedded System etc. The best part of it, it is in Public Domain. Which mean any software maker, individual or software company can use and impliment it into their application. SQLite is use in various open source and closed source system.

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
      - sqlite.org

    SQLite is use in various software appication:
  • Mozilla Firefox
  • Google Chrome
  • Opera
  • Ruby On Rails
  • Adobe System
  • and more..
    SQLite is also use in various OS:
  • NetBSD
  • OpenBSD
  • Apple iOS
  • Google Android
  • Windows Phone 8
  • Symbian OS
  • BlackBerry 10 OS
  • and more..
Despite it small size, it implement almost all SQL standard query. but few features are missing, like 'ALTER TABLE'.

A short tutorial

# Checking SQLite version:
sqlite3 -version
-- Loading resources from /home/user/.sqliterc

3.7.15.2 2013-01-09 11:53:05 c0e09560d26f0a6456be9dd3447f5311eb4f238f

# Getting Usage help:
sqlite3 -help

# Create a database 'foo.db' :
sqlite3 foo.db
This will create the foo.db (empty database) and drop to sqlite shell.
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

# To create a table, we will run an SQL query:
sqlite> CREATE TABLE person (name VARCHAR(12), age VARCHAR(3));
a table 'person' will be created with column name & age.

# Display all tables in the database:
sqlite> .tables
Or similar tables..
sqlite> .tables ??TABLE??

# Adding data to table:
sqlite> INSERT INTO person VALUES ('jack', '50');
sqlite> INSERT INTO person ('name') VALUES ('henry');

# Displaying the inserted data:
sqlite> SELECT * FROM person;

SQLite can also read SQL query from a text file.

sql.txt
select * from person;
select * from person where name='john';

# To run SQL query that is given in sql.txt .
sqlite> .read sql.txt

To manipulate any data in the databases the user will have to run SQL query. This author guess that the reader has prior knowledge of SQL query.

# To exit SQLite shell:
sqlite> .quit
sqlite> .exit


23 September 2013

Making USB Modem work in GNU/Linux

the short way

Short tutorial for those who donot have all the time in the world to read a lengthy tutorial.
Open ' Terminal ' and run..
eject /dev/sr1
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note the ID corresponding to USB/3G Modem.
sudo modprobe usbserial vendor=0x24e3 product=0x3e76


the long way

This tutorial will work for most 2G, 3G, 4G or any USB Modem under GNU/Linux using debian/ubuntu.

# Before inserting your usb modem. Open 'Terminal' and run the following command:
ls /dev/sr*
It'll output something like:
/dev/sr0
sr0 is mostly CD/DVD-Drive or any Serial Drive connected.

# Now insert your USB Modem and run the command again..
ls /dev/sr*
/dev/sr0 /dev/sr1
Note the extra serial device (sr1). it is your usb modem internal storage, because when attached they are dectcted as storage devices. It's explained in 'man usb_modeswitch'.
...When plugged in for the first time, they act like a flash storage and start installing the Windows driver from there. If the driver is already installed, it makes the storage device disappear and a new device, mainly composite with modem ports, shows up.

On Linux, in most cases the drivers are available as kernel modules, such as "usbserial" or "option". However, the device shows up as "usb-storage" by default...


# In 'Terminal':
lsusb
Bus 001 Device 004: ID 24e3:2205 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
note the ID corresponding your USB 3G Modem.

# Eject the modem storage:
eject /dev/sr1
..and..
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
It will show a new ID for the Modem.
24e3:3e76
24e3 is VendorID. 3e76 is ProductID of the modem.

# Make the modem visible to the system by running modprobe:
sudo modprobe usbserial vendor=0x24e3 product=0x3e76
Replace the ID with your Modem ID.

Wait a minute for the modem to appear in Network Manager.