Errata

MySQL Stored Procedure Programming

Errata for MySQL Stored Procedure Programming

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 1
$dbh->commit is missing in both examples for the already discussed value of $dbh-

>{AutoCommit} = 0

Anonymous   
Printed Page 2
(from the Perl DBI documentation)

--- snip ----------------------------------------------------
The recommended way to implement robust transactions in Perl applications is to use
RaiseError and eval { ... }
--- snip -----------------------------------

Anonymous   
Printed Page 25
Screenshot

The cursor was left on the page when the screen shot was taken, which makes these illustrations
sometimes confusing or hard to read. For instance, on page 32, you cannot tell if it is
"simple_loop()", "simple_loop(<something unintelligible>)", or "simple_loop)", and when first
learning the syntax of something, I think you need clearer examples.

This happens on 25, 27, 28, 29, 32, 34, 35, 36, 38, 42, 160, 164. In the early part of the book,
there are places where it is difficult to see parenthesis and such due to cursor or insert point,
or sometimes a selected character as if in the middle of a cut-and-paste operation.

Anonymous   
Printed Page 34
Example 2-6

The procedure defined in Figure 2-10 defines total_sales
to be type NUMERIC(8,2); however when the result is printed
out the value is displayed as 7 digits before the decimal
place and none after it - a NUMERIC(8,2) would have up to
six characters before the decimal point and 2 after it,
which means that the result doesn't even fit in the variable
and it displays as 999999.99!
Also, using the example database, I got the answer:
Total sales for 2 is 7270844.00
which is different from the answer printed in the book.

Anonymous   
Printed Page 40
line 30

Stored procedure CALLs for 1_new_salary procedure. I can't find how to create this stored
procedure.

Also, on page 41, example 2-8 CALLs cursor_example2(18) instead of putting_it_all_together(18).

Anonymous   
Printed Page 52
1st paragraph

Text says:

"So 2.4e is equivalent to 2.4 x 10 4 or 24,000." (Of course, I cannot superscript the '4' after the
'10.)

It should read:

"So 2.4e4 is equivalent to 2.4 x 10 4 or 24,000."

An even better example would be:

"So 2.3e4 is equivalent to 2.3 x 10 4 or 23,000."

Anonymous   
Printed Page 64
final example in section

Where bitwise operators are explained, the following example is given

The bitwise AND operator sets a bit only if both the bits are true in the input. So 5&6=7, because
101&110=111, which equals 4.

101&110=111 should of course read 101&110=100 and 5&6=7 should read 5&6=4

Anonymous   
Printed Page 68
Next-to-last paragraph

"requirements will be minimal and, use CHARs and VARCHARs can be used"
should probably be
"requirements will be minimal and, because CHARs and VARCHARs can be used"

Kerry Burton  Oct 22, 2020 
Printed Page 73
Sample code, assignment to variable c

c=a+" "+c;
should be
c=a+" "+b;

Kerry Burton  Oct 22, 2020 
Printed Page 83
Second paragraph, last sentence

"if l_version is NULL"
should be
"if l_version_string is NULL"

Kerry Burton  Oct 22, 2020 
Printed Page 91
First paragraph

"if none of the WHERE clauses is matched"
should be
"if none of the WHEN clauses is matched"

Kerry Burton  Oct 22, 2020 
Printed Page 107
Second paragraph, first sentence

Replace "post-processing" with "processing".

Replace "FETCH has reached" with "FETCH has not reached".

Kerry Burton  Oct 23, 2020 
Printed Page 107
Last paragraph

It is not true that "the WHILE loop also requires a LEAVE statement if there is any processing of the cursor results attempted within the loop".

As shown in Example 5-13 for REPEAT loops, a LEAVE statement is not required in a WHILE loop if the FETCH is followed by an IF that performs processing after determining that the end of the result set has NOT been reached.

Proposed Example 5-14A:
* Start with a copy of Example 5-14
* Change

IF no_more_departments=1 THEN
LEAVE dept_loop;
END IF;
SET l_department_count=l_department_count+1;

to

IF no_more_departments=0 THEN
SET l_department_count=l_department_count+1;
END IF;

Kerry Burton  Oct 23, 2020 
Printed Page 112
Example 5-19

Remove "//" after "END;"

Kerry Burton  Oct 24, 2020 
Printed Page 118
Last sentence

The comma in the final sentence does not belong:

"The prepared statement is executed with the, EXECUTE statement:"

Kerry Burton  Oct 24, 2020 
Printed Page 126
End of Example 6-1

"END$$" should be "END;"

Kerry Burton  Oct 24, 2020 
Printed Page 127
1st paragraph

"...set the variable p_status to ..."
should be
"...set the variable out_status to ..."

Anonymous   
Printed Page 135
Last two bullets

"DECLARE CONTINUE HANDER FOR"
should be
"DECLARE CONTINUE HANDLER FOR"

Kerry Burton  Oct 24, 2020 
Printed Page 141
1st paragraph

"...ability to display the SQLSTATE or SQLSTATE..."
should be
"...ability to display the SQLCODE or SQLSTATE..."

Anonymous   
Printed Page 141
Indented tip after first paragraph

"implements a SQLSTATE or SQLSTATE variable"
should be
"implements a SQLCODE or SQLSTATE variable"

Kerry Burton  Oct 24, 2020 
143
Example 6-17 line 8

Should be MESSAGE_TEXT instead of MESSAGE_TEST (also in ex06-17.sql in the sample files)

Anonymous  Jun 30, 2011 
Printed Page 145
Examples 6-19 and 6-20

END$$
should be
END;

Kerry Burton  Oct 24, 2020 
Printed Page 146-147,149
Examples 6-22 and 6-23

In both examples, the first call to the just-defined procedure fails because the department to be added already exists. Then, the second call attempts to create the same (duplicate) department but fails because no manager ID could found for the specified name.

Would it be better to reverse the order of these first two calls? That way, the conditions would be tested in the order that their associated checks appear in the code, and the reader wouldn't wonder why the user is trying (again) to add a department that they've already been told is a duplicate.

Kerry Burton  Oct 24, 2020 
Printed Page 148
Example 6-23

line 33:
SET p_sqlcode=1052;
should be:
SET p_sqlcode=1062;

Anonymous  Nov 19, 2008 
Printed Page 148
Example 6-23, line 43

For consistency,
"HANDLER FOR not FOUND"
should be
"HANDLER FOR NOT FOUND"

Kerry Burton  Oct 24, 2020 
Printed Page 149
Line-by-line code review at top of page

Entry for line 53 is actually for line 63.

Kerry Burton  Oct 24, 2020 
Printed Page 149
Example 6-24, first result set

@p_sqlcode value is
1052
but should be
1062

Kerry Burton  Oct 24, 2020 
Printed Page 156
Last paragraph, first sentence

"the ability to directly access the SQLSTATE or SQLSTATE variables"
should be
"the ability to directly access the SQLSTATE or SQLCODE variables"

Kerry Burton  Oct 24, 2020 
Printed Page 156
Last paragraph, second sentence

"In the absence of a SQLSTATE or SQLCODE variable, it is good practice for you to define handlers against all error conditions [...] that populate a SQLCODE-like variable..."

Replace "that populate" with "and populate".

Kerry Burton  Oct 24, 2020 
Printed Page 173
Line 16 (including paragraph headings)

The book says "IF EXISTS is only valid for stored procedures
and triggers, not for triggers", which seems a bit self-contradictory.

Presumably it should say "... only valid for stored procedures and
functions, ..."

Anonymous   
Printed Page 186
Example 8-3, line 8

Drop 'sp_' from 'sp_location_exists'. Later reference is to 'location_exists'.

Anonymous   
Printed Page 201
Example 8-12, line 59

END$$ should read: END;

Anonymous   
PDF Page 217
5th item in Table 9-1 on page 217

Function name "EXPORT_SET" should be changed to "ENCODE_SET" to match the description of the "ENCODE_SET" function in the table.

Joseph Chen  Nov 15, 2010 
Printed Page 286
Example 13-14

Trying to reproduce the example code causes an error:
"Number of bind variables doesn't match number of fields in prepared statement"
It seems calling bind_result on a statement with a different number of params than are bound to the prepared statement is not allowed.

Anonymous  Jan 04, 2012 
Printed Page 346
Example 15-1

Strict should be all lowercase, e.g.,
use strict;
use DBI;

otherwise call results in
Can't locate Strict.pm in @INC (@INC contains: ...)

Anonymous   
Printed Page 348
Example 15-7

In perl the concatenation operator is '.' not '||' (as in SQL) ;-)
Example 15-7 should read

