Thursday, April 30, 2015

Working with #Sqlite database in #Android

Log in into android Shell

adb root
adb remount
adb shell

Not in shell, cd to the folder where sql db is located at.

cd /data/user/0//databases/

Make sure you have the needed db

ls
example.db


Activate the sqlite commands

sqlite3 and ENTER


to see version of database
.headers on

PRAGMA user_version;

You will see sqlite tab now. Type following command to open the needed database.

sqlite> .open example.db

see the tables in the database

sqlite> .tables

table1  table2 table3

To see schema of table1

sqlite>.schema table1


CREATE TABLE table1 (_id INTEGER PRIMARY KEY, name TEXT NOT NULL, license TEXT NOT NULL);

to see contents of table
sqlite> select * from table1;


To see what all supported commands are there -
sqlite> .help
.backup ?DB? FILE      Backup DB (default "main") to FILE
.bail on|off                     Stop after hitting an error.  Default OFF
.clone NEWDB             Clone data into NEWDB from the existing database
.databases                      List names and files of attached databases
.dump ?TABLE? ...      Dump the database in an SQL text format
                         If TABLE specified, only dump tables matching
                         LIKE pattern TABLE.
.echo on|off                 Turn command echo on or off
.eqp on|off                   Enable or disable automatic EXPLAIN QUERY PLAN
.exit                             Exit this program
.explain ?on|off?         Turn output mode suitable for EXPLAIN on or off.
                         With no args, it turns EXPLAIN on.
.fullschema                 Show schema and the content of sqlite_stat tables
.headers on|off           Turn display of headers on or off
.help                            Show this message
.import FILE TABLE     Import data from FILE into TABLE
.indices ?TABLE?       Show names of all indices
                         If TABLE specified, only show indices for tables
                         matching LIKE pattern TABLE.
.log FILE|off          Turn logging on or off.  FILE can be stderr/stdout
.mode MODE ?TABLE?     Set output mode where MODE is one of:
                         csv      Comma-separated values
                         column   Left-aligned columns.  (See .width)
                         html     HTML code
                         insert   SQL insert statements for TABLE
                         line     One value per line
                         list     Values delimited by .separator string
                         tabs     Tab-separated values
                         tcl      TCL list elements
.nullvalue STRING      Use STRING in place of NULL values
.once FILENAME         Output for the next SQL command only to FILENAME
.open ?FILENAME?       Close existing database and reopen FILENAME
.output ?FILENAME?     Send output to FILENAME or stdout
.print STRING...       Print literal STRING
.prompt MAIN CONTINUE  Replace the standard prompts
.quit                  Exit this program
.read FILENAME         Execute SQL in FILENAME
.restore ?DB? FILE     Restore content of DB (default "main") from FILE
.save FILE             Write in-memory database into FILE
.schema ?TABLE?        Show the CREATE statements
                         If TABLE specified, only show tables matching
                         LIKE pattern TABLE.
.separator STRING ?NL? Change separator used by output mode and .import
                         NL is the end-of-line mark for CSV
.shell CMD ARGS...     Run CMD ARGS... in a system shell
.show                  Show the current values for various settings
.stats on|off          Turn stats on or off
.system CMD ARGS...    Run CMD ARGS... in a system shell
.tables ?TABLE?        List names of tables
                         If TABLE specified, only list tables matching
                         LIKE pattern TABLE.
.timeout MS            Try opening locked tables for MS milliseconds
.timer on|off          Turn SQL timer on or off
.trace FILE|off        Output each SQL statement as it is run
.vfsname ?AUX?         Print the name of the VFS stack
.width NUM1 NUM2 ...   Set column widths for "column" mode

                         Negative values right-justify




Monday, April 27, 2015

MY SQL commands

My SQL commands to keep safe update off
SET SQL_SAFE_UPDATES = 0;

Wednesday, April 22, 2015

Unix commands - maven and file listing

Maven command to run java program

mvn exec:java -Dexec.mainClass="com.lochbridge.hadoop.NewCollectDriver" -Dexec.args="Sample.txt trips"  -Dlog4j.configuration=log4j.properties


Unix command to find non-zero files created today

find -maxdepth 1 -size +0 -mtime -1


List files details 

ls -al 
ls -al file1 file2 file3


Merge multiple files
cat file1 file2 file3 >ResultFile

Setting Maven on Amazon Ubuntu Linux


Download the compressed maven binary. 

$ sudo wget ftp://apache.mirrors.pair.com/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz

If the link is old, get the latest link from maven site. Copy the link address, by selecting a proper mirror site.
Once you have proper link, the above command will download the compressed file.

$ ls
apache-maven-3.3.1-bin.tar.gz

$ sudo tar -xzvf apache-maven*

$sudo mv apache-maven-3.3.1 /usr/local/maven

$vi ~/.bashrc

type Esc , then i

Go to last line
add 
export M2_HOME=/usr/local/maven
export MAVEN_HOME=/usr/local/maven
export M2=/usr/local/maven/bin
export PATH=${PATH}:$M2

then type following commands :

Esc
:wq!

This will exit the vi editor

$source ~/.bashrc  
$mvn -version

You are all set. You will see following logs
Apache Maven 3.3.1
Maven home: /usr/local/maven