Re: Re: bashSQL: SQL API for BaSH

From NAT, 6 Years ago, written in Bash, viewed 733 times. This paste is a reply to Re: bashSQL: SQL API for BaSH from NAT - view diff
URL https://code.nat.moe/view/d8486b37 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2. #
  3. # bashSQL: A BaSH SQL lib
  4. # usage:
  5. #
  6. # sql.conn <host> <port> <user> <pass>
  7. # create a new sql session. Return session ID.
  8. #
  9. # sql.disconn <session>
  10. # disconnect a sql session
  11. #
  12. # sql.query <session>
  13. # do SQL query. Read SQL from stdin.
  14. #
  15. # sample usage:
  16. #
  17. # % sql.conn localhost 3306 root toor
  18. # 1003
  19. # % echo 'show databases;' | sql.query 1003
  20. # information_schema
  21. # mysql
  22. # & sql.disconn 1003
  23.  
  24. function sql.conn {
  25.         local host=$1
  26.         local port=$2
  27.         local user=$3
  28.         local pass=$4
  29.         local id=$RANDOM
  30.         mkfifo /tmp/bashsql.$id
  31.         cat > /tmp/bashsql.$id &; echo $! > /tmp/bashsql.$id.pid
  32.         cat /tmp/bashsql.$id | mysql -h$host --port=$port -p$pass -u$user &
  33.         echo $! >> /tmp/bashsql.$id.pid
  34.         echo $id
  35. }
  36.  
  37. function sql.disconn {
  38.         echo 'quit' | sql.query $1
  39.         local kills="$(cat /tmp/bashsql.$1.pid)"
  40.         IFS='\n'
  41.         for tar in $kills
  42.         do
  43.                 kill $tar
  44.         done
  45.         rm /tmp/bashsql.$1.*
  46.         echo "killed $1"
  47. }
  48.  
  49. function sql.query {
  50.         cat > /tmp/bashsql.$1
  51. }

Replies to Re: Re: bashSQL: SQL API for BaSH rss

Title Name Language When
Re: Re: Re: bashSQL: SQL API for BaSH NAT bash 6 Years ago.

Reply to "Re: Re: bashSQL: SQL API for BaSH"

Here you can reply to the paste above

captcha