DBD-mysql-4.033/0000755000175000017500000000000012613570357011740 5ustar patgpatgDBD-mysql-4.033/TODO0000644000175000017500000000160012524125336012417 0ustar patgpatg- update tests to use get_info(SQL_IDENTIFIER_QUOTE_CHAR) for quoting (when s///ing suff out or update tests to use quoted names). x use DBD::ODBC & its type_info_all() to test type_info_all in DBD::mysql - write test scripts for quote_idenitifer(); - add tests for autoreconnect (dev only -- since these will require restarting mysqld ?) - Write up test for found_rows = 1 + document change of behaviour in found_rows + Document compile time options to change found_rows behaviour + Document compile time option for SSL: 'perl Makefile.PL -ssl' is not documented - dbd_login6 with attrib (maybe) - f_key_info() func & tests. + update type_info_all. - Warnings when invalid GetTypeInfo type is passed into get_type_info; - make tests should test all mysql column types for native2sql() -- or better yet have native2sql be generated by a script that also generates the types table. DBD-mysql-4.033/constants.h0000644000175000017500000000363412524125336014125 0ustar patgpatg#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include static double mysql_constant(char* name, char* arg) { errno = 0; arg= arg; switch (*name) { case 'B': if (strEQ(name, "BLOB_FLAG")) return BLOB_FLAG; break; case 'F': if (strnEQ(name, "FIELD_TYPE_", 11)) { char* n = name+11; switch(*n) { case 'B': if (strEQ(n, "BLOB")) return FIELD_TYPE_BLOB; break; case 'C': if (strEQ(n, "CHAR")) return FIELD_TYPE_CHAR; break; case 'D': if (strEQ(n, "DECIMAL")) return FIELD_TYPE_DECIMAL; if (strEQ(n, "DATE")) return FIELD_TYPE_DATE; if (strEQ(n, "DATETIME")) return FIELD_TYPE_DATETIME; if (strEQ(n, "DOUBLE")) return FIELD_TYPE_DOUBLE; break; case 'F': if (strEQ(n, "FLOAT")) return FIELD_TYPE_FLOAT; break; case 'I': if (strEQ(n, "INT24")) return FIELD_TYPE_INT24; break; case 'L': if (strEQ(n, "LONGLONG")) return FIELD_TYPE_LONGLONG; if (strEQ(n, "LONG_BLOB")) return FIELD_TYPE_LONG_BLOB; if (strEQ(n, "LONG")) return FIELD_TYPE_LONG; break; case 'M': if (strEQ(n, "MEDIUM_BLOB")) return FIELD_TYPE_MEDIUM_BLOB; break; case 'N': if (strEQ(n, "NULL")) return FIELD_TYPE_NULL; break; case 'S': if (strEQ(n, "SHORT")) return FIELD_TYPE_SHORT; if (strEQ(n, "STRING")) return FIELD_TYPE_STRING; break; case 'T': if (strEQ(n, "TINY")) return FIELD_TYPE_TINY; if (strEQ(n, "TINY_BLOB")) return FIELD_TYPE_TINY_BLOB; if (strEQ(n, "TIMESTAMP")) return FIELD_TYPE_TIMESTAMP; if (strEQ(n, "TIME")) return FIELD_TYPE_TIME; break; case 'V': if (strEQ(n, "VAR_STRING")) return FIELD_TYPE_VAR_STRING; break; } } break; case 'N': if (strEQ(name, "NOT_NULL_FLAG")) return NOT_NULL_FLAG; break; case 'P': if (strEQ(name, "PRI_KEY_FLAG")) return PRI_KEY_FLAG; break; } errno = EINVAL; return 0; } DBD-mysql-4.033/LICENSE0000644000175000017500000004370012524125336012743 0ustar patgpatgThis software is copyright (c) 2015 by Patrick Galbraith, Michiel Beijen and all other contributors. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End DBD-mysql-4.033/Makefile.PL0000644000175000017500000006500212524125336013707 0ustar patgpatg# -*- cperl -*- use strict; use warnings; use 5.008_001; use Config; use Getopt::Long; use ExtUtils::MakeMaker; use Data::Dumper; use File::Path; use File::Copy; use File::Basename; use File::Spec; require DBI::DBD; my $TESTDB = "test"; our $opt = { "help" => \&Usage, }; Getopt::Long::GetOptions( $opt, "help", "testdb=s", "testhost=s", "testport=s", "testuser=s", "testpassword=s", "testsocket=s", "cflags=s", "libs=s", "verbose", "ps-protocol", "bind-type-guessing", "nocatchstderr", "ssl!", "nofoundrows!", "embedded=s", "mysql_config=s", "force-embedded", "with-mysql=s" ) || die Usage(); my $source = {}; #Check for mysql_config first $source->{'mysql_config'} = "guessed"; if ($opt->{'mysql_config'}) { $source->{'mysql_config'} = 'Users choice'; } if (!$opt->{'mysql_config'} && $ENV{DBD_MYSQL_CONFIG}) { $opt->{'mysql_config'} = $ENV{DBD_MYSQL_CONFIG}; $source->{'mysql_config'} = 'environment'; } if ($opt->{'mysql_config'}) { $opt->{'mysql_config'} = Win32::GetShortPathName($opt->{'mysql_config'}) if $^O eq 'MSWin32'; if (!-f $opt->{'mysql_config'}) { print <<"MSG"; Specified mysql configuration script '$opt->{'mysql_config'}' doesn't exist. Please check path/permissions. Will try to use default mysql_config script found through PATH. MSG $opt->{'mysql_config'}= "mysql_config"; } } else { if (! `mysql_config`) { print <{'mysql_config'} = "mysql_config"; } for my $key (qw/testdb testhost testuser testpassword testsocket testport cflags embedded libs nocatchstderr ssl nofoundrows ps-protocol bind-type-guessing force-embedded/) { Configure($opt, $source, $key); } #if we have a testport but no host, assume localhost if ( $opt->{testport} && !$opt->{testhost} ) { $opt->{testhost} = 'localhost'; $source->{testhost} = 'guessed'; } #We have to rename/move Makefile.PL in mysqlEmb directory #since MakeMaker will find it and will try to execute it. if (-f "mysqlEmb/Makefile.PL") { move ("mysqlEmb/Makefile.PL", "mysqlEmb/Makefile.PL.old"); } #Disable of building of dbd::mysqlEmb driver by default $opt->{'embedded'}="" if !$opt->{'force-embedded'}; if ($opt->{'embedded'}) { if ($source->{'embedded'} eq 'mysql_config') { #We have to use libmygcc to resolve linking problem # this causes problems for cygwin #$opt->{'embedded'} .= " -lmygcc"; # Under Cygwin (at least) we have to use libstdc++ to resolve linking # problem because libmysqld is built using g++ rather than gcc. $opt->{'embedded'} .= " -lstdc++"; } my @files = ($^O =~ /mswin32/i) ? qw(mysqlclient.lib) : qw(libmysqld.a); my @dirs = $opt->{'embedded'} =~ /-L(.*?)(?:\s|$)/g; if( !(SearchFor('lib', @files)) && !(SearchFor2(\@files,\@dirs)) ) { warn <<"MSG"; You intended to build DBD::mysqlEmb driver by using option: --embedded=$opt->{'embedded'}. But we failed to determine directory of @files. Building of DBD::mysqlEmb driver was disabled. Please use perl Makefile.PL --embedded="-L " to set correct directory. For details see DBD::mysql::INSTALL, section "Linker flags" or type perl Makefile.PL --help MSG $source->{'embedded'} = "guessed"; $opt->{'embedded'}=""; } } if ($opt->{'embedded'} && !check_include_version($opt->{'cflags'}, 40003)) { die <<"MSG"; WARNING: Wrong version or unable to check version of mysql include files. To build embedded version of DBD you ought to be sure that you use include files from MySQL server >= 4.0.3. MSG } print <<"MSG"; I will use the following settings for compiling and testing: MSG delete $opt->{'help'}; my $keylen = 0; for my $key (keys %$opt) { $keylen = length($key) if length($key) > $keylen; } my $slen = 0; for my $val (values %$source) { $slen = length($val) if length($val) > $slen; } for my $key (sort { $a cmp $b} keys %$opt) { printf(" %-" . $keylen . "s (%-" . $slen . "s) = %s\n", $key, $source->{$key}, $opt->{$key}) } print <<"MSG"; To change these settings, see 'perl Makefile.PL --help' and 'perldoc DBD::mysql::INSTALL'. MSG sleep 1; my $dsn= ''; if (exists $opt->{'ps-protocol'}) { $dsn = "\$::test_dsn .= \";mysql_server_prepare=1\";\n"; } elsif (exists $opt->{'bind-type-guessing'}) { $dsn= "\$::test_dsn .= \";mysql_bind_type_guessing=1\";\n"; } my $fileName = $@ ? "t/mysql.mtest" : File::Spec->catfile("t", "mysql.mtest"); (open(FILE, ">$fileName") && (print FILE ("{ local " . Data::Dumper->Dump([$opt], ["opt"]) . "\$::test_host = \$opt->{'testhost'};\n" . "\$::test_port = \$opt->{'testport'};\n" . "\$::test_user = \$opt->{'testuser'};\n" . "\$::test_socket = \$opt->{'testsocket'};\n" . "\$::test_password = \$opt->{'testpassword'};\n" . "\$::test_db = \$opt->{'testdb'};\n" . "\$::test_dsn = \"DBI:mysql:\$::test_db\";\n" . "\$::test_dsn .= \";mysql_socket=\$::test_socket\" if \$::test_socket;\n" . "\$::test_dsn .= \":\$::test_host\" if \$::test_host;\n" . "\$::test_dsn .= \":\$::test_port\" if \$::test_port;\n". $dsn . "} 1;\n")) && close(FILE)) || die "Failed to create $fileName: $!"; my $cflags = "-I\$(DBI_INSTARCH_DIR) $opt->{'cflags'}"; if ($^O eq 'VMS') { $cflags = "\$(DBI_INSTARCH_DIR),$opt->{'cflags'}"; } $cflags .= " -DDBD_MYSQL_WITH_SSL" if $opt->{'ssl'}; $cflags .= " -DDBD_MYSQL_INSERT_ID_IS_GOOD" if $DBI::VERSION > 1.42; $cflags .= " -DDBD_NO_CLIENT_FOUND_ROWS" if $opt->{'nofoundrows'}; $cflags .= " -g "; my %o = ( 'NAME' => 'DBD::mysql', 'INC' => $cflags, 'dist' => { 'SUFFIX' => ".gz", 'DIST_DEFAULT' => 'all tardist', 'COMPRESS' => "gzip -9f" }, 'clean' => { 'FILES' => '*.xsi' }, 'realclean' => { 'FILES' => 't/mysql.mtest' }, 'C' => ["dbdimp.c", "mysql.c"], 'XS' => {'mysql.xs' => 'mysql.c'}, 'OBJECT' => '$(O_FILES)', 'LIBS' => $opt->{'libs'}, $opt->{'ldflags'} ? ('LDFLAGS' => $opt->{'ldflags'}) : (), 'VERSION_FROM' => 'lib/DBD/mysql.pm' ); my %embedded_files=(); if ($opt->{'embedded'}) { %embedded_files = ( 'mysql.xs' => { filename => 'mysqlEmb/mysqlEmb.xs', replace => { ':mysql' => ':mysqlEmb', 'mysql.xsi' => 'mysqlEmb.xsi'}, makedir => 'mysqlEmb' }, 'lib/DBD/mysql.pm' => { filename => 'mysqlEmb/lib/DBD/mysqlEmb.pm', replace => { ':mysql' => ':mysqlEmb', '=> \'mysql\'' => '=> \'mysqlEmb\''}, makedir => 'mysqlEmb/lib/DBD' }, 'lib/DBD/mysql/GetInfo.pm' => { filename => 'mysqlEmb/lib/DBD/mysqlEmb/GetInfo.pm', replace => {':mysql' => ':mysqlEmb', '\'mysql\'' => '\'mysqlEmb\''}, makedir => 'mysqlEmb/lib/DBD/mysqlEmb' }, 't/mysql.dbtest' => { filename => 'mysqlEmb/t/mysqlEmb.dbtest', makedir => 'mysqlEmb/t' }, 't/mysql.mtest' => { filename => 'mysqlEmb/t/mysqlEmb.mtest', makedir => 'mysqlEmb/t', replace => { 'DBI:mysql'=> 'DBI:mysqlEmb', 'test_db";' => 'test_db;mysql_embedded_options=--datadir=./t,--skip-innodb,--skip-bdb";' } }, 't/lib.pl' => { filename => 'mysqlEmb/t/lib.pl', replace => { '\$mdriver =.*' => "\$mdriver =\'mysqlEmb\';"}, makedir => 'mysqlEmb/t' }, 't/20createdrop.t' => { filename => 'mysqlEmb/t/20createdrop.t', makedir => 'mysqlEmb/t' }, 't/30insertfetch.t' => { filename => 'mysqlEmb/t/30insertfetch.t', makedir => 'mysqlEmb/t' }, 't/40bindparam.t' => { filename => 'mysqlEmb/t/40bindparam.t', makedir => 'mysqlEmb/t' }, 't/40blobs.t' => { filename => 'mysqlEmb/t/40blobs.t', makedir => 'mysqlEmb/t' }, 't/40listfields.t' => { filename => 'mysqlEmb/t/40listfields.t', makedir => 'mysqlEmb/t' }, 't/40nulls.t' => { filename => 'mysqlEmb/t/40nulls.t', makedir => 'mysqlEmb/t' }, 't/40numrows.t' => { filename => 'mysqlEmb/t/40numrows.t', makedir => 'mysqlEmb/t' }, 't/50chopblanks.t' => { filename => 'mysqlEmb/t/50chopblanks.t', makedir => 'mysqlEmb/t' }, 't/50commit.t' => { filename => 'mysqlEmb/t/50commit.t', makedir => 'mysqlEmb/t' }, 't/60leaks.t' => { filename => 'mysqlEmb/t/60leaks.t', makedir => 'mysqlEmb/t' }, 't/00base.t' => { filename => 'mysqlEmb/t/00base.t', makedir => 'mysqlEmb/t' }, 'myld' => { filename => 'mysqlEmb/myld', makedir => 'mysqlEmb' }, 'dbdimp.c' => { filename => 'mysqlEmb/dbdimp.c', makedir => 'mysqlEmb' }, 'dbdimp.h' => { filename => 'mysqlEmb/dbdimp.h', makedir => 'mysqlEmb' }, 'constants.h' => { filename => 'mysqlEmb/constants.h', makedir => 'mysqlEmb' }, 'Makefile.PL.embedded' => { filename => 'mysqlEmb/Makefile.PL', makedir => 'mysqlEmb' }, ); #Create embedded files from original ones prepare_files(\%embedded_files); my %e=%o; $o{'clean'}->{'FILES'} .= " ./mysqlEmb"; $o{'DIR'}=['mysqlEmb']; $e{'NAME'} = 'DBD::mysqlEmb'; $e{'C'} = ["dbdimp.c", "mysqlEmb.c"]; $e{'XS'} = {'mysqlEmb.xs' => 'mysqlEmb.c'}; $e{'VERSION_FROM'} = 'lib/DBD/mysqlEmb.pm'; $e{'LIBS'} = $opt->{'embedded'}; $e{'INC'} .= " -DDBD_MYSQL_EMBEDDED"; print "Preparing embedded Makefile\n"; #Create Makefile.conf for mysqlEmb Makefile.PL create_makefile(Data::Dumper->Dump([\%e], ["o"])); } if (eval $ExtUtils::MakeMaker::VERSION >= 5.43) { $o{'CAPI'} = 'TRUE' if (eval $ExtUtils::MakeMaker::VERSION >= 5.43 && $Config::Config{'archname'} =~ /-object\b/i); $o{'AUTHOR'} = 'Patrick Galbraith '; $o{'ABSTRACT'} = 'A MySQL driver for the Perl5 Database Interface (DBI)'; $o{'PREREQ_PM'} = { 'DBI' => 1.08, 'Data::Dumper' => 0 }; %o=(%o, LICENSE => 'perl', MIN_PERL_VERSION => '5.008001', META_MERGE => { resources => { repository => 'https://github.com/perl5-dbi/DBD-mysql', MailingList => 'mailto:dbi-dev@perl.org', license => 'http://dev.perl.org/licenses/', homepage => 'http://dbi.perl.org/', IRC => 'irc://irc.perl.org/#dbi', }, }, BUILD_REQUIRES => { 'Test::Simple' => '0.90', 'Test::Deep' => 0, }, CONFIGURE_REQUIRES => { 'DBI' => 1.08, }, ); } WriteMakefile1(%o); exit 0; ############################################################################ # # Name: Usage # # Purpose: Print Usage message and exit with error status. # ############################################################################ sub Usage { print STDERR <<"USAGE"; Usage: perl $0 [options] Possible options are: --cflags= Use for running the C compiler; defaults to the value of "mysql_config --cflags" or a guessed value --libs= Use for running the linker; defaults to the value of "mysql_config --libs" or a gussed value --force-embedded Build version of driver supporting mysqlEmb --embedded= Use these libs when building the embedded version of DBD (with --force-embedded). Defaults to the value of "mysql_config --embedded". --testdb= Use the database for running the test suite; defaults to $TESTDB --testuser= Use the username for running the test suite; defaults to no username --testpassword= Use the password for running the test suite; defaults to no password --testhost= Use as a database server for running the test suite; defaults to localhost. --testport= Use as the port number of the database; by default the port number is choosen from the mysqlclient library --mysql_config= Specify for mysql_config script --with-mysql= Specify for the root of the MySQL installation. --nocatchstderr Supress using the "myld" script that redirects STDERR while running the linker. --nofoundrows Change the behavior of \$sth->rows() so that it returns the number of rows physically modified instead of the rows matched --ps-protocol Toggle the use of driver emulated prepared statements prepare, requires MySQL server >= 4.1.3 for server side prepared statements, off by default --bind-type-guessing Toggle the use of driver attribute mysql_bind_type_guessing This feature makes it so driver-emulated prepared statements try to "guess" if a value being bound is numeric, in which case, quotes will not be put around the value. --ssl Enable SSL support --help Print this message and exit All options may be configured on the command line. If they are not present on the command line, then mysql_config is called (if it can be found): mysql_config --cflags mysql_config --libs mysql_config --embedded mysql_config --testdb and so on. See DBD::mysql::INSTALL for details. USAGE exit 1; } ############################################################################ # # Name: Configure # # Purpose: Automatic configuration # # Inputs: $param - Name of the parameter being configured # # Returns: Generated value, never undef # ############################################################################ sub Configure { my($opt, $source, $param) = @_; if ($param eq 'bind-type-guessing') { $source->{$param}= ($opt->{$param}) ? "User's choice" : 'default'; return; } if ($param eq 'ps-protocol') { $source->{$param}= ($opt->{$param}) ? "User's choice" : 'default'; return; } if (exists($opt->{$param})) { $source->{$param} = "User's choice"; return; } # First try to get options values from mysql_config my @mysql_config_options = qw( cflags include libs libs_r plugindir socket port version libmysqld-libs ); if ( grep {$_ eq $param} @mysql_config_options ) { my $command = $opt->{'mysql_config'} . " --$param"; eval { open(PIPE, "$command |") or die "Can't find mysql_config."; }; if (!$@) { my $str = ""; while (defined(my $line = )) { $str .= $line; } if ($str ne "" && $str !~ /Options:/) { $str =~ s/\s+$//s; $str =~ s/^\s+//s; # Unfortunately ExtUtils::MakeMaker doesn't deal very well # with -L'...' $str =~ s/\-L\'(.*?)\'/-L$1/sg; $str =~ s/\-L\"(.*?)\"/-L$1/sg; # Separate libs from ldflags if ($param eq 'libs') { my (@libs, @ldflags); for (split ' ', $str) { if (/^-[Ll]/) { push @libs, $_ } else { push @ldflags, $_ } } $str = "@libs"; $opt->{ldflags} = "@ldflags"; $source->{ldflags} = "mysql_config"; } $opt->{$param} = $str; $source->{$param} = "mysql_config"; return; } } else { print "Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located\n"; } } # Ok, mysql_config doesn't work. We need to do our best # First check environment variables if (defined($ENV{'DBD_MYSQL_'.uc($param)})) { $opt->{$param} = $ENV{'DBD_MYSQL_'.uc($param)}; $source->{$param} = 'environment'; } # Then try to guess unless ($opt->{$param}) { if ($param eq 'testuser') { my $user = $ENV{USER} || ''; print " PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user '$user' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to '$user'\@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username "; $opt->{$param} = $user; $source->{$param} = 'guessed'; } elsif ($param eq "nocatchstderr" || $param eq "nofoundrows") { $source->{$param} = "default"; $opt->{$param} = 0; } elsif ($param eq "testdb") { $source->{$param} = "default"; $opt->{$param} = $TESTDB; } elsif ($param eq "testhost" || $param eq "testport" || $param eq "testpassword" || $param eq "testsocket" ) { $source->{$param} = "default"; $opt->{$param} = ""; } elsif($param eq 'force-embedded') { $source->{$param} = $opt->{$param} ? "default" : 'not set'; } elsif ($param eq "cflags") { $source->{$param} = "guessed"; my $dir = SearchFor('include', 'mysql.h'); if ($dir) { $opt->{$param} = "-I$dir"; return; } die <<"MSG"; Failed to determine directory of mysql.h. Use perl Makefile.PL --cflags=-I to set this directory. For details see DBD::mysql::INSTALL, section "C Compiler flags" or type perl Makefile.PL --help MSG } elsif ($param eq "libs" || $param eq "embedded") { $source->{$param} = "guessed"; if ($param eq "embedded" && !$opt->{'embedded'}) { $opt->{$param}=""; return; } my @files=(); my $default_libs; if ($param eq "embedded") { $default_libs= "-lmysqld -lpthread -lz -lm -lcrypt -lnsl"; @files = ($^O =~ /mswin32/i) ? qw(mysqlclient.lib) : qw(libmysqld.a); } else { $default_libs= "-lmysqlclient -lz -lm -lcrypt -lnsl"; @files = ($^O =~ /mswin32/i) ? qw(mysqlclient.lib) : qw(libmysqlclient.a libmysqlclient.so); } my $dir = SearchFor('lib', @files); if ($dir) { $opt->{$param} = "-L$dir $default_libs"; return; } my $f = join("|", @files); die <<"MSG"; Failed to determine directory of $f. Use perl Makefile.PL "--$param=-L $default_libs" to set this directory. For details see the DBD::mysql::INSTALL, section "Linker flags" or type perl Makefile.PL --help MSG } elsif ($param eq "ssl") { $opt->{$param} = ($opt->{"libs"} =~ /ssl/) ? 1 : 0; $source->{$param} = "guessed"; } else { die "Unknown configuration parameter: $param"; } } } my $fineDir; sub SearchFor { my($subdir, @files) = @_; my @dirs = ($^O eq 'MSWin32') ? qw(C:) : qw(/usr/local /usr /opt); unshift(@dirs, $fineDir) if defined($fineDir); for my $f (@files) { for my $dir (@dirs) { my $try1 = File::Spec->catdir($dir, $subdir); my $try2 = File::Spec->catdir($dir, "mysql"); my $try3 = File::Spec->catdir($try1, "mysql"); my $try4 = File::Spec->catdir($try2, $subdir); for my $path ($try3, $try4, $try2, $try1, $dir) { my $file = File::Spec->catfile($path, $f); if (-f $file) { $fineDir = $dir; return $path; } } } } } sub SearchFor2 { my($files, $dirs) = @_; for my $f (@{$files}) { for my $dir (@{$dirs}) { if (-f File::Spec->catfile($dir, $f)) { $fineDir = $dir; return $dir; } } } } sub check_include_version { my ($dir, $ver) = @_; my $headerfile; $dir =~ s/-I//; $dir =~ s/'//g; $dir =~ s/\s.*//g; open(HEADERFILE ,"<${dir}/mysql_version.h") or (print "Unable to open header file ${dir}/mysql_version.h" && exit(0)); { local undef $/; $headerfile = ; } close(HEADERFILE); my ($version_id) = ($headerfile =~ /MYSQL_VERSION_ID[\t\s]+(\d+)[\n\r]/); if ($version_id < $ver) { print <<"MSG"; Version of MySQL include files in $dir - $1 MSG return 0; } return 1; } sub replace { my ($str, $ref)=@_; for my $find (keys %{$ref}) { $str =~ s/$find/$ref->{$find}/g; } $str; } sub prepare_files { my ($files)= @_; my $line; my @lib; for my $file (keys %{$files}) { if ($files->{$file}->{makedir}) { mkpath $files->{$file}->{makedir} or die "Can't create dir $files->{$file}->{makedir}" unless (-e $files->{$file}->{makedir} && -d $files->{$file}->{makedir}); } my $replace=$files->{$file}->{replace}; if ($replace) { open(FILE, $file) or die "Can't open file $file"; @lib= map { $replace ? replace($_, $replace) : $_; } ; close(FILE); open(FILE, ">".$files->{$file}->{filename}) or die "Can't open file $files->{$file}->{filename}"; print FILE @lib; close(FILE); } else { if(!copy($file, $files->{$file}->{filename})) { die "Unable to copy $file to $files->{$file}->{filename}\n"; } } } } sub create_makefile { my ($cnf)=@_; open(LOG, ">mysqlEmb/Makefile.conf") or die "Can't write to file mysqlEmb/Makefile.conf"; print LOG $cnf; close(LOG); } package MY; sub libscan { my($self, $path) = @_; return '' if $path =~ /\B\.svn\b|~#|\BSCCS\b/; $path; } sub macro { "\n" . DBI::DBD::dbd_postamble(@_) . <<"POSTAMBLE"; installhtml: lib/DBD/mysql/INSTALL.pod \tpod2html --infile=lib/DBD/mysql/INSTALL.pod --outfile=INSTALL.html POSTAMBLE }; sub dynamic_lib { my $self = shift; my $result = $self->SUPER::dynamic_lib(@_); if (!$::opt->{nocatchstderr} && $result =~ /\$\(LD\)/) { $result =~ s/(\$\(LD\))/\$\(PERL\) myld \$(LD)/sg; } return $result; } package main; sub WriteMakefile1 { #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params=@_; my $eumm_version=$ExtUtils::MakeMaker::VERSION; $eumm_version=eval $eumm_version; die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; die "License not specified" if not exists $params{LICENSE}; if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{META_ADD} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; delete $params{AUTHOR} if $] < 5.005; delete $params{ABSTRACT_FROM} if $] < 5.005; delete $params{BINARY_LOCATION} if $] < 5.005; ExtUtils::MakeMaker::WriteMakefile(%params); } __DATA__ my %opts = (); GetOptions(\%opts, 'cflags', 'libs', 'port', 'version', 'libmysqld-libs', 'embedded', 'embedded-libs', 'help', ) or usage(); usage() if ($opts{help} or not %opts); SWITCH : { local $\ = "\n"; $opts{cflags} and do { print $cflags; last SWITCH; }; $opts{libs} and do { print $libs; last SWITCH; }; $opts{port} and do { print $port; last SWITCH; }; $opts{version} and do { print $version; last SWITCH; }; ($opts{'libmysqld-libs'} or $opts{embedded} or $opts{'libmysqld-libs'} ) and do { print $embedded_libs; last SWITCH; }; usage(); } exit(0); sub usage { print << "EOU"; Usage: $0 [OPTIONS] Options: --cflags [$cflags] --libs [$libs] --port [$port] --version [$version] --libmysqld-libs [$embedded_libs] EOU exit(1); } DBD-mysql-4.033/META.json0000664000175000017500000000242312613570357013364 0ustar patgpatg{ "abstract" : "A MySQL driver for the Perl5 Database Interface (DBI)", "author" : [ "Patrick Galbraith " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "DBD-mysql", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::Deep" : "0", "Test::Simple" : "0.90" } }, "configure" : { "requires" : { "DBI" : "1.08" } }, "runtime" : { "requires" : { "DBI" : "1.08", "Data::Dumper" : "0", "perl" : "5.008001" } } }, "release_status" : "stable", "resources" : { "homepage" : "http://dbi.perl.org/", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/perl5-dbi/DBD-mysql" }, "x_IRC" : "irc://irc.perl.org/#dbi", "x_MailingList" : "mailto:dbi-dev@perl.org" }, "version" : "4.033" } DBD-mysql-4.033/lib/0000755000175000017500000000000012613570357012506 5ustar patgpatgDBD-mysql-4.033/lib/Bundle/0000755000175000017500000000000012613570357013717 5ustar patgpatgDBD-mysql-4.033/lib/Bundle/DBD/0000755000175000017500000000000012613570357014310 5ustar patgpatgDBD-mysql-4.033/lib/Bundle/DBD/mysql.pm0000644000175000017500000000037212613567262016016 0ustar patgpatgpackage Bundle::DBD::mysql; use strict; use warnings; our $VERSION = '4.033'; 1; __END__ =pod =head1 NAME Bundle::DBD::mysql =head1 DESCRIPTION This package only exists for legacy reasons. Please use the L package instead. =cut DBD-mysql-4.033/lib/DBD/0000755000175000017500000000000012613570357013077 5ustar patgpatgDBD-mysql-4.033/lib/DBD/mysql/0000755000175000017500000000000012613570357014244 5ustar patgpatgDBD-mysql-4.033/lib/DBD/mysql/GetInfo.pm0000644000175000017500000003732112524125336016135 0ustar patgpatgpackage DBD::mysql::GetInfo; ######################################## # DBD::mysql::GetInfo # # # Generated by DBI::DBD::Metadata # $Author$ <-- the person to blame # $Revision$ # $Date$ use strict; use warnings; use DBD::mysql; # Beware: not officially documented interfaces... # use DBI::Const::GetInfoType qw(%GetInfoType); # use DBI::Const::GetInfoReturn qw(%GetInfoReturnTypes %GetInfoReturnValues); my $sql_driver = 'mysql'; # SQL_DRIVER_VER should be formatted as dd.dd.dddd my $dbdversion = $DBD::mysql::VERSION; $dbdversion .= '_00' if $dbdversion =~ /^\d+\.\d+$/; my $sql_driver_ver = sprintf("%02d.%02d.%04d", split(/[\._]/,$dbdversion)); my @Keywords = qw( BIGINT BLOB DEFAULT KEYS LIMIT LONGBLOB MEDIMUMBLOB MEDIUMINT MEDIUMTEXT PROCEDURE REGEXP RLIKE SHOW TABLES TINYBLOB TINYTEXT UNIQUE UNSIGNED ZEROFILL ); sub sql_keywords { return join ',', @Keywords; } sub sql_data_source_name { my $dbh = shift; return "dbi:$sql_driver:" . $dbh->{Name}; } sub sql_user_name { my $dbh = shift; # Non-standard attribute return $dbh->{CURRENT_USER}; } #################### # makefunc() # returns a ref to a sub that calls into XS to get # values for info types that must needs be coded in C sub makefunk ($) { my $type = shift; return sub {dbd_mysql_get_info(shift, $type)} } our %info = ( 20 => 'N', # SQL_ACCESSIBLE_PROCEDURES 19 => 'Y', # SQL_ACCESSIBLE_TABLES 0 => 0, # SQL_ACTIVE_CONNECTIONS 116 => 0, # SQL_ACTIVE_ENVIRONMENTS 1 => 0, # SQL_ACTIVE_STATEMENTS 169 => 127, # SQL_AGGREGATE_FUNCTIONS 117 => 0, # SQL_ALTER_DOMAIN 86 => 3, # SQL_ALTER_TABLE 10021 => makefunk 10021, # SQL_ASYNC_MODE 120 => 2, # SQL_BATCH_ROW_COUNT 121 => 2, # SQL_BATCH_SUPPORT 82 => 0, # SQL_BOOKMARK_PERSISTENCE 114 => 1, # SQL_CATALOG_LOCATION 10003 => 'Y', # SQL_CATALOG_NAME 41 => makefunk 41, # SQL_CATALOG_NAME_SEPARATOR 42 => makefunk 42, # SQL_CATALOG_TERM 92 => 29, # SQL_CATALOG_USAGE 10004 => '', # SQL_COLLATING_SEQUENCE 10004 => '', # SQL_COLLATION_SEQ 87 => 'Y', # SQL_COLUMN_ALIAS 22 => 0, # SQL_CONCAT_NULL_BEHAVIOR 53 => 259071, # SQL_CONVERT_BIGINT 54 => 0, # SQL_CONVERT_BINARY 55 => 259071, # SQL_CONVERT_BIT 56 => 259071, # SQL_CONVERT_CHAR 57 => 259071, # SQL_CONVERT_DATE 58 => 259071, # SQL_CONVERT_DECIMAL 59 => 259071, # SQL_CONVERT_DOUBLE 60 => 259071, # SQL_CONVERT_FLOAT 48 => 0, # SQL_CONVERT_FUNCTIONS # 173 => undef, # SQL_CONVERT_GUID 61 => 259071, # SQL_CONVERT_INTEGER 123 => 0, # SQL_CONVERT_INTERVAL_DAY_TIME 124 => 0, # SQL_CONVERT_INTERVAL_YEAR_MONTH 71 => 0, # SQL_CONVERT_LONGVARBINARY 62 => 259071, # SQL_CONVERT_LONGVARCHAR 63 => 259071, # SQL_CONVERT_NUMERIC 64 => 259071, # SQL_CONVERT_REAL 65 => 259071, # SQL_CONVERT_SMALLINT 66 => 259071, # SQL_CONVERT_TIME 67 => 259071, # SQL_CONVERT_TIMESTAMP 68 => 259071, # SQL_CONVERT_TINYINT 69 => 0, # SQL_CONVERT_VARBINARY 70 => 259071, # SQL_CONVERT_VARCHAR 122 => 0, # SQL_CONVERT_WCHAR 125 => 0, # SQL_CONVERT_WLONGVARCHAR 126 => 0, # SQL_CONVERT_WVARCHAR 74 => 1, # SQL_CORRELATION_NAME 127 => 0, # SQL_CREATE_ASSERTION 128 => 0, # SQL_CREATE_CHARACTER_SET 129 => 0, # SQL_CREATE_COLLATION 130 => 0, # SQL_CREATE_DOMAIN 131 => 0, # SQL_CREATE_SCHEMA 132 => 1045, # SQL_CREATE_TABLE 133 => 0, # SQL_CREATE_TRANSLATION 134 => 0, # SQL_CREATE_VIEW 23 => 2, # SQL_CURSOR_COMMIT_BEHAVIOR 24 => 2, # SQL_CURSOR_ROLLBACK_BEHAVIOR 10001 => 0, # SQL_CURSOR_SENSITIVITY 2 => \&sql_data_source_name, # SQL_DATA_SOURCE_NAME 25 => 'N', # SQL_DATA_SOURCE_READ_ONLY 119 => 7, # SQL_DATETIME_LITERALS 17 => 'MySQL', # SQL_DBMS_NAME 18 => makefunk 18, # SQL_DBMS_VER 170 => 3, # SQL_DDL_INDEX 26 => 2, # SQL_DEFAULT_TRANSACTION_ISOLATION 26 => 2, # SQL_DEFAULT_TXN_ISOLATION 10002 => 'N', # SQL_DESCRIBE_PARAMETER # 171 => undef, # SQL_DM_VER 3 => 137076632, # SQL_DRIVER_HDBC # 135 => undef, # SQL_DRIVER_HDESC 4 => 137076088, # SQL_DRIVER_HENV # 76 => undef, # SQL_DRIVER_HLIB # 5 => undef, # SQL_DRIVER_HSTMT 6 => 'libmyodbc3.so', # SQL_DRIVER_NAME 77 => '03.51', # SQL_DRIVER_ODBC_VER 7 => $sql_driver_ver, # SQL_DRIVER_VER 136 => 0, # SQL_DROP_ASSERTION 137 => 0, # SQL_DROP_CHARACTER_SET 138 => 0, # SQL_DROP_COLLATION 139 => 0, # SQL_DROP_DOMAIN 140 => 0, # SQL_DROP_SCHEMA 141 => 7, # SQL_DROP_TABLE 142 => 0, # SQL_DROP_TRANSLATION 143 => 0, # SQL_DROP_VIEW 144 => 0, # SQL_DYNAMIC_CURSOR_ATTRIBUTES1 145 => 0, # SQL_DYNAMIC_CURSOR_ATTRIBUTES2 27 => 'Y', # SQL_EXPRESSIONS_IN_ORDERBY 8 => 63, # SQL_FETCH_DIRECTION 84 => 0, # SQL_FILE_USAGE 146 => 97863, # SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1 147 => 6016, # SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2 81 => 11, # SQL_GETDATA_EXTENSIONS 88 => 3, # SQL_GROUP_BY 28 => 4, # SQL_IDENTIFIER_CASE #29 => sub {dbd_mysql_get_info(shift,$GetInfoType {SQL_IDENTIFIER_QUOTE_CHAR})}, 29 => makefunk 29, # SQL_IDENTIFIER_QUOTE_CHAR 148 => 0, # SQL_INDEX_KEYWORDS 149 => 0, # SQL_INFO_SCHEMA_VIEWS 172 => 7, # SQL_INSERT_STATEMENT 73 => 'N', # SQL_INTEGRITY 150 => 0, # SQL_KEYSET_CURSOR_ATTRIBUTES1 151 => 0, # SQL_KEYSET_CURSOR_ATTRIBUTES2 89 => \&sql_keywords, # SQL_KEYWORDS 113 => 'Y', # SQL_LIKE_ESCAPE_CLAUSE 78 => 0, # SQL_LOCK_TYPES 34 => 64, # SQL_MAXIMUM_CATALOG_NAME_LENGTH 97 => 0, # SQL_MAXIMUM_COLUMNS_IN_GROUP_BY 98 => 32, # SQL_MAXIMUM_COLUMNS_IN_INDEX 99 => 0, # SQL_MAXIMUM_COLUMNS_IN_ORDER_BY 100 => 0, # SQL_MAXIMUM_COLUMNS_IN_SELECT 101 => 0, # SQL_MAXIMUM_COLUMNS_IN_TABLE 30 => 64, # SQL_MAXIMUM_COLUMN_NAME_LENGTH 1 => 0, # SQL_MAXIMUM_CONCURRENT_ACTIVITIES 31 => 18, # SQL_MAXIMUM_CURSOR_NAME_LENGTH 0 => 0, # SQL_MAXIMUM_DRIVER_CONNECTIONS 10005 => 64, # SQL_MAXIMUM_IDENTIFIER_LENGTH 102 => 500, # SQL_MAXIMUM_INDEX_SIZE 104 => 0, # SQL_MAXIMUM_ROW_SIZE 32 => 0, # SQL_MAXIMUM_SCHEMA_NAME_LENGTH 105 => makefunk 105, # SQL_MAXIMUM_STATEMENT_LENGTH # 20000 => undef, # SQL_MAXIMUM_STMT_OCTETS # 20001 => undef, # SQL_MAXIMUM_STMT_OCTETS_DATA # 20002 => undef, # SQL_MAXIMUM_STMT_OCTETS_SCHEMA 106 => makefunk 106, # SQL_MAXIMUM_TABLES_IN_SELECT 35 => 64, # SQL_MAXIMUM_TABLE_NAME_LENGTH 107 => 16, # SQL_MAXIMUM_USER_NAME_LENGTH 10022 => makefunk 10022, # SQL_MAX_ASYNC_CONCURRENT_STATEMENTS 112 => 0, # SQL_MAX_BINARY_LITERAL_LEN 34 => 64, # SQL_MAX_CATALOG_NAME_LEN 108 => 0, # SQL_MAX_CHAR_LITERAL_LEN 97 => 0, # SQL_MAX_COLUMNS_IN_GROUP_BY 98 => 32, # SQL_MAX_COLUMNS_IN_INDEX 99 => 0, # SQL_MAX_COLUMNS_IN_ORDER_BY 100 => 0, # SQL_MAX_COLUMNS_IN_SELECT 101 => 0, # SQL_MAX_COLUMNS_IN_TABLE 30 => 64, # SQL_MAX_COLUMN_NAME_LEN 1 => 0, # SQL_MAX_CONCURRENT_ACTIVITIES 31 => 18, # SQL_MAX_CURSOR_NAME_LEN 0 => 0, # SQL_MAX_DRIVER_CONNECTIONS 10005 => 64, # SQL_MAX_IDENTIFIER_LEN 102 => 500, # SQL_MAX_INDEX_SIZE 32 => 0, # SQL_MAX_OWNER_NAME_LEN 33 => 0, # SQL_MAX_PROCEDURE_NAME_LEN 34 => 64, # SQL_MAX_QUALIFIER_NAME_LEN 104 => 0, # SQL_MAX_ROW_SIZE 103 => 'Y', # SQL_MAX_ROW_SIZE_INCLUDES_LONG 32 => 0, # SQL_MAX_SCHEMA_NAME_LEN 105 => 8192, # SQL_MAX_STATEMENT_LEN 106 => 31, # SQL_MAX_TABLES_IN_SELECT 35 => makefunk 35, # SQL_MAX_TABLE_NAME_LEN 107 => 16, # SQL_MAX_USER_NAME_LEN 37 => 'Y', # SQL_MULTIPLE_ACTIVE_TXN 36 => 'Y', # SQL_MULT_RESULT_SETS 111 => 'N', # SQL_NEED_LONG_DATA_LEN 75 => 1, # SQL_NON_NULLABLE_COLUMNS 85 => 2, # SQL_NULL_COLLATION 49 => 16777215, # SQL_NUMERIC_FUNCTIONS 9 => 1, # SQL_ODBC_API_CONFORMANCE 152 => 2, # SQL_ODBC_INTERFACE_CONFORMANCE 12 => 1, # SQL_ODBC_SAG_CLI_CONFORMANCE 15 => 1, # SQL_ODBC_SQL_CONFORMANCE 73 => 'N', # SQL_ODBC_SQL_OPT_IEF 10 => '03.80', # SQL_ODBC_VER 115 => 123, # SQL_OJ_CAPABILITIES 90 => 'Y', # SQL_ORDER_BY_COLUMNS_IN_SELECT 38 => 'Y', # SQL_OUTER_JOINS 115 => 123, # SQL_OUTER_JOIN_CAPABILITIES 39 => '', # SQL_OWNER_TERM 91 => 0, # SQL_OWNER_USAGE 153 => 2, # SQL_PARAM_ARRAY_ROW_COUNTS 154 => 3, # SQL_PARAM_ARRAY_SELECTS 80 => 3, # SQL_POSITIONED_STATEMENTS 79 => 31, # SQL_POS_OPERATIONS 21 => 'N', # SQL_PROCEDURES 40 => '', # SQL_PROCEDURE_TERM 114 => 1, # SQL_QUALIFIER_LOCATION 41 => '.', # SQL_QUALIFIER_NAME_SEPARATOR 42 => 'database', # SQL_QUALIFIER_TERM 92 => 29, # SQL_QUALIFIER_USAGE 93 => 3, # SQL_QUOTED_IDENTIFIER_CASE 11 => 'N', # SQL_ROW_UPDATES 39 => '', # SQL_SCHEMA_TERM 91 => 0, # SQL_SCHEMA_USAGE 43 => 7, # SQL_SCROLL_CONCURRENCY 44 => 17, # SQL_SCROLL_OPTIONS 14 => '\\', # SQL_SEARCH_PATTERN_ESCAPE 13 => makefunk 13, # SQL_SERVER_NAME 94 => 'ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜáíóúñÑ', # SQL_SPECIAL_CHARACTERS 155 => 7, # SQL_SQL92_DATETIME_FUNCTIONS 156 => 0, # SQL_SQL92_FOREIGN_KEY_DELETE_RULE 157 => 0, # SQL_SQL92_FOREIGN_KEY_UPDATE_RULE 158 => 8160, # SQL_SQL92_GRANT 159 => 0, # SQL_SQL92_NUMERIC_VALUE_FUNCTIONS 160 => 0, # SQL_SQL92_PREDICATES 161 => 466, # SQL_SQL92_RELATIONAL_JOIN_OPERATORS 162 => 32640, # SQL_SQL92_REVOKE 163 => 7, # SQL_SQL92_ROW_VALUE_CONSTRUCTOR 164 => 255, # SQL_SQL92_STRING_FUNCTIONS 165 => 0, # SQL_SQL92_VALUE_EXPRESSIONS 118 => 4, # SQL_SQL_CONFORMANCE 166 => 2, # SQL_STANDARD_CLI_CONFORMANCE 167 => 97863, # SQL_STATIC_CURSOR_ATTRIBUTES1 168 => 6016, # SQL_STATIC_CURSOR_ATTRIBUTES2 83 => 7, # SQL_STATIC_SENSITIVITY 50 => 491519, # SQL_STRING_FUNCTIONS 95 => 0, # SQL_SUBQUERIES 51 => 7, # SQL_SYSTEM_FUNCTIONS 45 => 'table', # SQL_TABLE_TERM 109 => 0, # SQL_TIMEDATE_ADD_INTERVALS 110 => 0, # SQL_TIMEDATE_DIFF_INTERVALS 52 => 106495, # SQL_TIMEDATE_FUNCTIONS 46 => 3, # SQL_TRANSACTION_CAPABLE 72 => 15, # SQL_TRANSACTION_ISOLATION_OPTION 46 => 3, # SQL_TXN_CAPABLE 72 => 15, # SQL_TXN_ISOLATION_OPTION 96 => 0, # SQL_UNION 96 => 0, # SQL_UNION_STATEMENT 47 => \&sql_user_name, # SQL_USER_NAME 10000 => 1992, # SQL_XOPEN_CLI_YEAR ); 1; __END__ DBD-mysql-4.033/lib/DBD/mysql/INSTALL.pod0000644000175000017500000005643112524125336016061 0ustar patgpatg=encoding utf8 =head1 NAME DBD::mysql::INSTALL - How to install and configure DBD::mysql =head1 SYNOPSIS perl Makefile.PL [options] make make test make install =head1 DESCRIPTION This document describes the installation and configuration of DBD::mysql, the Perl DBI driver for the MySQL database. Before reading on, make sure that you have the prerequisites available: Perl, MySQL and DBI. For details see the separate section L. Depending on your version of Perl, it might be possible to use a binary distribution of DBD::mysql. If possible, this is recommended. Otherwise you need to install from the sources. If so, you will definitely need a C compiler. Installation from binaries and sources are both described in separate sections. L. L. Finally, if you encounter any problems, do not forget to read the section on known problems L. If that doesn't help, you should check the section on L. =head1 PREREQUISITES =over =item Perl Preferably a version of Perl, that comes preconfigured with your system. For example, all Linux and FreeBSD distributions come with Perl. For Windows, using ActivePerl or Strawberry Perl is recommended, see L and L for details. =item MySQL You need not install the actual MySQL database server, the client files and the development files are sufficient. For example, Fedora Linux distribution comes with RPM files (using YUM) B and B (use "yum search" to find exact package names). These are sufficient, if the MySQL server is located on a foreign machine. You may also create client files by compiling from the MySQL source distribution and using configure --without-server If you are using Windows and need to compile from sources (which is only the case if you are not using ActivePerl or Strawberry Perl), then you must ensure that the header and library files are installed. This may require choosing a "Custom installation" and selecting the appropriate option when running the MySQL setup program. =item DBI DBD::mysql is a DBI driver, hence you need DBI. It is available from the same source where you got the DBD::mysql distribution from. =item C compiler A C compiler is only required if you install from source. In most cases there are binary distributions of DBD::mysql available. However, if you need a C compiler, make sure, that it is the same C compiler that was used for compiling Perl and MySQL! Otherwise you will almost definitely encounter problems because of differences in the underlying C runtime libraries. In the worst case, this might mean to compile Perl and MySQL yourself. But believe me, experience shows that a lot of problems are fixed this way. =item Gzip libraries Late versions of MySQL come with support for compression. Thus it B be required that you have install an RPM package like libz-devel, libgz-devel or something similar. =back =head1 BINARY INSTALLATION Binary installation is possible in the most cases, depending on your system. =head2 Windows =head3 Strawberry Perl Strawberry Perl comes bundled with DBD::mysql and the needed client libraries. =head3 ActiveState Perl ActivePerl offers a PPM archive of DBD::mysql. All you need to do is typing in a cmd.exe window: ppm install DBD-mysql This will fetch the module via HTTP and install them. If you need to use a WWW proxy server, the environment variable HTTP_proxy must be set: set HTTP_proxy=http://myproxy.example.com:8080/ ppm install DBD-mysql Of course you need to replace the host name C and the port number C<8080> with your local values. If the above procedure doesn't work, please upgrade to the latest version of ActivePerl. ActiveState has a policy where it only provides access free-of-charge for the PPM mirrors of the last few stable Perl releases. If you have an older perl, you'd either need to upgrade your perl or contact ActiveState about a subscription. =head2 Red Hat Enterprise Linux (RHEL), CentOS and Fedora Red Hat Enterprise Linux, its community derivatives such as CentOS, and Fedora come with MySQL and DBD::mysql. Use the following command to install DBD::mysql: yum install "perl(DBD::mysql)" =head2 Debian and Ubuntu On Debian, Ubuntu and derivatives you can install DBD::mysql from the repositories with the following command: sudo apt-get install libdbd-mysql-perl =head2 SLES and openSUSE On SUSE Linux Enterprise and the community version openSUSE, you can install DBD::mysql from the repositories with the following command: zypper install perl-DBD-mysql =head2 Other systems In the case of other Linux or FreeBSD distributions it is very likely that all you need comes with your distribution. I just cannot give you names, as I am not using these systems. Please let me know if you find the files in your favorite Linux or FreeBSD distribution so that I can extend the above list. =head1 SOURCE INSTALLATION So you need to install from sources. If you are lucky, the Perl module C will do all for you, thanks to the excellent work of Andreas König. Otherwise you will need to do a manual installation. All of these installation types have their own section: L, L and L. The DBD::mysql Makefile.PL needs to know where to find your MySQL installation. This may be achieved using command line switches (see L) or automatically using the mysql_config binary which comes with most MySQL distributions. If your MySQL distribution contains mysql_config the easiest method is to ensure this binary is on your path. Typically, this is the case if you've installed the mysql library from your systems' package manager. e.g. PATH=$PATH:/usr/local/mysql/bin export PATH As stated, to compile DBD::mysql you'll need a C compiler. This should be the same compiler as the one used to build perl AND the mysql client libraries. If you're on linux, this is most typically the case and you need not worry. If you're on UNIX systems, you might want to pay attention. Also you'll need to get the MySQL client and development headers on your system. The easiest is to get these from your package manager. To run the tests that ship with the module, you'll need access to a running MySQL server. This can be running on localhost, but it can also be on a remote machine. On Fedora the process is as follows. Please note that Fedora actually ships with MariaDB but not with MySQL. This is not a problem, it will work just as well. In this example we install and start a local server for running the tests against. yum -y install make gcc mariadb-devel mariadb-libs mariadb-server yum -y install "perl(Test::Deep)" "perl(Test::More)" systemctl start mariadb.service =head2 Environment Variables For ease of use, you can set environment variables for DBD::mysql installation. You can set any or all of the options, and export them by putting them in your .bashrc or the like: export DBD_MYSQL_CFLAGS=-I/usr/local/mysql/include/mysql export DBD_MYSQL_LIBS="-L/usr/local/mysql/lib/mysql -lmysqlclient" export DBD_MYSQL_EMBEDDED= export DBD_MYSQL_CONFIG=mysql_config export DBD_MYSQL_NOCATCHSTDERR=0 export DBD_MYSQL_NOFOUNDROWS=0 export DBD_MYSQL_SSL= export DBD_MYSQL_TESTDB=test export DBD_MYSQL_TESTHOST=localhost export DBD_MYSQL_TESTPASSWORD=s3kr1+ export DBD_MYSQL_TESTPORT=3306 export DBD_MYSQL_TESTUSER=me The most useful may be the host, database, port, socket, user, and password. Installation will first look to your mysql_config, and then your environment variables, and then it will guess with intelligent defaults. =head2 CPAN installation Installation of DBD::mysql can be incredibly easy: cpan DBD::mysql Please note that this will only work if the prerequisites are fulfilled, which means you have a C-compiler installed, and you have the development headers and mysql client libraries available on your system. If you are using the CPAN module for the first time, just answer the questions by accepting the defaults which are fine in most cases. If you cannot get the CPAN module working, you might try manual installation. If installation with CPAN fails because the your local settings have been guessed wrong, you need to ensure MySQL's mysql_config is on your path (see L) or alternatively create a script called C. This is described in more details later. L. =head2 Manual installation For a manual installation you need to fetch the DBD::mysql source distribution. The latest version is always available from https://metacpan.org/module/DBD::mysql The name is typically something like DBD-mysql-4.025.tar.gz The archive needs to be extracted. On Windows you may use a tool like 7-zip, on *nix you type tar xf DBD-mysql-4.025.tar.gz This will create a subdirectory DBD-mysql-4.025. Enter this subdirectory and type perl Makefile.PL make make test (On Windows you may need to replace "make" with "dmake" or "nmake".) If the tests seem to look fine, you may continue with make install If the compilation (make) or tests fail, you might need to configure some settings. For example you might choose a different database, the C compiler or the linker might need some flags. L. L. L. For Cygwin there is a special section below. L. =head2 Configuration The install script "Makefile.PL" can be configured via a lot of switches. All switches can be used on the command line. For example, the test database: perl Makefile.PL --testdb= If you do not like configuring these switches on the command line, you may alternatively create a script called C. This is described later on. Available switches are: =over =item testdb Name of the test database, defaults to B. =item testuser Name of the test user, defaults to empty. If the name is empty, then the currently logged in users name will be used. =item testpassword Password of the test user, defaults to empty. =item testhost Host name or IP number of the test database; defaults to localhost. =item testport Port number of the test database =item ps-protcol=1 or 0 Whether to run the test suite using server prepared statements or driver emulated prepared statements. ps-protocol=1 means use server prepare, ps-protocol=0 means driver emulated. =item cflags This is a list of flags that you want to give to the C compiler. The most important flag is the location of the MySQL header files. For example, on Red Hat Linux the header files are in /usr/include/mysql and you might try -I/usr/include/mysql On Windows the header files may be in C:\mysql\include and you might try -IC:\mysql\include The default flags are determined by running mysql_config --cflags More details on the C compiler flags can be found in the following section. L. =item libs This is a list of flags that you want to give to the linker or loader. The most important flags are the locations and names of additional libraries. For example, on Red Hat Linux your MySQL client libraries are in /usr/lib/mysql and you might try -L/usr/lib/mysql -lmysqlclient -lz On Windows the libraries may be in C:\mysql\lib and -LC:\mysql\lib -lmysqlclient might be a good choice. The default flags are determined by running mysql_config --libs More details on the linker flags can be found in a separate section. L. =back If a switch is not present on the command line, then the script C will be executed. This script comes as part of the MySQL distribution. For example, to determine the C compiler flags, we are executing mysql_config --cflags mysql_config --libs If you want to configure your own settings for database name, database user and so on, then you have to create a script with the same name, that replies =head2 Compiler flags Note: the following info about compiler and linker flags, you shouldn't have to use these options because Makefile.PL is pretty good at utilizing mysql_config to get the flags that you need for a successful compile. It is typically not so difficult to determine the appropriate flags for the C compiler. The linker flags, which you find in the next section, are another story. The determination of the C compiler flags is usually left to a configuration script called F, which can be invoked with mysql_config --cflags When doing so, it will emit a line with suggested C compiler flags, for example like this: -L/usr/include/mysql The C compiler must find some header files. Header files have the extension C<.h>. MySQL header files are, for example, F and F. In most cases the header files are not installed by default. For example, on Windows it is an installation option of the MySQL setup program (Custom installation), whether the header files are installed or not. On Red Hat Linux, you need to install an RPM archive F or F. If you know the location of the header files, then you will need to add an option -L
to the C compiler flags, for example C<-L/usr/include/mysql>. =head2 Linker flags Appropriate linker flags are the most common source of problems while installing DBD::mysql. I will only give a rough overview, you'll find more details in the troubleshooting section. L The determination of the C compiler flags is usually left to a configuration script called F, which can be invoked with mysql_config --libs When doing so, it will emit a line with suggested C compiler flags, for example like this: -L'/usr/lib/mysql' -lmysqlclient -lnsl -lm -lz -lcrypt The following items typically need to be configured for the linker: =over =item The mysqlclient library The MySQL client library comes as part of the MySQL distribution. Depending on your system it may be a file called F statically linked library, Unix F dynamically linked library, Unix F statically linked library, Windows F dynamically linked library, Windows or something similar. As in the case of the header files, the client library is typically not installed by default. On Windows you will need to select them while running the MySQL setup program (Custom installation). On Red Hat Linux an RPM archive F or F must be installed. The linker needs to know the location and name of the mysqlclient library. This can be done by adding the flags -L -lmysqlclient or by adding the complete path name. Examples: -L/usr/lib/mysql -lmysqlclient -LC:\mysql\lib -lmysqlclient If you would like to use the static libraries (and there are excellent reasons to do so), you need to create a separate directory, copy the static libraries to that place and use the -L switch above to point to your new directory. For example: mkdir /tmp/mysql-static cp /usr/lib/mysql/*.a /tmp/mysql-static perl Makefile.PL --libs="-L/tmp/mysql-static -lmysqlclient" make make test make install rm -rf /tmp/mysql-static =item The gzip library The MySQL client can use compression when talking to the MySQL server, a nice feature when sending or receiving large texts over a slow network. On Unix you typically find the appropriate file name by running ldconfig -p | grep libz ldconfig -p | grep libgz Once you know the name (libz.a or libgz.a is best), just add it to the list of linker flags. If this seems to be causing problem you may also try to link without gzip libraries. =back =head1 MARIADB NATIVE CLIENT INSTALLATION The MariaDB native client is another option for connecting to a MySQL· database licensed LGPL 2.1. To build DBD::mysql against this client, you will first need to build the client. Generally, this is done with the following: cd path/to/src/mariadb-native-client cmake -G "Unix Makefiles' make sudo make install Once the client is built and installed, you can build DBD::mysql against it: perl Makefile.PL --testuser=xxx --testpassword=xxx --testsocket=/path/to//mysqld.sock --mysql_config=/usr/local/bin/mariadb_config· make make test make install =head1 SPECIAL SYSTEMS Below you find information on particular systems: =head2 Mac OS X Please see the the post at L (Thanks to Kris Davey for pointing this out to me). I plan to see if I can get the build process to be more intelligent about using build flags that work. It is very difficult as it's not a driver problem per se but a problem in how one builds DBD::mysql with a binary client lib built on a different compiler than the one the user is using. Quite simply, using the binary MySQL installation from Oracle, you will need to first run: perl Makefile.PL --mysql_config=/usr/local/mysql-5.6.16-osx10.7-x86_64/bin/mysql_config There are some runtime issues you may encounter with OS X. Upon running make test, you might encounter the error: Error: Can't load '/Users/username/DBD-mysql/blib/arch/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Users/username/DBD-mysql/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib To solve this issue, you need to set the library path, similar to LD_LIBRARY_PATH on other Unix variants, buit on OS X you need to do the following (this is for a binary install of MySQL from Oracle) export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/mysql-5.6.16-osx10.7-x86_64/lib/ =head2 Cygwin If you are a user of Cygwin you already know, it contains a nicely running perl 5.6.1, installation of additional modules usually works like a charm via the standard procedure of perl makefile.PL make make test make install The Windows binary distribution of MySQL runs smoothly under Cygwin. You can start/stop the server and use all Windows clients without problem. But to install DBD::mysql you have to take a little special action. Don't attempt to build DBD::mysql against either the MySQL Windows or Linux/Unix BINARY distributions: neither will work! You MUST compile the MySQL clients yourself under Cygwin, to get a 'libmysqlclient.a' compiled under Cygwin. Really! You'll only need that library and the header files, you don't need any other client parts. Continue to use the Windows binaries. And don't attempt (currently) to build the MySQL Server part, it is unnecessary, as MySQL AB does an excellent job to deliver optimized binaries for the mainstream operating systems, and it is told, that the server compiled under Cygwin is unstable. Install a MySQL server for testing against. You can install the regular Windows MySQL server package on your Windows machine, or you can also test against a MySQL server on a remote host. =head3 Build MySQL clients under Cygwin: download the MySQL LINUX source from L, unpack mysql-.tar.gz into some tmp location and from this directory run configure: ./configure --prefix=/usr/local/mysql --without-server This prepares the Makefile with the installed Cygwin features. It takes some time, but should finish without error. The 'prefix', as given, installs the whole Cygwin/MySQL thingy into a location not normally in your PATH, so that you continue to use already installed Windows binaries. The --without-server parameter tells configure to only build the clients. make This builds all MySQL client parts ... be patient. It should finish finally without any error. make install This installs the compiled client files under /usr/local/mysql/. Remember, you don't need anything except the library under /usr/local/mysql/lib and the headers under /usr/local/mysql/include! Essentially you are now done with this part. If you want, you may try your compiled binaries shortly; for that, do: cd /usr/local/mysql/bin ./mysql -h 127.0.0.1 The host (-h) parameter 127.0.0.1 targets the local host, but forces the mysql client to use a TCP/IP connection. The default would be a pipe/socket connection (even if you say '-h localhost') and this doesn't work between Cygwin and Windows (as far as I know). If you have your MySQL server running on some other box, then please substitute '127.0.0.1' with the name or IP-number of that box. Please note, in my environment the 'mysql' client did not accept a simple RETURN, I had to use CTRL-RETURN to send commands ... strange, but I didn't attempt to fix that, as we are only interested in the built lib and headers. At the 'mysql>' prompt do a quick check: mysql> use mysql mysql> show tables; mysql> select * from db; mysql> exit You are now ready to build DBD::mysql! =head3 compile DBD::mysql download and extract DBD-mysql-.tar.gz from CPAN cd into unpacked dir DBD-mysql- you probably did that already, if you are reading this! cp /usr/local/mysql/bin/mysql_config . This copies the executable script mentioned in the DBD::mysql docs from your just built Cywin/MySQL client directory; it knows about your Cygwin installation, especially about the right libraries to link with. perl Makefile.PL --testhost=127.0.0.1 The --testhost=127.0.0.1 parameter again forces a TCP/IP connection to the MySQL server on the local host instead of a pipe/socket connection for the 'make test' phase. make This should run without error make test make install This installs DBD::mysql into the Perl hierarchy. =head1 KNOWN PROBLEMS =head2 no gzip on your system Some Linux distributions don't come with a gzip library by default. Running "make" terminates with an error message like LD_RUN_PATH="/usr/lib/mysql:/lib:/usr/lib" gcc -o blib/arch/auto/DBD/mysql/mysql.so -shared -L/usr/local/lib dbdimp.o mysql.o -L/usr/lib/mysql -lmysqlclient -lm -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -lgcc -lz /usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status make: *** [blib/arch/auto/DBD/mysql/mysql.so] Error 1 If this is the case for you, install an RPM archive like libz-devel, libgz-devel, zlib-devel or gzlib-devel or something similar. =head2 different compiler for mysql and perl If Perl was compiled with gcc or egcs, but MySQL was compiled with another compiler or on another system, an error message like this is very likely when running "Make test": t/00base............install_driver(mysql) failed: Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql: ../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol: _umoddi3 at /usr/local/perl-5.005/lib/5.005/i586-linux-thread/DynaLoader.pm line 168. This means, that your linker doesn't include libgcc.a. You have the following options: The solution is telling the linker to use libgcc. Run gcc --print-libgcc-file to determine the exact location of libgcc.a or for older versions of gcc gcc -v to determine the directory. If you know the directory, add a -L -lgcc to the list of C compiler flags. L. L. =head1 SUPPORT Finally, if everything else fails, you are not alone. First of all, for an immediate answer, you should look into the archives of the dbi-users mailing list, which is available at L To subscribe to this list, send and email to dbi-users-subscribe@perl.org If you don't find an appropriate posting and reply in the mailing list, please post a question. Typically a reply will be seen within one or two days. DBD-mysql-4.033/lib/DBD/mysql.pm0000644000175000017500000017236212613567262014616 0ustar patgpatg#!/usr/bin/perl use strict; use warnings; require 5.008_001; # just as DBI package DBD::mysql; use DBI; use DynaLoader(); use Carp; our @ISA = qw(DynaLoader); # please make sure the sub-version does not increase above '099' # SQL_DRIVER_VER is formatted as dd.dd.dddd # for version 5.x please switch to 5.00(_00) version numbering # keep $VERSION in Bundle/DBD/mysql.pm in sync our $VERSION = '4.033'; bootstrap DBD::mysql $VERSION; our $err = 0; # holds error code for DBI::err our $errstr = ""; # holds error string for DBI::errstr our $drh = undef; # holds driver handle once initialised my $methods_are_installed = 0; sub driver{ return $drh if $drh; my($class, $attr) = @_; $class .= "::dr"; # not a 'my' since we use it above to prevent multiple drivers $drh = DBI::_new_drh($class, { 'Name' => 'mysql', 'Version' => $VERSION, 'Err' => \$DBD::mysql::err, 'Errstr' => \$DBD::mysql::errstr, 'Attribution' => 'DBD::mysql by Patrick Galbraith' }); if (!$methods_are_installed) { DBD::mysql::db->install_method('mysql_fd'); DBD::mysql::db->install_method('mysql_async_result'); DBD::mysql::db->install_method('mysql_async_ready'); DBD::mysql::st->install_method('mysql_async_result'); DBD::mysql::st->install_method('mysql_async_ready'); $methods_are_installed++; } $drh; } sub CLONE { undef $drh; } sub _OdbcParse($$$) { my($class, $dsn, $hash, $args) = @_; my($var, $val); if (!defined($dsn)) { return; } while (length($dsn)) { if ($dsn =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) { $val = $1; $dsn = $2; $val =~ s/\[|]//g; # Remove [] if present, the rest of the code prefers plain IPv6 addresses } else { $val = $dsn; $dsn = ''; } if ($val =~ /([^=]*)=(.*)/) { $var = $1; $val = $2; if ($var eq 'hostname' || $var eq 'host') { $hash->{'host'} = $val; } elsif ($var eq 'db' || $var eq 'dbname') { $hash->{'database'} = $val; } else { $hash->{$var} = $val; } } else { foreach $var (@$args) { if (!defined($hash->{$var})) { $hash->{$var} = $val; last; } } } } } sub _OdbcParseHost ($$) { my($class, $dsn) = @_; my($hash) = {}; $class->_OdbcParse($dsn, $hash, ['host', 'port']); ($hash->{'host'}, $hash->{'port'}); } sub AUTOLOAD { my ($meth) = $DBD::mysql::AUTOLOAD; my ($smeth) = $meth; $smeth =~ s/(.*)\:\://; my $val = constant($smeth, @_ ? $_[0] : 0); if ($! == 0) { eval "sub $meth { $val }"; return $val; } Carp::croak "$meth: Not defined"; } 1; package DBD::mysql::dr; # ====== DRIVER ====== use strict; use DBI qw(:sql_types); use DBI::Const::GetInfoType; sub connect { my($drh, $dsn, $username, $password, $attrhash) = @_; my($port); my($cWarn); my $connect_ref= { 'Name' => $dsn }; my $dbi_imp_data; # Avoid warnings for undefined values $username ||= ''; $password ||= ''; $attrhash ||= {}; $attrhash->{mysql_conn_attrs} ||= {}; $attrhash->{mysql_conn_attrs}->{'program_name'} ||= $0; # create a 'blank' dbh my($this, $privateAttrHash) = (undef, $attrhash); $privateAttrHash = { %$privateAttrHash, 'Name' => $dsn, 'user' => $username, 'password' => $password }; DBD::mysql->_OdbcParse($dsn, $privateAttrHash, ['database', 'host', 'port']); if ($DBI::VERSION >= 1.49) { $dbi_imp_data = delete $attrhash->{dbi_imp_data}; $connect_ref->{'dbi_imp_data'} = $dbi_imp_data; } if (!defined($this = DBI::_new_dbh($drh, $connect_ref, $privateAttrHash))) { return undef; } DBD::mysql::db::_login($this, $dsn, $username, $password) or $this = undef; if ($this && ($ENV{MOD_PERL} || $ENV{GATEWAY_INTERFACE})) { $this->{mysql_auto_reconnect} = 1; } $this; } sub data_sources { my($self) = shift; my($attributes) = shift; my($host, $port, $user, $password) = ('', '', '', ''); if ($attributes) { $host = $attributes->{host} || ''; $port = $attributes->{port} || ''; $user = $attributes->{user} || ''; $password = $attributes->{password} || ''; } my(@dsn) = $self->func($host, $port, $user, $password, '_ListDBs'); my($i); for ($i = 0; $i < @dsn; $i++) { $dsn[$i] = "DBI:mysql:$dsn[$i]"; } @dsn; } sub admin { my($drh) = shift; my($command) = shift; my($dbname) = ($command eq 'createdb' || $command eq 'dropdb') ? shift : ''; my($host, $port) = DBD::mysql->_OdbcParseHost(shift(@_) || ''); my($user) = shift || ''; my($password) = shift || ''; $drh->func(undef, $command, $dbname || '', $host || '', $port || '', $user, $password, '_admin_internal'); } package DBD::mysql::db; # ====== DATABASE ====== use strict; use DBI qw(:sql_types); %DBD::mysql::db::db2ANSI = ( "INT" => "INTEGER", "CHAR" => "CHAR", "REAL" => "REAL", "IDENT" => "DECIMAL" ); ### ANSI datatype mapping to MySQL datatypes %DBD::mysql::db::ANSI2db = ( "CHAR" => "CHAR", "VARCHAR" => "CHAR", "LONGVARCHAR" => "CHAR", "NUMERIC" => "INTEGER", "DECIMAL" => "INTEGER", "BIT" => "INTEGER", "TINYINT" => "INTEGER", "SMALLINT" => "INTEGER", "INTEGER" => "INTEGER", "BIGINT" => "INTEGER", "REAL" => "REAL", "FLOAT" => "REAL", "DOUBLE" => "REAL", "BINARY" => "CHAR", "VARBINARY" => "CHAR", "LONGVARBINARY" => "CHAR", "DATE" => "CHAR", "TIME" => "CHAR", "TIMESTAMP" => "CHAR" ); sub prepare { my($dbh, $statement, $attribs)= @_; return unless $dbh->func('_async_check'); # create a 'blank' dbh my $sth = DBI::_new_sth($dbh, {'Statement' => $statement}); # Populate internal handle data. if (!DBD::mysql::st::_prepare($sth, $statement, $attribs)) { $sth = undef; } $sth; } sub db2ANSI { my $self = shift; my $type = shift; return $DBD::mysql::db::db2ANSI{"$type"}; } sub ANSI2db { my $self = shift; my $type = shift; return $DBD::mysql::db::ANSI2db{"$type"}; } sub admin { my($dbh) = shift; my($command) = shift; my($dbname) = ($command eq 'createdb' || $command eq 'dropdb') ? shift : ''; $dbh->{'Driver'}->func($dbh, $command, $dbname, '', '', '', '_admin_internal'); } sub _SelectDB ($$) { die "_SelectDB is removed from this module; use DBI->connect instead."; } sub table_info ($) { my ($dbh, $catalog, $schema, $table, $type, $attr) = @_; $dbh->{mysql_server_prepare}||= 0; my $mysql_server_prepare_save= $dbh->{mysql_server_prepare}; $dbh->{mysql_server_prepare}= 0; my @names = qw(TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS); my @rows; my $sponge = DBI->connect("DBI:Sponge:", '','') or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr"); # Return the list of catalogs if (defined $catalog && $catalog eq "%" && (!defined($schema) || $schema eq "") && (!defined($table) || $table eq "")) { @rows = (); # Empty, because MySQL doesn't support catalogs (yet) } # Return the list of schemas elsif (defined $schema && $schema eq "%" && (!defined($catalog) || $catalog eq "") && (!defined($table) || $table eq "")) { my $sth = $dbh->prepare("SHOW DATABASES") or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return undef); $sth->execute() or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return DBI::set_err($dbh, $sth->err(), $sth->errstr())); while (my $ref = $sth->fetchrow_arrayref()) { push(@rows, [ undef, $ref->[0], undef, undef, undef ]); } } # Return the list of table types elsif (defined $type && $type eq "%" && (!defined($catalog) || $catalog eq "") && (!defined($schema) || $schema eq "") && (!defined($table) || $table eq "")) { @rows = ( [ undef, undef, undef, "TABLE", undef ], [ undef, undef, undef, "VIEW", undef ], ); } # Special case: a catalog other than undef, "", or "%" elsif (defined $catalog && $catalog ne "" && $catalog ne "%") { @rows = (); # Nothing, because MySQL doesn't support catalogs yet. } # Uh oh, we actually have a meaty table_info call. Work is required! else { my @schemas; # If no table was specified, we want them all $table ||= "%"; # If something was given for the schema, we need to expand it to # a list of schemas, since it may be a wildcard. if (defined $schema && $schema ne "") { my $sth = $dbh->prepare("SHOW DATABASES LIKE " . $dbh->quote($schema)) or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return undef); $sth->execute() or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return DBI::set_err($dbh, $sth->err(), $sth->errstr())); while (my $ref = $sth->fetchrow_arrayref()) { push @schemas, $ref->[0]; } } # Otherwise we want the current database else { push @schemas, $dbh->selectrow_array("SELECT DATABASE()"); } # Figure out which table types are desired my ($want_tables, $want_views); if (defined $type && $type ne "") { $want_tables = ($type =~ m/table/i); $want_views = ($type =~ m/view/i); } else { $want_tables = $want_views = 1; } for my $database (@schemas) { my $sth = $dbh->prepare("SHOW /*!50002 FULL*/ TABLES FROM " . $dbh->quote_identifier($database) . " LIKE " . $dbh->quote($table)) or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return undef); $sth->execute() or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return DBI::set_err($dbh, $sth->err(), $sth->errstr())); while (my $ref = $sth->fetchrow_arrayref()) { my $type = (defined $ref->[1] && $ref->[1] =~ /view/i) ? 'VIEW' : 'TABLE'; next if $type eq 'TABLE' && not $want_tables; next if $type eq 'VIEW' && not $want_views; push @rows, [ undef, $database, $ref->[0], $type, undef ]; } } } my $sth = $sponge->prepare("table_info", { rows => \@rows, NUM_OF_FIELDS => scalar @names, NAME => \@names, }) or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return $dbh->DBI::set_err($sponge->err(), $sponge->errstr())); $dbh->{mysql_server_prepare}= $mysql_server_prepare_save; return $sth; } sub _ListTables { my $dbh = shift; if (!$DBD::mysql::QUIET) { warn "_ListTables is deprecated, use \$dbh->tables()"; } return map { $_ =~ s/.*\.//; $_ } $dbh->tables(); } sub column_info { my ($dbh, $catalog, $schema, $table, $column) = @_; return unless $dbh->func('_async_check'); $dbh->{mysql_server_prepare}||= 0; my $mysql_server_prepare_save= $dbh->{mysql_server_prepare}; $dbh->{mysql_server_prepare}= 0; # ODBC allows a NULL to mean all columns, so we'll accept undef $column = '%' unless defined $column; my $ER_NO_SUCH_TABLE= 1146; my $table_id = $dbh->quote_identifier($catalog, $schema, $table); my @names = qw( TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE CHAR_SET_CAT CHAR_SET_SCHEM CHAR_SET_NAME COLLATION_CAT COLLATION_SCHEM COLLATION_NAME UDT_CAT UDT_SCHEM UDT_NAME DOMAIN_CAT DOMAIN_SCHEM DOMAIN_NAME SCOPE_CAT SCOPE_SCHEM SCOPE_NAME MAX_CARDINALITY DTD_IDENTIFIER IS_SELF_REF mysql_is_pri_key mysql_type_name mysql_values mysql_is_auto_increment ); my %col_info; local $dbh->{FetchHashKeyName} = 'NAME_lc'; # only ignore ER_NO_SUCH_TABLE in internal_execute if issued from here my $desc_sth = $dbh->prepare("DESCRIBE $table_id " . $dbh->quote($column)); my $desc = $dbh->selectall_arrayref($desc_sth, { Columns=>{} }); #return $desc_sth if $desc_sth->err(); if (my $err = $desc_sth->err()) { # return the error, unless it is due to the table not # existing per DBI spec if ($err != $ER_NO_SUCH_TABLE) { $dbh->{mysql_server_prepare}= $mysql_server_prepare_save; return undef; } $dbh->set_err(undef,undef); $desc = []; } my $ordinal_pos = 0; my @fields; for my $row (@$desc) { my $type = $row->{type}; $type =~ m/^(\w+)(\((.+)\))?\s?(.*)?$/; my $basetype = lc($1); my $typemod = $3; my $attr = $4; push @fields, $row->{field}; my $info = $col_info{ $row->{field} }= { TABLE_CAT => $catalog, TABLE_SCHEM => $schema, TABLE_NAME => $table, COLUMN_NAME => $row->{field}, NULLABLE => ($row->{null} eq 'YES') ? 1 : 0, IS_NULLABLE => ($row->{null} eq 'YES') ? "YES" : "NO", TYPE_NAME => uc($basetype), COLUMN_DEF => $row->{default}, ORDINAL_POSITION => ++$ordinal_pos, mysql_is_pri_key => ($row->{key} eq 'PRI'), mysql_type_name => $row->{type}, mysql_is_auto_increment => ($row->{extra} =~ /auto_increment/i ? 1 : 0), }; # # This code won't deal with a pathological case where a value # contains a single quote followed by a comma, and doesn't unescape # any escaped values. But who would use those in an enum or set? # my @type_params= ($typemod && index($typemod,"'")>=0) ? ("$typemod," =~ /'(.*?)',/g) # assume all are quoted : split /,/, $typemod||''; # no quotes, plain list s/''/'/g for @type_params; # undo doubling of quotes my @type_attr= split / /, $attr||''; $info->{DATA_TYPE}= SQL_VARCHAR(); if ($basetype =~ /^(char|varchar|\w*text|\w*blob)/) { $info->{DATA_TYPE}= SQL_CHAR() if $basetype eq 'char'; if ($type_params[0]) { $info->{COLUMN_SIZE} = $type_params[0]; } else { $info->{COLUMN_SIZE} = 65535; $info->{COLUMN_SIZE} = 255 if $basetype =~ /^tiny/; $info->{COLUMN_SIZE} = 16777215 if $basetype =~ /^medium/; $info->{COLUMN_SIZE} = 4294967295 if $basetype =~ /^long/; } } elsif ($basetype =~ /^(binary|varbinary)/) { $info->{COLUMN_SIZE} = $type_params[0]; # SQL_BINARY & SQL_VARBINARY are tempting here but don't match the # semantics for mysql (not hex). SQL_CHAR & SQL_VARCHAR are correct here. $info->{DATA_TYPE} = ($basetype eq 'binary') ? SQL_CHAR() : SQL_VARCHAR(); } elsif ($basetype =~ /^(enum|set)/) { if ($basetype eq 'set') { $info->{COLUMN_SIZE} = length(join ",", @type_params); } else { my $max_len = 0; length($_) > $max_len and $max_len = length($_) for @type_params; $info->{COLUMN_SIZE} = $max_len; } $info->{"mysql_values"} = \@type_params; } elsif ($basetype =~ /int/ || $basetype eq 'bit' ) { # big/medium/small/tiny etc + unsigned? $info->{DATA_TYPE} = SQL_INTEGER(); $info->{NUM_PREC_RADIX} = 10; $info->{COLUMN_SIZE} = $type_params[0]; } elsif ($basetype =~ /^decimal/) { $info->{DATA_TYPE} = SQL_DECIMAL(); $info->{NUM_PREC_RADIX} = 10; $info->{COLUMN_SIZE} = $type_params[0]; $info->{DECIMAL_DIGITS} = $type_params[1]; } elsif ($basetype =~ /^(float|double)/) { $info->{DATA_TYPE} = ($basetype eq 'float') ? SQL_FLOAT() : SQL_DOUBLE(); $info->{NUM_PREC_RADIX} = 2; $info->{COLUMN_SIZE} = ($basetype eq 'float') ? 32 : 64; } elsif ($basetype =~ /date|time/) { # date/datetime/time/timestamp if ($basetype eq 'time' or $basetype eq 'date') { #$info->{DATA_TYPE} = ($basetype eq 'time') ? SQL_TYPE_TIME() : SQL_TYPE_DATE(); $info->{DATA_TYPE} = ($basetype eq 'time') ? SQL_TIME() : SQL_DATE(); $info->{COLUMN_SIZE} = ($basetype eq 'time') ? 8 : 10; } else { # datetime/timestamp #$info->{DATA_TYPE} = SQL_TYPE_TIMESTAMP(); $info->{DATA_TYPE} = SQL_TIMESTAMP(); $info->{SQL_DATA_TYPE} = SQL_DATETIME(); $info->{SQL_DATETIME_SUB} = $info->{DATA_TYPE} - ($info->{SQL_DATA_TYPE} * 10); $info->{COLUMN_SIZE} = ($basetype eq 'datetime') ? 19 : $type_params[0] || 14; } $info->{DECIMAL_DIGITS}= 0; # no fractional seconds } elsif ($basetype eq 'year') { # no close standard so treat as int $info->{DATA_TYPE} = SQL_INTEGER(); $info->{NUM_PREC_RADIX} = 10; $info->{COLUMN_SIZE} = 4; } else { Carp::carp("column_info: unrecognized column type '$basetype' of $table_id.$row->{field} treated as varchar"); } $info->{SQL_DATA_TYPE} ||= $info->{DATA_TYPE}; #warn Dumper($info); } my $sponge = DBI->connect("DBI:Sponge:", '','') or ( $dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr")); my $sth = $sponge->prepare("column_info $table", { rows => [ map { [ @{$_}{@names} ] } map { $col_info{$_} } @fields ], NUM_OF_FIELDS => scalar @names, NAME => \@names, }) or return ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && $dbh->DBI::set_err($sponge->err(), $sponge->errstr())); $dbh->{mysql_server_prepare}= $mysql_server_prepare_save; return $sth; } sub primary_key_info { my ($dbh, $catalog, $schema, $table) = @_; return unless $dbh->func('_async_check'); $dbh->{mysql_server_prepare}||= 0; my $mysql_server_prepare_save= $dbh->{mysql_server_prepare}; my $table_id = $dbh->quote_identifier($catalog, $schema, $table); my @names = qw( TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME KEY_SEQ PK_NAME ); my %col_info; local $dbh->{FetchHashKeyName} = 'NAME_lc'; my $desc_sth = $dbh->prepare("SHOW KEYS FROM $table_id"); my $desc= $dbh->selectall_arrayref($desc_sth, { Columns=>{} }); my $ordinal_pos = 0; for my $row (grep { $_->{key_name} eq 'PRIMARY'} @$desc) { $col_info{ $row->{column_name} }= { TABLE_CAT => $catalog, TABLE_SCHEM => $schema, TABLE_NAME => $table, COLUMN_NAME => $row->{column_name}, KEY_SEQ => $row->{seq_in_index}, PK_NAME => $row->{key_name}, }; } my $sponge = DBI->connect("DBI:Sponge:", '','') or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr")); my $sth= $sponge->prepare("primary_key_info $table", { rows => [ map { [ @{$_}{@names} ] } sort { $a->{KEY_SEQ} <=> $b->{KEY_SEQ} } values %col_info ], NUM_OF_FIELDS => scalar @names, NAME => \@names, }) or ($dbh->{mysql_server_prepare}= $mysql_server_prepare_save && return $dbh->DBI::set_err($sponge->err(), $sponge->errstr())); $dbh->{mysql_server_prepare}= $mysql_server_prepare_save; return $sth; } sub foreign_key_info { my ($dbh, $pk_catalog, $pk_schema, $pk_table, $fk_catalog, $fk_schema, $fk_table, ) = @_; return unless $dbh->func('_async_check'); # INFORMATION_SCHEMA.KEY_COLUMN_USAGE was added in 5.0.6 # no one is going to be running 5.0.6, taking out the check for $point > .6 my ($maj, $min, $point) = _version($dbh); return if $maj < 5 ; my $sql = <<'EOF'; SELECT NULL AS PKTABLE_CAT, A.REFERENCED_TABLE_SCHEMA AS PKTABLE_SCHEM, A.REFERENCED_TABLE_NAME AS PKTABLE_NAME, A.REFERENCED_COLUMN_NAME AS PKCOLUMN_NAME, A.TABLE_CATALOG AS FKTABLE_CAT, A.TABLE_SCHEMA AS FKTABLE_SCHEM, A.TABLE_NAME AS FKTABLE_NAME, A.COLUMN_NAME AS FKCOLUMN_NAME, A.ORDINAL_POSITION AS KEY_SEQ, NULL AS UPDATE_RULE, NULL AS DELETE_RULE, A.CONSTRAINT_NAME AS FK_NAME, NULL AS PK_NAME, NULL AS DEFERABILITY, NULL AS UNIQUE_OR_PRIMARY FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE A, INFORMATION_SCHEMA.TABLE_CONSTRAINTS B WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME AND B.CONSTRAINT_TYPE IS NOT NULL EOF my @where; my @bind; # catalogs are not yet supported by MySQL # if (defined $pk_catalog) { # push @where, 'A.REFERENCED_TABLE_CATALOG = ?'; # push @bind, $pk_catalog; # } if (defined $pk_schema) { push @where, 'A.REFERENCED_TABLE_SCHEMA = ?'; push @bind, $pk_schema; } if (defined $pk_table) { push @where, 'A.REFERENCED_TABLE_NAME = ?'; push @bind, $pk_table; } # if (defined $fk_catalog) { # push @where, 'A.TABLE_CATALOG = ?'; # push @bind, $fk_schema; # } if (defined $fk_schema) { push @where, 'A.TABLE_SCHEMA = ?'; push @bind, $fk_schema; } if (defined $fk_table) { push @where, 'A.TABLE_NAME = ?'; push @bind, $fk_table; } if (@where) { $sql .= ' AND '; $sql .= join ' AND ', @where; } $sql .= " ORDER BY A.TABLE_SCHEMA, A.TABLE_NAME, A.ORDINAL_POSITION"; local $dbh->{FetchHashKeyName} = 'NAME_uc'; my $sth = $dbh->prepare($sql); $sth->execute(@bind); return $sth; } # #86030: PATCH: adding statistics_info support # Thank you to David Dick http://search.cpan.org/~ddick/ sub statistics_info { my ($dbh, $catalog, $schema, $table, $unique_only, $quick, ) = @_; return unless $dbh->func('_async_check'); # INFORMATION_SCHEMA.KEY_COLUMN_USAGE was added in 5.0.6 # no one is going to be running 5.0.6, taking out the check for $point > .6 my ($maj, $min, $point) = _version($dbh); return if $maj < 5 ; my $sql = <<'EOF'; SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME AS TABLE_NAME, NON_UNIQUE AS NON_UNIQUE, NULL AS INDEX_QUALIFIER, INDEX_NAME AS INDEX_NAME, LCASE(INDEX_TYPE) AS TYPE, SEQ_IN_INDEX AS ORDINAL_POSITION, COLUMN_NAME AS COLUMN_NAME, COLLATION AS ASC_OR_DESC, CARDINALITY AS CARDINALITY, NULL AS PAGES, NULL AS FILTER_CONDITION FROM INFORMATION_SCHEMA.STATISTICS EOF my @where; my @bind; # catalogs are not yet supported by MySQL # if (defined $catalog) { # push @where, 'TABLE_CATALOG = ?'; # push @bind, $catalog; # } if (defined $schema) { push @where, 'TABLE_SCHEMA = ?'; push @bind, $schema; } if (defined $table) { push @where, 'TABLE_NAME = ?'; push @bind, $table; } if (@where) { $sql .= ' WHERE '; $sql .= join ' AND ', @where; } $sql .= " ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION"; local $dbh->{FetchHashKeyName} = 'NAME_uc'; my $sth = $dbh->prepare($sql); $sth->execute(@bind); return $sth; } sub _version { my $dbh = shift; return $dbh->get_info($DBI::Const::GetInfoType::GetInfoType{SQL_DBMS_VER}) =~ /(\d+)\.(\d+)\.(\d+)/; } #################### # get_info() # Generated by DBI::DBD::Metadata sub get_info { my($dbh, $info_type) = @_; return unless $dbh->func('_async_check'); require DBD::mysql::GetInfo; my $v = $DBD::mysql::GetInfo::info{int($info_type)}; $v = $v->($dbh) if ref $v eq 'CODE'; return $v; } BEGIN { my @needs_async_check = qw/data_sources quote_identifier begin_work/; foreach my $method (@needs_async_check) { no strict 'refs'; my $super = "SUPER::$method"; *$method = sub { my $h = shift; return unless $h->func('_async_check'); return $h->$super(@_); }; } } package DBD::mysql::st; # ====== STATEMENT ====== use strict; BEGIN { my @needs_async_result = qw/fetchrow_hashref fetchall_hashref/; my @needs_async_check = qw/bind_param_array bind_col bind_columns execute_for_fetch/; foreach my $method (@needs_async_result) { no strict 'refs'; my $super = "SUPER::$method"; *$method = sub { my $sth = shift; if(defined $sth->mysql_async_ready) { return unless $sth->mysql_async_result; } return $sth->$super(@_); }; } foreach my $method (@needs_async_check) { no strict 'refs'; my $super = "SUPER::$method"; *$method = sub { my $h = shift; return unless $h->func('_async_check'); return $h->$super(@_); }; } } 1; __END__ =pod =encoding utf8 =head1 NAME DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI) =head1 SYNOPSIS use DBI; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password); $drh = DBI->install_driver("mysql"); @databases = DBI->data_sources("mysql"); or @databases = DBI->data_sources("mysql", {"host" => $host, "port" => $port, "user" => $user, password => $pass}); $sth = $dbh->prepare("SELECT * FROM foo WHERE bla"); or $sth = $dbh->prepare("LISTFIELDS $table"); or $sth = $dbh->prepare("LISTINDEX $table $index"); $sth->execute; $numRows = $sth->rows; $numFields = $sth->{'NUM_OF_FIELDS'}; $sth->finish; $rc = $drh->func('createdb', $database, $host, $user, $password, 'admin'); $rc = $drh->func('dropdb', $database, $host, $user, $password, 'admin'); $rc = $drh->func('shutdown', $host, $user, $password, 'admin'); $rc = $drh->func('reload', $host, $user, $password, 'admin'); $rc = $dbh->func('createdb', $database, 'admin'); $rc = $dbh->func('dropdb', $database, 'admin'); $rc = $dbh->func('shutdown', 'admin'); $rc = $dbh->func('reload', 'admin'); =head1 EXAMPLE #!/usr/bin/perl use strict; use warnings; use DBI; # Connect to the database. my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost", "joe", "joe's password", {'RaiseError' => 1}); # Drop table 'foo'. This may fail, if 'foo' doesn't exist # Thus we put an eval around it. eval { $dbh->do("DROP TABLE foo") }; print "Dropping foo failed: $@\n" if $@; # Create a new table 'foo'. This must not fail, thus we don't # catch errors. $dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))"); # INSERT some data into 'foo'. We are using $dbh->quote() for # quoting the name. $dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")"); # same thing, but using placeholders (recommended!) $dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen"); # now retrieve data from the table. my $sth = $dbh->prepare("SELECT * FROM foo"); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n"; } $sth->finish(); # Disconnect from the database. $dbh->disconnect(); =head1 DESCRIPTION B is the Perl5 Database Interface driver for the MySQL database. In other words: DBD::mysql is an interface between the Perl programming language and the MySQL programming API that comes with the MySQL relational database management system. Most functions provided by this programming API are supported. Some rarely used functions are missing, mainly because no-one ever requested them. :-) In what follows we first discuss the use of DBD::mysql, because this is what you will need the most. For installation, see the separate document L. See L for a simple example above. From perl you activate the interface with the statement use DBI; After that you can connect to multiple MySQL database servers and send multiple queries to any of them via a simple object oriented interface. Two types of objects are available: database handles and statement handles. Perl returns a database handle to the connect method like so: $dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $user, $password, {RaiseError => 1}); Once you have connected to a database, you can execute SQL statements with: my $query = sprintf("INSERT INTO foo VALUES (%d, %s)", $number, $dbh->quote("name")); $dbh->do($query); See L for details on the quote and do methods. An alternative approach is $dbh->do("INSERT INTO foo VALUES (?, ?)", undef, $number, $name); in which case the quote method is executed automatically. See also the bind_param method in L. See L below for more details on database handles. If you want to retrieve results, you need to create a so-called statement handle with: $sth = $dbh->prepare("SELECT * FROM $table"); $sth->execute(); This statement handle can be used for multiple things. First of all you can retrieve a row of data: my $row = $sth->fetchrow_hashref(); If your table has columns ID and NAME, then $row will be hash ref with keys ID and NAME. See L below for more details on statement handles. But now for a more formal approach: =head2 Class Methods =over =item B use DBI; $dsn = "DBI:mysql:$database"; $dsn = "DBI:mysql:database=$database;host=$hostname"; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password); A C must always be specified. =over =item host =item port The hostname, if not specified or specified as '' or 'localhost', will default to a MySQL server running on the local machine using the default for the UNIX socket. To connect to a MySQL server on the local machine via TCP, you must specify the loopback IP address (127.0.0.1) as the host. Should the MySQL server be running on a non-standard port number, you may explicitly state the port number to connect to in the C argument, by concatenating the I and I together separated by a colon ( C<:> ) character or by using the C argument. To connect to a MySQL server on localhost using TCP/IP, you must specify the hostname as 127.0.0.1 (with the optional port). =item mysql_client_found_rows Enables (TRUE value) or disables (FALSE value) the flag CLIENT_FOUND_ROWS while connecting to the MySQL server. This has a somewhat funny effect: Without mysql_client_found_rows, if you perform a query like UPDATE $table SET id = 1 WHERE id = 1; then the MySQL engine will always return 0, because no rows have changed. With mysql_client_found_rows however, it will return the number of rows that have an id 1, as some people are expecting. (At least for compatibility to other engines.) =item mysql_compression If your DSN contains the option "mysql_compression=1", then the communication between client and server will be compressed. =item mysql_connect_timeout If your DSN contains the option "mysql_connect_timeout=##", the connect request to the server will timeout if it has not been successful after the given number of seconds. =item mysql_write_timeout If your DSN contains the option "mysql_write_timeout=##", the write operation to the server will timeout if it has not been successful after the given number of seconds. =item mysql_read_timeout If your DSN contains the option "mysql_read_timeout=##", the read operation to the server will timeout if it has not been successful after the given number of seconds. =item mysql_init_command If your DSN contains the option "mysql_init_command=##", then this SQL statement is executed when connecting to the MySQL server. It is automatically re-executed if reconnection occurs. =item mysql_skip_secure_auth This option is for older mysql databases that don't have secure auth set. =item mysql_read_default_file =item mysql_read_default_group These options can be used to read a config file like /etc/my.cnf or ~/.my.cnf. By default MySQL's C client library doesn't use any config files unlike the client programs (mysql, mysqladmin, ...) that do, but outside of the C client library. Thus you need to explicitly request reading a config file, as in $dsn = "DBI:mysql:test;mysql_read_default_file=/home/joe/my.cnf"; $dbh = DBI->connect($dsn, $user, $password) The option mysql_read_default_group can be used to specify the default group in the config file: Usually this is the I group, but see the following example: [client] host=localhost [perl] host=perlhost (Note the order of the entries! The example won't work, if you reverse the [client] and [perl] sections!) If you read this config file, then you'll be typically connected to I. However, by using $dsn = "DBI:mysql:test;mysql_read_default_group=perl;" . "mysql_read_default_file=/home/joe/my.cnf"; $dbh = DBI->connect($dsn, $user, $password); you'll be connected to I. Note that if you specify a default group and do not specify a file, then the default config files will all be read. See the documentation of the C function mysql_options() for details. =item mysql_socket It is possible to choose the Unix socket that is used for connecting to the server. This is done, for example, with mysql_socket=/dev/mysql Usually there's no need for this option, unless you are using another location for the socket than that built into the client. =item mysql_ssl A true value turns on the CLIENT_SSL flag when connecting to the MySQL database: mysql_ssl=1 This means that your communication with the server will be encrypted. If you turn mysql_ssl on, you might also wish to use the following flags: =item mysql_ssl_client_key =item mysql_ssl_client_cert =item mysql_ssl_ca_file =item mysql_ssl_ca_path =item mysql_ssl_cipher These are used to specify the respective parameters of a call to mysql_ssl_set, if mysql_ssl is turned on. =item mysql_local_infile The LOCAL capability for LOAD DATA may be disabled in the MySQL client library by default. If your DSN contains the option "mysql_local_infile=1", LOAD DATA LOCAL will be enabled. (However, this option is *ineffective* if the server has also been configured to disallow LOCAL.) =item mysql_multi_statements Support for multiple statements separated by a semicolon (;) may be enabled by using this option. Enabling this option may cause problems if server-side prepared statements are also enabled. =item Prepared statement support (server side prepare) As of 3.0002_1, server side prepare statements were on by default (if your server was >= 4.1.3). As of 3.0009, they were off by default again due to issues with the prepared statement API (all other mysql connectors are set this way until C API issues are resolved). The requirement to use prepared statements still remains that you have a server >= 4.1.3 To use server side prepared statements, all you need to do is set the variable mysql_server_prepare in the connect: $dbh = DBI->connect( "DBI:mysql:database=test;host=localhost;mysql_server_prepare=1", "", "", { RaiseError => 1, AutoCommit => 1 } ); * Note: delimiter for this param is ';' There are many benefits to using server side prepare statements, mostly if you are performing many inserts because of that fact that a single statement is prepared to accept multiple insert values. To make sure that the 'make test' step tests whether server prepare works, you just need to export the env variable MYSQL_SERVER_PREPARE: export MYSQL_SERVER_PREPARE=1 =item mysql_embedded_options The option can be used to pass 'command-line' options to embedded server. Example: use DBI; $testdsn="DBI:mysqlEmb:database=test;mysql_embedded_options=--help,--verbose"; $dbh = DBI->connect($testdsn,"a","b"); This would cause the command line help to the embedded MySQL server library to be printed. =item mysql_embedded_groups The option can be used to specify the groups in the config file(I) which will be used to get options for embedded server. If not specified [server] and [embedded] groups will be used. Example: $testdsn="DBI:mysqlEmb:database=test;mysql_embedded_groups=embedded_server,common"; =item mysql_conn_attrs The option is a hash of attribute names and values which can be used to send custom connection attributes to the server. Some attributes like '_os', '_platform', '_client_name' and '_client_version' are added by libmysqlclient and 'program_name' is added by DBD::mysql. You can then later read these attributes from the performance schema tables which can be quite helpful for profiling your database or creating statistics. You'll have to use a MySQL 5.6 server and libmysqlclient or newer to leverage this feature. my $dbh= DBI->connect($dsn, $user, $password, { AutoCommit => 0, mysql_conn_attrs => { foo => 'bar', wiz => 'bang' }, }); Now you can select the results from the performance schema tables. You can do this in the same session, but also afterwards. It can be very useful to answer questions like 'which script sent this query?'. my $results = $dbh->selectall_hashref( 'SELECT * FROM performance_schema.session_connect_attrs', 'ATTR_NAME' ); This returns: $result = { 'foo' => { 'ATTR_VALUE' => 'bar', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => 'foo', 'ORDINAL_POSITION' => '6' }, 'wiz' => { 'ATTR_VALUE' => 'bang', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => 'wiz', 'ORDINAL_POSITION' => '3' }, 'program_name' => { 'ATTR_VALUE' => './foo.pl', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => 'program_name', 'ORDINAL_POSITION' => '5' }, '_client_name' => { 'ATTR_VALUE' => 'libmysql', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => '_client_name', 'ORDINAL_POSITION' => '1' }, '_client_version' => { 'ATTR_VALUE' => '5.6.24', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => '_client_version', 'ORDINAL_POSITION' => '7' }, '_os' => { 'ATTR_VALUE' => 'osx10.8', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => '_os', 'ORDINAL_POSITION' => '0' }, '_pid' => { 'ATTR_VALUE' => '59860', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => '_pid', 'ORDINAL_POSITION' => '2' }, '_platform' => { 'ATTR_VALUE' => 'x86_64', 'PROCESSLIST_ID' => '3', 'ATTR_NAME' => '_platform', 'ORDINAL_POSITION' => '4' } }; =back =back =head2 Private MetaData Methods =over =item B my $drh = DBI->install_driver("mysql"); @dbs = $drh->func("$hostname:$port", '_ListDBs'); @dbs = $drh->func($hostname, $port, '_ListDBs'); @dbs = $dbh->func('_ListDBs'); Returns a list of all databases managed by the MySQL server running on C<$hostname>, port C<$port>. This is a legacy method. Instead, you should use the portable method @dbs = DBI->data_sources("mysql"); =back =head2 Server Administration =over =item admin $rc = $drh->func("createdb", $dbname, [host, user, password,], 'admin'); $rc = $drh->func("dropdb", $dbname, [host, user, password,], 'admin'); $rc = $drh->func("shutdown", [host, user, password,], 'admin'); $rc = $drh->func("reload", [host, user, password,], 'admin'); or $rc = $dbh->func("createdb", $dbname, 'admin'); $rc = $dbh->func("dropdb", $dbname, 'admin'); $rc = $dbh->func("shutdown", 'admin'); $rc = $dbh->func("reload", 'admin'); For server administration you need a server connection. For obtaining this connection you have two options: Either use a driver handle (drh) and supply the appropriate arguments (host, defaults localhost, user, defaults to '' and password, defaults to ''). A driver handle can be obtained with $drh = DBI->install_driver('mysql'); Otherwise reuse the existing connection of a database handle (dbh). There's only one function available for administrative purposes, comparable to the mysqladmin programs. The command being execute depends on the first argument: =over =item createdb Creates the database $dbname. Equivalent to "mysqladmin create $dbname". =item dropdb Drops the database $dbname. Equivalent to "mysqladmin drop $dbname". It should be noted that database deletion is I in any way. Nor is it undo-able from DBI. Once you issue the dropDB() method, the database will be gone! These method should be used at your own risk. =item shutdown Silently shuts down the database engine. (Without prompting!) Equivalent to "mysqladmin shutdown". =item reload Reloads the servers configuration files and/or tables. This can be particularly important if you modify access privileges or create new users. =back =back =head1 DATABASE HANDLES The DBD::mysql driver supports the following attributes of database handles (read only): $errno = $dbh->{'mysql_errno'}; $error = $dbh->{'mysql_error'}; $info = $dbh->{'mysql_hostinfo'}; $info = $dbh->{'mysql_info'}; $insertid = $dbh->{'mysql_insertid'}; $info = $dbh->{'mysql_protoinfo'}; $info = $dbh->{'mysql_serverinfo'}; $info = $dbh->{'mysql_stat'}; $threadId = $dbh->{'mysql_thread_id'}; These correspond to mysql_errno(), mysql_error(), mysql_get_host_info(), mysql_info(), mysql_insert_id(), mysql_get_proto_info(), mysql_get_server_info(), mysql_stat() and mysql_thread_id(), respectively. =over 2 =item mysql_clientinfo List information of the MySQL client library that DBD::mysql was built against: print "$dbh->{mysql_clientinfo}\n"; 5.2.0-MariaDB =item mysql_clientversion print "$dbh->{mysql_clientversion}\n"; 50200 =item mysql_serverversion print "$dbh->{mysql_serverversion}\n"; 50200 =item mysql_dbd_stats $info_hashref = $dhb->{mysql_dbd_stats}; DBD::mysql keeps track of some statistics in the mysql_dbd_stats attribute. The following stats are being maintained: =over 8 =item auto_reconnects_ok The number of times that DBD::mysql successfully reconnected to the mysql server. =item auto_reconnects_failed The number of times that DBD::mysql tried to reconnect to mysql but failed. =back =back The DBD::mysql driver also supports the following attributes of database handles (read/write): =over =item mysql_auto_reconnect This attribute determines whether DBD::mysql will automatically reconnect to mysql if the connection be lost. This feature defaults to off; however, if either the GATEWAY_INTERFACE or MOD_PERL environment variable is set, DBD::mysql will turn mysql_auto_reconnect on. Setting mysql_auto_reconnect to on is not advised if 'lock tables' is used because if DBD::mysql reconnect to mysql all table locks will be lost. This attribute is ignored when AutoCommit is turned off, and when AutoCommit is turned off, DBD::mysql will not automatically reconnect to the server. It is also possible to set the default value of the C attribute for the $dbh by passing it in the C<\%attr> hash for Cconnect>. $dbh->{mysql_auto_reconnect} = 1; or my $dbh = DBI->connect($dsn, $user, $password, { mysql_auto_reconnect => 1, }); Note that if you are using a module or framework that performs reconnections for you (for example L in fixup mode), this value must be set to 0. =item mysql_use_result This attribute forces the driver to use mysql_use_result rather than mysql_store_result. The former is faster and less memory consuming, but tends to block other processes. mysql_store_result is the default due to that fact storing the result is expected behavior with most applications. It is possible to set the default value of the C attribute for the $dbh via the DSN: $dbh = DBI->connect("DBI:mysql:test;mysql_use_result=1", "root", ""); You can also set it after creation of the database handle: $dbh->{mysql_use_result} = 0; # disable $dbh->{mysql_use_result} = 1; # enable You can also set or unset the C setting on your statement handle, when creating the statement handle or after it has been created. See L. =item mysql_enable_utf8 This attribute determines whether DBD::mysql should assume strings stored in the database are utf8. This feature defaults to off. When set, a data retrieved from a textual column type (char, varchar, etc) will have the UTF-8 flag turned on if necessary. This enables character semantics on that string. You will also need to ensure that your database / table / column is configured to use UTF8. See Chapter 10 of the mysql manual for details. Additionally, turning on this flag tells MySQL that incoming data should be treated as UTF-8. This will only take effect if used as part of the call to connect(). If you turn the flag on after connecting, you will need to issue the command C to get the same effect. This option is experimental and may change in future versions. =item mysql_enable_utf8mb4 This is similar to mysql_enable_utf8, but is capable of handling 4-byte UTF-8 characters. =item mysql_bind_type_guessing This attribute causes the driver (emulated prepare statements) to attempt to guess if a value being bound is a numeric value, and if so, doesn't quote the value. This was created by Dragonchild and is one way to deal with the performance issue of using quotes in a statement that is inserting or updating a large numeric value. This was previously called C because it is experimental. I have successfully run the full test suite with this option turned on, the name can now be simply C. CAVEAT: Even though you can insert an integer value into a character column, if this column is indexed, if you query that column with the integer value not being quoted, it will not use the index: MariaDB [test]> explain select * from test where value0 = '3' \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test type: ref possible_keys: value0 key: value0 key_len: 13 ref: const rows: 1 Extra: Using index condition 1 row in set (0.00 sec) MariaDB [test]> explain select * from test where value0 = 3 -> \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test type: ALL possible_keys: value0 key: NULL key_len: NULL ref: NULL rows: 6 Extra: Using where 1 row in set (0.00 sec) See bug: https://rt.cpan.org/Ticket/Display.html?id=43822 C can be turned on via - through DSN my $dbh= DBI->connect('DBI:mysql:test', 'username', 'pass', { mysql_bind_type_guessing => 1}) - OR after handle creation $dbh->{mysql_bind_type_guessing} = 1; =item mysql_bind_comment_placeholders This attribute causes the driver (emulated prepare statements) will cause any placeholders in comments to be bound. This is not correct prepared statement behavior, but some developers have come to depend on this behavior, so I have made it available in 4.015 =item mysql_no_autocommit_cmd This attribute causes the driver to not issue 'set autocommit' either through explicit or using mysql_autocommit(). This is particularly useful in the case of using MySQL Proxy. See the bug report: https://rt.cpan.org/Public/Bug/Display.html?id=46308 C can be turned on when creating the database handle: my $dbh = DBI->connect('DBI:mysql:test', 'username', 'pass', { mysql_no_autocommit_cmd => 1}); or using an existing database handle: $dbh->{mysql_no_autocommit_cmd} = 1; =back =head1 STATEMENT HANDLES The statement handles of DBD::mysql support a number of attributes. You access these by using, for example, my $numFields = $sth->{NUM_OF_FIELDS}; Note, that most attributes are valid only after a successful I. An C value will returned otherwise. The most important exception is the C attribute, which forces the driver to use mysql_use_result rather than mysql_store_result. The former is faster and less memory consuming, but tends to block other processes. (That's why mysql_store_result is the default.) To set the C attribute, use either of the following: my $sth = $dbh->prepare("QUERY", { mysql_use_result => 1}); or my $sth = $dbh->prepare($sql); $sth->{mysql_use_result} = 1; Column dependent attributes, for example I, the column names, are returned as a reference to an array. The array indices are corresponding to the indices of the arrays returned by I and similar methods. For example the following code will print a header of table names together with all rows: my $sth = $dbh->prepare("SELECT * FROM $table") || die "Error:" . $dbh->errstr . "\n"; $sth->execute || die "Error:" . $sth->errstr . "\n"; my $names = $sth->{NAME}; my $numFields = $sth->{'NUM_OF_FIELDS'} - 1; for my $i ( 0..$numFields ) { printf("%s%s", $i ? "," : "", $$names[$i]); } print "\n"; while (my $ref = $sth->fetchrow_arrayref) { for my $i ( 0..$numFields ) { printf("%s%s", $i ? "," : "", $$ref[$i]); } print "\n"; } For portable applications you should restrict yourself to attributes with capitalized or mixed case names. Lower case attribute names are private to DBD::mysql. The attribute list includes: =over =item ChopBlanks this attribute determines whether a I will chop preceding and trailing blanks off the column values. Chopping blanks does not have impact on the I attribute. =item mysql_insertid MySQL has the ability to choose unique key values automatically. If this happened, the new ID will be stored in this attribute. An alternative way for accessing this attribute is via $dbh->{'mysql_insertid'}. (Note we are using the $dbh in this case!) =item mysql_is_blob Reference to an array of boolean values; TRUE indicates, that the respective column is a blob. This attribute is valid for MySQL only. =item mysql_is_key Reference to an array of boolean values; TRUE indicates, that the respective column is a key. This is valid for MySQL only. =item mysql_is_num Reference to an array of boolean values; TRUE indicates, that the respective column contains numeric values. =item mysql_is_pri_key Reference to an array of boolean values; TRUE indicates, that the respective column is a primary key. =item mysql_is_auto_increment Reference to an array of boolean values; TRUE indicates that the respective column is an AUTO_INCREMENT column. This is only valid for MySQL. =item mysql_length =item mysql_max_length A reference to an array of maximum column sizes. The I is the maximum physically present in the result table, I gives the theoretically possible maximum. I is valid for MySQL only. =item NAME A reference to an array of column names. =item NULLABLE A reference to an array of boolean values; TRUE indicates that this column may contain NULL's. =item NUM_OF_FIELDS Number of fields returned by a I