Re: freebcp error HINT -b doesnt work whit -f
"James K. Lowden" <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
rodrigo lopez wrote: > The option âb NOTt work with âf in > freebcp There seem to be a few problems with freebcp -n. Thank you for reporting this one. Anyone willing to work on this? I don't know when it broke, but it's been awhile. The attached Bourne shell script may be helpful in testing. I'm considering adding it to src/apps/unittests. It fails to reload a file it extracts with -n. --jkl _______________________________________________ FreeTDS mailing list [email protected] http://lists.ibiblio.org/mailman/listinfo/freetds
freebcp.sh
(application/x-sh, 1.9 KB)
#! /bin/sh
#
# Test freebcp by
# creating a table in tempdb and populating it,
# extracting the data, deleting the data from the table,
# re-loading the table from the file,
# re-extracting the data to a second file,
# and comparing the files.
#
set -e
# default location of PWD file
PWD=PWD
# default location of bsqldb and freebcp binaries
BINROOT=../../../build
# default bcp file format
NATCHAR=-n
#
# Process command-line options
#
args=$(getopt ncB:P: $*)
if [ $? -ne 0 ]; then
echo 'Usage: $(basename $0) [-n] [-c] [-B bin-prefix] [-P PWD-file] '
exit 2
fi
set -- $args
while [ $# -gt 0 ]
do
case "$1" in
-B)
BINROOT=$2; shift
;;
-P)
PWD=$2; shift
;;
-n|-c)
NATCHAR=$1;
;;
--)
shift; break
;;
esac
shift
done
if [ ! -r ${PWD} ]
then
echo could not open ${PWD} >&2
exit 1
fi
BSQLDB=$BINROOT/bsqldb
FREEBCP=$BINROOT/freebcp
#
# Process PWD file
#
U=$(awk -F= '/^UID/ {print $2}' ${PWD})
P=$(awk -F= '/^PWD/ {print $2}' ${PWD})
S=$(awk -F= '/^SRV/ {print $2}' ${PWD})
D=$(awk -F= '/^DB/ {print $2}' ${PWD})
#
# Create a table and fill it with data
#
TBL=tempdb..${U}_types
${BSQLDB} -S$S -D$D -U$U -P$P -v <<-SQL
if exists (select 1 from tempdb..sysobjects where name = '${U}_types')
drop table ${TBL}
go
select name, type, cast(type as float) as ftype, getdate() as now
into ${TBL}
from systypes
go
SQL
# Copy the data to the first file
${FREEBCP} ${TBL} out /tmp/types.n1.dat -S$S -U$U -P$P ${NATCHAR}
# Delete the data and upload the file
OPTIONS="delete from ${TBL}"
${FREEBCP} ${TBL} in /tmp/types.n1.dat -S$S -U$U -P$P ${NATCHAR} -O"${OPTIONS}"
# Copy the date to the second file
${FREEBCP} ${TBL} out /tmp/types.n2.dat -S$S -U$U -P$P ${NATCHAR}
# Compare files
cmp /tmp/types.n1.dat /tmp/types.n1.dat
# Drop the table
${BSQLDB} -S$S -D$D -U$U -P$P -v <<-SQL
drop table ${TBL}
go
SQL