Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Posts
    51

    Question Unanswered: 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?)

  2. #2
    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
    ***********************************************

  3. #3
    Join Date
    Sep 2002
    Posts
    51

    Talking thanks!

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

    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?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •