Re: bashSQL: SQL API for BaSH

From NAT, 6 Years ago, written in Bash, viewed 743 times. This paste is a reply to bashSQL: SQL API for BaSH from NAT - go back
URL https://code.nat.moe/view/4eb24d86/diff Embed
Viewing differences between bashSQL: SQL API for BaSH and Re: bashSQL: SQL API for BaSH
#!/bin/bash
#
# bashSQL: A BaSH SQL lib
# usage:
#
# sql.conn <host> <port> <user> <pass>
# create a new sql session. Return session ID.
#
# sql.disconn <session>
# disconnect a sql session
#
# sql.query <session>
# do SQL query. Read SQL from stdin.
#
# sample usage:
#
# % sql.conn localhost 3306 root toor
# 1003
# % echo 'show databases;' | sql.query 1003
# information_schema
# mysql
# & sql.disconn 1003

function sql.conn {
        local host=$1
        local port=$2
        local user=$3
        local pass=$4
        local id=$RANDOM
        mkfifo ./bashsql.mkfifo /tmp/bashsql.$id
        cat > ./bashsql.> /tmp/bashsql.$id & > /dev/null ; echo $! > ./bashsql.> /tmp/bashsql.$id.pid
        cat ./bashsql.cat /tmp/bashsql.$id | mysql -h$host --port=$port -p$pass -u$user & > /dev/nll
        echo $! >> ./bashsql.>> /tmp/bashsql.$id.pid
        echo $id
}

function sql.disconn {
        echo 'quit' | sql.query $1
        local kills="$(cat ./bashsql.kills="$(cat /tmp/bashsql.$1.pid)"
        IFS='\n'
        for tar in $kills
        do
                kill $tar
        done
        rm /tmp/bashsql.$1.*
        echo "killed $1"
}

function sql.query {
        cat > ./bashsql.> /tmp/bashsql.$1
}

Replies to Re: bashSQL: SQL API for BaSH rss

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

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

Here you can reply to the paste above

captcha