mysqli_multi_query error tolerance
mysqli_multi_query error tolerance
am 06.04.2009 13:15:29 von Filipe Martins
--=_0_21307_1239016529
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Hello.
I have a doubt about mysqli_multi_query and I couldn't find
anything on the Internet addressing it.
I think that mysqli_multi_query should execute all statements
even if some of them fail. As far as I can tell this doesn't
happen. The function stops returning results the moment it finds
an error.
I attached a test file proving my point. I ask your help for
figuring out if this is a bug, a limitation of the function, or
if simply it's my mistake.
Thanks to all.
Filipe Martins
http://www.maisqi.com
------------------------------------------------------------ -----------------------------------------------------------
Send big files for free. Simple steps. No registration.
Visit now http://www.nawelny.com
--=_0_21307_1239016529
Content-Type: text/plain; charset=us-ascii
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--=_0_21307_1239016529--
Re: mysqli_multi_query error tolerance
am 07.04.2009 00:57:00 von dmagick
Filipe Martins wrote:
> Hello.
> I have a doubt about mysqli_multi_query and I couldn't find
> anything on the Internet addressing it.
> I think that mysqli_multi_query should execute all statements
> even if some of them fail. As far as I can tell this doesn't
> happen. The function stops returning results the moment it finds
> an error.
The same happens in php, c, bash, java and everything else.
function do_stuff()
{
echo "in do_stuff\n";
return false;
}
function do_more_stuff()
{
echo "in do_more_stuff\n";
return true;
}
if (do_stuff() && do_more_stuff()) {
echo "all done!\n";
}
do_more_stuff() will never run because do_stuff() is broken returns a
non-success status.
This behaviour would be driven by mysql anyway, not php - the same thing
happens in postgres (where I can include an example more easily).
# begin;
BEGIN
Time: 0.723 ms
*# select now();
now
-------------------------------
2009-04-07 08:52:07.986149+10
(1 row)
Time: 99.173 ms
*# select field_from_table;
ERROR: column "field_from_table" does not exist
LINE 1: select field_from_table;
^
!# select now();
ERROR: current transaction is aborted, commands ignored until end of
transaction block
The whole thing is aborted because of the error.
> I attached a test file proving my point. I ask your help for
> figuring out if this is a bug, a limitation of the function, or
> if simply it's my mistake.
The mailing list doesn't accept attachments, you'll need to include it
inline with your email (as long as it's not too long) or place it
somewhere for everyone to see and send us a link.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysqli_multi_query error tolerance
am 07.04.2009 16:45:43 von Filipe Martins
Thanks for responding, Chris.
If I understand you right, you're saying that this is MySQL API
issue, right? But do you agree that mysqli_multi_query should at
least accept a parameter to configure how to treat errors -- for
example: RESUME_ON_ERROR, or ABORT_ON_ERROR? If you and other's
in this list share my view on this I'll send a feature
suggestion to MySQL AB.
Here goes my my test script:
/// Filipe Martins MAISQI.COM [2009-04-06]
///
http://www.maisqi.com
///
/// I'm trying to demonstrate that 'mysqli_multi_query' aborts
all the following statements
/// after an error. Or maybe it runs it but ignores the results.
Didn't test this possibilitie.
///
/// I think it should report the error but continue working.
Better yet, there should be a way
/// for us to control this behavior.
///
$host = 'localhost';
$user = 'root';
$pwd = '36981613';
$db = 'test';
$conn = mysqli_connect ($host, $user, $pwd, $db);
// The 2nd statement should fail but he others should work.
$sql = "SELECT -1;SELECT 0 FROM xyzzyz;SELECT 123;SELECT 'All
ok'";
$res = mysqli_multi_query ($conn, $sql);
$i = 0;
do {
++$i;
// Let's read this result.
if ($res = mysqli_store_result ($conn)) {
$a = mysqli_fetch_row ($res);
$s = print_r ($a, true);
echo "Statement #$i worked: $s\n
";
mysqli_free_result ($res);
}
else echo "Statement #$i failed\n
";
// Try to read until there's no more.
} while (mysqli_next_result ($conn) || mysqli_more_results
($conn));
echo "\n
";
if ($i < 4) echo "We finished quite early, didn't we?!\n
";
else echo "What?? It worked?!\n
";
Chris writes:
> Filipe Martins wrote:
>> Hello.
>> I have a doubt about mysqli_multi_query and I couldn't find
>> anything on the Internet addressing it.
>> I think that mysqli_multi_query should execute all statements
>> even if some of them fail. As far as I can tell this doesn't
>> happen. The function stops returning results the moment it finds
>> an error.
>
> The same happens in php, c, bash, java and everything else.
>
>
> function do_stuff()
> {
> echo "in do_stuff\n";
> return false;
> }
>
> function do_more_stuff()
> {
> echo "in do_more_stuff\n";
> return true;
> }
>
> if (do_stuff() && do_more_stuff()) {
> echo "all done!\n";
> }
>
> do_more_stuff() will never run because do_stuff() is broken returns a
> non-success status.
>
> This behaviour would be driven by mysql anyway, not php - the same thing
> happens in postgres (where I can include an example more easily).
>
> # begin;
> BEGIN
> Time: 0.723 ms
>
> *# select now();
> now
> -------------------------------
> 2009-04-07 08:52:07.986149+10
> (1 row)
>
> Time: 99.173 ms
>
> *# select field_from_table;
> ERROR: column "field_from_table" does not exist
> LINE 1: select field_from_table;
> ^
> !# select now();
> ERROR: current transaction is aborted, commands ignored until end of
> transaction block
>
> The whole thing is aborted because of the error.
>
>> I attached a test file proving my point. I ask your help for
>> figuring out if this is a bug, a limitation of the function, or
>> if simply it's my mistake.
>
> The mailing list doesn't accept attachments, you'll need to include it
> inline with your email (as long as it's not too long) or place it
> somewhere for everyone to see and send us a link.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
------------------------------------------------------------ -----------------------------------------------------------
Send big files for free. Simple steps. No registration.
Visit now http://www.nawelny.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysqli_multi_query error tolerance
am 08.04.2009 00:42:59 von dmagick
Filipe Martins wrote:
> Thanks for responding, Chris.
> If I understand you right, you're saying that this is MySQL API
> issue, right?
I assume it's handled by the database itself and not php. You could try
a different script (eg python, ruby, perl, whatever else can talk to
mysql) to see if that theory is correct.
> But do you agree that mysqli_multi_query should at
> least accept a parameter to configure how to treat errors
No, I don't agree with that.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysqli_multi_query error tolerance
am 08.04.2009 10:38:47 von Filipe Martins
Thanks again for responding.
I'd also welcome opinions from other members of this list...
Chris writes:
> Filipe Martins wrote:
>> Thanks for responding, Chris.
>> If I understand you right, you're saying that this is MySQL API
>> issue, right?
>
> I assume it's handled by the database itself and not php. You could try a
> different script (eg python, ruby, perl, whatever else can talk to mysql)
> to see if that theory is correct.
>
>> But do you agree that mysqli_multi_query should at
>> least accept a parameter to configure how to treat errors
>
> No, I don't agree with that.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
------------------------------------------------------------ -----------------------------------------------------------
Send big files for free. Simple steps. No registration.
Visit now http://www.nawelny.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php