If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > annoying and probably obvious question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-03, 16:26
dnix dnix is offline
Registered User
 
Join Date: Sep 2002
Posts: 51
Question annoying and probably obvious question

When you 'unload to' an output file is there a way to also output the field/column names?
__________________
When in doubt just ask your self,
-WWSBD?-
(what would Sponge Bob do?)
Reply With Quote
  #2 (permalink)  
Old 02-15-03, 03:33
eherber eherber is offline
Registered User
 
Join Date: Aug 2002
Location: Bonn/Germany
Posts: 152
Unfortunately this is not possible with Informix.

But it should be easy to implement, at least if you are working
on a Unix platform. Here is a sample shellscript which
simulates this behaviour.
However you might need to include more error checking functionality.

If you are not on a Unix based platform, it's time to change....


#!/usr/bin/ksh

if [ $# != 2 ]
then
echo "Usage: $0 <db_name> <tab_name>"
exit 1
fi

export DBACCNOIGN=1

DB_NAME=$1
TAB_NAME=$2
DATA_FILE="$DB_NAME.$TAB_NAME.dat"
HEADER_FILE="$DB_NAME.$TAB_NAME.hdr"
UNLOAD_FILE="$DB_NAME.$TAB_NAME.unl"

dbaccess -e $DB_NAME <<EOF

unload to $DATA_FILE
select * from $TAB_NAME;

unload to $HEADER_FILE
select sc.colname
from syscolumns sc, systables st
where sc.tabid = st.tabid
and st.tabname = "$TAB_NAME";
EOF

COL_HEADER="#"
for COL_NAME in $(cat $HEADER_FILE)
do
COL_HEADER="${COL_HEADER}${COL_NAME}"
done

echo $COL_HEADER > $UNLOAD_FILE
cat $DATA_FILE >> $UNLOAD_FILE

rm -f $DATA_FILE $HEADER_FILE > /dev/null 2>&1

echo "Database [$DB_NAME], Table [$TAB_NAME] unloaded to [$UNLOAD_FILE]"

exit 0
__________________

Best regards

Eric
--
IT-Consulting Herber
WWW: http://www.herber-consulting.de
Email: eric@herber-consulting.de

***********************************************
Download the IFMX Database-Monitor for free at:
http://www.herber-consulting.de/BusyBee
***********************************************
Reply With Quote
  #3 (permalink)  
Old 02-15-03, 16:17
dnix dnix is offline
Registered User
 
Join Date: Sep 2002
Posts: 51
Talking thanks!

Wow...It sucks that you cant do it natively but your solution is pretty ingenious. Thanks!

Quote:
Originally posted by eherber
Unfortunately this is not possible with Informix.

But it should be easy to implement, at least if you are working
on a Unix platform. Here is a sample shellscript which
simulates this behaviour.
However you might need to include more error checking functionality.

If you are not on a Unix based platform, it's time to change....


#!/usr/bin/ksh

if [ $# != 2 ]
then
echo "Usage: $0 <db_name> <tab_name>"
exit 1
fi

export DBACCNOIGN=1

DB_NAME=$1
TAB_NAME=$2
DATA_FILE="$DB_NAME.$TAB_NAME.dat"
HEADER_FILE="$DB_NAME.$TAB_NAME.hdr"
UNLOAD_FILE="$DB_NAME.$TAB_NAME.unl"

dbaccess -e $DB_NAME <<EOF

unload to $DATA_FILE
select * from $TAB_NAME;

unload to $HEADER_FILE
select sc.colname
from syscolumns sc, systables st
where sc.tabid = st.tabid
and st.tabname = "$TAB_NAME";
EOF

COL_HEADER="#"
for COL_NAME in $(cat $HEADER_FILE)
do
COL_HEADER="${COL_HEADER}${COL_NAME}"
done

echo $COL_HEADER > $UNLOAD_FILE
cat $DATA_FILE >> $UNLOAD_FILE

rm -f $DATA_FILE $HEADER_FILE > /dev/null 2>&1

echo "Database [$DB_NAME], Table [$TAB_NAME] unloaded to [$UNLOAD_FILE]"

exit 0
__________________
When in doubt just ask your self,
-WWSBD?-
(what would Sponge Bob do?)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On