Module: sip-router
Branch: master
Commit: 4bc07b15ae9a490273b2696b2860f78ebbd18104
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4bc07b1…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Aug 1 14:35:16 2013 +0200
kamctl: shortcut command to do q query to a database based on key and value
- kamctl db smatch table key value - return the record from table that
has column key matching the value as string (quoted value)
- kamctl db nmatch table key value - return the record from table that
has column key matching the value as non-quoted
- examples:
kamctl db smatch subscriber username test
kamctl db nmatch subscriber id 123
---
utils/kamctl/kamctl | 18 ++++++++++++++++++
utils/kamctl/kamctl.sqlbase | 4 ++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 0dee374..e25c6f2 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -992,6 +992,24 @@ db_ops() {
QUERY="select * FROM $1\\G;"
$DBROCMD "$QUERY"
;;
+ smatch)
+ shift
+ if [ $# -ne 3 ] ; then
+ merr "missing parameters"
+ exit 1
+ fi
+ QUERY="SELECT * FROM $1 WHERE $2='$3'\\G;"
+ $DBROCMD "$QUERY"
+ ;;
+ nmatch)
+ shift
+ if [ $# -ne 3 ] ; then
+ merr "missing parameters"
+ exit 1
+ fi
+ QUERY="SELECT * FROM $1 WHERE $2=$3\\G;"
+ $DBROCMD "$QUERY"
+ ;;
*)
usage_db_ops
exit 1
diff --git a/utils/kamctl/kamctl.sqlbase b/utils/kamctl/kamctl.sqlbase
index f07705f..6c43149 100644
--- a/utils/kamctl/kamctl.sqlbase
+++ b/utils/kamctl/kamctl.sqlbase
@@ -61,6 +61,10 @@ cat <<EOF
\$id variable
db show <table> ..................... display table content
db showg <table> .................... display formatted table content
+ db smatch <table> <key> <value>...... display record from table that
has
+ ........................... column key equal to value as string
+ db nmatch <table> <key> <value>...... display record from table that
has
+ ........................... column key equal to value as non-string
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops"