add listing to sqlite3ncsv
This commit is contained in:
22
sqlite3ncsv
22
sqlite3ncsv
@@ -1,14 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
[[ -f "$1" ]] || {
|
help() {
|
||||||
echo 'Sqlite3NCSV: view sqlite3 DB with ncsv.
|
echo 'Sqlite3NCSV: view sqlite3 DB with ncsv.
|
||||||
|
Usage: sqlite3ncsv [FILE] [TABLE/QUERY/-l]
|
||||||
|
|
||||||
first argument: sqlite3 file
|
first argument: sqlite3 file
|
||||||
second, optional argument: table name. If not given, first in schema used.
|
second, optional argument:
|
||||||
If the second argument contains spaces, it is assumed to be a SELECT query.
|
TABLE: If not given, first in schema used.
|
||||||
|
QUERY: If the second argument contains spaces, it is assumed to be a query.
|
||||||
|
-l: List table names
|
||||||
'
|
'
|
||||||
exit
|
}
|
||||||
|
[[ "$1" == "-h" ]] && {
|
||||||
|
help; exit
|
||||||
|
}
|
||||||
|
[[ -f "$1" ]] || {
|
||||||
|
help; exit
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlfile="$1"
|
sqlfile="$1"
|
||||||
|
[[ "$2" == "-l" ]] && {
|
||||||
|
sqlite3 "$sqlfile" "SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
[[ -z "$2" ]] && {
|
[[ -z "$2" ]] && {
|
||||||
table=$( sqlite3 "$sqlfile" "SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite%' LIMIT 1;" )
|
table=$( sqlite3 "$sqlfile" "SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite%' LIMIT 1;" )
|
||||||
} || {
|
} || {
|
||||||
|
|||||||
Reference in New Issue
Block a user