473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Multiple statements in single query batch

DG
Hi,

Can anyone advise how to execute multiple statements in a single query
batch. For example-

update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from customers;

I can execute each statement individually but get the 'you have an error in
you SQL syntax' when trying to execute them together.
Ultimately I'm looking to build multi-statement queries (some may contain
transactions) that do lots of work and then return a result for the client
to use :-

INSERT customers
(customer_name)
VALUES
(ucase('test3'));

SELECT c.customer_id, c.customer_name
FROM customers c
WHERE c.customer_name = ucase('test3');

Can anyone tell me what I'm missing?

Thanks,

David


Oct 16 '05 #1
4 16722
On Sun, 16 Oct 2005 13:36:58 +0100, DG wrote:
Hi,

Can anyone advise how to execute multiple statements in a single query
batch. For example-

update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from customers;

I can execute each statement individually but get the 'you have an error
in you SQL syntax' when trying to execute them together. Ultimately I'm
looking to build multi-statement queries (some may contain transactions)
that do lots of work and then return a result for the client to use :-

INSERT customers
(customer_name)
VALUES
(ucase('test3'));

SELECT c.customer_id, c.customer_name FROM customers c
WHERE c.customer_name = ucase('test3');

Can anyone tell me what I'm missing?


How are you delivering these query statements to MySQL?

The standard "mysql" application that comes packaged with the database can
easily manage multi-statment queries. Just so long as they are legal
statements properly terminated with a semicolon.

So - what is it that you are using to deliver your multi-statement queries?
Thomas Bartkus

Oct 16 '05 #2
Hi,

is this what you're looking for?

http://www.php.net/manual/en/functio...ulti-query.php

Cheers,
Markus
Oct 17 '05 #3
DG
I'm using .Net front end, essentially delivering a string of text then
'filling' the results into the clients memory. For the examples below I'm
using the Query Browser provided with MySQL to test queries first. The
problems occur from both clients.

I'm trying to disconnect the GUI from the db so I can change either in
future without major re-development costs. e.g. At work I use Sybase
extensively and build strings of SQL that are platform independent. This
means we have MS Access, .Net and Java GUIs connected to the same db with no
development overheads and allowing different teams to use the same db in
their own way. Note a lot of the work we do is in stored procs which
simplifies this further.

Any advice?

Thanks
"Thomas Bartkus" <th***********@comcast.net> wrote in message
news:pa****************************@comcast.net...
On Sun, 16 Oct 2005 13:36:58 +0100, DG wrote:
Hi,

Can anyone advise how to execute multiple statements in a single query
batch. For example-

update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from customers;

I can execute each statement individually but get the 'you have an error
in you SQL syntax' when trying to execute them together. Ultimately I'm
looking to build multi-statement queries (some may contain transactions)
that do lots of work and then return a result for the client to use :-

INSERT customers
(customer_name)
VALUES
(ucase('test3'));

SELECT c.customer_id, c.customer_name FROM customers c
WHERE c.customer_name = ucase('test3');

Can anyone tell me what I'm missing?


How are you delivering these query statements to MySQL?

The standard "mysql" application that comes packaged with the database can
easily manage multi-statment queries. Just so long as they are legal
statements properly terminated with a semicolon.

So - what is it that you are using to deliver your multi-statement
queries?
Thomas Bartkus

Oct 17 '05 #4
"DG" <dj*****@ukonline.co.uk> wrote in message
news:dj*******************@news.demon.co.uk...
I'm using .Net front end, essentially delivering a string of text then
'filling' the results into the clients memory. For the examples below I'm
using the Query Browser provided with MySQL to test queries first. The
problems occur from both clients. Query Browser provided with MySQL to test queries first. The
problems occur from both clients.
What query browser provided by MySQL?

The one I am familiar with is MySQLCC (MySQL Control Center) which has no
problem with multiple statements delivered via the query Window. And I know
it to work on both Linux and Windows versions.

The .Net front end means you are using Microsofts ADODB library - Yes? No?
Or have the come up with a working ADO.NET?
Here you may be having a problem since AFAIK, the .sql property of a
connection object doesn't work with multiple statements. If this is still
the case, it is a problem with the ADODB library, not MySQL.
This means we have MS Access, .Net and Java GUIs connected to the same db
with no development overheads
What about the Microsoft imposed ADODB overhead?

All the MySQL server needs is a stream of legitimate sql statements
terminated by semi-colons. I may not be familiar with the latest & greatest
ADODB incarnation - But in the past both DAO and ADODB were notorious for
the inability to manage multiple statement queries - even as passthroughs to
MySQL. Just try writing an Access query with multiple statements! If I
opened an ADODB connection object to a MySQL server, I would have to
cn.execute one sql statement at a time.

For example, using Access, you always had to create separate queries
"Query1, Query2. .... QueryN" and execute them sequentially even if they
were "dbSqlPassThrough". This was (and perhaps still is!) a limitation in
ADODB. Access as well as the underlying libraries DAO and ADO have no notion
of multiple statement queries and don't know what to do with them.

If you write directly to the MySQL ODBC driver, bypassing the MS libraries,
you would find no such limitation! The ODBC driver itself will execute each
statement in turn and throw query results back at you in the order in which
they are produced.
I'm trying to disconnect the GUI from the db so I can change either in
future without major re-development costs. e.g. At work I use Sybase
extensively and build strings of SQL that are platform independent. This
means we have MS Access, .Net and Java GUIs connected to the same db with no development overheads and allowing different teams to use the same db in
their own way. Note a lot of the work we do is in stored procs which
simplifies this further.

That generic SQL ("SQL that are platform independant") sounds a bit of a
tall order. Good luck with that!

My approach to bringing many disparate db platforms to the Microsoft world
is to use MS Access and linked tables. This is a forte of MS Access.
Whatever Oracle, Sybase, MySQL, or whatever might look like, they all look
like an Access table and can coexeist together given suitable ODBC drivers.
Doing it this way, everything looks like an Access database to Microsoft
developement tools. You can then use Microsoft's peculiar flavor of SQL to
talk to everything. When in Rome ....!

Not sure if this helps but it is the little I know!
Thomas Bartkus
Oct 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Shmuel | last post by:
Is it possible to query multiple statements at once? Like: $query = "set @p := 1; select @p + 1"; $results = mysql_query($query); I'm thinking of PHP4. There is in mysqli the prepare...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
4
by: | last post by:
Hello, I am attempting to convert multiple .wav files to the .flac format via a batch script. I know that this can be done with numerous software implementations automatically for me; however, i am...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
1
by: bharathi228 | last post by:
How to write two or more select statements in a single query here my requirement is SELECT dbo.SYS_PARAMS.PARAMETER_NAME, dbo.SYS_PARAMS.PARAMETER_UNITS, SYSTEM2.dbo.CALIBRATION.CAL_TYPE, ...
0
by: harsha318 | last post by:
Hi I need to have a single query and which can have multiple statements For eg: string str = string.Empty; str = "select * from Customers;Select * from Orders"; iDB2Connection iDB2con =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.