[Top][All Lists]

[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:


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
        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=                  # Server to connect to


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

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

//end snippet//
This output is produced:


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




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]