$sth->bind_param(2, 'Row# ' . $i);
^^^


Anonymous   
Printed Page 348
Examples 15-7, 15-8

Anonymous   
Printed Page 352
Example 15-17

Maybe it should be clarified that the returned TYPE attribute are integers and correspond to some
international standards. Maybe an example how to translate them would be great.

my $translated = $dbh->type_info( $type )->{TYPE_NAME};

Anonymous   
Printed Page 359
Example 15-30

If you use the downloaded file rather than typing the script, the script won't run without the "-w" on the shebang line under Linux/Unix:

"#!/usr/bin/perl" -> "#!/usr/bin/perl -w"

I believe this is due to the Windows-style line endings ("\r\n") which need to be changed to Linux/Unix style; then the script will run without the change to the shebang line.

Anonymous  May 28, 2014 
Printed Page 364
2nd paragraph

It's worth mentioning here that users wanting to use MySQLdb Extension with Python should use Python 2.7, as MySQLdb does not yet work with Python 3.x. The last notice that it would eventually work with Python 3.3 was in 2012, and it's still not done.

Anonymous  Jun 30, 2017 
Printed Page 379
Section Obtaining Output parameters

I have yet to be able to get output variables to work with stored procedures on MySQL. It always produces error 1414. Looking through a few forums on the internet, it's apparent that many people have this problem, using both IN and INOUT.

The solution offered is that they need to run it on MySQL 5.0 or higher.
I am running MySQL 5.5.55, and still get this error. (Shrug).

Anonymous  Jun 30, 2017 
Printed, PDF Page 382
Example 16-31, line 15

The latest version of MySQL-python (1.2.5) will error without changing the csr1.execute() call database parameter to a tuple (or dictionary) rather than a list.

e.g.

csr1.execute("call sp_mysql_info(%s,@server_version)", (mdatabase))

should now be:

csr1.execute("call sp_mysql_info(%s,@server_version)", (mdatabase,))

Note the extra comma after mdatabase, before the first of the two, outer parentheses.

Anonymous  May 28, 2014 
Printed, PDF Page 429
Example 18-3, line 12

Line:

"WHERE db_user=l_user_name;" in cursor definition throws an error -

'Unknown column 'db_user' in where clause.

At the very least this should be:

"WHERE firstname=l_user_name;"

And this assummes you have a user that matches one of the firstnames in the employee table - you might have multiple matches.

Presumably the idea is to have a "db_user" unique for each employee that would need access to your tables and then the original code would stand?

Anonymous  May 28, 2014 
Printed Page 463
Line 1

The chapter begins "In this chapter, we will tune of simple SQL statements...",
which doesn't make sense. Is "of" superfluous?

Anonymous   
Printed Page 567-568
Dynamic SQL Example - bind order

The example SQL code appears to get "in_where_val" and "in_set_val" mixed up.

While the code is "technically" correct, it definitely does not follow best practices illustrated earlier in the same chapter.

If you look at the input parameters:
(in_table varchar(60),
in_where_col varchar(60),
in_set_col varchar(60),
in_where_val varchar(60),
in_set_val varchar(60))

And compare that with your sample:
CALL update_anything_g('employees','employee_id','salary',100000,1)

Judging by the way the variables are named, it would seem that you are going to update the salary = 1 where the employee_id = 100000.

But in fact, the procedure works as intended because your items are in the wrong order in the USING clause:

'UPDATE employees SET salary = ? WHERE employee_id = ?'

EXECUTE s1 USING @where_val,@set_val;

So your procedure works because you know the correct order for submitting variables. However, as far as self-documenting code goes - any future developer is going to really be confused using this procedure because they are probably going to first submit the data logically according to the input parameter labels.

Anonymous   
Printed Page 607
SUBSTRNG

typo SUBSTRNG
should be SUBSTRING

Anonymous  Nov 26, 2008