I have forgotten a lot about SQL and would like to be (gently) reminded how
to do this:
In a MySQL query on the database (one table with 15 variable length fields,
I want to put each field into a Bash variable so that I can handle each
field as an entity.
The query I have is something like this:
mysql -e "use $database; select field1, field2, field3..., from Table1 where
fieldN like '%something%';"
can I / How do I do something like:
mysql -e "use $database; select field1,..., var1=field1, var2=field2,... .;"
do
stuff with var1, var2...,
done
I ask because SQL is subtle and quick to anger and I'm in a bit of a hurry.
Thanks!
--
If you wrestle in the mud with a pig.
you both get dirty, and the pig likes it.
-- Dave Dawson 2 6811
David Dawson wrote: In a MySQL query on the database (one table with 15 variable length fields, I want to put each field into a Bash variable so that I can handle each field as an entity.
I'd use mysql --batch to output the columns tab-separated, and then use
the shell builtin command "read" to assign several variables:
mysql --batch -e 'select col1, col2, col3 from...' | read col1 col2 col3
echo "$col1, $col2, $col3"
If your data contain whitespace, it might confuse the above method. You
might benefit from using the "--vertical" option of the mysql client
tool, to output the SQL columns one per line, instead of tab-separated.
mysql --vertical -e 'select col1, col2, col3 from...' | {
read col1
read col2
read col3
}
Note that the shell can group commands in the current shell by using
curly braces {}, or in a subshell by using parens (). Variables
assigned values in a subshell evaporate when the subshell ends.
See docs at http://dev.mysql.com/doc/refman/5.0/...d-options.html
Regards,
Bill K.
Bill Karwin wrote: David Dawson wrote:
Note that the shell can group commands in the current shell by using curly braces {}, or in a subshell by using parens (). Variables assigned values in a subshell evaporate when the subshell ends.
See docs at http://dev.mysql.com/doc/refman/5.0/...d-options.html
Regards, Bill K.
Thanks a lot!
I had intended to re-write this application in Perl, towards which I wrote a
small script to handle this very query with the cpan DBI package and the
Mysql class, but this give me a neat alternative to explore
..--
If you wrestle in the mud with a pig.
you both get dirty, and the pig likes it.
-- Dave Dawson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
Hi,
I have a very long string, someting like:
DISPLAY=localhost:0.0,FORT_BUFFERED=true,
F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,
GAMESS=/opt/gamess,GAUSS_ARCHDIR=/opt/g03b05/g03/arch,
GAUSS_EXEDIR=/opt/g03b05/g03/bsd:/opt/g03b05/g03/private:/opt/g03b05/g
|
by: v0lcan0 |
last post by:
Any help on extracting the time part from the datetime field in SQL
database.
even though i had entered only the time part in the database when i
extract the field it gives me only the date part. i’m using Vb.net
datagrid as a front end.
any assistance appreciated!! :?:
--
|
by: tripyre |
last post by:
I have been trying to pull the data from a field on a form in Access.
I am trying to pass that value to a shell command. Below is my code,
but I cannot get it to work. The ping command works but passes the
variable name and not the actual value of the variable name. I am
trying to pull from the form (ipaddresses) the value for the field
(IPAddress).
1st version:
Dim stAppName As String
Dim stIPAddress As String
|
by: MLH |
last post by:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If LaborCost > 0 Then Me!LaborCost.Visible = True
If MatlsCost > 0 Then Me!MatlsCost.Visible = True
If OtherCost > 0 Then Me!OtherCost.Visible = True
End Sub
I use procedures similar to the above sub in forms to make controls
on the form visible when desired. I'm unable to accomplish this in a
report's OnFormat property code. How can I do this on a report?
|
by: dor |
last post by:
i have an input file named input.txt where all the data looks like
this:
(4,10) 20
(5,3) 13
(7,19) 6
..
..
..
the numbers are random. i need to use every number in each line
| |
by: Brett |
last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a
record in table2, then the not null fields in table1 that correspond to
the records in table1 needs to be updated to match the field in table2.
What I have is a form that is linked to Table2. If the users want to
change a field in the main database (table1), they fill the change in
to the form (which is linked to table2) If there is no change to the
field, they simply...
|
by: Debbiedo |
last post by:
My software program outputs an XML Driving Directions file that I need
to input into an Access table (although if need be I can import a dbf
or xls) so that I can relate one of the fields (fromStop) and its
associated driving directions back to a relational database. I have
asked my software vendor for solutions but thus far they have not come
up with anything. I am totally unfamiliar with XML so I am struggling
with how to do this. I have...
|
by: swanc04 |
last post by:
Greetings Master of PHP /bow
I would like to preform the following task but I'm unable to figure out how, I never really got into Arrays and usually just use work arounds. I would be very greatful for your assistance.
1. I want to Copy and Paste data from my computer into a text field (Multiline)
2. When I click submit the php code should then take all of the data from the text field and seperate each line into a seperate variable /...
|
by: DebadattaMishra |
last post by:
Introduction
In case of rich applications, you must have observed that a text field behaves like a dynamic combo box. When the user enters some characters in the text field, a popup will come up with a list of values as suggestions to the user. This feature is called auto completion. In case of Eclipse editor, you must have
seen while writing java code, if the developers presses "Ctrl+Space" a dynamic list box come up with multiple...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |