#!/bin/ash
# *********************************************************************
# mysqltotable: perform a MySQL(TM) database query and turn the result
#	        into a NoSQL table.
#
# See http://dev.mysql.com/doc/refman/5.0/en/tutorial.html for a quick
# introduction to MySQL(TM).
#
# Copyright (c) 2007,2009 Carlo Strozzi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# *********************************************************************

# Get local settings and apply defaults.
: ${TMPDIR:=/tmp} ${NOSQL_CHARSET:=utf-8}
: ${NOSQL_INSTALL:=@NOSQL_INSTALL@}
: ${SWU_INSTALL:=@SWU_INSTALL@}
: ${PATH:=@LOCAL_PATH@}

export NOSQL_INSTALL SWU_INSTALL PATH TMPDIR NOSQL_CHARSET

if [ "X$1" = X--show-copying ]
then
   cat $NOSQL_INSTALL/doc/COPYING
   exit 1
elif [ "X$1" = X--show-warranty ]
then
   cat $NOSQL_INSTALL/doc/WARRANTY
   exit 1
fi

mysql "$@" |
  _awk -F '\t' -- 'NR==1{
	gsub(/\t/,"\t\001"); sub(/^/,"\001")
  }
  { print }'

# EOF
