I've decided to start off my programming tools page with a tip, something I've never seen anyone else implement or use, but which I find extremely useful.
I'm a pretty heavy shell user in my day to day work, and use databases
a lot (Sybase in my case). I never liked the GUI sql shells, never quite got used to starting emacs to use sqsh. Dammit, I like the shell. I figured there has to be an easier way.
Sorry I can't post the code, but the trick is to write the function S:
function S {
...
eval 'function '"$1"' { (
my_isql_like_thingy '"$2"' '"$3"' '"$4"' ...
)}'
}
The idea is that I can run:
S mytag SERVER DB USER PASSWORD
and then whenever I want to run sql on that database, I need only run
mytag '... sql ...'
and I can use all the ordinary shell mechanics for editing the line, redirecting, loops, etc...
Step 2: simple enough... In your startup .rc file, autodefine a bunch of these for the databases you use most often.
Step 3: write a kick ass my_isql_like_thingy... Mine can present the data three different ways, bcp in/out raw data on stdin (streaming so you can bcp out with one sql and into something else at the same time), or list tables or procs or views, print the text of tables or procs or views. So, e.g., I can whip up simple scripties like:
for p in $(p2 print views | fgrep Equity) ; do
print "*** $p"
p2 cols "$p" | fgrep -i tick
done
in a flash...
Anyway, I find this useful. Where I work is a Sybase shop though, so even if I made a generic version who would care... Anything like this for mysql?