1 |
#!/bin/bash |
# $Id$ |
2 |
|
# mysql functions for bash |
|
# |
|
|
# mysql functions for the bash |
|
|
# Version 0.1 |
|
|
# |
|
|
# Niels Rogalla <niro@magellan-linux.de> |
|
|
# |
|
|
# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/mysqlfunctions,v 1.8 2005-10-09 21:32:33 niro Exp $ |
|
3 |
|
|
4 |
mysql_command() |
mysql_command() |
5 |
{ |
{ |
10 |
local SQL_DB |
local SQL_DB |
11 |
local SQL_COMMAND |
local SQL_COMMAND |
12 |
|
|
13 |
SQL_USER=$1 |
SQL_USER="$1" |
14 |
SQL_PASS=$2 |
SQL_PASS="$2" |
15 |
SQL_HOST=$3 |
SQL_HOST="$3" |
16 |
SQL_DB=$4 |
SQL_DB="$4" |
17 |
SQL_COMMAND=$5 |
SQL_COMMAND="$5" |
18 |
|
|
19 |
#fallback (SQL_OPTS not, they are optional ) |
# fallback (SQL_OPTS not, they are optional ) |
20 |
if [ -z "${SQL_USER}" \ |
if [ -z "${SQL_USER}" \ |
21 |
-o -z "${SQL_PASS}" \ |
-o -z "${SQL_PASS}" \ |
22 |
-o -z "${SQL_HOST}" \ |
-o -z "${SQL_HOST}" \ |
29 |
echo |
echo |
30 |
return 1 |
return 1 |
31 |
fi |
fi |
32 |
|
|
33 |
mysql \ |
mysql \ |
34 |
--user="${SQL_USER}" \ |
--user="${SQL_USER}" \ |
35 |
--password="${SQL_PASS}" \ |
--password="${SQL_PASS}" \ |
39 |
--skip-column-names \ |
--skip-column-names \ |
40 |
--execute="${SQL_COMMAND}" \ |
--execute="${SQL_COMMAND}" \ |
41 |
|| return 1 |
|| return 1 |
42 |
|
|
43 |
return 0 |
return 0 |
44 |
} |
} |
45 |
|
|
60 |
local key |
local key |
61 |
local default |
local default |
62 |
local extra |
local extra |
63 |
|
|
64 |
SQL_USER=$1 |
SQL_USER=$1 |
65 |
SQL_PASS=$2 |
SQL_PASS=$2 |
66 |
SQL_HOST=$3 |
SQL_HOST=$3 |
67 |
SQL_DB=$4 |
SQL_DB=$4 |
68 |
SQL_TABLE=$5 |
SQL_TABLE=$5 |
69 |
|
|
70 |
#show the column names ? |
# show the column names ? |
71 |
if [ -n "${6}" -a "${6}" == "show" ] |
if [ -n "${6}" -a "${6}" == "show" ] |
72 |
then |
then |
73 |
SHOWTABLES=true |
SHOWTABLES=true |
75 |
SHOWTABLES=false |
SHOWTABLES=false |
76 |
fi |
fi |
77 |
|
|
78 |
#fallback (SQL_OPTS not, they are optional ) |
# fallback (SQL_OPTS not, they are optional ) |
79 |
if [ -z "${SQL_USER}" \ |
if [ -z "${SQL_USER}" \ |
80 |
-o -z "${SQL_PASS}" \ |
-o -z "${SQL_PASS}" \ |
81 |
-o -z "${SQL_HOST}" \ |
-o -z "${SQL_HOST}" \ |