bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OT: Getting MySQL fields with embedded spaces into array


From: Gerard
Subject: OT: Getting MySQL fields with embedded spaces into array
Date: Wed, 28 Oct 2009 06:04:00 -0400

I apologize for asking this here; however, I cannot seem to locate an
answer anywhere else.

I am writing a script that will use MySQL for a back end. I access MySQL
and store the results in arrays like this:

//snippet//

database: MyDataBase
table: MyTable
field: defaults

Now, I have populated the 'defaults' fields with the declare
statements that I will use in the script. They are entered similar to
this:
 
        declare -a MSRBL_LIST

Now, I issue this from my bash script:

SQL_USER=user                   # MySQL user
SQL_PASSWORD=secret             # MySQL password
DB=MyDataBase                   # MySQL data base name
HOST=127.0.0.1                  # Server to connect to
NO_COLUMN_NAME="--skip-column-names"
COM_LINE="-u${SQL_USER} -p${SQL_PASSWORD} -h ${HOST} ${NO_COLUMN_NAME}"

table=MyTable

DECLARE_STATEMENTS=($(mysql ${COM_LINE} -i -e"use ${DB}; SELECT defaults FROM 
"${table}" WHERE 1;"))

for (( i=0;i<${#DECLARE_STATEMENTS[*]};i++)); do
echo  ${DECLARE_STATEMENTS[i]}
done

//end snippet//
 
This output is produced:

declare
-a
MSRBL_LIST

Obviously, that is not what I want. I have tried setting:

        IFS=$( echo )

Prior to the invocation of the "DECLARE_STATEMENTS" statement; however,
that produced another error message and MySQL would not start.

I have been exploring different hacks to make this work. Perhaps
writing to a file and then using 'READ' to put the data into an array.
I was hoping that someone might have a working solution that I could
try. This problem only happens when the data stored in a MySQL field
contains embedded spaces or tabs. At least that is all that I am aware
of.

Thanks!

-- 
Gerard
gerard@seibercom.net

|::::=======
|::::=======
|===========
|===========
|

It isn't easy being the parent of a six-year-old.  However, it's a
pretty small price to pay for having somebody around the house who
understands computers.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]