DBD-MariaDB-1.22/0000755000175000017500000000000014230360635011722 5ustar palipaliDBD-MariaDB-1.22/META.json0000644000175000017500000001273714230360635013355 0ustar palipali{ "abstract" : "MariaDB and MySQL driver for the Perl5 Database Interface (DBI)", "author" : [ "Pali " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "DBD-MariaDB", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "Config" : "0", "DBI" : "1.608", "Data::Dumper" : "0", "Devel::CheckLib" : "1.12", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Getopt::Long" : "0", "strict" : "0", "utf8" : "0", "warnings" : "0" } }, "runtime" : { "requires" : { "DBI" : "1.608", "DynaLoader" : "0", "perl" : "5.008001", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta::YAML" : "0", "Net::SSLeay" : "1.43", "Proc::ProcessTable" : "0", "TAP::Harness" : "3.31" }, "requires" : { "B" : "0", "DBI" : "0", "DBI::Const::GetInfoType" : "0", "Data::Dumper" : "0", "Encode" : "0", "File::Temp" : "0", "FindBin" : "0", "Test::Deep" : "0", "Test::More" : "0.90", "Time::HiRes" : "0", "bigint" : "0", "lib" : "0", "strict" : "0", "utf8" : "0", "vars" : "0", "warnings" : "0" }, "suggests" : { "Storable" : "0", "Test::DistManifest" : "0", "Test::Pod" : "1.41" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/gooddata/DBD-MariaDB/issues" }, "homepage" : "https://github.com/gooddata/DBD-MariaDB", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/gooddata/DBD-MariaDB.git", "web" : "https://github.com/gooddata/DBD-MariaDB" }, "x_IRC" : "irc://irc.perl.org/#dbi", "x_MailingList" : "mailto:dbi-dev@perl.org" }, "version" : "1.22", "x_contributors" : [ "Alexandr Ciornii ", "Alexey Molchanov ", "Amiri Barksdale at Home ", "Andrew Miller ", "Aran Deltac ", "Bernt M. Johnsen ", "Branislav Zahradník ", "Chase Whitener ", "Chip Salzenberg ", "Chris Hammond ", "Chris Weyl ", "Christian Walde ", "Dagfinn Ilmari Mannsåker ", "Daisuke Murase ", "Damyan Ivanov ", "Dan Book ", "Daniël van Eeden ", "Dave Lambley ", "David Farrell ", "David Steinbrunner ", "Dominik Sauer ", "Giovanni Bechis ", "Graham Ollis ", "H.Merijn Brand - Tux ", "Hanno ", "James McCoy ", "Jan Holcapek ", "Jim Winstead ", "Juergen Weigert ", "Kenny Gryp ", "Lu Shengliang ", "Masahiro Chiba ", "Matthew Horsfall (alh) ", "Michiel Beijen ", "Mike Pomraning ", "Mohammad S Anwar ", "Pali ", "Patrick Galbraith ", "Perlover ", "Peter Botha ", "Petr Písař ", "Reini Urban ", "Rob Hoelz ", "Rob Van Dam ", "Rudy Lippan ", "Scimon ", "Sergey Zhuravlev ", "Sergiy Borodych ", "Sharif Nassar ", "Steffen Mueller ", "Steven Hartland ", "Taro Kobayashi <9re.3000@gmail.com>", "Tatsuhiko Miyagawa ", "Tim Mullin ", "Ville Skyttä ", "Vladimir Marek ", "katyavoid ", "kmx ", "tokuhirom ", "zefram ", "zentooo " ], "x_serialization_backend" : "JSON::PP version 2.97001" } DBD-MariaDB-1.22/META.yml0000644000175000017500000000763614230360635013207 0ustar palipali--- abstract: 'MariaDB and MySQL driver for the Perl5 Database Interface (DBI)' author: - 'Pali ' build_requires: B: '0' DBI: '0' DBI::Const::GetInfoType: '0' Data::Dumper: '0' Encode: '0' ExtUtils::MakeMaker: '0' File::Temp: '0' FindBin: '0' Test::Deep: '0' Test::More: '0.90' Time::HiRes: '0' bigint: '0' lib: '0' strict: '0' utf8: '0' vars: '0' warnings: '0' configure_requires: Config: '0' DBI: '1.608' Data::Dumper: '0' Devel::CheckLib: '1.12' ExtUtils::MakeMaker: '0' File::Spec: '0' Getopt::Long: '0' strict: '0' utf8: '0' warnings: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: DBD-MariaDB no_index: directory: - t - inc requires: DBI: '1.608' DynaLoader: '0' perl: '5.008001' strict: '0' warnings: '0' resources: IRC: irc://irc.perl.org/#dbi MailingList: mailto:dbi-dev@perl.org bugtracker: https://github.com/gooddata/DBD-MariaDB/issues homepage: https://github.com/gooddata/DBD-MariaDB license: http://dev.perl.org/licenses/ repository: git://github.com/gooddata/DBD-MariaDB.git version: '1.22' x_contributors: - 'Alexandr Ciornii ' - 'Alexey Molchanov ' - 'Amiri Barksdale at Home ' - 'Andrew Miller ' - 'Aran Deltac ' - 'Bernt M. Johnsen ' - 'Branislav Zahradník ' - 'Chase Whitener ' - 'Chip Salzenberg ' - 'Chris Hammond ' - 'Chris Weyl ' - 'Christian Walde ' - 'Dagfinn Ilmari Mannsåker ' - 'Daisuke Murase ' - 'Damyan Ivanov ' - 'Dan Book ' - 'Daniël van Eeden ' - 'Dave Lambley ' - 'David Farrell ' - 'David Steinbrunner ' - 'Dominik Sauer ' - 'Giovanni Bechis ' - 'Graham Ollis ' - 'H.Merijn Brand - Tux ' - 'Hanno ' - 'James McCoy ' - 'Jan Holcapek ' - 'Jim Winstead ' - 'Juergen Weigert ' - 'Kenny Gryp ' - 'Lu Shengliang ' - 'Masahiro Chiba ' - 'Matthew Horsfall (alh) ' - 'Michiel Beijen ' - 'Mike Pomraning ' - 'Mohammad S Anwar ' - 'Pali ' - 'Patrick Galbraith ' - 'Perlover ' - 'Peter Botha ' - 'Petr Písař ' - 'Reini Urban ' - 'Rob Hoelz ' - 'Rob Van Dam ' - 'Rudy Lippan ' - 'Scimon ' - 'Sergey Zhuravlev ' - 'Sergiy Borodych ' - 'Sharif Nassar ' - 'Steffen Mueller ' - 'Steven Hartland ' - 'Taro Kobayashi <9re.3000@gmail.com>' - 'Tatsuhiko Miyagawa ' - 'Tim Mullin ' - 'Ville Skyttä ' - 'Vladimir Marek ' - 'katyavoid ' - 'kmx ' - 'tokuhirom ' - 'zefram ' - 'zentooo ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' DBD-MariaDB-1.22/LICENSE0000644000175000017500000004370014230360604012727 0ustar palipaliThis 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-MariaDB-1.22/MariaDB.xs0000644000175000017500000001520114230360604013530 0ustar palipali/* Hej, Emacs, this is -*- C -*- mode! Copyright (c) 2018 GoodData Corporation Copyright (c) 2015-2017 Pali Rohár Copyright (c) 2004-2017 Patrick Galbraith Copyright (c) 2013-2017 Michiel Beijen Copyright (c) 2004-2007 Alexey Stroganov Copyright (c) 2003-2005 Rudolf Lippan Copyright (c) 1997-2003 Jochen Wiedmann You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. */ #include "dbdimp.h" #define ASYNC_CHECK_XS(h)\ if(imp_dbh->async_query_in_flight) {\ mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Calling a synchronous function on an asynchronous handle", "HY000");\ XSRETURN_UNDEF;\ } DBISTATE_DECLARE; MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB INCLUDE: MariaDB.xsi MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB BOOT: { HV *stash = gv_stashpvs("DBD::MariaDB", GV_ADD); #define newTypeSub(stash, type) newCONSTSUB((stash), #type + sizeof("MYSQL_")-1, newSViv(type)) newTypeSub(stash, MYSQL_TYPE_DECIMAL); newTypeSub(stash, MYSQL_TYPE_TINY); newTypeSub(stash, MYSQL_TYPE_SHORT); newTypeSub(stash, MYSQL_TYPE_LONG); newTypeSub(stash, MYSQL_TYPE_FLOAT); newTypeSub(stash, MYSQL_TYPE_DOUBLE); newTypeSub(stash, MYSQL_TYPE_NULL); newTypeSub(stash, MYSQL_TYPE_TIMESTAMP); newTypeSub(stash, MYSQL_TYPE_LONGLONG); newTypeSub(stash, MYSQL_TYPE_INT24); newTypeSub(stash, MYSQL_TYPE_DATE); newTypeSub(stash, MYSQL_TYPE_TIME); newTypeSub(stash, MYSQL_TYPE_DATETIME); newTypeSub(stash, MYSQL_TYPE_YEAR); newTypeSub(stash, MYSQL_TYPE_NEWDATE); newTypeSub(stash, MYSQL_TYPE_VARCHAR); newTypeSub(stash, MYSQL_TYPE_BIT); newTypeSub(stash, MYSQL_TYPE_NEWDECIMAL); newTypeSub(stash, MYSQL_TYPE_ENUM); newTypeSub(stash, MYSQL_TYPE_SET); newTypeSub(stash, MYSQL_TYPE_TINY_BLOB); newTypeSub(stash, MYSQL_TYPE_MEDIUM_BLOB); newTypeSub(stash, MYSQL_TYPE_LONG_BLOB); newTypeSub(stash, MYSQL_TYPE_BLOB); newTypeSub(stash, MYSQL_TYPE_VAR_STRING); newTypeSub(stash, MYSQL_TYPE_STRING); #undef newTypeSub #if defined(HAVE_DEINITIALIZE_SSL) && defined(HAVE_PROBLEM_WITH_OPENSSL) /* Do not deinitialize OpenSSL library after mysql_server_end() * See: https://github.com/gooddata/DBD-MariaDB/issues/119 */ mariadb_deinitialize_ssl = 0; #endif #ifndef _WIN32 /* Calling mysql_thread_init() on WIN32 cause crash */ mysql_thread_init(); #endif } MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB::db void connected(dbh, ...) SV* dbh PPCODE: /* Called by DBI when connect method finished */ D_imp_dbh(dbh); imp_dbh->connected = TRUE; XSRETURN_EMPTY; void type_info_all(dbh) SV* dbh PPCODE: { PERL_UNUSED_VAR(dbh); ST(0) = sv_2mortal(newRV_noinc((SV*) mariadb_db_type_info_all())); XSRETURN(1); } #ifndef HAVE_DBI_1_642 IV do(dbh, statement, attr=Nullsv, ...) SV *dbh SV *statement SV *attr CODE: { /* Compatibility for DBI version prior to 1.642 which does not support dbd_db_do6 API */ D_imp_dbh(dbh); RETVAL = mariadb_db_do6(dbh, imp_dbh, statement, attr, items-3, ax+3); if (RETVAL == 0) /* ok with no rows affected */ XSRETURN_PV("0E0"); /* (true but zero) */ else if (RETVAL < -1) /* -1 == unknown number of rows */ XSRETURN_UNDEF; } OUTPUT: RETVAL #endif bool ping(dbh) SV* dbh; CODE: { D_imp_dbh(dbh); ASYNC_CHECK_XS(dbh); if (!imp_dbh->pmysql) XSRETURN_NO; RETVAL = (mysql_ping(imp_dbh->pmysql) == 0); if (!RETVAL) { if (mariadb_db_reconnect(dbh, NULL)) RETVAL = (mysql_ping(imp_dbh->pmysql) == 0); } } OUTPUT: RETVAL void quote(dbh, str, type=NULL) SV* dbh SV* str SV* type PPCODE: { SV* quoted; D_imp_dbh(dbh); ASYNC_CHECK_XS(dbh); quoted = mariadb_db_quote(dbh, str, type); ST(0) = quoted ? sv_2mortal(quoted) : str; XSRETURN(1); } SV * mariadb_sockfd(dbh) SV* dbh CODE: D_imp_dbh(dbh); RETVAL = imp_dbh->pmysql ? newSViv(imp_dbh->pmysql->net.fd) : &PL_sv_undef; OUTPUT: RETVAL SV * mariadb_async_result(dbh) SV* dbh CODE: { my_ulonglong retval; retval = mariadb_db_async_result(dbh, NULL); if (retval == 0) XSRETURN_PV("0E0"); else if (retval == (my_ulonglong)-1) XSRETURN_UNDEF; RETVAL = my_ulonglong2sv(retval); } OUTPUT: RETVAL void mariadb_async_ready(dbh) SV* dbh PPCODE: { int retval; retval = mariadb_db_async_ready(dbh); if(retval > 0) { XSRETURN_YES; } else if(retval == 0) { XSRETURN_NO; } else { XSRETURN_UNDEF; } } void _async_check(dbh) SV* dbh PPCODE: { D_imp_dbh(dbh); ASYNC_CHECK_XS(dbh); XSRETURN_YES; } MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB::st bool more_results(sth) SV * sth CODE: { D_imp_sth(sth); RETVAL = mariadb_st_more_results(sth, imp_sth); } OUTPUT: RETVAL SV * rows(sth) SV* sth CODE: D_imp_sth(sth); D_imp_dbh_from_sth; if(imp_dbh->async_query_in_flight) { if (mariadb_db_async_result(sth, &imp_sth->result) == (my_ulonglong)-1) { XSRETURN_UNDEF; } } if (imp_sth->row_num == (my_ulonglong)-1) XSRETURN_IV(-1); RETVAL = my_ulonglong2sv(imp_sth->row_num); OUTPUT: RETVAL #ifndef HAVE_DBI_1_642 void last_insert_id(sth, catalog=&PL_sv_undef, schema=&PL_sv_undef, table=&PL_sv_undef, field=&PL_sv_undef, attr=Nullsv) SV *sth SV *catalog SV *schema SV *table SV *field SV *attr PPCODE: { /* Compatibility for DBI version prior to 1.642 which does not support dbd_st_last_insert_id API */ D_imp_sth(sth); ST(0) = mariadb_st_last_insert_id(sth, imp_sth, catalog, schema, table, field, attr); XSRETURN(1); } #endif SV * mariadb_async_result(sth) SV* sth CODE: { D_imp_sth(sth); my_ulonglong retval; retval= mariadb_db_async_result(sth, &imp_sth->result); if (retval == (my_ulonglong)-1) XSRETURN_UNDEF; if (retval == 0) XSRETURN_PV("0E0"); RETVAL = my_ulonglong2sv(retval); } OUTPUT: RETVAL void mariadb_async_ready(sth) SV* sth PPCODE: { int retval; retval = mariadb_db_async_ready(sth); if(retval > 0) { XSRETURN_YES; } else if(retval == 0) { XSRETURN_NO; } else { XSRETURN_UNDEF; } } void _async_check(sth) SV* sth PPCODE: { D_imp_sth(sth); D_imp_dbh_from_sth; ASYNC_CHECK_XS(sth); XSRETURN_YES; } DBD-MariaDB-1.22/Changes.historic0000644000175000017500000024072314230360604015044 0ustar palipali2017-??-?? Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.042_01) * Use Devel::CheckLib 1.09 or newer, fixes https://github.com/perl5-dbi/DBD-mysql/issues/109 * Improve CI testing on AppVeyor: caching, path to cpan, configure deps (pali) * Specify bigint as test dependency. 2017-03-08 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.042) * Full release to include development releases 4.041_2 and 4.041_1. 2017-02-28 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.041_2) * Statement handle now also has mysql_sock attribute, just as database handle. (by Pali) * Fix type conversions for magic types. Issue reported by Dmitriy Yatsenko and Giovanni Bechis, fix by Pali. https://lists.amavis.org/pipermail/amavis-users/2016-December/004674.html https://github.com/perl5-dbi/DBD-mysql/issues/78 * Fix UTF8-encoding of table names, field names, warnings and error messages. Reported by Tanabe Yoshinori, fix by Pali. https://rt.cpan.org/Public/Bug/Display.html?id=120141 * Fix mysql_auto_reconnect when using mysql_server_prepare (pali). Reported by Vladimir Marek. https://github.com/perl5-dbi/DBD-mysql/pull/95 * Improve regex for removing database from dsn (pali) https://rt.cpan.org/Public/Bug/Display.html?id=118837 * Locate MySQL libs using Devel::CheckLib (pali) * Support async on Windows (pali) * Fix test suite on range of older and newer MySQL and MariaDB versions (https://github.com/perl5-dbi/DBD-mysql/pull/87) * Fix compilation on MySQL 4.1 (pali) * Do not leak dangling pointer to mysql result (pali) * Fix logic when assigning to variable bind_comment_placeholders (pali) * mysql_fd() still returned file descriptor after closing connection. Reported by Larry Leszczynski, fixed by Pali Rohár. (https://rt.cpan.org/Public/Bug/Display.html?id=110983) * Fix parsing configure libs from mysql_config --libs output in Makefile.PL Libraries in mysql_config --libs output can be specified by library name with the -l prefix or by absolute path to library name without any prefix. Parameters must start with a hyphen, so treat all options without leading hyphen in mysql_config --libs output as libraries with full path. Partially fixes bug https://rt.cpan.org/Public/Bug/Display.html?id=100898 Fix by Pali Rohár. * Fix support for magic scalars (pali) (https://github.com/perl5-dbi/DBD-mysql/pull/76) 2016-12-12 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.041_1) * Unicode fixes: when using mysql_enable_utf8 or mysql_enable_utf8mb4, previous versions of DBD::mysql did not properly encode input statements to UTF-8 and retrieved columns were always UTF-8 decoded regardless of the column charset. Fix by Pali Rohár. Reported and feedback on fix by Marc Lehmann (https://rt.cpan.org/Public/Bug/Display.html?id=87428) Also, the UTF-8 flag was not set for decoded data: (https://rt.cpan.org/Public/Bug/Display.html?id=53130) * Return INTs with ZEROFILL as strings. Reported by Knarf, fix by Pali Rohár. (https://rt.cpan.org/Public/Bug/Display.html?id=118977) 2016-11-28 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.041) * Fix use-after-free for repeated fetchrow_arrayref calls when mysql_server_prepare=1 Function dbd_st_fetch() via Renew() can reallocate output buffer for mysql_stmt_fetch() call. But it does not update pointer to that buffer in imp_sth->stmt structure initialized by mysql_stmt_bind_result() function. That leads to use-after-free in any mysql function which access imp_sth->stmt structure (e.g. mysql_stmt_fetch()). This patch fix this problem and properly updates pointer in imp_sth->stmt structure after Renew() call. This is a medium level security issue to which the Debian security team assigned identifier CVE-2016-1251. Discovered and fixed by Pali Rohár. * auto_reconnect now also matches CR_SERVER_LOST, previously this only matched CR_SERVER_GONE. Fixes http://bugs.mysql.com/bug.php?id=27613 Fix suggested by Wouter de Jong. * Fix compilation fixes (Pali Rohár). 2016-11-19 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.040) * Since 4.038 we had problems compiling on big-endian architectures, such as MIPS, s390 and Sparc. Thanks to Salvatore Bonaccorso @ Debian project (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=844538) and Vladimir Marek (https://rt.cpan.org/Public/Bug/Display.html?id=118835) for reporting the issues. Fix by Pali Rohár. Fix integer types when server side prepare statements are enabled Fixed problems: * SQL_BIGINT was incorrectly handled as 32bit MYSQL_TYPE_LONG type instead 64bit MYSQL_TYPE_LONGLONG which led to integer overflow/underflow * 32bit MYSQL_TYPE_LONG was used for perl's IV storage when IV was 64bit and 64bit MYSQL_TYPE_LONGLONG was used when IV was 32bit * All unsigned types were handled as signed, so all high positive values were treated as negative * Numeric conversions in perl which led to overflow/underflow was ignored even when mysql strict mode was enabled * Test t/41int_min_max.t was running only for normal non-prepared statements * Test t/40server_prepare.t used incorrect SQL type for big (64bit) integers 2016-11-15 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.039) * Fix for security issue Out-of-bounds read by DBD::mysql CVE-2016-1249 (pali) 2016-10-30 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.038_01) * Fix compilation of embedded server (pali) (https://github.com/perl5-dbi/DBD-mysql/pull/68) * Fix compilation against libmariadbclient. First version by H.Merijn Brand, improved by Bernt Johnsen @ Oracle. * For efficiency use newSVpvn() instead newSVpv() where possible (pali) * Correctly coerce fetched scalar values when mysql_server_prepare is not used (pali) * Add support for fetching columns of BIT type with mysql_server_prepare = 1 (pali) Fixes https://rt.cpan.org/Public/Bug/Display.html?id=88006 * Use correct format in printf instead of casting variable types (pali) * Include errno.h for MYSQL_ASYNC because it uses errno variable (pali) * Travis: also test on perl 5.22 and 5.24. 2016-10-19 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.038) * Version 4.037_1 had fixes for MySQL 8.0 provided Bernt Johnsen @ Oracle that were not in the Changelogs (https://github.com/perl5-dbi/DBD-mysql/pull/56) * Fixes for compiling against newer libmysqlclient on Windows (kmx) * Fix unit test for 40server_prepare_crash on Windows (pali) * Perl's IV in scalar can store 64bit integer when perl was compiled with 64 bit support (default on 64bit linux with gcc). Use this feature and stores MYSQL_TYPE_LONGLONG as integers instead of strings when possible. (pali, https://github.com/perl5-dbi/DBD-mysql/pull/57) 2016-10-14 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.037_01) * Newest versions of libmysqlclient and the MariaDB C connector no longer export the __WIN__ macro. If this macro is not present we would not compile in the poll.h-based async-support. Changed to use the _WIN32 macro instead. Thanks to Sergei Golubchik for suggesting the fix. * Fix from Pali Rohár for use-after-free in prepared statements, changes to bind logic, and added test 40server_prepare_crash. 2016-10-03 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.037) * Security release to patch possible buffer overflow in unsafe sprintf with variable length. Reported and fixed by Pali Rohár. This vulnerability is present in all releases at least back to versions 3.0 of the driver, which were released in 2005. The CVE identifier for this vulnerability is CVE-2016-1246. 2016-08-23 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.036) Stable version, to include all changes since 4.035. 2016-08-19 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035_03) * By mistake, when DBD::mysql was compiled against libmariadb, it did not compile in SSL support. Reported by Jitka Plesnikova @ Red Hat (https://rt.cpan.org/Public/Bug/Display.html?id=116959) (https://bugzilla.redhat.com/show_bug.cgi?id=1366773) * If the database test server was not on localhost and the test database was not yet created, we would not correctly create the test database. Reported by Vladimir Marek. (https://rt.cpan.org/Ticket/Display.html?id=112072) 2016-08-11 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035_02) * Test 56connattr.t failed when run when performance schema is enabled, but tests were run as a user with limited permissions. Reported by Jérôme Étévé. (https://rt.cpan.org/Public/Bug/Display.html?id=115980) * In 4.033_03 we added a patch from Petr Písař @ Red Hat for a problem on 64-bit big-endian systems. The patch was applied but the unit test was not, also, there was no entry in the change log. Unit test provided by Vladimir Marek. t/40server_prepare.t test failed on s390x platform. Server-prepared values of types int, smallint, and tinyint are passed to application as 32-bit integer. The same buffer was interpreted as long integer by DBD::MySQL. This caused misaligned read/write and bogus interpretation of the values. (https://rt.cpan.org/Public/Bug/Display.html?id=57266) * Remove dropdb, createdb, reload and shutdown admin functions from perldoc. These are deprecated by the C API. Use 'CREATE DATABASE..', 'DROP DATABASE...' and other SQL commands instead. * Test rt75353-innodb-lock-timeout.t fails on MySQL Server 5.1 and earlier because innodb_lock_wait_timeout is not modifyable per session. * Test rt25389-bin-case.t does not work on MySQL Server < 5.1, reported by GAAS. 2016-08-01 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035_01) * Apparently, on t/31insertid.t, there is one test that fails when compiled against libmysqlclient 5.7 or up; issuing a SELECT statement on the same database handle that previously executed an INSERT clears $dbh->{mysql_insertid}, while previously this was retained. (https://rt.cpan.org/Ticket/Display.html?id=108000) * Removed appveyor.yml and mysql.mtest from CPAN releases. * Converted README.pod to README.md because of installation failures on FreeBSD, reported by Don Randolph. (https://rt.cpan.org/Public/Bug/Display.html?id=114177) 2016-07-09 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035) * Add DBI back to configure_requires, fix by miyagawa. 2016-07-06 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.034) * Full version, to include all changes since 4.033. 2016-07-04 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.033_03) * Check for errors after calling mysql_affected_rows(), by Pali. (https://rt.cpan.org/Public/Bug/Display.html?id=75353) * Fix reference to MySQL manual, chapter Character Set Support, suggested by Slaven Rezić (https://rt.cpan.org/Public/Bug/Display.html?id=114148) * Improve documentation on current database, suggested by Vladimir Marek. (https://rt.cpan.org/Ticket/Display.html?id=112587) 2015-12-18 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.033_02) * Compile against libssl by default. This allows to connect against remote MySQL servers using SSL. Previously this was only achieved with an explicit switch provided to Makefile.PL - if for some reason you can't or don't want to link against libssl, you can use the new --nossl switch to Makefile.PL. * Made tests more robust after CPAN Testers failures. 2015-12-15 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.033_01) * Raise minimum DBI version to 1.609 (from 2009!) in order to make tests pass on RHEL5. * Add explicit documentation for how to enable SSL at build time, provided by genio. * Improve test suite to make it more robust using mixed versions of client and server. * Fix use after free error in my_login, provided by hannob. * Add explicit instructions stating brackets are required around ipv6-addresses in connection strings, provided by Kenny Gryp. 2015-10-26 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.033) * Full-release to include 03. 2015-10-25 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.032_03) * Use mysql_get_option to read net_buffer_length and mysql_get_parameter where available, needed for MySQL 5.7.9. Patch from berntm @ Oracle. https://github.com/perl5-dbi/DBD-mysql/pull/42 * Fix mysql_conn_attrs test when run against MySQL 5.1 server. * Fix for memory leak to $sth->{ParamValues} , RT83051 https://rt.cpan.org/Public/Bug/Display.html?id=83051 * Fixes for running test suite on MySQL 5.7. * Fix running test suite with InnoDB disabled, reported by bor. 2015-07-20 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.032) * Full-release to include 02 and 01. 2015-06-15 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.032_02) * Added support for utf8mb4 by Daniël van Eeden and Eric Herman (Booking.com) * Added patch for connection attributes in MySQL 5.6.6+, by Daniël van Eeden and Eric Herman (Booking.com). 2015-04-16 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.032_01) * Fixed test rt88006-bit-prepare on MyISAM storage (Reported both in RT102657 and by Scimon on github) * Fix for https://rt.cpan.org/Public/Bug/Display.html?id=102717 "Fritz" Friedrich Haubensak (hsk AT fli-leibniz DOT de) Vielen Danken! * Corrected name ofINSTALL.pm in POD David Farrell Corrected name of INSTALL.pm in POD 2015-03-05 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.031) * Added LICENSE * Reworked installation documentation in POD. * Allow use of bracketed IPv6 addresses in connection string (RT70640), fix by Tim Mullin @ cPanel). * Locate mysql_config in path on MSWin32 (RT94838, reported by CHORNY). * Environment variable DBD_MYSQL_CONFIG actually works now. * Makefile.PL now correcly handles MariaDB's mysql_config. * Correct attribution to David Dick #86030: PATCH: adding statistics_info support * Test suite can now be run in parallel. Fixes RT98994 reported by DOHERTY. * Fixes for MySQL 5.6+ and for prepared statement handling (stevenh on github). * Fix for RT100792, New test t/05dbcreate.t fails if user has no permissions. * Fix for bit test (RT68374, BJDEAN@cpan.org) CaptTofu added 40bit.t to test. 2015-03-02 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.030_02) * Reworked installation documentation in POD. * Allow use of bracketed IPv6 addresses in connection string (RT70640), fix by Tim Mullin @ cPanel). * Locate mysql_config in path on MSWin32 (RT94838, reported by CHORNY). * Environment variable DBD_MYSQL_CONFIG actually works now. * Makefile.PL now correcly handles MariaDB's mysql_config. 2015-01-27 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.030_01) * Correct attribution to David Dick #86030: PATCH: adding statistics_info support * Test suite can now be run in parallel. Fixes RT98994 reported by DOHERTY. * Fixes for MySQL 5.6+ and for prepared statement handling (stevenh on github). * Fix for RT100792, New test t/05dbcreate.t fails if user has no permissions. * Fix for bit test (RT68374, BJDEAN@cpan.org) CaptTofu added 40bit.t to test. 2014-12-08 Patrick Galbraith (aka CaptTofu) and community (4.029) * Added fix to tests to create test database if not exists (contstant failure on Travis) (CaptTofu) * Support the fraction of (Oracle) MySQL Fabric that is supported by the most recent Connector/C (Steffen Mueller smuellercpanorg * Statistics Info Milan ¿orm is4ucz> for work on statistics_info * Fix for RT 97625, use after free(), Reini Urban rurbancpanorg 2014-08-01 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.028) * Fixed bug in mysql.xs where dbh was being used as error code * RT #97570: fix wrong salloc free in mysql_st_internal_execute - (Reini Urban, cPanel) * Fix RT #97625 use-after-free in mysql_dr_error, and #86153 - (Reini Urban, cPanel) * find mysql.h for MariaDB on Win32 (Graham Ollis) * Update mysql.pm to work with ipv6 and ipv4 addresses (katyavoid) 2014-03-19 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.027) * Added more OS X notes and fixed compiler warnings * Skip tests if test database is not present-RT92330 (zefram * metacpan.org and search.cpan.org didn't display module POD, caused by fix for RT90101. Reported by Oleg, RT92350. 2014-01-15 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.026) * t/29warnings.t fails on MySQL Server 5.1.something - Reported by RT91202, Gisle Aas. Now is handled depending on version. * README.pod misses proper NAME heading - RT90101 - Damyan Ivanov, Debian Perl Group * Added fix and test for RT91715 * Added feature from Jacob Gelbman (cPanel) mysql_skip_secure_auth 2013-11-05 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.025) * Set with parentheses and column_info - RT50304 - reported and fixed by Kevin Bosak. * Fix method redefinition warnings in threads on Perl >= 5.16 - Dagfinn Ilmari Mannsåker * use strict and warnings everywhere. * Minimum perl version is now 5.8.1, just as for DBI. * Improved database version check so tests run correctly on MariaDB 10. * Fix manifest - RT89106, reported by Joe Grasse. * set auto_increment_offset explicitly to make tests pass if they are set on server - RT83487, reported by Ian Barton. * Assume 'localhost' when testport is set but no testhost in Makefile.PL - RT83496, reported by Philip Stoev. * Corrected documentation for mysql_init_command option - Alexey Molchanov * Skip stored procedure tests if user is unpriviliged - RT83348 - Chris Weyl * Fix example in POD doc for NUM_OF_FIELDS - RT36730, reported by tapoutmma. * Fix for memory leak (RT86153) when connecting with incorrect password * Bail if connect fails early on (RT31823) 2013-09-17 Michiel Beijen, Patrick Galbraith, DBI/DBD community (4.024) * Fix memory leak if mysql_server_prepare is enabled - RT76462 - Masahiro Chiba * Small dist improvements: Michiel Beijen * Undefined $DBI::errstr on execute fail on Windows: Michiel Beijen * Better diagnostics for 80procs.t Fixes RT#71199: Alexandr Ciornii * Fix #64013: INSTALL.pod is shown with 'man install': Juergen Weigert * Added 'testport' to keys in Makefile.PL Fixes RT#83492: Michiel Beijen * Fixed test 70takeimp warning. Michiel Beijen * Made test t/87async.t not stop on Win32. Michiel Beijen * Update github location. Update support information. Michiel Beijen * POD Fixes Patch from RT77043 by Gunnar Wolf, Debian Perl Group. Michiel Beijen 2013-04-12 Patrick Galbraith et open source community (4.023) Fix memory leak if mysql_server_prepare is enabled. * Fix primary_key_info result ordering - https://github.com/CaptTofu/DBD-mysql/pull/39 - Dagfinn Ilmari Mannsåker * allow compilation with msvc - https://github.com/CaptTofu/DBD-mysql/pull/37 - Walde Christian * just to set MYSQL_OPT_WRITE_TIMEOUT and MYSQL_OPT_READ_TIMEOUT by dsn - https://github.com/CaptTofu/DBD-mysql/pull/36 - Naosuke Yokoe * just remove unnecessary "my" - https://github.com/CaptTofu/DBD-mysql/pull/34 - Shoichi Kaji * eval $ExtUtils::MakeMaker::VERSION requires for old ExtUtils::MakeMaker - https://github.com/CaptTofu/DBD-mysql/pull/32 - Daisuke Murase * Updated documentation to reflect that bugs will be reported at rt.cpan.org * Updated version * Chased tail finding issue with -1 being converted to max unsigned int in PS mode * Various typos and other unicode fixes dsteinbrunner * Fixed permissions on files. * Clarified documentation and bumped version for next release 2012-08-28 Patrick Galbraith et open source community (4.022) * Fixes for Win32 from Rom Hoelz (https://github.com/hoelzro) * Pulling back in work for 4.021 that didn't get pushed and much other work from Chip Salzenberg (https://github.com/chipdude) * Column info order fix from Tokuhiro Matsuno (https://github.com/tokuhirom) * Fix AutoCommit comparison logic to avoid spurious commands to mysql from Matthew Horsfall (https://github.com/wolfsage) * server_preapre can't bind placeholder on comment. from Misahiro Chiba (https://github.com/nihen) * server_prepare; data is null, allocate big memory bug. from Misahiro Chiba (https://github.com/nihen) 2012-04-15 Patrick Galbraith (work of others) (4.021) * Fix to enable PERL_NO_GET_CONTEXT to spee up DBD on thread Perls (Dave Mitchell ) Thank you! * Fix to is_prefix not being exported by mysql Aran Deltax Thank you! * Eliminate DBIS usage Dagfinn Ilmari Mannsåker Thank you! * Enhanced / Fixed server side prepared statement checks (Steven Hartland) Thank you! * Fix missprint in doc of DBD::mysql of mysql_bind_type_guessing (Perlover http://blog.perloever.com) Thank you! * Misprint in lib/DBD/mysql.pm (Perlover) Thank you! 2011-08-15 Patrick Galbraith (4.020) * Numerous (!! Thank you!!) fixes for prepared statements: Masahiro Chiba - Chop blanks fixed - UTF8 improvements - fixed memory allocation for BLOBs - auto-reconnect * Fix in leak test, which failed sometime due to first assignment $prev_size over paging (Masahiro Chiba) * Catalog test allows use of schemas other than 'test' (Masahiro Chiba) * Documentation fix for auto_reconnect (Karen Etheridge ) * Win32 and general installation fixes (Alexandr Ciornii, http://chorny.net) 2011-05-08 Patrick Galbraith Rob Hoelz (4.019) * Asynchronous support added by Rob Hoelz - Thanks! * Amiri Barksdale - Enable environment variables for installation options, add docs to POD - Thanks! * Pedro Melo - fix to change sv_undef to PL_sv_undef from 4.018 - Thanks! 2010-10-11 Patrick Galbraith (4.018) * Added client and server info patch from Robert M. Jansen * Added documentation and tests for new features * More code cleanup 2010-08-11 Patrick Galbraith (4.017) * BUG #60085, Andreas Koenig's patch for DBI changes * Updated documents 2010-07-10 Patrick Galbraith (4.016) * Disabled mysql_bind_type_guessing due to one performance issue querying on an indexed character column unquoted will mean the index is not used * Fixed int types that should be bools 2010-07-09 Patrick Galbraith (4.015) * BUG #56664 fixed t/40blobs.t skip_all logic (W. Phillip Moore) * BUG #57253 Fixed iteration past end of string (crash). (Chris Butler) * Added a new parameter for old behavior- mysql_bind_comment_placeholders which will make it possible to have placeholders bound for those who really want that behavior. * Fixed bind_type_guessing - always on now 2010-04-14 Patrick Galbraith (4.014) * BUG #30033 Fixed handling of comments to allow comments that contain characters that might otherwise cause placeholder detection to not work properly * BUG #53844, Fix for memory leak in stats. (Gregory Burmistrov) * BUG #49719, Fix for handling of NULLs in prepared statements (Gert Pache) * BUG #55627, Fix for testing failure due to strict mode (Yves) * BUG #51784, Fix for mysqladmin on Windows in Makefile (Zeeshan Muhammad) * BUG #41630, Typo in Makefile * Had to define true and false in dbdimp.h. Didn't work out of the box on Linux 2009-09-16 Patrick Galbraith (4.013) * #49484: PATCH add support for MYSQL_INIT_COMMAND - Peter John Edwards * #48242: 'mysql_bind_type_guessing' doesn't work correctly with minus sign - Thanks Serguei Trouchelle! * #45616: t/40blobs.t cannot pass without database access - ServerError() not declared - Thanks ysth http://ysth.livejournal.com/ 2009-06-18 Patrick Galbraith (4.012) * Patch to bind_type_guessing from Craigslist, Thanks to Chris! Happiness is no quoted numbers. Fixed ChopBlanks to work with bind_type_guessing * Patch for win32 strawberry build Thanks to Curtis Jewell! Windows needs love * Patch for auto-reconnect to set active flag Thanks to Doug Fischer! * Fixed bug 32464 http://bugs.mysql.com/bug.php?id=32464. See https://rt.cpan.org/Ticket/Display.html?id=46308 Add connection flag mysql_no_autocommit_cmd which users of MySQL Proxy can use to prevent 'set autocommit=#' from being issued by the driver. 'perldoc DBD::mysql' to see how to use this new flag * Added bind-type-guessing options to Makefile.PL so the entire test suite can be run with bind_type_guessing set. 2009-04-13 Patrick Galbraith (4.011) * Renamed unsafe_bind_type_guessing, fixed some of the logic. This can be used to deal with bug 43822 (https://rt.cpan.org/Ticket/Display.html?id=43822) * Patch from Daniel Frett (daniel Dot frett At ccci Dot org) to fix issue of binding sever side integer parameters (server-side prepare statements) resulting in corrupt data, bug 42723 (https://rt.cpan.org/Ticket/Display.html?id=42723) * Updated documentation, cruft cleanup (as always) 2008-10-24 Patrick Galbraith (4.010) * Fix to dbd_bind_ph() for uninitialized value 'buffer_length' thanks for bug report and patch from Askniel.com (thanks!) 2008-10-21 Patrick Galbraith (4.009) * Fix to re-enable TAKE_IMP_DATA_VERSION. Still have to ensure DBI version 1.607 or higher * Fix to escaped single quotes throwing off bind param detection. Patch from Zhurs (zhurs@yandex.ru) Spasibo! 2008-8-15 Patrick Galbraith (4.008) * Multi statement patch, thanks to Chris Heath! * Disabled TAKE_IMP_DATA_VERSION because segfault with DBI < 1.607 * #29528: bind_param(..., SQL_FLOAT) ignores exponents - fixed, Thanks to Tokuhiro Matsuno! * Cleanups to make mysqlEmb work under Cygwin - Thanks to Chris Rodgers ! * Modified and disabled tests for MySQL version < 4.1 for unsupported features 2008-5-11 Patrick Galbraith (4.007) * Took out mysql_server_init call where not needed * Complete re-write of test suit to use Test::More - tons of cleanups! * Makefile.PL changes to use current user in 'make test' if not defined 2007-12-26 Patrick Galbraith (4.006) * Cleanups on OS X compile * Fixes to syntax errors on AIX * Removed test code that was leaving trace files around 2007-3-22 Patrick Galbraith (4.005) * Fixed mysql_warning issue < 4.1 (reminers, patches, help from ROAM, (issue 25713) * makerealclean patch from ROAM (issue #25714) * sqlstate cleanup patch from ROAM * Replaced all references to dbis to use imp_xxh per DBI best practices * Fix to dbd_st_destroy - added back previously removed 'free everything' code which had been moved to dbd_st_finish, causing a crash upon freeing of bind values after all rows resulting from one execution of a query have been fetched. This meant that next attempt to execute the prepared statement would segfault. This work thanks to Rainer Weikusat! * Removed all 'FindNewTable' calls in all tests. Just use 't1' for all tests to simplify things. Plus, this is how MySQL internall tests. * Better 'skip test' logic in some tests that were still running when they shouldn't have been. 2007-3-22 Patrick Galbraith Jim Winstead (4.004) * Work around a bug in old 3.23 servers by specifying NOT NULL for fields used as a primary key in tests. (Bug #20325, reported by Julian Ladisch) * Add support for mysql_warning_count statement handle attribute. (Bug #25457, patch from Philip Stoev) * Add support for mysql_multi_statements connection option. (RT #12322, based on patch from Doug Morris) * Had to bump to 4.003 do to print statement in mysql.pm that made it into the dist. Even though you can delete a file on CPAN, you cannot re-upload it if it's the same name. Mea Culpa. * UTF8-Flag not set with flag mysql_enable_utf8 and column collation utf8_bin patch, Joost Diepenmaat, (RT #24738) * Fixed do_error definition (Scott Hildreth, Tim Bunce) * Conversion of test suite to Test::More 2007-3-5 Patrick Galbraith Jim Winstead (4.003) * Fix inclusion of non-primary keys in primary_key_info. (Bug #26786, reported and patch by Dave Rolsky) 2007-3-1 Patrick Galbraith Jim Winstead (4.002) * Fix re-exec of Makefile.PL when forcing $ENV{LANG} to 'C'. (RT #25233, reported by Slaven Rezic) * Rewrote table_info method to support all arguments (previously it would only ever return all of the tables in the current database, no matter what was specified) * Fixed $DBD::mysql::VERSION to be a string instead of a float, which caused problems for certain locales * Fixed bug #23974. $dbh->column_info now returns handle with no rows upon table not existing. Much thanks to Tim Bunce for help fixing the problem in mysql.pm vs. dbdimp.c * Removed #ifdefs for do error (sqlstate being passed as last arg depending on version) * Fixed insertid test to work with auto_increment_increment replication setup. * Patch from Tim Bunce fixing do() not set $dbh->{Statement} attribute, which prevented DBD::Profile from giving correct results for calls to do() and causing ShowErrorStatement to possibly report the wrong statement in the error message * Patch from Tim Bunce clearing out the sth attribute cache when switching between result, sets which prevented the adjustedment of NUM_OF_FIELDS * Cleanup of several unused variables * Added support for wildcards in last argument of column_info(). * Add mysql_is_auto_increment to results of column_info(). (Bug #26603, original patch from Dave Rolsky) * Return the correct table type for both tables and views from the table_info() method. (Bug #26603, original patch from Dave Rolsky) * Add implementation of foreign_key_info() (Bug #26604, original patch from Dave Rolsky, and final implementation based on Connector/J code) 2007-1-8 Jim Winstead Patrick Galbraith (4.001) * Fix handling of unsigned integer values in result sets when using server-side prepared statements (they were not retrieved at all). * Fix handling of signed integer values when using server-side prepared statements (they were being forced to unsigned values). * Do not tell Perl that the contents of binary fields are UTF-8. [rt.cpan.org #22123], original patch by Joost Diepenmaat * Fix double-free of bound parameters when freeing statements. (Bug #20559) * Make sure to handle "magical" values in a couple of places. (Bug #20104) * Update the hints about what to do when zlib is found missing while linking. (Bug #13803, reported by Philip Stoev) * Explicitly initialize the MySQL client library to avoid possible race conditions in a multithreaded application. (Bug #21792) * Fix warning when no connection attributes are passed to the connect method (Bug #17323, reported by Phil Randal) * Removed redundant warnings when commit or rollback is called while AutoCommit is enabled. [rt.cpan.org #15802], reported by Tyler MacDonald * Report correct type for decimal columns from MySQL 5.0 and later [rt.cpan.org #18294], reported by Ray Zimmerman * Fix t/40bindparam.t to work when ANSI_QUOTES SQL_MODE is set. [rt.cpan.org #21521], reported by David Wheeler * Return a statement handle with an error when column_info is called on a table that does not exist. (Bug #23974, patch by Philip Stoev) * Fix handling of table names with characters that did not match /\w/ in the column_info method. (Bug #22005, reported by Philip Stoev) * Fix handling of negative integers bound to a column marked as SQL_INTEGER. [rt.cpan.org #18976], patch from Mike Schilli. * Add support for the primary_key_info method. [rt.cpan.org #8541] * Fixed Bundle::DBD::mysql to only include modules required for using DBD::mysql, not the old Mysql package. [rt.cpan.org #24096] * Updated Makefile.PL to not include files in .svn directories * Fixed various compile warnings in mysql.xs (ISO C) * Cleaned up stored procedure examples, made strict * Fixed bug that blew away subsequent result sets if you fetched all rows, only in result sets that had more than one row * Added test for bug #14979 http://rt.cpan.org/Ticket/Display.html?id=14979, which still fails * Tested with ALL mysql versions, fixed 40types, 40bind_param tests to work with 4.0, 4.1 * Fixed dbdimp.c to not test for MYSQL_DATA_TRUNCATED unless >= mysql 5.0 2006-12-22 Patrick Galbraith , Alexey Stroganov (4.00) * Added Alexey Stroganov's patch which fixes varying number of columns in multiple result sets. Added new test cases to 80procs.t based of his test script (bug #21028) (Thanks Alexey!). Also fixed 80procs.t to allow 'CALL' to be prepared * Added Philip Stoev's patch for DATA_TYPE date and time columns (bug #23988) (Thanks Philip!) * Reworked (for working with 4.0, which doesn't support sqlstate) Philip Stoev's patch for sqlstate, bug #23935 (Thanks Philip!) * New Versioning! 4.00 now. This dev tree will now become trunk * Cleaned up much code that failed between versions (!!!) * Turned off prepared statements by default * Tested this with 5.1, 5.0, 4.1, 4.0. Works with ALL these versions! 2006-10-10 Patrick Galbraith , Alexey Stroganov (3.0009_1) * Added fbind and bind alloc to dbd_st_describe. This was causing a crash when using with mod_perl 2006-10-10 Patrick Galbraith (3.0008_1) * Added patch for SSL Verify Certificate (Thanks Eric Chen!) * Added multiple fixes to dbd_st_prepare which fixed variable overwrite and unset increment counter. Also improved loop which checks statements for presence of "LIMIT" by using a pointer as opposed to char array increment variable. These errors were showing up in OpenBSD and other Unixen (which I think all BSD-based) (Thanks to Kyle George!) * Added fix to Makefile.PL to obtain correct build flags on VMS (Thanks to Eric Milkie!) * Fixed casting of num_params to unsigned int in calls to NewZ in mysql.xs 2006-10-07 Patrick Galbraith , Jim Winstead (3.0007_2) * Added UTF8 patch from Dominic Mitchell (Thanks!) * Fixed declaration of "row" in mysql_st_internal_execute which caused compile errors on some platforms * Fix documentation for _ListDBs to remove incorrect information about limitations of data_sources(). (RT #20843, patch by Ann Barcomb) * Fix typo in example (missing quote). (RT #15086) * Mention in POD that 'localhost' always means to connect via UNIX socket, and 127.0.0.1 must be used for TCP/IP to localhost (RT #14942, reported by Alessandro Ranellucci) * Fix typos in Makefile.PL (RT#16178, reported by Gavin Shelley) 2006-09-08 Jim Winstead , Patrick Galbraith (3.0007_1) (3.0006/3.0006_1 is the same as 3.0005/3.0005_1) * Make sure to call dbd_st_finish when all rows from a statement handle have been fetched. (Bug #20153, Bug #21607, RT #20464, RT #21241) * Patch from Steve Hay to fix bind_param to deal properly with insertion of a NULL into an INT or DOUBLE column using server-side prepare. Converted Steve's dbi.pl script to expose this problem to 40bindparam2 test. * Fix to mysql_st_internal_execute to keep from passing undefined dbh handle member (bind_type_guessing) to parse_param causing crash on OpenBSD. Reported on rt.cpan.org (#20868) by Kyle Georg, as well as info from Sam Smith and Federico Giannici * Cleaned up tests to make sure test table is dropped at end of test. 2006-06-10 Patrick Galbraith do, and bind_param to deal with passing substr to "do" for placeholder value. Thanks Martin Waite for the patch to parse_params (extended to mysql.xs "do" and bind_param for server-side prepared statements. 2006-05-17 Patrick Galbraith do("set character set utf8"); $dbh->do("set names utf8"); to get utf8 back and even then you only get it back if the column is defined as utf8 in mysql. * Fix to dbd_bind_ph to deal with numbers (ints, floats) correctly (Alexey Stroganov) * Test changes - bind_param 41 and 42 * Turned off 70takeimp test 2006-04-29 Patrick Galbraith (3.0002_5) * Fixed bugs 15546 (selectcol_arrayref failing on SHOW TABLES) and 15665, 'USE dbname' failing when driver is not in emulated prepare mode 2005-10-26 Patrick Galbraith (3.0002_4) * Added Guy Harrison's patch for multiple result sets * Fixed bugs with declarations in middle of functions * Cleaned up code, rewrote several loops using pointers instead of iterators * Rewrote 'SHOW', 'ALTER', 'CALL', 'CREATE' toggling code that turns off server prepared statements (these calls are not supported) * Updated documentation 2005-09-28 Patrick Galbraith (3.0002_3) * Added code to mysql_st_internal_execute that determines whether the SV *h is a sth or dbh, and then imports imp_dbh appropriately 2005-09-26 Patrick Galbraith (3.0002_2) * Fixed bug in dbd_st_execute where imp_sth was being imported unecessarily, when only imp_dbh is needed. This caused a core dump in some cases. Thanks to Andy Maas at Proofpoint for his execellent detective work! * Small changes to Makefile.PL to make sure --ps-protocol works as advertised. * Updated install.html with current info about prepared statements and FC RPM/YUM packages. 2005-08-04 Patrick Galbraith (3.0002_1) * Prepared statement support is default now. To turn it off a parameter 'mysql_emulated_prepare' must be turned ON * Better error handling in mysql_internal_execute_ps (renamed from mysql_internal_execute41). Also free the result if error - that could have been a memory bug * Added a simply 'do' to t/35prepare.test to see if you can turn off prepared statements in the 'do' call. * Cleaned up a LOT of cruft. Added more 'caveat' blurbage to old Mysql.pm lib, which will not work with prepared statements 2005-07-06 Parick Galbraith (3.0001_3) * Fix to ensure MYSQL_BIND is only defined when mysql client version is >= 4.1.3. Thanks to Tom Parkison 2005-07-06 Patrick Galbraith (3.0001_2) * Fixed runtime bug (when inserting or updating quotes or double quotes) (Thanks to Brad Choate, Six Apart Ltd.) 2005-07-04 Patrick Galbraith (3.0001_1) * Changed uint argument in safe_sv_fetch to int due to uint not being available on windows unless you include my_globals.h in dbdimp.h, which also breaks on unixen! * Removed // comments from mysql.xs (thanks Bodo Bergman!) 2005-07-03 Patrick Galbraith (3.0000_0) * Special Thanks to Steve Hay for his patch to fix windows * Fixed Makefile.PM for windows compiles * Removed long long type from dbdimp.h * Changed strncasecmp to strncmp (still need a better long-term solution) in dbdimp.c * Modified Makefile.PM to make prepared statements on by default 2005-04-26 Patrick Galbraith (2.9015_3) * Added patch from Stas Beckman for new DBI feature take_imp_data, needed for DBI::Pool * Fix to Statement.pm for old API call for numfields that caused warnings on 40numrows and akmisc tests * Fix to bind_ph to throw an error if trying to bind a non-numeric value as numeric * Better fix for dealing with error condition in $sth->rows() * Fix to bind_param to throw error when trying to bind a non-numeric as numeric 2005-04-04 Patrick Galbraith (2.9015_2) * Merged all code changes from 2.900x tree from the last 9 months - unsafe bind type guessing patch from Dragonchild - Removed mysql.mtest - Fixed sth->rows to return my_ulongloong and also handle error from client API - Fix to make autocommit work was already part of this version - Auto-reconnect bug fixed in 2.9006 included * Added simple test to 35limit test to check if using malicious code in LIMIT ?, ? placeholders works, which it doesn't. * Fix that sets mysql_server_prepare to 0 if SQL statement is 'SHOW ...' which is not supported by prepared statement API currently 2004-10-28 Rudolf Lippan (2.9015_1) * Merged Makefile.PL from 2.9005_3 * Bumped version number to 2.9015 for release of Dev Branch. Which will become 2.9020 when tested and merged into HEAD. * fixed typo/compiler warning in bind_param_guessing '*testchar' should have been 'testchar'. 2004-10-20 Patrick Galbraith patg@mysql.com (Dev-2_9 - 2.9005) * merged changes from 2.9005_1 * fix to blob in dbd_st_fetch (Alexey Stroganov ranger@mysql.com) In case of BLOB/TEXT fields we allocate only 8192 bytes in dbd_describe() for data. Here we know real size of field so we should increase buffer size and refetch column value 2004-07-25 Patrick Galbraith patg@mysql.com (2.9004) * Prepared statement support * Use of mysql_stmt_* API (>= 4.1.3) * mysql_shutdown fix * MySQL Embedded Server support (Alexey Stroganov) * Fixed link failure on MacOSX * Cleaned up tests * Fixed various compile warnings 2003-10-26 Rudy Lippan (2.9003) * Applied patch from Aaron and Chuck that added basic testing of the table_info/column_info functions [Aaron Ross ] * Applied patch removing Jochen Wiedmann's contanct information and also removing the restriction on CD ROM distribution. [Jochen Wiedmen ] * The check for the innodb table type was broken so the transaction tests were skipped even though the database supported transactions. * :sql_types were not being inported in column info, so SQL_VARCAR was thowing an error. Also, the :sql_types were not being pulled into DBD::mysq::db package * Patch for dbdadmin.t so that it respects username and password [Alexey Stroganov ] * Fix for memory leak in bind_param() introduced in 2.9002 (2.9002 changed bind_param so that changing the value of a scalar after binding would not affect what was passed to execute eg: $sth->bind_param(1,$foo); $foo = 'bar' $sth->execute() -- $foo would contain 'bar') [reported by ] * don't define dbd_discon_all so that mysql uses DBI's This fixes a bug whereby DBD::mysql was dropping perl's destruct level. * patch to myld so that it uses strict and fixes scoping problem with $contents [Jochen Wiedmann ] * Modified Makefile.PL so that it gives a usage message if any unknown options are passed in. * patch to INSTALL.pod on how to link DBD::mysql against a static libmysqlclient [Jochen Wiedmann ] 2003-06-22 Rudy Lippan (2.9002) * moved pod into mysql.pm from mysql.pod * Changed the default behaviour of mysql_found_rows, so now 'UPDATE table set field=?' will return the number of rows matched and not the number of rows physically changed. You can get the old behaviour back by adding "mysql_found_rows=0" to the dsn passed to connect. * Updated type_info_all() to be more inline with what DBD::ODBC returns. * Added attribute 'mysql_auto_reconnect' that allows the auto reconnect behaviour to be toggled. : ** NOTE** The behaviour of auto reconnect has changed. If either the MOD_PERL or the GATEWAY_INTERFACE environment variable is set, auto_reconnect will default to ON; otherwise auto_reconnect will default to off. Earlier versions of this driver would always try to reconnect to the database on error; however, this is dangerous because table locks could be lost without the application knowing. * Fixed a segfault with failed reconnects that were trapped in an eval. The next tine DBD::mysql tried to reconnect, the process would segfault. * Added statistics attribute, 'mysql_dbd_stats' which returns a hash ref that contains 2 keys 'auto_reconnects_ok' and 'auto_reconnects_failed'. * Fixed bug where strings that were used in numeric context were not getting quoted on execute(). Now all parameters are bound as varchar by default. **NOTE** this is a change in behaviour that MAY cause problems with some SQL statements. If quoted integers, for example, cause any problems, use bind_param(, undef, SQL_INTEGER) to force a column to be bound as an integer. * Added get_info() method. See 'perldoc DBI' for more info * Added column_info(). See 'perldoc DBI' for more info [Tim Bunce] 2003-03-03 Jochen Wiedmann (2.1026) * Fixed the handling of case insensitive file names. Jan Dubois, * lib/Mysql.pm (listdbs): Added support for user name and password. 2003-01-21 Jochen Wiedmann (2.1025) * lib/DBD/mysql.pm: added support for optional DBI->data_sources() \%attributes parameter. Georg Rehfeld, * lib/DBD/mysql.pod: documented optional DBI->data_sources() \%attributes parameter. Georg Rehfeld, * t/dbdadmin.t: changed to use optional DBI->data_sources() \%attributes parameter. Georg Rehfeld, 2003-01-20 Jochen Wiedmann (2.1024) * dbdimp.c: Fixed missing support for double quotes in ParseParam. JUERD@cpan.org * Test suite: Multiple patches for Windows/CygWin (case insensitive file names and the like). Georg Rehfeld, * lib/DBD/mysql/INSTALL.pod: Added description on how to install with Windows/CygWin. Georg Rehfeld, 2003-01-18 Jochen Wiedmann (2.1023) * Remove compiler warnings Fix some small issues to get it to work with MySQL 4.1 (Mostly checking return values from MySQL API functions) Michael Widenius (2.1022a) 2003-01-03 Jochen Wiedmann (2.1022) * Added hints to Randy Kobes PPM repository, because DBD::mysql is currently missing in ActiveState's repository. 2002-11-18 Jochen Wiedmann (2.1021) * lib/Mysql.pm (errno): Added handling for non-ref arguments. Raphael Hertzog 2002-09-23 Jochen Wiedmann (2.1020) * Added mysql_local_infile option. (Paul DuBois, paul@snake.net) 2002-09-16 Jochen Wiedmann (2.1019) * Added hints to installing DBD::mysql with PPM 3. (Stefan Prehn, stefanprehngmx.de) * Added $DBD::mysql::CLONE 2002-08-12 Jochen Wiedmann (0.2018) * t/dbdadmin.t: The call to func('createdb') was missing user name and password. Wolfgang Friebel * mysql.xs: If the connect in func('...', 'admin') failed, a core dump was triggered. Wolfgang Friebel 2002-05-02 Jochen Wiedmann (0.2017) * dbdimp.c: Added a required check for mysql_errno. Steve Hay 2002-05-01 Jochen Wiedmann (0.2016) * dbdimp.c: Removed use of mysql_eof. Jay Lawrence 2002-04-30 Jochen Wiedmann (0.2015) * Makefile.PL: Removed dbimon and pmysql from the EXE_FILES list. Andreas Koenig 2002-04-17 Jochen Wiedmann (2.1014) * dbdimp.c: Fixed mysql_is_auto_increment. Paul Walmsley and Paul Dubois 2002-04-12 Jochen Wiedmann (2.1013) * dbdimp.c: Added use of mysql_ssl_set. Chris Hanes 2002-04-12 Jochen Wiedmann (2.1012) * Some fixes in the docs. Paul Dubois * Added mysql_is_auto_increment. (Someone else, but forgot his email, sorry!) 2002-02-12 Jochen Wiedmann (2.1011) * Makefile.PL: DBI::DBD is no longer loaded by default, to allow CPAN's requirements detection note and install a missing DBI. 2001-12-28 Jochen Wiedmann (2.1010) * Bumped version number in Mysql/Statement.pm to 1.24, so that it is always higher than that from the Msql-Mysql-modules. 2001-12-28 Jochen Wiedmann (2.1008) * lib/DBD/mysql.pod: Fixed minor bug in an example. 2001-12-27 Jochen Wiedmann (2.1007) * Bumped version number in Mysql.pm to 1.24, so that it is always higher than that from the Msql-Mysql- modules. 2001-12-27 Jochen Wiedmann (2.1006) * Within AutoCommit mode, reconnect is now turned off, because the transaction state is unpredictable otherwise. 2001-12-13 Jochen Wiedmann (2.1005) * dbdimp.c: Added use of SvMAGICAL to dbd_db_quote. Rudy Lippan 2001-11-13 Jochen Wiedmann (2.1004) * Makefile.PL: Fixed handling of --testdb, --testuser, ... 2001-11-05 Jochen Wiedmann (2.1003) * bind_param now using mysql_real_escape_string as well. Dave Rolsky 2001-11-04 Jochen Wiedmann (2.1002) * Added mysql_ssl flag to DBI->connect. 2001-11-04 Jochen Wiedmann (2.1001) * Quoting now based on mysql_real_escape_string. Thanks to Dave Rolsky for suggesting this. 2001-11-02 Jochen Wiedmann (2.1000) * Portability changes for MySQL 4. 2001-05-25 Jochen Wiedmann (2.0901) * dbdimp.c: Fixed $dbh->{mysql_insertid}; added t/insertid.t 2001-04-01 Jochen Wiedmann (2.0900) * Added transaction support for MySQL. (Bob Lyons ) * dbd/dbdimp.c: Fixed MAXLENGTH warning; used to hint for a not existing mysql_maxlength, which should read mysql_max_length. (Paul DuBois ) * Fixed installation problem when a directory was specified, but did not exist. (Will Partain ) * Fixed that mysql_errno wasn't used properly. (Chris Adams ) * Fixed test suite problem, when user name and password have been interpolated. (Bruno Hivert (LMC) ) * mysql_insertid and mysql_affectedrows are no longer treated as integers, but longs. Thanks to Michael G Schwern . 2000-08-20 Jochen Wiedmann (1.2215) * lib/DBD/mysql/Install.pm (Initialize): Adding -lz -lgz by default now. * dbd/dbd.pm.in: Minor doc change. 2000-05-10 Jochen Wiedmann (1.2214) * dbd/dbdimp.c: Fixed bug that timestamp fields weren't quoted. Chris Winters 2000-04-26 Jochen Wiedmann (1.2213) * dbd/dbimon.in: Fixed tags in pod. 2000-04-15 Jochen Wiedmann (1.2212) * Makefile.PL: Fixed use of builder-provided passwords. Buck Huppmann * Makefile.PL: Fixed WIN32 installation. 2000-04-03 Jochen Wiedmann (1.2211) * Fixed $dbh->{Name} (David Jacobs ) 1999-11-30 Jochen Wiedmann (1.2210) * Makefile.PL (SelectDrivers): Hopefully ensured that a README is always created successfully. * Makefile.PL: Fixed docs of --mysql-install etc. (loic@ceic.com) 1999-10-13 Jochen Wiedmann (1.2209) * Fixed bug in $dbh->tables(): Didnt't work with empty databases. 1999-09-17 Jochen Wiedmann (1.2208) * dbd/bindparam.h: Added support for MySQL's double quotes. (Although I don't like it. :-) * dbd/dbd.pm.in: Fixed a lot of docs for deprecated features in favour of current. * Makefile.PL: Fixed use of -e (should be exists). tschulth@debis.com (Thomas Schultheis) * MONEY seems to be a numeric type with mSQL. Ernst Paalvast 1999-09-15 Jochen Wiedmann (1.2207) * dbd/dbdimp.c: Added mysql_connect_timeout. Matthias Urlichs () 1999-08-29 Jochen Wiedmann (1.2206) * dbd/dbimon.in: Fixed a bug in tab completion. (FieldList was used in scalar context). Thanks to "Scott R. Every" * lib/DBD/mysql/Install.pm (Initialize): Now checking for MySQL version 3.22 or later. 1999-08-22 Jochen Wiedmann * lib/DBD/mysql/Install.pm (Initialize): Added sco\d+* to the list of SCO-like operating systems. Thanks to Jukka Inkeri 1999-08-22 Jochen Wiedmann (1.2203) * dbd/dbd.xs.in: Fixed a memory leak in $dbh->quote(). Arun Bhalla 1999-07-22 Jochen Wiedmann (1.2202) * dbd/dbd.pm.in: The hint for experimental software is now enabled or disabled automatically, thanks to ExtUtils::PerlPP. * dbd/dbdimp.c: Changed fprintf to PerlIO_printf, required by DBI 1.14. * nodbd/nodbd.pm.in (quote): Changed ~DBD_DRIVER~ to ~~dbd_driver~~, thanks to Maurice Aubrey . 1999-07-08 Jochen Wiedmann (1.2201) * lib/DBD/mSQL/Install.pm (Initialize): Fixed an ugly bug, that caused unusable Config.pm files. 1999-03-09 Jochen Wiedmann * lib/DBD/mysql/Install.pm (CheckForLibGcc): No longer linking against libgcc.a with OpenBSD. * nodbd/nodbd.pm.in (selectdb): Calling selectdb twice triggered a warning. (Nick Hibma ) * dbd/dbdimp.c: Date and time types now have literal_prefix and suffix set to "'". 1999-01-25 Jochen Wiedmann (1.21_15) * dbd/myMsql.h: mSQL 2.0.6 requires including common/ portability.h. * dbd/dbdimp.c: Fixed some instances of ~var~ to ~~var~~. * Makefile.PL: Added PREREQ_PM to WriteMakefile options. * Renamed Bundle::M(y)sql to Bundle::DBD::mysql and Bundle::DBD::mSQL. 1999-01-05 Jochen Wiedmann (1.21_13) * nodbd/nodbd.pm.in (query): Now setting $db_errstr (Andreas König, andreas.koenig@anima.de). * dbd/dbdimp.c (dbd_db_quote): Giving up to use "NULL" as a static string. :-( My thanks to David Foo (dfoo@web.fairfax.com.au) and Christian Schwarz (schwarz@monet.m.isar.de) for convincing me. * nodbd/nodbd.pm.in (listdbs): Now setting $db_errstr. 1998-12-30 Jochen Wiedmann (1.21_12) * dbd/dbd.pm.in (prepare): Fixed missing attribs argument. Thanks to Peter Ludemann (ludemann@inxight.com). * dbd/dbdimp.c: Portability fixes for Perl 5.005_54. 1998-12-29 Jochen Wiedmann (1.21_11) * Makefile.PL: .pm files are no longer removed, because they are missing in MANIFEST otherwise. 1998-12-22 Jochen Wiedmann (1.21_09) * INSTALL: Updated the WIN32 INSTALLATION section. * nodbd/statement.pm.in (fetchrow): Enhanced compatibility to previous Msql versions by returning the first column now in scalar context. (Andreas König, andreas.koenig@anima.de) * Makefile.PL (Init): Default of installing Msql, Mysql and Msql1 is now "no", unless you already have the Mysql emulation layer installed. * Makefile.PL: Added --config option. 1998-11-20 Jochen Wiedmann (1.21_08) * lib/DBD/mysql/Install.pm (Initialize): Added -lc on Unixware; thanks to Orion Poplawski . * lib/DBD/mysql/Install.pm (Initialize): Added -lzlib on Win32. * dbd/dbd.pm.in (connect): Added $dbh->{'Name'}. * t/dbdadmin.t: Forgot to change _DropDB to func("dropdb", ..., "admin). My thanks to schinder@pobox.com. * Some patches for compatibility with ActiveState Perl. 1998-11-08 Jochen Wiedmann (1.21_07) * _ListTables is now obsolete. * _InsertID, affected_rows, IS_PRI_KEY, is_pri_key, IS_NOT_NULL, is_not_null, IS_KEY, is_key, IS_BLOB, is_blob, IS_NUM, is_num, LENGTH, length, MAXLENGTH, maxlength, NUMROWS, NUMFIELDS, RESULT, result, TABLE, table, format_max_size, format_default_size and format_type_name are now deprecated. * _CreateDB, _DropDB, _ListFields, _ListSelectedFields and _NumRows have been removed. * dbd/dbd.xs.in: $dbh->func('_ListDBs') was closing the socket. Thanks to Lars Kellogg-Stedman . * dbd/dbd.pm.in: $drh->func('_ListDBs' was documented wrong. Thanks to Lars Kellogg-Stedman . 1998-11-06 Jochen Wiedmann (1.21_06) * dbd/dbdimp.c: Changed isspace(c) to c == ' ' in ChopBlanks handling. * dbd/dbdimp.c: Added $dbh->{'mysql_read_default_file'} and $dbh->{'mysql_read_default_group'}. * dbd/dbdimp.c: Added $dbh->{'mysql_insertid'}. 1998-10-23 Jochen Wiedmann (1.21_05) * dbd/dbd.xs.in: Fixed bug in $dbh->quote($n, SQL_INTEGER). * Makefile.PL (CheckForLibGcc()): Disabled linking against libgcc.a under NetBSD. (Curt Sampson, cjs@portal.com) * Forgot to remove the warning for experimental software. * Added Monty's patches for use of mysqlclients. * dbd/dbdimp.c: Added msql_configfile. * Makefile.PL: Added option -static. 1998-10-06 Jochen Wiedmann (1.21_04) * INSTALL: Added hints for Win32 installation. * lib/DBD/mysql/Install.pm: Added portability fixes for Win32 installation with MyODBC. This is now the recommended way of installing DBD::mysql under Win32. 1998-09-27 Jochen Wiedmann (1.21_02) * INSTALL: Added a hint for Remote_Access in msql.conf * nodbd/nodbd.pm.in (quote): Made quote a class method; Andreas König . * dbd/myMsql.h (MyReconnect): Fixed $dbh->ping() for MySQL. My thanks to Nikki Chumakov (nikki@paranoia.ru). * dbd/dbimon.in: Added dump mode. * dbd/dbimon.in: TableList now based on $dbh->tables(), thus portable. * dbd/dbimon.in: Shell completion with TableList case independent. * tests/60leaks.t: No longer calling exit() within BEGIN. (Workaround for a bug within Perl 5.00404) * tests/ak-dbd.t: Removed "local $sth->{PrintError} = 0"; yet another workaround. 1998-07-28 Jochen Wiedmann (1.21_00) * INSTALL: Added a description of the missing-libgcc problem. * INSTALL: Added a patch for the mSQL problem with ORDER BY. * dbd/dbd.pm.in: Added a description of mSQL's problem with ORDER BY. * Fixed pointers to DBI home (was www.hermetica.com, now www.arcana.co.uk) * lib/DBD/mysql/Install.pm (Initialize): Added $ENV{'MYSQL_HEADERDIR'} and $ENV{'MYSQL_LIBDIR'}. * dbd/dbdimp.c: mysql_fetch_lengths() returns longs under MySQL 3.22.04 * nodbd/nodbd.pm.in (errno): Fixed missing definition of $self. * Makefile.PL (InitializeMysql): Looking for libmysqlclient.a and libmysqlclient.so now. * dbd/dbdimp.c (dbd_st_internal_execute): Fixed memory leak, *cdaPtr was not checked for <> NULL. My thanks to Marc Lehmann for the report. * dbd/dbd.pm.in: Added table_info(). 1998-07-16 Jochen Wiedmann (1.19_22) * dbd/dbdimp.c: Added dTHR to some more functions for 5.005 compatibility. Thanks to Chris Leach . * nodbd/statement.pm.in: Changed length to CORE::length in some cases to prevent 5.005 warnings. * Added a section on multithrading to the manual. 1998-07-07 Jochen Wiedmann (1.19_21) * nodbd/nodbd.pm.in (query): Fixed a missing "bless($sth, ...)". My thanks to Ray Zimmermann . (Gives me a familiar feeling to always meet the same people ... :-) 1998-07-06 Jochen Wiedmann (1.19_20) * Makefile.lib (InitializeMsql): Added /usr to the search path for mSQL headers and libraries. * tests/msql1.t (unctrl): Renamed "character" column to "chrctr". ("character" is not a valid column name under msql-2.0.4.1) * dbd/dbd.xs.in (DBD::mysql::ping): Now using mysql_ping(). * dbd/dbdimp.c (_MyLogin): Added mysql_compression. 1998-06-25 Jochen Wiedmann (1.19_19) * dbd/dbdimp.c: Added $sth->{mysql_type} and $sth->{msql_type}, which are in fact just what $sth->{TYPE} used to be. $sth->{TYPE} is now returning portable SQL types. * MANIFEST: Removed nodbd/Makefile.PL.in. * Makefile.PL: Made test databases configurable. 1998-06-14 Jochen Wiedmann (1.19_18) * Makefile.PL: dbdadmin.t was missing in the list of tests * nodbd/nodbd.pm.in (query): Now really returning undef in case of errors. (Possible Perl bug?) * Makefile.PL: Fixed realclean attribute of WriteMakefile. * Makefile.PL (Init): Setting $Data::Dumper::Indent to 1. * Makefile.PL (InitializeMsql): Fixed query for mSQL, if only one version gets installed. * dbd/dbdimp.c: Now calling mysql_init before mysql_connect. * dbd/dbdimp.c: For whatever reason, MyGetProtoInfo was treated like returning a char* under Mysql. 1998-05-16 Jochen Wiedmann (1.19_17) * Makefile.PL: Fixed typo in InitializeMsql (dbiDriver = mSQL1). * dbd/dbdimp.c: mysql_real_connect is now using a dbname argument 1998-05-07 Jochen Wiedmann (1.19_16) * dbd/dbdimp.c: ChopBlanks no longer chops from the left side. * dbd/dbdimp.c: Fixed memory leak in dbd_st_FETCH_internal. 1998-04-13 Jochen Wiedmann (1.19_15) * Added the DBD::mSQL1 and Msql1 drivers. * Fixed minor icompatibilities with perl 5.005. * nodbd/nodbd.pm.in (errmsg): Msql->errmsg() should now recognize error messages in $DBI::errstr (hopefully ...) 1998-04-03 Jochen Wiedmann (1.19_13) * dbd/dbdimp.c: msqlGetProtoInfo returns an int, not a char* (Erik Bertelsen, erik@mediator.uni-c.dk) * dbd/dbdimp.c: Fixed typo in _MyLogin: User was set to NULL when password had zero length. (Erik Bertelsen, erik@mediator.uni-c.dk) * dbd/dbdimp.c: One more time fixing reconnect problems with Mysql and old client libraries (without mysql_real_connect it's just too ugly! :-( 1998-03-15 Jochen Wiedmann (1.19_11) * Makefile.PL: Fixed Bugs in _OdbcParse and version numbers. * dbd/dbimon.in: Fixed bugs in export mode (Nem W. Schlecht ) 1998-02-26 Jochen Wiedmann (1.19_10) * M(y)sqlPerl now emulated by DBI drivers. * dbd/dbdimp.c: Added $dbh->{'info'} and $dbh->{'thread_id'} (mysql only) * dbd/dbimon.in: Fixed minor bug in "rel db test" * dbd/dbimon.in (Connect): Added noecho mode for entering passwords. * dbd/myMsql.c: Fixed bugs in OdbcParse. 1998-02-06 Jochen Wiedmann (1.19_03) * dbd/dbd.xs.in: Fixed $dbh->quote(undef) to return "NULL" and not 'undef'. * Requires DBI 0.93. (I assume it still works with 0.91, but whoever reinstalls Msql-Mysql-modules can well reinstall DBI.) * dbd/dbdimp.c: $sth->fetch* now inactivates the sth in case of errors or no more data; this follows the specification of the 'Active' attribute. * Added a missing DROP TABLE in ak-dbd.t. * Added ODBC style DSN's like DBI:mysql:database=test;host=localhost. 1998-01-20 Jochen Wiedmann (1.19_02) * dbd/dbd.xs.in (quote): Fixed "int len" to "STRLEN len"; the Irix compiler refuses to compile this. (A little bit picky, a warning would really be sufficient here ...) My thanks to Simon Matthews . * Added "LISTINDEX" handling. * Makefile.lib: Now always linking against libgcc.a when using gcc and compiling for MySQL. * tests/mysql.dbtest: Now using "IS NULL" in SQL queries instead of "= NULL". (Required as of mysql 3.21.22) 1998-01-18 Jochen Wiedmann (1.19_01) * README: Added hint for not using msqlperl mailing lists except for MsqlPerl and MysqlPerl related things. * Makefile.lib: Modified version number to contain underscores, so that CPAN considers 1.18xx as the correct version. * dbd/dbimon.in: Leaving pager mode worked unreliable; fixed. Andreas Koenig * tests/akmisc.t, tests/mysql.t, tests/mysql2.t: Minor modifications in the connect parameters for passing the test suite under Windows/NT. 1998-01-07 Jochen Wiedmann (1.1900) * dbd/dbd.xs.in: Implemented $dbh->quote() in XS. * dbd/dbd.xs.in: Added '_Admin' function. * dbd/dbd.xs.in, dbd/dbdimp.c: Added automatic reconnect when mysql returns CR_SERVER_GONE_ERROR. * Makefile.lib (InitializeMysql): Modified order of -I statements (Inside MySQL distribution it can happen that headers of recently installed DBI versions are used instead of the correct headers.) * nodbd/nodbd.xs.in, nodbd/typemap: Suppressed warning for undef'd argument in connect method. (Chris Holt, ) * nodbd/nodbd.xs.in: Fixed definition of 'HOST' attribute in dbh's. * Makefile.lib (InitializeMsql): Fixed typo that made MSQL_HOME useless. (Ray Zimmermann, ) * Makefile.lib (InitializeMysql): Fixed typo "lib/mysqlclient.a" to "lib/libmysqlclient.a". (Michael 'Monty' Widenius, ) 1997-12-31 Jochen Wiedmann (1.1823) * Added support for mysql_use_result, requested by Jesse Eversole . * nodbd/typemap: Replaced sv_isa with sv_derived_from so that subclassing works, reported by Gisle Aas . 1997-12-11 Jochen Wiedmann (1.1822) * dbd/myMsql.c: DSN's like DBI:mysql:test;hostname=$host;port=$port haven't been working. * dbd/dbimon.in: POD modifications, suggested by Jesse N. Glick * INSTALL: Added hints for "make test". * nodbd/statement.pm.in (as_string): Still bugs in the new as_string method, thanks to Frank D. Cringle . * Enabled SQL_DATE, SQL_TIME, ... (available in DBI 0.91) * Makefiles: Modified postamble to use a common function which calls module dependent hooks. * nodbd/nodbd.xs.in/fetchinternal: Fixed the problem RETVAL == NULL. Wed Nov 19 19:50:29 1997 Jochen Wiedmann (1.1821) * dbd/dbd.pm.in: Added AUTOLOAD for constants like DBD::mysql::FIELD_TYPE_STRING or DBD::mSQL::CHAR_TYPE. * xtract, dbd/Makefile.PL.in nodbd/Makefile.PL.in: Removed first line in case users perl is different from /usr/local/bin/perl. * All Makefiles: Added chmod for xtracted files. * Added bindparam.h for reuse in DBD::pNET. * Makefile.lib: Some (hopefully) upward compatible modifications for integration into the MySQL distribution. Sat Nov 1 17:04:27 1997 Jochen Wiedmann (1.1820) * xtract: Added "#xtract " ... "#endxtract". * nodbd/statement.pm.in, nodbd/nodbd.pm.in, nodbd/pmsql.in: Using "#xtract now". * Reorganized source tree (again). Wed Oct 29 00:41:41 1997 Jochen Wiedmann (1.1819) * nodbd/bundle.pm.in: Fixed syntax error. * Fixed distribution problems. Not all .pm files have been included. (Only PAUSE should have noticed.) Mon Oct 27 00:50:08 1997 Jochen Wiedmann (1.1818) * nodbd/Makefile.PL.in: Fixed dependencies for "xtract" files. * nodbd/nodbd.xs.in: Fixed ISNUM attribute in fetchinternal. * nodbd/statement.pm.in: Yet one more fix in the new as_string method. :-( * nodbd/statement.pm.in: Msql::Statement::maxlength caches its return value now Sat Oct 25 16:30:01 1997 Jochen Wiedmann (1.1817) * Makefile.PL,dbd/Makefile.PL.in,nodbd/Makefile.PL.in: Added dependencies for files being created from dbd and nodbd directories via the "xtract" script. * nodbd/pmsql.in,nodbd/statement.pm.in: Fixed minor problems with mSQL1; suggested by Andreas Koenig * dbd/dbd.pm.in,tests/ak-dbd.t: Removed support and tests for the old connect methods. * nodbd/statement.pm.in: Fixed bug in Msql::Statement::maxlength. Fri Oct 24 01:29:08 1997 Jochen Wiedmann (1.1816) * dbd/myMsql.c (MyConnect): Fixed use of mysql_real_connect * dbd/dbdimp.c: Added automatic type detection to bind_param * nodbd/statement.pm.in: Modified as_string for more efficiency under MySQL. Added maxlength and isnum methods. (Direct attribute fetches under MySQL, calculated under mSQL.) * nodbd/pmsql.pm.in: Fixed bug in creation of @typelabels: defined &Msql::TEXT_TYPE doesn't work before autoloading it. 1997-10-02 Jochen Wiedmann (1.1815) * dbd/dbd.xs: Fixed bug in insertid; &svsock was used instead of svsock * Fixed bug in nodbd.xs (formerly Mysql.xs): key INSERTID had length of 9 (reported by Maurice Aubrey, ) * t/ak-dbd.t, t/akmisc.t: Added tests for mysql's insertid feature. * Merged source trees of Mysql and Msql. * lib/M(y)sql.pm: Added some words on createdb, dropdb and shutdown to the man page. Missed by Ray Zimmermann (rz10@cornell.edu) * dbd/dbd.xs.in: Implemented $dbh->do as a direct XS call. * dbd/dbd.xs.in, nodbd/nodbd.xs.in: Suppressed some warnings due to uninitialized RETVAL. George Hartlieb (ghartlieb@mail.arc.nasa.gov) 1997-09-29 Andreas Koenig (1.1814) * t/50commit.t: Fixed printing of warning message when commit issues a warning. * lib/DBD/mSQL.pm (connect): Fixed warning in connect, if attrhash is present. * pmsql.PL: Fixed use of Msql 2 constants in @typelabel definition and similar things. * lib/Msql/Statement.pm: Fixed use of Msql::TEXT_TYPE without checking whether we are running Msql 1. DBD::mysql for DBI - Written by Jochen Wiedmann 97.09.27 V1.1812 Added t/50commit.t to test suite. Included in myMsql.h for redefining my_setenv(). Made AutoCommit, Commit and Rollback DBI conformant. Fixed reconnect problems with Mysql: mysql_port was 0 on some systems. Added support of mysql_real_connect to myMsql.c. Fixed Msql::errno returning a char*. Added lib/Bundle::Mysql.pm. Fixed 'use Mysql' to 'require Mysql' in t/mysql2.t. 97.09.12 V1.1810 Fixed bug in dbd_st_FETCH_internal: newRV_noinc was used for the return value. This resulted in invalid cache values, reported by Michael Bletzinger 97.09.12 V1.1809 Adapted changes from DBD-Oracle 0.46 to 0.47; in particular the files Driver.xst and dbd_xsh.h from the DBI distribution are used now. (LongReadLen, LongTruncOk, ... are still meaningless, but they are not that important for m(y)sql: The complete results are in RAM anyways ...) Fixed man page of DBD::M(y)SQL: "@names = $sth->{'NAME'}". Added parameter completion for "set" command to dbimon. 97.09.08 V1.1808 Fixed bug in dbimon, a closing brace was missing causing a syntax error. Fixed problems in the Term::ReadLine::GNU support, reported by Nem W. Schlecht (nem@abattoir.cc.ndsu.nodak.edu). Modified dbimon for internally using the Data::ShowTable module. My thanks to Tim Bunce for the hint. Compatibility fixes for SunOS and Solaris, supplied by Neil Bowers (neilb@cre.canon.co.uk). 97.09.03 V1.1806 Fixed bug in Mysql.xs: $sth->numfields dumped core because no check for a result was done. Fixed bug in lib/Mysql/Statement.pm: Mysql::Statement.as_string did not check for $sth->numfields != 0. Added patch from Nem W. Schlecht (nem@abattoir.cc.ndsu.nodak.edu) for Term::ReadLine::GNU support to pmysql and dbimon. 97.09.03 V1.1805 Fixed bug in DBD::mysql: Executing a non-select statement always returned -1 (unknown number of rows) although the correct number was returned by $sth->rows(). Fixed bug in DBD::mysql: strlen was executed on a NULL value when mysql_fetch_rows returned a NULL field. Added all _ListField attributes to statement handles. Added support for "LISTFIELDS " to $sth->execute. Modified $sth->func("_ListSelectedFields") and $dbh->func("
", "_ListFields") to use the new possibilities; in fact these are only stubs now. Added dbimon. Added some internal attributes for dbimon to DBD::mysql: format_default_size, format_max_size, format_type_name and format_right_justification. 97.08.30 V1.1804 Added "fancy", "quote", "separator" and "escape" commands to pm(y)sql.PL, patch supplied by Nem W Schlecht (nem@abattoir.cc.ndsu.nodak.edu). Modified pm(y)sql.PL and pmsql.PL so that it automatically adapts pm(y)sql for use with Msql and Mysql, respectively. Makefile.PL and M(y)sqlPerl/Makefile.PL now automatically adapt lib/M(y)sql.pm, lib/M(y)sql/Statement.pm and lib/DBD/mSQL.pm or lib/DBD/mysql.pm for use in Msql-modules or Mysql-modules; just copy these files, rename them and run "perl Makefile.PL". 97.08.29 V1.1803 Added mysql_errno() Modified perl modules for use of $driver and isa($driver). Modified Msql.xs and Mysql.xs for use of Package and StPackage. Modified test for fetch of non-result sth in akmisc.t: Msql returns number of rows and not an sth. 97.08.27 Removed use of TEXT_TYPE from pmysql and Mysql/Statement.pm. 97.08.16 Modified mysql.xs, dbdimp.h and dbdimp.c for use in DBD::mSQL. Now using Andreas König´s Makefile.PL from the DBD::mSQL distribution. Added check for disabled '-lgcc' on Linux; this leads to a missing __moddi3 symbol in libmysqlclient.a, when running mysql.so. Added mysqlperl support. 97.08.02 Almost completely rewritten, with the exception of private functions like _ListTables. Implemented bind_param. Test suite rewritten for portability. Many sources moved from mysql.pm and mysql.xs to dbdimp.h; mysql.pm and mysql.xs are now close to Oracle.xs and Oracle.pm. 97.07.28 Added $dbh->quote method. Modified internal use of "char* statement" to "SV* statement". Modified use of mysql_query to mysql_real_query. (The above three things should fix blob problems hopefully.) Bumped revision number to 2.00 because of API changes: The connect method works now as described in the DBI man page, compatibility to DBD::msql seems deprecated. Heavy internal modifications in order to use DBIS->get_fbav(); this gives compatibility to DBI 0.88. Modified test suite to use Test::Harness. Added blob tests. DBD::mysql for DBI - Written by Alligator Descartes 96.06.22 Get new patched version 1.65 from gnat@frii.com Added the memory bug patch to this. 96.06.18 Added pod documentation to mysql.pm and the possibility to retrieve insert_id. This was done by Nathan Torkington. Fixed memory bug that sql results never was freed. Now a result is freed when one calls the 'finish' action. The patch was done by gareth@netcom.co.uk & Monty 96.05.27 Changed Makefile.PL after suggestions from Raymond Wiker 96.04.25 Changed the README and fixed a typo in mysql.xs Changed version to DBD-mysql-1.63.1 to have a reference to mSQL-0.63 96.04.19 Updated with differences from DBD:mSQL-0.63 96.11.03 Changed from DBD:mysql-0.60pl10 to DBD:mysql-1.0 by Michael Widenius Original ChangeLog: 18/07/95: Started. Version 0.0.0 ( Totally pre-alpha! ) 19/07/95:22:00 Code now basically seems to work. I've got connection to a database, and clean disconnection. 23:45 I'm now working on the statement cycle stuff, which I've mapped out. It's just a case of coding, which shouldn't take too long, hopefully. Posted notice of approaching doom to perldb-interest. 20/07/95:01:25 Fetching appears to work OK now. I need to read the API on msqlFieldSeek, since I can't work out why fetch is returning the same row over and over! 21/07/95:09:22 Added a field into imp_sth (currow) which keeps track of the current row that's been fetched from the result struct. If I can fix the return codes coming from fetchrow, it'll work! 21/07/95:10:30 Pondered bind variables in cursors. Since there isn't a bind function in the API, I may have to frig the way that prepare/ execute works, ie, move the call to msqlQuery *after* it's done some parsing for bind values......Hm. 21/07/95:10:35 Twiddled some bits in the fetchrow cycle. 23/07/95:15:50 Fetch is fetching a row, but it's not returning it to the calling cycle, so I need to fart about with the sv stuff, which is not amusing me greatly! 26/07/95:23:42 Decided in agreement with Andreas that the first release is to be 0.61! 27/07/95:14:14 Finally! It fucking works! After splendid quantities of hacking around with the prepare/execute/fetchrow/finish cycle it's actually returning rows correctly! NOTE: The SV handling within dbd_describe is shot to buggery, but I've kludged it in mSQL.xs::fetchrow to do a sv_2mortal instead of a sv_mortalcopy. 27/07/95:14:22 Tidied up mSQL.xs::finish to do an msqlFreeResult. Annoyingly enough, there's no return code to msqlFR, so I can't test whether or not it's worked! Bah! 27/07/95:15:15 Altered test to do several bits and bobs. I'm testing INSERT statements now. These only execute an msqlQuery, but the stuff needs to continue to pass through the execute and finish stages cleanly.......*sigh* 27/07/95:15:22 My dubious 'INSERT' check hack works, sort of. Pity it converts the entire statement to lower case.....! 27/07/95:17:33 Twiddled some more stuff so it seems to do CREATE TABLE, INSERT statements too. Of course, there's no error checking yet, but it seems to be OK........Hm. 27/07/95:17:38 Mailed out a statement saying the 0.61 code would be up for grabs as of Monday 31st July! Still waiting on Alpha reports. 27/07/95:12:11 Fixed the lower-case all the INSERT/CREATE &c. statement bug. It now checks to see if you're in quotes. 28/07/95:xx:xx Got a report back from Andreas to say compilation barfs on his Indy. Fixed a load of do_error bugs in dbdimp.c. 13/08/95:18:25 Finally got back to this after a rather long break. Fixed some Makefile.PL bugs that were kicking about. Finally fixed ( or appeared to fix ) the strlen signedness bug in dbdimp.c that may halt compilation on the Indy. Emailed Karsten the debug info to see what's causing problems on the NeXTStep platform. 14/08/95:13:48 Got email back from Andreas. signedness broke mSQL.xs as well! Fixed that and emailed him a quick patch. 14/08/95:14:45 Andreas now has a successful compile. The tests are crap, but appear to ( sort of ) work. 29/08/95:23:18 Converted driver across to new DBI format. It now appears to compile, install and run fairly reasonably. There are some serious messes that need cleared up in it, but it's fundamentally OK, I hope. Announced for pl0 testing. 04/09/95:15:04 Started back on getting the 0.60pl0 out. Tidied up the parsing of statements for INSERT, CREATE &c statements. It just takes the first word of the statement now. 04/09/95:15:19 Looks OK. Tested against DBI 0.63 and looks reasonable. Announced release of 0.60pl1 and put up for ftp. 20/09/95:15:20 Patched a load of stuff including NULLs, and local device handling ( SV ). Released pl4, which was bogus. Released pl5 which should fix those issues. 20/09/95:22:17 Fixed overhang of old DBI bug with DBIc_ENDING remaining in DESTROY in mSQL.xs. Spotted by Marti Rijken and fixed. ( Hopefully! ) 18/10/95:15:13 Added in the missing API chunks for ListTables, ListDBs and ListFields. ListFields isnae working, but I'll fix that sometime soon.... 05/11/95:11:32 Fixed $sth->readblob to return undef. Fixed Makefile.PL, dbdimp.h, mSQL.h, dbdimp.c for release of 0.60pl7. Also tested 'make test' which now works! 23/11/95:19:22 Fixed ListFields from the pointers given to me by Sven V. 24/11/95:03:13 Fixed error handling in all the func methods 24/11/95:13:01 Added 'NumRows' method to statement handles to return the number of rows returned ( or affected ) by a statement.o 30/12/95:18:10 Altered mSQL.pm to allow for hostname:port style connections to known remote port machines. Sets ENV var since the msqlConnect API call doesn't support port arguments. 30/12/95:18:15 Added 'length' key into the hash returned by ListFields, so we can get the scale of the field. 24/03/96:22:34 Fixed bugs and upgraded versioning for perl5.002 to work properly. Released as pl10 -> Lamentable lack of ChangeLog information here! 27/03/97: Tidied up things with regard to 0.61 release. 28/03/97: Patched NULL as undef bug DBD-MariaDB-1.22/Changes0000644000175000017500000002476514230360604013227 0ustar palipali1.22 2022-04-22 - Disable usage of libmysqld.a from MySQL 8.x series - Install README.pod into DBD/MariaDB/ subdirectory (https://github.com/gooddata/DBD-MariaDB/issues/146) - Do not export driver private C functions - Fix typo in error message - Fix compatibility with new MariaDB client and server versions (https://github.com/perl5-dbi/DBD-MariaDB/issues/164) (https://github.com/perl5-dbi/DBD-MariaDB/issues/167) (https://github.com/perl5-dbi/DBD-mysql/issues/333) 1.21 2019-02-27 - Fix skipping test t/14destruct.t - Revert "MySQL bug #93276 is fixed in 8.0.15" (https://github.com/gooddata/DBD-MariaDB/issues/137) 1.20 2019-02-22 - Fix compilation on Windows - Fix tests for MariaDB 10.2.20+, 10.3.12+ and 10.4.1+ - Fix processing of unfetched multi result sets - Cover a protocol design error for multi result statements - Fix $dbh->last_insert_id for async calls and multi result statements - Add more robust solution to prevent deinitializing OpenSSL functions (https://github.com/gooddata/DBD-MariaDB/issues/119) - Set $sth->{Active} to off after fetching all data (https://github.com/jhthorsen/mojo-mysql/pull/47#issuecomment-448095164) - Fix $sth->rows for async, multi results and when error occurred - Fix disconnect_all() method to work also during global destruction phase - Address MySQL bug #93276 which is fixed in 8.0.15 1.11 2019-01-02 - Fix breakage of Net::SSLeay / OpenSSL library after DBI disconnect (https://github.com/gooddata/DBD-MariaDB/issues/119) 1.10 2018-12-05 - Fix spelling error (https://github.com/gooddata/DBD-MariaDB/issues/82) - Fix MinGW build (https://github.com/gooddata/DBD-MariaDB/issues/91) - Fix DBI SQL types (https://github.com/gooddata/DBD-MariaDB/issues/109) - Fix overflow in mariadb_thread_id and mariadb_warning_count attributes - Fix parsing LIMIT keyword (case-insensitive + allow whitespaces around) - Fix allocating and releasing memory when using Embedded Server - Fix escaping placeholders when sql_mode is NO_BACKSLASH_ESCAPES - Fix output from Unicode related tests - Fix setting client_flag for mysql_real_connect() - Fix calling DBI->data_sources() without second argument - Fix $dbh->last_insert_id() for multi and prepared server side statements - Use dbd_db_do6 API from DBI 1.642 when available - Add support for a new DBI method call $sth->last_insert_id() - Add sanity check for Makefile.PL --testsocket, --testhost and --testport - Report error when $dbh->{mariadb_ssl_cipher} attribute is not supported - Check that correct number of bind parameters are in $dbh->do() - Update workarounds for bugs in MariaDB client library (some were fixed) - Allow to set zero read, write and connect timeout (which means infinite) - Set default session collation to utf8mb4_unicode_ci for real Unicode - Change minimal MySQL client version to 4.1.8 (older is incompatible) - Skip tests which cannot be started on current system/architecture - Move testrules.yml to t/ directory - Miscellaneous fixes in tests 1.00 2018-07-12 - Do not remove test name and line from test error messages - Update documentation for mariadb_length and mariadb_max_length - Fix retrieving ODBC attribute SQL_USER_NAME via $dbh->get_info() - Do not show internal DBI packages on cpan - Fix checking for error value from mariadb_embedded options - Makefile.PL shows error message when no client library was specified - Fix checking if integer value should be signed or unsigned 0.90_01 2018-06-26 (beta) - This is a new DBD::MariaDB driver, fork of DBD::mysql 4.041 with fixes - Attributes and methods with mysql_* prefix were renamed to mariadb_* [1. Security fixes] - CVE-2017-10788: Fix use-after-free after calling mysql_stmt_close() - CVE-2017-3302: Add workaround for defect of leaking dangling pointers - CVE-2018-2767: Handle SSL problems of MySQL and MariaDB clients [2. Client/server changes] - New support for MySQL 8.0+ clients - New support for MariaDB 10.2.4+ clients - New support for MariaDB 10.3.0+ clients - New support for MariaDB Connector/C 2.3.0+ clients - New support for MariaDB Connector/C 3.0.2+ clients - Minimal DBI version is now 1.608 - Minimal MySQL client library version is now 4.1.3 - Minimal MySQL server version is now 4.1.0 - Requirement for utf8mb4 (preferred) or utf8(mb3) connection charset [3. Functional changes] - Full Unicode support for all Perl strings in all methods according to Perl Unicode model (same as in recent DBD::Pg and DBD::SQLite drivers), activated by default, improperly written applications may have problems - Embedded Server support is now in main DBD::MariaDB module and enabled at compile time if MariaDB/MySQL linking library supports it, additional module DBD::MariaDBEmb was therefore removed - Fix lot of bugs related to Unicode, mysql utf8mb4 charset and login - Remove support for Latin1 encoding [4. Client compatibility changes] - Fix initialization of MySQL/MariaDB client library, fix MariaDB 10.2.4+ - Fix crashing when prepared statements are used - Do not access internal MYSQL* and MYSQL_STMT* structures [5. Statement handling changes] - Stop parsing SQL statements (exception are client side placeholders) - Fix support for client side placeholder replacing with MySQL 5.7.6+ - Fix $dbh->quote() method for MySQL 5.7.6+ and MySQL 8.0+ clients - Fix error handling for statements with LIMIT and OFFSET - Fix processing statements with nul bytes - Fix calculation of buffer size for client side placeholder replacing - Fix checking if bind value is mysql number and if needs to be quoted - Check that correct number of bind parameters were supplied [6. Miscellaneous changes] - Fix fetching numeric values of types with fixed-length of decimals - Fix ChopBlanks for binary fields - Fix $dbh->ping() and $dbh->last_insert_id() with MySQL 5.7+ and 8.0+ - Fix tests so can be run in parallel (via testrules.yml) - Fix retrieving $sth attributes after $sth->fetchall* call - Fix usage of normal eval, $@ and error handling - Fix and simplify code which uses number of returned or affected rows - Fix usage of boolean variables - Fix creating perl scalars with unsigned numbers - Fix autoreconnect for server side prepared statements - Fix and cleanup ODBC attributes returned by $dbh->get_info() method - Fix support for IMP_DATA - Fix propagating server error code and messages to DBI - Remove usage of %llu and %lld for PerlIO_printf - Remove usage of stringified eval - Remove old undocumented, legacy and hidden options and methods - Remove nonsense prototypes for object methods - Distinguish between undef (NULL) and "" for mysql_real_connect() - Check for valid and supported attribute names - Cleanup Makefile.PL options - Hide passwords in trace logs - Use DBI dbd_st_execute_iv() API when available - Add support for mariadb_conn_attrs attribute with MariaDB 10+ clients - Disable autoreconnect by default also for mod_perl - Implement $dbh->disconnect_all() method - Makefile.PL now depends on Devel::CheckLib 1.12 (ensure correct linking) [7. List of fixed issues] - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866821#17 - https://github.com/gooddata/DBD-MariaDB/issues/13 - https://github.com/perl5-dbi/DBD-mysql/issues/78 - https://github.com/perl5-dbi/DBD-mysql/issues/110 - https://github.com/perl5-dbi/DBD-mysql/issues/120 - https://github.com/perl5-dbi/DBD-mysql/issues/126 - https://github.com/perl5-dbi/DBD-mysql/issues/139 - https://github.com/perl5-dbi/DBD-mysql/issues/140 - https://github.com/perl5-dbi/DBD-mysql/issues/149 - https://github.com/perl5-dbi/DBD-mysql/issues/165 - https://github.com/perl5-dbi/DBD-mysql/issues/167 - https://github.com/perl5-dbi/DBD-mysql/issues/169 - https://github.com/perl5-dbi/DBD-mysql/issues/170 - https://github.com/perl5-dbi/DBD-mysql/issues/182 - https://github.com/perl5-dbi/DBD-mysql/issues/185 - https://github.com/perl5-dbi/DBD-mysql/issues/187 - https://github.com/perl5-dbi/DBD-mysql/issues/197 - https://github.com/perl5-dbi/DBD-mysql/issues/201 - https://github.com/perl5-dbi/DBD-mysql/issues/203 - https://github.com/perl5-dbi/DBD-mysql/issues/204 - https://github.com/perl5-dbi/DBD-mysql/issues/207 - https://github.com/perl5-dbi/DBD-mysql/issues/211 - https://github.com/perl5-dbi/DBD-mysql/issues/212 - https://github.com/perl5-dbi/DBD-mysql/issues/214 - https://github.com/perl5-dbi/DBD-mysql/issues/215 - https://github.com/perl5-dbi/DBD-mysql/issues/218 - https://github.com/perl5-dbi/DBD-mysql/issues/219 - https://github.com/perl5-dbi/DBD-mysql/issues/220 - https://github.com/perl5-dbi/DBD-mysql/issues/221 - https://github.com/perl5-dbi/DBD-mysql/issues/228 - https://github.com/perl5-dbi/DBD-mysql/issues/232 - https://github.com/perl5-dbi/DBD-mysql/issues/244 - https://github.com/perl5-dbi/DBD-mysql/issues/249 - https://github.com/perl5-dbi/DBD-mysql/issues/250 - https://github.com/perl5-dbi/DBD-mysql/issues/251 - https://github.com/perl5-dbi/DBD-mysql/pull/133 - https://github.com/perl5-dbi/DBD-mysql/pull/138 - https://github.com/perl5-dbi/DBD-mysql/pull/223 - https://github.com/perl5-dbi/DBD-mysql/pull/224 - https://github.com/perl5-dbi/DBD-mysql/pull/225#issuecomment-357522793 - https://github.com/perl5-dbi/DBD-mysql/pull/227 - https://github.com/perl5-dbi/DBD-mysql/pull/230 - https://github.com/perl5-dbi/DBD-mysql/pull/245 - https://github.com/perl5-dbi/DBD-mysql/pull/246 - https://rt.cpan.org/Public/Bug/Display.html?id=25590 - https://rt.cpan.org/Public/Bug/Display.html?id=53130 - https://rt.cpan.org/Public/Bug/Display.html?id=60987 - https://rt.cpan.org/Public/Bug/Display.html?id=62516 - https://rt.cpan.org/Public/Bug/Display.html?id=87428 - https://rt.cpan.org/Public/Bug/Display.html?id=97541 - https://rt.cpan.org/Public/Bug/Display.html?id=103306 - https://rt.cpan.org/Public/Bug/Display.html?id=106527 - https://rt.cpan.org/Public/Bug/Display.html?id=108650 - https://rt.cpan.org/Public/Bug/Display.html?id=110983 - https://rt.cpan.org/Public/Bug/Display.html?id=118837 - https://rt.cpan.org/Public/Bug/Display.html?id=118977 - https://rt.cpan.org/Public/Bug/Display.html?id=119902 - https://rt.cpan.org/Public/Bug/Display.html?id=119904 - https://rt.cpan.org/Public/Bug/Display.html?id=120141 - https://rt.cpan.org/Public/Bug/Display.html?id=120709 - https://rt.cpan.org/Public/Bug/Display.html?id=122065 - https://rt.cpan.org/Public/Bug/Display.html?id=122429 - https://rt.cpan.org/Public/Bug/Display.html?id=122431 - https://rt.cpan.org/Public/Bug/Display.html?id=122541 - https://rt.cpan.org/Public/Bug/Display.html?id=123826 - https://rt.cpan.org/Public/Bug/Display.html?id=125517 DBD-MariaDB-1.22/dbdimp.c0000644000175000017500000063572614230360604013344 0ustar palipali/* * DBD::MariaDB - DBI driver for the MariaDB and MySQL database * * Copyright (c) 2018 GoodData Corporation * Copyright (c) 2015-2017 Pali Rohár * Copyright (c) 2004-2017 Patrick Galbraith * Copyright (c) 2013-2017 Michiel Beijen * Copyright (c) 2004-2007 Alexey Stroganov * Copyright (c) 2003-2005 Rudolf Lippan * Copyright (c) 1997-2003 Jochen Wiedmann * * You may distribute this under the terms of either the GNU General Public * License or the Artistic License, as specified in the Perl README file. */ #include "dbdimp.h" #ifdef HAVE_GET_CHARSET_NUMBER /* Available only in some clients and declared in header file my_sys.h which cannot be included */ unsigned int get_charset_number(const char *cs_name, unsigned int cs_flags); #endif #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) /* Do not export non-static functions from driver library */ #pragma GCC visibility push(hidden) #endif #define ASYNC_CHECK_RETURN(h, value)\ if(imp_dbh->async_query_in_flight) {\ mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Calling a synchronous function on an asynchronous handle", "HY000");\ return (value);\ } static bool is_mysql_number(char *string, STRLEN len); DBISTATE_DECLARE; typedef struct sql_type_info_s { const char *type_name; int data_type; int column_size; const char *literal_prefix; const char *literal_suffix; const char *create_params; int nullable; int case_sensitive; int searchable; int unsigned_attribute; int fixed_prec_scale; int auto_unique_value; const char *local_type_name; int minimum_scale; int maximum_scale; int num_prec_radix; int sql_datatype; int sql_datetime_sub; int interval_precision; int native_type; bool is_num; } sql_type_info_t; /* This function manually counts the number of placeholders in an SQL statement, used for emulated prepare statements. */ static unsigned long int count_params(imp_dbh_t *imp_dbh, pTHX_ char *statement, STRLEN statement_len, bool bind_comment_placeholders) { bool comment_end = FALSE; char* ptr= statement; unsigned long int num_params = 0; int comment_length= 0; char *end = statement + statement_len; char c; if (DBIc_DBISTATE(imp_dbh)->debug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), ">count_params statement %.1000s%s\n", statement, statement_len > 1000 ? "..." : ""); while (ptr < end) { c = *ptr++; switch (c) { /* so, this is a -- comment, so let's burn up characters */ case '-': { if (ptr >= end) break; if (bind_comment_placeholders) { ptr++; break; } else { comment_length= 1; /* let's see if the next one is a dash */ c = *ptr++; if (c == '-') { /* if two dashes, ignore everything until newline */ while (ptr < end) { c = *ptr++; if (DBIc_DBISTATE(imp_dbh)->debug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "%c\n", c); comment_length++; if (c == '\n') { comment_end = TRUE; break; } } /* if not comment_end, the comment never ended and we need to iterate back to the beginning of where we started and let the database handle whatever is in the statement */ if (! comment_end) ptr-= comment_length; } /* otherwise, only one dash/hyphen, backtrack by one */ else ptr--; break; } } /* c-type comments */ case '/': { if (ptr >= end) break; if (bind_comment_placeholders) { ptr++; break; } else { c = *ptr++; /* let's check if the next one is an asterisk */ if (c == '*') { comment_length= 0; comment_end = FALSE; /* ignore everything until closing comment */ while (ptr < end) { c = *ptr++; comment_length++; if (c == '*' && ptr < end) { c = *ptr++; /* alas, end of comment */ if (c == '/') { comment_end = TRUE; break; } /* nope, just an asterisk, not so fast, not end of comment, go back one */ else ptr--; } } /* if the end of the comment was never found, we have to backtrack to wherever we first started skipping over the possible comment. This means we will pass the statement to the database to see its own fate and issue the error */ if (!comment_end) ptr -= comment_length; } else ptr--; break; } } case '`': case '"': case '\'': /* Skip string */ { char end_token = c; if (ptr >= end) break; while (ptr < end && *ptr != end_token) { if (*ptr == '\\' && ptr+1 < end) ++ptr; ++ptr; } if (ptr < end) ++ptr; break; } case '?': ++num_params; if (num_params == ULONG_MAX) return ULONG_MAX; break; default: break; } } return num_params; } /* allocate memory in statement handle per number of placeholders */ static imp_sth_ph_t *alloc_param(int num_params) { imp_sth_ph_t *params; if (num_params) Newz(908, params, num_params, imp_sth_ph_t); else params= NULL; return params; } /* allocate memory in MYSQL_BIND bind structure per number of placeholders */ static MYSQL_BIND *alloc_bind(int num_params) { MYSQL_BIND *bind; if (num_params) Newz(908, bind, num_params, MYSQL_BIND); else bind= NULL; return bind; } /* allocate memory in fbind imp_sth_phb_t structure per number of placeholders */ static imp_sth_phb_t *alloc_fbind(int num_params) { imp_sth_phb_t *fbind; if (num_params) Newz(908, fbind, num_params, imp_sth_phb_t); else fbind= NULL; return fbind; } /* alloc memory for imp_sth_fbh_t fbuffer per number of fields */ static imp_sth_fbh_t *alloc_fbuffer(int num_fields) { imp_sth_fbh_t *fbh; if (num_fields) Newz(908, fbh, num_fields, imp_sth_fbh_t); else fbh= NULL; return fbh; } /* free MYSQL_BIND bind struct */ static void free_bind(MYSQL_BIND *bind) { if (bind) Safefree(bind); } /* free imp_sth_phb_t fbind structure */ static void free_fbind(imp_sth_phb_t *fbind) { if (fbind) Safefree(fbind); } /* free imp_sth_fbh_t fbh structure */ static void free_fbuffer(imp_sth_fbh_t *fbh) { if (fbh) Safefree(fbh); } /* free statement param structure per num_params */ static void free_param(pTHX_ imp_sth_ph_t *params, int num_params) { if (params) { int i; for (i= 0; i < num_params; i++) { imp_sth_ph_t *ph= params+i; if (ph->value) Safefree(ph->value); } Safefree(params); } } enum perl_type { PERL_TYPE_UNDEF, PERL_TYPE_INTEGER, PERL_TYPE_NUMERIC, PERL_TYPE_BINARY, PERL_TYPE_STRING }; /* Convert a MySQL type to a type that perl can handle */ static enum perl_type mysql_to_perl_type(enum enum_field_types type) { switch (type) { case MYSQL_TYPE_NULL: return PERL_TYPE_UNDEF; case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONG: #if IVSIZE >= 8 case MYSQL_TYPE_LONGLONG: #endif case MYSQL_TYPE_YEAR: return PERL_TYPE_INTEGER; case MYSQL_TYPE_FLOAT: #if NVSIZE >= 8 case MYSQL_TYPE_DOUBLE: #endif return PERL_TYPE_NUMERIC; case MYSQL_TYPE_BIT: case MYSQL_TYPE_GEOMETRY: case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: return PERL_TYPE_BINARY; default: return PERL_TYPE_STRING; } } /* Convert a DBI SQL type to a MySQL type for prepared statement storage See: http://dev.mysql.com/doc/refman/5.7/en/c-api-prepared-statement-type-codes.html */ static enum enum_field_types sql_to_mysql_type(IV sql_type) { switch (sql_type) { case SQL_BOOLEAN: case SQL_TINYINT: return MYSQL_TYPE_TINY; case SQL_SMALLINT: return MYSQL_TYPE_SHORT; case SQL_INTEGER: return MYSQL_TYPE_LONG; case SQL_BIGINT: return MYSQL_TYPE_LONGLONG; case SQL_FLOAT: return MYSQL_TYPE_FLOAT; case SQL_DOUBLE: case SQL_REAL: return MYSQL_TYPE_DOUBLE; /* TODO: datetime structures */ #if 0 case SQL_TIME: return MYSQL_TYPE_TIME; case SQL_DATE: return MYSQL_TYPE_DATE; case SQL_DATETIME: return MYSQL_TYPE_DATETIME; case SQL_TIMESTAMP: return MYSQL_TYPE_TIMESTAMP; #endif case SQL_BIT: case SQL_BLOB: case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: return MYSQL_TYPE_BLOB; default: return MYSQL_TYPE_STRING; } } /* Returns true if MySQL type for prepared statement storage uses dynamically allocated buffer */ static bool mysql_type_needs_allocated_buffer(enum enum_field_types type) { switch (type) { case MYSQL_TYPE_NULL: case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: return FALSE; default: return TRUE; } } /* Numeric types with leading zeros or with fixed length of decimals in fractional part cannot be represented by IV or NV */ static bool mysql_field_needs_string_type(MYSQL_FIELD *field) { if (field->flags & ZEROFILL_FLAG) return TRUE; if ((field->type == MYSQL_TYPE_FLOAT || field->type == MYSQL_TYPE_DOUBLE) && field->decimals < NOT_FIXED_DEC) return TRUE; return FALSE; } /* Allocated buffer is needed by all non-primitive types (which have non-fixed length) */ static bool mysql_field_needs_allocated_buffer(MYSQL_FIELD *field) { if (mysql_type_needs_allocated_buffer(field->type) || mysql_field_needs_string_type(field)) return TRUE; else return FALSE; } /* Returns true if DBI SQL type should be treated as binary sequence of octets, not UNICODE string */ static bool sql_type_is_binary(IV sql_type) { switch (sql_type) { case SQL_BIT: case SQL_BLOB: case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: return TRUE; default: return FALSE; } } /* Returns true if DBI SQL type represents numeric value (regardless of how is stored) */ static bool sql_type_is_numeric(IV sql_type) { switch (sql_type) { case SQL_BOOLEAN: case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: case SQL_BIGINT: case SQL_FLOAT: case SQL_DOUBLE: case SQL_REAL: case SQL_NUMERIC: case SQL_DECIMAL: return TRUE; default: return FALSE; } } /* Check if attribute can be skipped by driver and handled by DBI itself */ static bool skip_attribute(const char *key) { return strBEGINs(key, "private_") || strBEGINs(key, "dbd_") || strBEGINs(key, "dbi_") || isUPPER(*key); } PERL_STATIC_INLINE bool mysql_charsetnr_is_utf8(unsigned int id) { /* Check if supplied id belongs to some UTF-8 related MySQL charset number */ /* List of all utf8 charset numbers is harcoded in MySQL and MariaDB source code, to retrieve it grep source code */ /* Shell fragment for MySQL or MariaDB server source code: grep -E '^(CHARSET_INFO|struct charset_info_st).*utf8' -A 2 -r strings | grep number | sed -E 's/^.*- *([^,]+),.*$/\1/' | sort -n */ /* Shell fragment for MariaDB Connector/C source code: sed -n '/mariadb_compiled_charsets\[\]/,/^};$/{/utf8/I{s%,.*%%;s%\s*{\s*%%p}}' libmariadb/ma_charset.c | sort -n */ /* Runtime SQL statement (returns only subset selected at compile time): SELECT ID FROM INFORMATION_SCHEMA.COLLATIONS WHERE CHARACTER_SET_NAME LIKE 'utf8%' ORDER BY ID */ return (id == 33 || id == 45 || id == 46 || id == 56 || id == 76 || id == 83 || (id >= 192 && id <= 215) || (id >= 223 && id <= 247) || (id >= 254 && id <= 307) || (id >= 576 && id <= 578) || (id >= 608 && id <= 610) || id == 1057 || (id >= 1069 && id <= 1070) || id == 1107 || id == 1216 || id == 1238 || id == 1248 || id == 1270); } /* count embedded options */ static int count_embedded_options(char *st) { int rc; char c; char *ptr; ptr= st; rc= 0; if (st) { while ((c= *ptr++)) { if (c == ',') rc++; } rc++; } return rc; } /* Free embedded options */ static int free_embedded_options(char ** options_list, int options_count) { int i; for (i= 0; i < options_count; i++) { if (options_list[i]) Safefree(options_list[i]); } Safefree(options_list); return 1; } /* Print out embedded option settings */ static int print_embedded_options(PerlIO *stream, char ** options_list, int options_count) { int i; for (i=0; idebug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), ">parse_params statement %.1000s%s\n", statement, slen > 1000 ? "..." : ""); if (num_params == 0) return NULL; while (isspace(*statement)) { ++statement; --slen; } /* Calculate the number of bytes being allocated for the statement */ alen= slen; for (i= 0, ph= params; i < num_params; i++, ph++) { alen--; /* Erase '?' */ if (!ph->value) alen += 4; /* insert 'NULL' */ else alen += 3 + 2*ph->len; /* 2 bytes for quotes, one for 'X' and in the worst case two bytes for each character */ } /* +1 for null term byte */ New(908, salloc, alen+1, char); ptr= salloc; i= 0; /* Now create the statement string; compare count_params above */ statement_ptr_end= (statement_ptr= statement)+ slen; while (statement_ptr < statement_ptr_end) { /* LIMIT should be the last part of the query, in most cases */ if (! limit_flag) { if (statement_ptr+4 < statement_ptr_end) { char *s = statement_ptr; if ((s[0] == 'l' || s[0] == 'L') && (s[1] == 'i' || s[1] == 'I') && (s[2] == 'm' || s[2] == 'M') && (s[3] == 'i' || s[3] == 'I') && (s[4] == 't' || s[4] == 'T')) { limit_flag = TRUE; } } } switch (*statement_ptr) { /* comment detection. Anything goes in a comment */ case '-': { if (bind_comment_placeholders) { *ptr++= *statement_ptr++; break; } else { comment_length= 1; comment_end = FALSE; *ptr++ = *statement_ptr++; if (*statement_ptr == '-') { /* ignore everything until newline or end of string */ while (*statement_ptr) { comment_length++; *ptr++ = *statement_ptr++; if (!*statement_ptr || *statement_ptr == '\n') { comment_end = TRUE; break; } } /* if not end of comment, go back to where we started, no end found */ if (! comment_end) { statement_ptr -= comment_length; ptr -= comment_length; } } break; } } /* c-type comments */ case '/': { if (bind_comment_placeholders) { *ptr++= *statement_ptr++; break; } else { comment_length= 1; comment_end = FALSE; *ptr++ = *statement_ptr++; if (*statement_ptr == '*') { /* use up characters everything until newline */ while (*statement_ptr) { *ptr++ = *statement_ptr++; comment_length++; if (!strncmp(statement_ptr, "*/", 2)) { comment_length += 2; comment_end = TRUE; break; } } /* Go back to where started if comment end not found */ if (! comment_end) { statement_ptr -= comment_length; ptr -= comment_length; } } break; } } case '`': case '\'': case '"': /* Skip string */ { char endToken = *statement_ptr++; *ptr++ = endToken; while (statement_ptr != statement_ptr_end && *statement_ptr != endToken) { if (*statement_ptr == '\\') { *ptr++ = *statement_ptr++; if (statement_ptr == statement_ptr_end) break; } *ptr++= *statement_ptr++; } if (statement_ptr != statement_ptr_end) *ptr++= *statement_ptr++; } break; case '?': /* Insert parameter */ statement_ptr++; if (i >= num_params) { break; } ph = params+ (i++); if (!ph->value) { *ptr++ = 'N'; *ptr++ = 'U'; *ptr++ = 'L'; *ptr++ = 'L'; } else { bool quote_value, is_value_num; is_value_num = is_mysql_number(ph->value, ph->len); if (limit_flag && is_value_num) /* After a LIMIT clause must be unquoted numeric value */ quote_value = FALSE; else if (bind_type_guessing && !ph->type) /* If SQL type was not specified and bind_type_guessing is enabled, then quote only if needed */ quote_value = !is_value_num; else if (sql_type_is_numeric(ph->type)) /* If SQL type is numeric then quote only in case value is not numeric */ quote_value = !is_value_num; else /* Otherwise always quote */ quote_value = TRUE; if (quote_value) { #if MYSQL_VERSION_ID < 50001 if (sock->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) { *ptr++ = '\''; ptr += string_escape_quotes(ptr, ph->value, ph->len); *ptr++ = '\''; } else #endif { *ptr++ = '\''; #if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50706 && MYSQL_VERSION_ID != 60000 ptr += mysql_real_escape_string_quote(sock, ptr, ph->value, ph->len, '\''); #else ptr += mysql_real_escape_string(sock, ptr, ph->value, ph->len); #endif *ptr++ = '\''; } } else { memcpy(ptr, ph->value, ph->len); ptr += ph->len; } } break; /* in case this is a nested LIMIT */ case ')': limit_flag = FALSE; *ptr++ = *statement_ptr++; break; default: *ptr++ = *statement_ptr++; break; } } *slen_ptr = ptr - salloc; *ptr++ = '\0'; return(salloc); } static void bind_param(imp_sth_ph_t *ph, SV *value, IV sql_type) { dTHX; char *buf; if (ph->value) { Safefree(ph->value); ph->value = NULL; } ph->bound = TRUE; if (sql_type) ph->type = sql_type; if (SvOK(value)) { if (sql_type_is_binary(ph->type)) buf = SvPVbyte_nomg(value, ph->len); /* Ensure that buf is always byte orientated */ else buf = SvPVutf8_nomg(value, ph->len); /* Ensure that buf is always UTF-8 encoded */ ph->value = savepvn(buf, ph->len); } } static const sql_type_info_t SQL_GET_TYPE_INFO_values[]= { { "varchar", SQL_VARCHAR, 255, "'", "'", "max length", 1, 0, 3, 0, 0, 0, "variable length string", 0, 0, 0, SQL_VARCHAR, 0, 0, MYSQL_TYPE_STRING, 0, }, { "decimal", SQL_DECIMAL, 15, NULL, NULL, "precision,scale", 1, 0, 3, 0, 0, 0, "double", 0, 6, 2, SQL_DECIMAL, 0, 0, MYSQL_TYPE_DECIMAL, 1 }, { "tinyint", SQL_TINYINT, 3, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "Tiny integer", 0, 0, 10, SQL_TINYINT, 0, 0, MYSQL_TYPE_TINY, 1 }, { "smallint", SQL_SMALLINT, 5, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "Short integer", 0, 0, 10, SQL_SMALLINT, 0, 0, MYSQL_TYPE_SHORT, 1 }, { "integer", SQL_INTEGER, 10, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "integer", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "float", SQL_FLOAT, 7, NULL, NULL, NULL, 1, 0, 0, 0, 0, 0, "float", 0, 2, 10, SQL_FLOAT, 0, 0, MYSQL_TYPE_FLOAT, 1 }, { "null", SQL_CHAR, 0, NULL, NULL, NULL, 1, 0, 0, 0, 0, 1, "null", 0, 0, 0, SQL_CHAR, 0, 0, MYSQL_TYPE_NULL, 1 }, { "double", SQL_DOUBLE, 15, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "double", 0, 4, 10, SQL_DOUBLE, 0, 0, MYSQL_TYPE_DOUBLE, 1 }, { "timestamp", SQL_TIMESTAMP, 14, "'", "'", NULL, 0, 0, 3, 0, 0, 0, "timestamp", 0, 0, 0, SQL_TIMESTAMP, 0, 0, MYSQL_TYPE_TIMESTAMP, 0 }, { "bigint", SQL_BIGINT, 19, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "Longlong integer", 0, 0, 10, SQL_BIGINT, 0, 0, MYSQL_TYPE_LONGLONG, 1 }, { "mediumint", SQL_INTEGER, 8, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "Medium integer", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1 }, { "date", SQL_DATE, 10, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "date", 0, 0, 0, SQL_DATE, 0, 0, MYSQL_TYPE_DATE, 0 }, { "time", SQL_TIME, 6, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "time", 0, 0, 0, SQL_TIME, 0, 0, MYSQL_TYPE_TIME, 0 }, { "datetime", SQL_TIMESTAMP, 21, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "datetime", 0, 0, 0, SQL_TIMESTAMP, 0, 0, MYSQL_TYPE_DATETIME, 0 }, { "year", SQL_SMALLINT, 4, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "year", 0, 0, 10, SQL_SMALLINT, 0, 0, MYSQL_TYPE_YEAR, 1 }, { "date", SQL_DATE, 10, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "date", 0, 0, 0, SQL_DATE, 0, 0, MYSQL_TYPE_NEWDATE, 0 }, { "enum", SQL_VARCHAR, 255, "'", "'", NULL, 1, 0, 1, 0, 0, 0, "enum(value1,value2,value3...)", 0, 0, 0, 0, 0, 0, MYSQL_TYPE_ENUM, 0 }, { "set", SQL_VARCHAR, 255, "'", "'", NULL, 1, 0, 1, 0, 0, 0, "set(value1,value2,value3...)", 0, 0, 0, 0, 0, 0, MYSQL_TYPE_SET, 0 }, { "blob", SQL_LONGVARBINARY, 65535, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "binary large object (0-65535)", 0, 0, 0, SQL_LONGVARBINARY, 0, 0, MYSQL_TYPE_BLOB, 0 }, { "tinyblob", SQL_VARBINARY, 255, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "binary large object (0-255) ", 0, 0, 0, SQL_VARBINARY, 0, 0, MYSQL_TYPE_TINY_BLOB, 0 }, { "mediumblob", SQL_LONGVARBINARY, 16777215, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "binary large object", 0, 0, 0, SQL_LONGVARBINARY, 0, 0, MYSQL_TYPE_MEDIUM_BLOB, 0 }, { "longblob", SQL_LONGVARBINARY, 2147483647, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "binary large object, use mediumblob instead", 0, 0, 0, SQL_LONGVARBINARY, 0, 0, MYSQL_TYPE_LONG_BLOB, 0 }, { "char", SQL_CHAR, 255, "'", "'", "max length", 1, 0, 3, 0, 0, 0, "string", 0, 0, 0, SQL_CHAR, 0, 0, MYSQL_TYPE_STRING, 0 }, { "decimal", SQL_NUMERIC, 15, NULL, NULL, "precision,scale", 1, 0, 3, 0, 0, 0, "double", 0, 6, 2, SQL_NUMERIC, 0, 0, MYSQL_TYPE_DECIMAL, 1 }, { "tinyint unsigned", SQL_TINYINT, 3, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "Tiny integer unsigned", 0, 0, 10, SQL_TINYINT, 0, 0, MYSQL_TYPE_TINY, 1 }, { "smallint unsigned", SQL_SMALLINT, 5, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "Short integer unsigned", 0, 0, 10, SQL_SMALLINT, 0, 0, MYSQL_TYPE_SHORT, 1 }, { "mediumint unsigned", SQL_INTEGER, 8, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "Medium integer unsigned", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1 }, { "int unsigned", SQL_INTEGER, 10, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "integer unsigned", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "int", SQL_INTEGER, 10, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "integer", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "integer unsigned", SQL_INTEGER, 10, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "integer", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "bigint unsigned", SQL_BIGINT, 20, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "Longlong integer unsigned", 0, 0, 10, SQL_BIGINT, 0, 0, MYSQL_TYPE_LONGLONG, 1 }, { "text", SQL_LONGVARCHAR, 65535, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "large text object (0-65535)", 0, 0, 0, SQL_LONGVARCHAR, 0, 0, MYSQL_TYPE_BLOB, 0 }, { "mediumtext", SQL_LONGVARCHAR, 16777215, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "large text object", 0, 0, 0, SQL_LONGVARCHAR, 0, 0, MYSQL_TYPE_MEDIUM_BLOB, 0 }, { "mediumint unsigned auto_increment", SQL_INTEGER, 8, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "Medium integer unsigned auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1, }, { "tinyint unsigned auto_increment", SQL_TINYINT, 3, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "tinyint unsigned auto_increment", 0, 0, 10, SQL_TINYINT, 0, 0, MYSQL_TYPE_TINY, 1 }, { "smallint auto_increment", SQL_SMALLINT, 5, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "smallint auto_increment", 0, 0, 10, SQL_SMALLINT, 0, 0, MYSQL_TYPE_SHORT, 1 }, { "int unsigned auto_increment", SQL_INTEGER, 10, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "integer unsigned auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "mediumint", SQL_INTEGER, 7, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "Medium integer", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1 }, { "bit", SQL_BIT, 1, NULL, NULL, NULL, 1, 0, 3, 0, 0, 0, "bit", 0, 0, 0, SQL_BIT, 0, 0, #if MYSQL_VERSION_ID >= NEW_DATATYPE_VERSION MYSQL_TYPE_BIT, #else MYSQL_TYPE_TINY, #endif 0 }, { "numeric", SQL_NUMERIC, 19, NULL, NULL, "precision,scale", 1, 0, 3, 0, 0, 0, "numeric", 0, 19, 10, SQL_NUMERIC, 0, 0, MYSQL_TYPE_DECIMAL, 1, }, { "integer unsigned auto_increment", SQL_INTEGER, 10, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "integer unsigned auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1, }, { "mediumint unsigned", SQL_INTEGER, 8, NULL, NULL, NULL, 1, 0, 3, 1, 0, 0, "Medium integer unsigned", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1 }, { "smallint unsigned auto_increment", SQL_SMALLINT, 5, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "smallint unsigned auto_increment", 0, 0, 10, SQL_SMALLINT, 0, 0, MYSQL_TYPE_SHORT, 1 }, { "int auto_increment", SQL_INTEGER, 10, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "integer auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1 }, { "long varbinary", SQL_LONGVARBINARY, 16777215, "0x", NULL, NULL, 1, 0, 3, 0, 0, 0, "mediumblob", 0, 0, 0, SQL_LONGVARBINARY, 0, 0, MYSQL_TYPE_LONG_BLOB, 0 }, { "double auto_increment", SQL_FLOAT, 15, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "double auto_increment", 0, 4, 2, SQL_FLOAT, 0, 0, MYSQL_TYPE_DOUBLE, 1 }, { "double auto_increment", SQL_DOUBLE, 15, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "double auto_increment", 0, 4, 10, SQL_DOUBLE, 0, 0, MYSQL_TYPE_DOUBLE, 1 }, { "integer auto_increment", SQL_INTEGER, 10, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "integer auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_LONG, 1, }, { "bigint auto_increment", SQL_BIGINT, 19, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "bigint auto_increment", 0, 0, 10, SQL_BIGINT, 0, 0, MYSQL_TYPE_LONGLONG, #if IVSIZE < 8 0 #else 1 #endif }, { "bit auto_increment", SQL_BIT, 1, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "bit auto_increment", 0, 0, 0, SQL_BIT, 0, 0, #if MYSQL_VERSION_ID >= NEW_DATATYPE_VERSION MYSQL_TYPE_BIT, #else MYSQL_TYPE_TINY, #endif 0 }, { "mediumint auto_increment", SQL_INTEGER, 7, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "Medium integer auto_increment", 0, 0, 10, SQL_INTEGER, 0, 0, MYSQL_TYPE_INT24, 1 }, { "float auto_increment", SQL_REAL, 7, NULL, NULL, NULL, 0, 0, 0, 0, 0, 1, "float auto_increment", 0, 2, 10, SQL_FLOAT, 0, 0, MYSQL_TYPE_FLOAT, 1 }, { "long varchar", SQL_LONGVARCHAR, 16777215, "'", "'", NULL, 1, 0, 3, 0, 0, 0, "mediumtext", 0, 0, 0, SQL_LONGVARCHAR, 0, 0, MYSQL_TYPE_MEDIUM_BLOB, 1 }, { "tinyint auto_increment", SQL_TINYINT, 3, NULL, NULL, NULL, 0, 0, 3, 0, 0, 1, "tinyint auto_increment", 0, 0, 10, SQL_TINYINT, 0, 0, MYSQL_TYPE_TINY, 1 }, { "bigint unsigned auto_increment", SQL_BIGINT, 20, NULL, NULL, NULL, 0, 0, 3, 1, 0, 1, "bigint unsigned auto_increment", 0, 0, 10, SQL_BIGINT, 0, 0, MYSQL_TYPE_LONGLONG, #if IVSIZE < 8 0 #else 1 #endif }, /* END MORE STUFF */ }; /* static const sql_type_info_t* native2sql (int t) */ static const sql_type_info_t *native2sql(int t) { switch (t) { case MYSQL_TYPE_VAR_STRING: return &SQL_GET_TYPE_INFO_values[0]; case MYSQL_TYPE_DECIMAL: return &SQL_GET_TYPE_INFO_values[1]; case MYSQL_TYPE_NEWDECIMAL: return &SQL_GET_TYPE_INFO_values[1]; case MYSQL_TYPE_TINY: return &SQL_GET_TYPE_INFO_values[2]; case MYSQL_TYPE_SHORT: return &SQL_GET_TYPE_INFO_values[3]; case MYSQL_TYPE_LONG: return &SQL_GET_TYPE_INFO_values[4]; case MYSQL_TYPE_FLOAT: return &SQL_GET_TYPE_INFO_values[5]; case MYSQL_TYPE_NULL: return &SQL_GET_TYPE_INFO_values[6]; case MYSQL_TYPE_DOUBLE: return &SQL_GET_TYPE_INFO_values[7]; case MYSQL_TYPE_TIMESTAMP: return &SQL_GET_TYPE_INFO_values[8]; case MYSQL_TYPE_LONGLONG: return &SQL_GET_TYPE_INFO_values[9]; case MYSQL_TYPE_INT24: return &SQL_GET_TYPE_INFO_values[10]; case MYSQL_TYPE_DATE: return &SQL_GET_TYPE_INFO_values[11]; case MYSQL_TYPE_TIME: return &SQL_GET_TYPE_INFO_values[12]; case MYSQL_TYPE_DATETIME: return &SQL_GET_TYPE_INFO_values[13]; case MYSQL_TYPE_YEAR: return &SQL_GET_TYPE_INFO_values[14]; case MYSQL_TYPE_NEWDATE: return &SQL_GET_TYPE_INFO_values[15]; case MYSQL_TYPE_ENUM: return &SQL_GET_TYPE_INFO_values[16]; case MYSQL_TYPE_SET: return &SQL_GET_TYPE_INFO_values[17]; case MYSQL_TYPE_BLOB: return &SQL_GET_TYPE_INFO_values[18]; case MYSQL_TYPE_TINY_BLOB: return &SQL_GET_TYPE_INFO_values[19]; case MYSQL_TYPE_MEDIUM_BLOB: return &SQL_GET_TYPE_INFO_values[20]; case MYSQL_TYPE_LONG_BLOB: return &SQL_GET_TYPE_INFO_values[21]; case MYSQL_TYPE_STRING: return &SQL_GET_TYPE_INFO_values[22]; case MYSQL_TYPE_BIT: return &SQL_GET_TYPE_INFO_values[38]; default: return &SQL_GET_TYPE_INFO_values[0]; } } #define SQL_GET_TYPE_INFO_num \ (sizeof(SQL_GET_TYPE_INFO_values)/sizeof(sql_type_info_t)) /*************************************************************************** * * Name: mariadb_dr_init * * Purpose: Called when the driver is installed by DBI * * Input: dbistate - pointer to the DBI state variable, used for some * DBI internal things * * Returns: Nothing * **************************************************************************/ void mariadb_dr_init(dbistate_t* dbistate) { dTHX; DBISTATE_INIT; PERL_UNUSED_ARG(dbistate); } /************************************************************************** * * Name: mariadb_dr_do_error * * Purpose: Called to associate an error code and an error message * to some handle * * Input: h - the handle in error condition * rc - the error code * what - the error message * * Returns: Nothing * **************************************************************************/ void mariadb_dr_do_error(SV* h, unsigned int rc, const char *what, const char *sqlstate) { dTHX; D_imp_xxh(h); SV *errstr; SV *errstate; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\t--> mariadb_dr_do_error\n"); errstr= DBIc_ERRSTR(imp_xxh); sv_setuv(DBIc_ERR(imp_xxh), rc); /* set err early */ SvUTF8_off(errstr); sv_setpv(errstr, what); sv_utf8_decode(errstr); if (sqlstate) { errstate= DBIc_STATE(imp_xxh); sv_setpv(errstate, sqlstate); } /* NO EFFECT DBIh_EVENT2(h, ERROR_event, DBIc_ERR(imp_xxh), errstr); */ if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "error %u recorded: %" SVf "\n", rc, SVfARG(errstr)); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\t<-- mariadb_dr_do_error\n"); } static void error_unknown_attribute(SV *h, const char *key) { dTHX; mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, SvPVX(sv_2mortal(newSVpvf("Unknown attribute %s", key))), "HY000"); } static void error_nul_character(SV *h, const char *key) { dTHX; mariadb_dr_do_error(h, CR_CONNECTION_ERROR, SvPVX(sv_2mortal(newSVpvf("Connection error: %s contains nul character", key))), "HY000"); } static void error_no_connection(SV *h, const char *msg) { dTHX; #ifdef HAVE_LAST_ERROR /* Some versions of MySQL/MariaDB clients provides last error via NULL parameter, so use it instead of generic error */ unsigned int last_errno = mysql_errno(NULL); const char *last_error = mysql_error(NULL); if (last_errno && last_error && last_error[0]) { mariadb_dr_do_error(h, last_errno, last_error, mysql_sqlstate(NULL)); return; } #endif mariadb_dr_do_error(h, CR_CONNECTION_ERROR, msg, "HY000"); } /*************************************************************************** * * Name: mariadb_dr_connect * * Purpose: Replacement for mysql_connect * * Input: dbh - database handle being connected * imp_dbh_t *imp_dbh - Pointer to internal dbh structure * char* mysql_socket - Name of a UNIX socket being used * or NULL * char* host - Host name being used or NULL for localhost * unsigned int port - Port number being used or 0 for default * char* user - User name being used or NULL * char* password - Password being used or NULL * char* dbname - Database name being used or NULL * * Returns: TRUE for success, FALSE otherwise; mariadb_dr_do_error will * be called in the latter case * **************************************************************************/ static bool mariadb_dr_connect( SV* dbh, imp_dbh_t *imp_dbh, char* mysql_socket, char* host, unsigned int port, char* user, char* password, char* dbname) { unsigned int client_flag; bool client_supports_utf8mb4; bool connected; unsigned int read_timeout, write_timeout; MYSQL *sock; dTHX; D_imp_xxh(dbh); SV *sv = DBIc_IMP_DATA(imp_dbh); D_imp_drh_from_dbh; #ifdef MARIADB_PACKAGE_VERSION bool read_timeout_set = FALSE; bool write_timeout_set = FALSE; #endif if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: host = |%s|, port = %u," " uid = %s, pwd = %s\n", host ? host : "NULL", port, user ? user : "NULL", !password ? "NULL" : !password[0] ? "" : "****"); #if !defined(HAVE_EMBEDDED) && defined(HAVE_BROKEN_INIT) if (imp_drh->non_embedded_finished) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Method disconnect_all() was already called and library functions unloaded", "HY000"); return FALSE; } #endif /* host=localhost means to connect via unix socket, host=embedded means to use embedded server, so do not allow specifying port */ if (port && host && (strcmp(host, "localhost") == 0 || strcmp(host, "embedded") == 0)) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: port cannot be specified when host is localhost or embedded", "HY000"); return FALSE; } /* when connecting via unix socket do not allow specifying port or host != localhost */ if (mysql_socket && (port || (host && strcmp(host, "localhost") != 0))) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: host or port cannot be specified together with mariadb_socket", "HY000"); return FALSE; } if (host && strcmp(host, "embedded") == 0) { #ifndef HAVE_EMBEDDED mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Embedded server is not supported", "HY000"); return FALSE; #endif if (sv && SvROK(sv)) { SV** svp; SV *embedded_groups = NULL; SV *embedded_args = NULL; STRLEN options_len; char * options; int server_args_cnt= 0; int server_groups_cnt= 0; int rc= 0; char ** server_args = NULL; char ** server_groups = NULL; HV* hv = (HV*) SvRV(sv); if (SvTYPE(hv) != SVt_PVHV) return FALSE; if (imp_drh->instances == 0 && !imp_drh->non_embedded_started) { if ((svp = hv_fetchs(hv, "mariadb_embedded_groups", FALSE)) && *svp && SvTRUE(*svp)) { embedded_groups = *svp; options = SvPVutf8_nomg(embedded_groups, options_len); if (strlen(options) != options_len) { error_nul_character(dbh, "mariadb_embedded_groups"); return FALSE; } if ((server_groups_cnt=count_embedded_options(options))) { /* number of server_groups always server_groups+1 */ server_groups = fill_out_embedded_options(options, 0, options_len, ++server_groups_cnt); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "Groups names passed to embedded server:\n"); print_embedded_options(DBIc_LOGPIO(imp_xxh), server_groups, server_groups_cnt); } } } if ((svp = hv_fetchs(hv, "mariadb_embedded_options", FALSE)) && *svp && SvTRUE(*svp)) { embedded_args = *svp; options = SvPVutf8_nomg(embedded_args, options_len); if (strlen(options) != options_len) { if (server_groups_cnt) free_embedded_options(server_groups, server_groups_cnt); error_nul_character(dbh, "mariadb_embedded_options"); return FALSE; } if ((server_args_cnt=count_embedded_options(options))) { /* number of server_options always server_options+1 */ server_args = fill_out_embedded_options(options, 1, options_len, ++server_args_cnt); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "Server options passed to embedded server:\n"); print_embedded_options(DBIc_LOGPIO(imp_xxh), server_args, server_args_cnt); } } } /* Init embedded server */ rc = mysql_server_init(server_args_cnt, server_args, server_groups); if (server_args_cnt) free_embedded_options(server_args, server_args_cnt); if (server_groups_cnt) free_embedded_options(server_groups, server_groups_cnt); if (rc) { error_no_connection(dbh, "Connection error: Cannot start embedded server"); return FALSE; } if (embedded_groups) imp_drh->embedded_groups = newSVsv(embedded_groups); if (embedded_args) imp_drh->embedded_args = newSVsv(embedded_args); imp_drh->embedded_started = TRUE; } else if (imp_drh->non_embedded_started) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Non-embedded connection was already established", "HY000"); return FALSE; } else if (imp_drh->embedded_started) { /* * Check if embedded parameters passed to connect() differ from * first ones */ if ( ((svp = hv_fetchs(hv, "mariadb_embedded_groups", FALSE)) && *svp && SvTRUE(*svp))) rc += abs(sv_cmp_flags(*svp, imp_drh->embedded_groups, 0)); if ( ((svp = hv_fetchs(hv, "mariadb_embedded_options", FALSE)) && *svp && SvTRUE(*svp)) ) rc += abs(sv_cmp_flags(*svp, imp_drh->embedded_args, 0)); if (rc) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Embedded server was already started, cannot pass different init parameters to embedded server", "HY000"); return FALSE; } } else { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Unknown internal state (possible bug in driver)", "HY000"); return FALSE; } } } else { if (imp_drh->instances == 0 && !imp_drh->non_embedded_started) { /* negative value means to not start embedded server and just to initialize client library */ /* initializing client library is needed prior to any other mysql_* call from client library */ if (mysql_server_init(-1, NULL, NULL)) { error_no_connection(dbh, "Connection error: Cannot initialize client library"); return FALSE; } imp_drh->non_embedded_started = TRUE; } } sock = imp_dbh->pmysql = mysql_init(NULL); if (!sock) { error_no_connection(dbh, "Connection error: Cannot initialize client structures"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } imp_drh->instances++; client_flag = CLIENT_FOUND_ROWS | CLIENT_MULTI_RESULTS; DBIc_set(imp_dbh, DBIcf_AutoCommit, TRUE); if (sv && SvROK(sv)) { HV* hv = (HV*) SvRV(sv); HV* processed = newHV(); HE* he; SV** svp; sv_2mortal(newRV_noinc((SV *)processed)); /* Automatically free HV processed */ /* These options are already handled and processed */ (void)hv_stores(processed, "host", &PL_sv_yes); (void)hv_stores(processed, "port", &PL_sv_yes); (void)hv_stores(processed, "user", &PL_sv_yes); (void)hv_stores(processed, "password", &PL_sv_yes); (void)hv_stores(processed, "database", &PL_sv_yes); (void)hv_stores(processed, "mariadb_socket", &PL_sv_yes); #ifdef HAVE_EMBEDDED if (host && strcmp(host, "embedded") == 0) { (void)hv_stores(processed, "mariadb_embedded_groups", &PL_sv_yes); (void)hv_stores(processed, "mariadb_embedded_options", &PL_sv_yes); mysql_options(sock, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL); host = NULL; } else { mysql_options(sock, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL); } #endif /* thanks to Peter John Edwards for mysql_init_command */ (void)hv_stores(processed, "mariadb_init_command", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_init_command", FALSE)) && *svp && SvTRUE(*svp)) { STRLEN len; char* df = SvPVutf8_nomg(*svp, len); if (strlen(df) != len) { error_nul_character(dbh, "mariadb_init_command"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Setting" " init command (%s).\n", df); mysql_options(sock, MYSQL_INIT_COMMAND, df); } (void)hv_stores(processed, "mariadb_compression", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_compression", FALSE)) && *svp && SvTRUE(*svp)) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Enabling" " compression.\n"); mysql_options(sock, MYSQL_OPT_COMPRESS, NULL); } (void)hv_stores(processed, "mariadb_connect_timeout", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_connect_timeout", FALSE)) && *svp) { UV uv = SvUV(*svp); unsigned int to = (uv <= UINT_MAX ? uv : UINT_MAX); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Setting" " connect timeout (%u).\n", to); mysql_options(sock, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&to); } (void)hv_stores(processed, "mariadb_write_timeout", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_write_timeout", FALSE)) && *svp) { UV uv = SvUV(*svp); write_timeout = (uv <= UINT_MAX ? uv : UINT_MAX); #ifdef MARIADB_PACKAGE_VERSION write_timeout_set = TRUE; #endif if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Setting" " write timeout (%u).\n", write_timeout); mysql_options(sock, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&write_timeout); } (void)hv_stores(processed, "mariadb_read_timeout", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_read_timeout", FALSE)) && *svp) { UV uv = SvUV(*svp); read_timeout = (uv <= UINT_MAX ? uv : UINT_MAX); #ifdef MARIADB_PACKAGE_VERSION read_timeout_set = TRUE; #endif if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Setting" " read timeout (%u).\n", read_timeout); mysql_options(sock, MYSQL_OPT_READ_TIMEOUT, (const char *)&read_timeout); } #ifdef MARIADB_PACKAGE_VERSION { /* Version is in format: "2.3.2" */ const char version[] = MARIADB_PACKAGE_VERSION; bool broken_timeouts; if (sizeof(version) != 6 || version[0] != '2' || version[1] != '.' || version[3] != '.' || version[5] != '\0') broken_timeouts = FALSE; else if (version[2] >= '0' && version[2] < '3' && version[4] >= '0' && version[4] <= '9') broken_timeouts = TRUE; else if (version[2] == '3' && version[4] >= '0' && version[4] < '3') broken_timeouts = TRUE; else broken_timeouts = FALSE; if (broken_timeouts) { /* MariaDB Connector/C prior to version 2.3.3 has broken MYSQL_OPT_WRITE_TIMEOUT. Write timeout is set by MYSQL_OPT_READ_TIMEOUT option. See file libmariadb/libmariadb.c, line "vio_write_timeout(net->vio, mysql->options.read_timeout);". Therefore specifying different read and write timeout is not possible. */ if ((read_timeout_set || write_timeout_set) && (!read_timeout_set || !write_timeout_set || read_timeout != write_timeout)) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: Specifying different mariadb_read_timeout and mariadb_write_timeout is broken by current version of MariaDB/MySQL client", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } /* MariaDB Connector/C prior to version 2.3.3 has broken zero write timeout. See file libmariadb/violite.c, function vio_write(). Variable vio->write_timeout is signed and on some places zero value is tested as "boolean" and on some as "> 0". Therefore we need to force non-zero timeout, otherwise some operation fail. Maximal possible value is INT_MAX/1000. So use it for simulation of infinite timeout. Also set this timeout when no timeout was provided. */ if ((!read_timeout_set || !write_timeout_set) || write_timeout == 0) { read_timeout = INT_MAX/1000; write_timeout = INT_MAX/1000; mysql_options(sock, MYSQL_OPT_READ_TIMEOUT, (const char *)&read_timeout); mysql_options(sock, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&write_timeout); } } } #endif (void)hv_stores(processed, "mariadb_max_allowed_packet", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_max_allowed_packet", FALSE)) && *svp && SvTRUE(*svp)) { UV uv = SvUV_nomg(*svp); unsigned long packet_size = (uv <= ULONG_MAX ? uv : ULONG_MAX); #if (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50709 && MYSQL_VERSION_ID != 60000) || (defined(MARIADB_VERSION_ID) && MARIADB_VERSION_ID >= 100202) /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in mysql 5.7.9 */ /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in MariaDB 10.2.2 */ mysql_options(sock, MYSQL_OPT_MAX_ALLOWED_PACKET, &packet_size); #else /* before MySQL 5.7.9 and MariaDB 10.2.2 use max_allowed_packet macro */ max_allowed_packet = packet_size; #endif } (void)hv_stores(processed, "mariadb_skip_secure_auth", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_skip_secure_auth", FALSE)) && *svp && SvTRUE(*svp)) { int error = 1; #ifdef HAVE_SECURE_AUTH my_bool secauth = FALSE; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Skipping" " secure auth\n"); error = mysql_options(sock, MYSQL_SECURE_AUTH, &secauth); #endif if (error) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: mariadb_skip_secure_auth=1 is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } (void)hv_stores(processed, "mariadb_read_default_file", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_read_default_file", FALSE)) && *svp && SvTRUE(*svp)) { STRLEN len; char* df = SvPVutf8_nomg(*svp, len); if (strlen(df) != len) { error_nul_character(dbh, "mariadb_read_default_file"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Reading" " default file %s.\n", df); mysql_options(sock, MYSQL_READ_DEFAULT_FILE, df); } (void)hv_stores(processed, "mariadb_read_default_group", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_read_default_group", FALSE)) && *svp && SvTRUE(*svp)) { STRLEN len; char* gr = SvPVutf8_nomg(*svp, len); if (strlen(gr) != len) { error_nul_character(dbh, "mariadb_read_default_group"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Using" " default group %s.\n", gr); mysql_options(sock, MYSQL_READ_DEFAULT_GROUP, gr); } (void)hv_stores(processed, "mariadb_conn_attrs", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_conn_attrs", FALSE)) && *svp) { /* mysql_options4 with MYSQL_OPT_CONNECT_ATTR_ADD is supported by libraries: * MariaDB 10.0.5+ and any MariaDB Connector/C; MySQL 5.6.6+ except MySQL Connector/C 6.0.0 */ #if (defined(MARIADB_BASE_VERSION) && (MYSQL_VERSION_ID >= 100005 || defined(MARIADB_PACKAGE_VERSION))) || (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50606 && MYSQL_VERSION_ID != 60000) HV* attrs = (HV*) SvRV(*svp); HE* entry = NULL; I32 num_entries = hv_iterinit(attrs); while (num_entries && (entry = hv_iternext(attrs))) { I32 attr_name_len = 0; char *attr_name = hv_iterkey(entry, &attr_name_len); SV *sv_attr_val = hv_iterval(attrs, entry); STRLEN attr_val_len; char *attr_val = SvPVutf8(sv_attr_val, attr_val_len); if (strlen(attr_name) != (STRLEN)attr_name_len || strlen(attr_val) != attr_val_len) { error_nul_character(dbh, "mariadb_conn_attrs"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } mysql_options4(sock, MYSQL_OPT_CONNECT_ATTR_ADD, attr_name, attr_val); } #else mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: mariadb_conn_attrs is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; #endif } (void)hv_stores(processed, "mariadb_client_found_rows", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_client_found_rows", FALSE)) && *svp) { if (SvTRUE(*svp)) client_flag |= CLIENT_FOUND_ROWS; else client_flag &= ~CLIENT_FOUND_ROWS; } (void)hv_stores(processed, "mariadb_auto_reconnect", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_auto_reconnect", FALSE)) && *svp) { imp_dbh->auto_reconnect = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->auto_reconnect: %d\n", imp_dbh->auto_reconnect); } (void)hv_stores(processed, "mariadb_use_result", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_use_result", FALSE)) && *svp) { imp_dbh->use_mysql_use_result = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->use_mysql_use_result: %d\n", imp_dbh->use_mysql_use_result ? 1 : 0); } (void)hv_stores(processed, "mariadb_bind_type_guessing", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_bind_type_guessing", FALSE)) && *svp) { imp_dbh->bind_type_guessing= SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->bind_type_guessing: %d\n", imp_dbh->bind_type_guessing); } (void)hv_stores(processed, "mariadb_bind_comment_placeholders", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_bind_comment_placeholders", FALSE)) && *svp) { imp_dbh->bind_comment_placeholders = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->bind_comment_placeholders: %d\n", imp_dbh->bind_comment_placeholders); } (void)hv_stores(processed, "mariadb_no_autocommit_cmd", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_no_autocommit_cmd", FALSE)) && *svp) { imp_dbh->no_autocommit_cmd= SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->no_autocommit_cmd: %d\n", imp_dbh->no_autocommit_cmd); } (void)hv_stores(processed, "mariadb_use_fabric", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_use_fabric", FALSE)) && *svp && SvTRUE(*svp)) { #ifdef HAVE_FABRIC if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->use_fabric: Enabling use of" " MySQL Fabric.\n"); mysql_options(sock, MYSQL_OPT_USE_FABRIC, NULL); #else mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: mariadb_use_fabric is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; #endif } (void)hv_stores(processed, "mariadb_multi_statements", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_multi_statements", FALSE)) && *svp) { if (SvTRUE(*svp)) client_flag |= CLIENT_MULTI_STATEMENTS; else client_flag &= ~CLIENT_MULTI_STATEMENTS; } (void)hv_stores(processed, "mariadb_server_prepare", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_server_prepare", FALSE)) && *svp) imp_dbh->use_server_side_prepare = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->use_server_side_prepare: %d\n", imp_dbh->use_server_side_prepare ? 1 : 0); if (imp_dbh->bind_type_guessing && imp_dbh->use_server_side_prepare) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: mariadb_bind_type_guessing and mariadb_server_prepare cannot be enabled together", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } (void)hv_stores(processed, "mariadb_server_prepare_disable_fallback", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_server_prepare_disable_fallback", FALSE)) && *svp) imp_dbh->disable_fallback_for_server_prepare = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->disable_fallback_for_server_prepare: %d\n", imp_dbh->disable_fallback_for_server_prepare ? 1 : 0); (void)hv_stores(processed, "mariadb_ssl", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_optional", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_verify_server_cert", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_client_key", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_client_cert", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_ca_file", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_ca_path", &PL_sv_yes); (void)hv_stores(processed, "mariadb_ssl_cipher", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_ssl", FALSE)) && *svp && SvTRUE(*svp)) { char *client_key = NULL; char *client_cert = NULL; char *ca_file = NULL; char *ca_path = NULL; char *cipher = NULL; STRLEN len = 0; #if defined(HAVE_SSL_MODE) || defined(HAVE_SSL_MODE_ONLY_REQUIRED) unsigned int ssl_mode; #endif my_bool ssl_enforce = TRUE; my_bool ssl_verify = FALSE; #ifndef HAVE_SSL_MODE my_bool ssl_verify_set = FALSE; #endif if ((svp = hv_fetchs(hv, "mariadb_ssl_optional", FALSE)) && *svp) ssl_enforce = !SvTRUE(*svp); /* Verify if the hostname we connect to matches the hostname in the certificate */ if ((svp = hv_fetchs(hv, "mariadb_ssl_verify_server_cert", FALSE)) && *svp) { #if defined(HAVE_SSL_VERIFY) || defined(HAVE_SSL_MODE) ssl_verify = SvTRUE(*svp); #ifndef HAVE_SSL_MODE ssl_verify_set = TRUE; #endif #else mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_verify_server_cert=1 is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; #endif } if ((svp = hv_fetchs(hv, "mariadb_ssl_client_key", FALSE)) && *svp) { client_key = SvPVutf8(*svp, len); if (strlen(client_key) != len) { error_nul_character(dbh, "mariadb_ssl_client_key"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if ((svp = hv_fetchs(hv, "mariadb_ssl_client_cert", FALSE)) && *svp) { client_cert = SvPVutf8(*svp, len); if (strlen(client_cert) != len) { error_nul_character(dbh, "mariadb_ssl_client_cert"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if ((svp = hv_fetchs(hv, "mariadb_ssl_ca_file", FALSE)) && *svp) { ca_file = SvPVutf8(*svp, len); if (strlen(ca_file) != len) { error_nul_character(dbh, "mariadb_ssl_ca_file"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if ((svp = hv_fetchs(hv, "mariadb_ssl_ca_path", FALSE)) && *svp) { ca_path = SvPVutf8(*svp, len); if (strlen(ca_path) != len) { error_nul_character(dbh, "mariadb_ssl_ca_path"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if ((svp = hv_fetchs(hv, "mariadb_ssl_cipher", FALSE)) && *svp) { cipher = SvPVutf8(*svp, len); if (strlen(cipher) != len) { error_nul_character(dbh, "mariadb_ssl_cipher"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } mysql_ssl_set(sock, client_key, client_cert, ca_file, ca_path, cipher); if (ssl_verify && !(ca_file || ca_path)) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_verify_server_cert=1 is not supported without mariadb_ssl_ca_file or mariadb_ssl_ca_path", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #ifdef HAVE_SSL_MODE if (!ssl_enforce) ssl_mode = SSL_MODE_PREFERRED; else if (ssl_verify) ssl_mode = SSL_MODE_VERIFY_IDENTITY; else if (ca_file || ca_path) ssl_mode = SSL_MODE_VERIFY_CA; else ssl_mode = SSL_MODE_REQUIRED; if (mysql_options(sock, MYSQL_OPT_SSL_MODE, &ssl_mode) != 0) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #else if (ssl_enforce) { #if defined(HAVE_SSL_MODE_ONLY_REQUIRED) ssl_mode = SSL_MODE_REQUIRED; if (mysql_options(sock, MYSQL_OPT_SSL_MODE, &ssl_mode) != 0) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #elif defined(HAVE_SSL_ENFORCE) if (mysql_options(sock, MYSQL_OPT_SSL_ENFORCE, &ssl_enforce) != 0) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #elif defined(HAVE_SSL_VERIFY) if (!ssl_verify_also_enforce_ssl()) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (ssl_verify_set && !ssl_verify) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported without mariadb_ssl_verify_server_cert=1", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } ssl_verify = TRUE; #else mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: Enforcing SSL encryption is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; #endif } #ifdef HAVE_SSL_VERIFY if (!ssl_enforce && ssl_verify && ssl_verify_also_enforce_ssl()) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_optional=1 with mariadb_ssl_verify_server_cert=1 is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #endif if (ssl_verify) { if (!ssl_verify_usable() && ssl_enforce && ssl_verify_set) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_verify_server_cert=1 is broken by current version of MariaDB/MySQL client", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #ifdef HAVE_SSL_VERIFY if (mysql_options(sock, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &ssl_verify) != 0) { mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_verify_server_cert=1 is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } #else mariadb_dr_do_error(dbh, CR_SSL_CONNECTION_ERROR, "SSL connection error: mariadb_ssl_verify_server_cert=1 is not supported", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; #endif } #endif } else { #ifdef HAVE_SSL_MODE unsigned int ssl_mode = SSL_MODE_DISABLED; mysql_options(sock, MYSQL_OPT_SSL_MODE, &ssl_mode); #endif } (void)hv_stores(processed, "mariadb_local_infile", &PL_sv_yes); if ((svp = hv_fetchs(hv, "mariadb_local_infile", FALSE)) && *svp) { unsigned int flag = SvTRUE(*svp); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: Using" " local infile %u.\n", flag); mysql_options(sock, MYSQL_OPT_LOCAL_INFILE, (const char *) &flag); } hv_iterinit(hv); while ((he = hv_iternext(hv)) != NULL) { I32 len; const char *key; key = hv_iterkey(he, &len); if (skip_attribute(key) || hv_exists(processed, key, len)) continue; error_unknown_attribute(dbh, key); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: client_flags = %d\n", client_flag); /* MySQL's "utf8mb4" charset is capable of handling 4-byte UTF-8 characters. MySQL's "utf8" charset is capable of handling only up to 3-byte UTF-8 characters. MySQL's "utf8mb4" charset was introduced in MySQL server version 5.5.3. If MySQL's "utf8mb4" is not supported by server, fallback to MySQL's "utf8". If MySQL's "utf8mb4" is not supported by client, connect with "utf8" and issue SET NAMES 'utf8mb4'. MYSQL_SET_CHARSET_NAME option (prior to establishing connection) sets client's charset. Some clients think that they were connected with MYSQL_SET_CHARSET_NAME, but reality can be different. This problem was reported in MariaDB bug tracker https://jira.mariadb.org/browse/CONC-342 but problem is not going to be fixed. So always manually issue SET NAMES to prevent misbehave. To enable UTF-8 storage on server it is needed to configure it via session variable character_set_server. Some clients provides function get_charset_number() to check if charset is supported. If MySQL client does not support specified charset it used to print error message to stdout or stderr. DBD::MariaDB expects that whole communication with server is encoded in UTF-8. By default broken utf8mb4_general_ci collation is used. So change it to utf8mb4_unicode_ci which is according to the Unicode 4.0.0. */ #ifdef HAVE_GET_CHARSET_NUMBER client_supports_utf8mb4 = get_charset_number("utf8mb4", MY_CS_PRIMARY) ? TRUE : FALSE; #elif MYSQL_VERSION_ID < 50503 client_supports_utf8mb4 = FALSE; #else client_supports_utf8mb4 = TRUE; #endif connected = FALSE; if (client_supports_utf8mb4) { mysql_options(sock, MYSQL_SET_CHARSET_NAME, "utf8mb4"); connected = mysql_real_connect(sock, host, user, password, dbname, port, mysql_socket, client_flag | CLIENT_REMEMBER_OPTIONS) ? TRUE : FALSE; if (!connected && mysql_errno(sock) != CR_CANT_READ_CHARSET) { mariadb_dr_do_error(dbh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock)); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (connected && mysql_get_server_version(sock) < 40100) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: MariaDB or MySQL server version is older than 4.1.0", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if (!connected) { mysql_options(sock, MYSQL_SET_CHARSET_NAME, "utf8"); connected = mysql_real_connect(sock, host, user, password, dbname, port, mysql_socket, client_flag) ? TRUE : FALSE; if (!connected) { mariadb_dr_do_error(dbh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock)); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (mysql_get_server_version(sock) < 40100) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: MariaDB or MySQL server version is older than 4.1.0", "HY000"); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if (mysql_query(sock, "SET NAMES 'utf8mb4'") != 0 || mysql_query(sock, "SET character_set_server = 'utf8mb4'") != 0) { if (mysql_errno(sock) != ER_UNKNOWN_CHARACTER_SET) { mariadb_dr_do_error(dbh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock)); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } if (mysql_query(sock, "SET NAMES 'utf8'") != 0 || mysql_query(sock, "SET character_set_server = 'utf8'") != 0 || mysql_query(sock, "SET collation_connection = 'utf8_unicode_ci'") != 0 || mysql_query(sock, "SET collation_server = 'utf8_unicode_ci'") != 0) { mariadb_dr_do_error(dbh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock)); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } else { if (mysql_query(sock, "SET collation_connection = 'utf8mb4_unicode_ci'") != 0 || mysql_query(sock, "SET collation_server = 'utf8mb4_unicode_ci'") != 0) { mariadb_dr_do_error(dbh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock)); mariadb_db_disconnect(dbh, imp_dbh); return FALSE; } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_dr_connect: <-"); /* we turn off Mysql's auto reconnect and handle re-connecting ourselves so that we can keep track of when this happens. */ #if MYSQL_VERSION_ID >= 50013 { my_bool reconnect = FALSE; mysql_options(sock, MYSQL_OPT_RECONNECT, &reconnect); } #else sock->reconnect = FALSE; #endif imp_dbh->async_query_in_flight = NULL; mariadb_list_add(imp_drh->active_imp_dbhs, imp_dbh->list_entry, imp_dbh); return TRUE; } /* safe_hv_fetch */ static char *safe_hv_fetch(pTHX_ SV *dbh, HV *hv, const char *name, int name_length) { SV **svp; char *str; STRLEN len; svp = hv_fetch(hv, name, name_length, FALSE); if (!svp || !*svp) return NULL; SvGETMAGIC(*svp); if (!SvOK(*svp)) return NULL; str = SvPVutf8_nomg(*svp, len); if (strlen(str) != len) { error_nul_character(dbh, name); return (void *)-1; } return str; } #define safe_hv_fetchs(dbh, hv, name) safe_hv_fetch(aTHX_ (dbh), (hv), "" name "", sizeof((name))-1) /* Frontend for mariadb_dr_connect */ static bool mariadb_db_my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh) { SV* sv; HV* hv; SV **svp; UV port; char* dbname; char* host; char* user; char* password; char* mysql_socket; struct mariadb_list_entry *entry; D_imp_xxh(dbh); D_imp_drh_from_dbh; if (DBIc_has(imp_dbh, DBIcf_IMPSET)) { /* eg from take_imp_data() */ if (DBIc_has(imp_dbh, DBIcf_ACTIVE)) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "mariadb_db_my_login skip connect\n"); /* tell our parent we've adopted an active child */ ++DBIc_ACTIVE_KIDS(DBIc_PARENT_COM(imp_dbh)); for (entry = imp_drh->taken_pmysqls; entry; entry = entry->next) { if ((MYSQL *)entry->data == imp_dbh->pmysql) { /* Remove MYSQL* entry from taken list */ mariadb_list_remove(imp_drh->taken_pmysqls, entry); /* Add imp_dbh entry into active_imp_dbhs list */ mariadb_list_add(imp_drh->active_imp_dbhs, imp_dbh->list_entry, imp_dbh); return TRUE; } } /* This imp_dbh data belongs to different connection, so destructor should not touch it */ imp_dbh->list_entry = NULL; imp_dbh->pmysql = NULL; mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: dbi_imp_data is not valid", "HY000"); return FALSE; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "mariadb_db_my_login IMPSET but not ACTIVE so connect not skipped\n"); } sv = DBIc_IMP_DATA(imp_dbh); if (!sv || !SvROK(sv)) return FALSE; hv = (HV*) SvRV(sv); if (SvTYPE(hv) != SVt_PVHV) return FALSE; host = safe_hv_fetchs(dbh, hv, "host"); if (host == (void *)-1) return FALSE; user = safe_hv_fetchs(dbh, hv, "user"); if (user == (void *)-1) return FALSE; password = safe_hv_fetchs(dbh, hv, "password"); if (password == (void *)-1) return FALSE; dbname = safe_hv_fetchs(dbh, hv, "database"); if (dbname == (void *)-1) return FALSE; mysql_socket = safe_hv_fetchs(dbh, hv, "mariadb_socket"); if (mysql_socket == (void *)-1) return FALSE; port = 0; svp = hv_fetchs(hv, "port", FALSE); if (svp && *svp) { SvGETMAGIC(*svp); if (SvOK(*svp)) { port = SvUV_nomg(*svp); if (port == 0 || port > UINT_MAX) { mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: port is not valid number", "HY000"); return FALSE; } } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->mariadb_db_my_login : dbname = %s, uid = %s, pwd = %s," "host = %s, port = %u\n", dbname ? dbname : "NULL", user ? user : "NULL", !password ? "NULL" : !password[0] ? "" : "****", host ? host : "NULL", (unsigned int)port); return mariadb_dr_connect(dbh, imp_dbh, mysql_socket, host, port, user, password, dbname); } SV *mariadb_db_take_imp_data(SV *dbh, imp_xxh_t *imp_xxh, void *foo) { dTHX; D_imp_dbh(dbh); D_imp_drh_from_dbh; struct mariadb_list_entry *entry; PERL_UNUSED_ARG(imp_xxh); PERL_UNUSED_ARG(foo); /* Add MYSQL* into taken list */ mariadb_list_add(imp_drh->taken_pmysqls, entry, imp_dbh->pmysql); /* MYSQL* was taken from imp_dbh so remove it also from active_imp_dbhs list */ mariadb_list_remove(imp_drh->active_imp_dbhs, imp_dbh->list_entry); return &PL_sv_no; } /************************************************************************** * * Name: mariadb_db_login6_sv * * Purpose: Called for connecting to a database and logging in. * * Input: dbh - database handle being initialized * imp_dbh - drivers private database handle data * dsn - the database we want to log into; may be like * "dbname:host" or "dbname:host:port" * user - user name to connect as * password - password to connect with * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error has already * been called in the latter case * **************************************************************************/ int mariadb_db_login6_sv(SV *dbh, imp_dbh_t *imp_dbh, SV *dsn, SV *user, SV *password, SV *attribs) { dTHX; D_imp_xxh(dbh); PERL_UNUSED_ARG(attribs); SvGETMAGIC(dsn); SvGETMAGIC(user); SvGETMAGIC(password); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "imp_dbh->connect: dsn = %s, uid = %s, pwd = %s\n", SvOK(dsn) ? neatsvpv(dsn, 0) : "NULL", SvOK(user) ? neatsvpv(user, 0) : "NULL", !SvOK(password) ? "NULL" : !(SvPV_nomg_nolen(password))[0] ? "''" : "****"); imp_dbh->stats.auto_reconnects_ok= 0; imp_dbh->stats.auto_reconnects_failed= 0; imp_dbh->bind_type_guessing= FALSE; imp_dbh->bind_comment_placeholders= FALSE; imp_dbh->auto_reconnect = FALSE; imp_dbh->connected = FALSE; /* Will be switched to TRUE after DBI->connect finish */ if (!mariadb_db_my_login(aTHX_ dbh, imp_dbh)) return 0; /* * Tell DBI, that dbh->disconnect should be called for this handle */ DBIc_ACTIVE_on(imp_dbh); /* Tell DBI, that dbh->destroy should be called for this handle */ DBIc_on(imp_dbh, DBIcf_IMPSET); return 1; } static my_ulonglong mariadb_st_internal_execute(SV *h, char *sbuf, STRLEN slen, int num_params, imp_sth_ph_t *params, MYSQL_RES **result, MYSQL **svsock, bool use_mysql_use_result); static my_ulonglong mariadb_st_internal_execute41(SV *h, char *sbuf, STRLEN slen, bool has_params, MYSQL_RES **result, MYSQL_STMT **stmt_ptr, MYSQL_BIND *bind, MYSQL **svsock, bool *has_been_bound); /************************************************************************** * * Name: mariadb_db_do6 * * Purpose: Function for preparing and executing simple statement. * * Input: dbh - database handle being initialized * imp_dbh - drivers private database handle data * statement - query being executed * attribs - statement attributes * items - number of arguments passed to XSUB * ax - stack base offset used by ST() macro * * Returns: -2 for errors, -1 for unknown number of rows, otherwise number * of rows; mariadb_dr_do_error will be called for errors * **************************************************************************/ IV mariadb_db_do6(SV *dbh, imp_dbh_t *imp_dbh, SV *statement_sv, SV *attribs, I32 items, I32 ax) { dTHX; I32 i; my_ulonglong retval; char *statement; STRLEN statement_len; struct imp_sth_ph_st *params = NULL; MYSQL_RES *result = NULL; bool async = FALSE; int next_result_rc; bool failed = FALSE; bool has_been_bound = FALSE; bool use_server_side_prepare = FALSE; bool disable_fallback_for_server_prepare = FALSE; MYSQL_STMT *stmt = NULL; MYSQL_BIND *bind = NULL; STRLEN blen; unsigned long int num_params; unsigned int error; ASYNC_CHECK_RETURN(dbh, -2); if (!imp_dbh->pmysql && !mariadb_db_reconnect(dbh, NULL)) { mariadb_dr_do_error(dbh, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return -2; } SvGETMAGIC(statement_sv); if (items < 0) items = 0; for (i = 0; i < items; i++) { SV *param = ST(i); SvGETMAGIC(param); } (void)hv_stores((HV *)SvRV(dbh), "Statement", SvREFCNT_inc(statement_sv)); statement = SvPVutf8_nomg(statement_sv, statement_len); /* * Globally enabled using of server side prepared statement * for dbh->do() statements. It is possible to force driver * to use server side prepared statement mechanism by adding * 'mariadb_server_prepare' attribute to do() method localy: * $dbh->do($stmt, {mariadb_server_prepare=>1}); */ use_server_side_prepare = imp_dbh->use_server_side_prepare; DBD_ATTRIBS_CHECK("do", dbh, attribs); if (attribs) { HV *hv; HE *he; SV **svp; HV *processed; processed = newHV(); sv_2mortal(newRV_noinc((SV *)processed)); /* Automatically free HV processed */ (void)hv_stores(processed, "mariadb_server_prepare", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_server_prepare"); use_server_side_prepare = svp ? SvTRUE(*svp) : imp_dbh->use_server_side_prepare; (void)hv_stores(processed, "mariadb_server_prepare_disable_fallback", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_server_prepare_disable_fallback"); disable_fallback_for_server_prepare = svp ? SvTRUE(*svp) : imp_dbh->disable_fallback_for_server_prepare; (void)hv_stores(processed, "mariadb_async", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_async"); async = svp ? SvTRUE(*svp) : FALSE; hv = (HV *)SvRV(attribs); hv_iterinit(hv); while ((he = hv_iternext(hv)) != NULL) { I32 len; const char *key; key = hv_iterkey(he, &len); if (hv_exists(processed, key, len)) continue; mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, SvPVX(sv_2mortal(newSVpvf("Unknown attribute %s", key))), "HY000"); return -2; } } if (DBIc_DBISTATE(imp_dbh)->debug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "mysql.xs do() use_server_side_prepare %d\n", use_server_side_prepare ? 1 : 0); if (DBIc_DBISTATE(imp_dbh)->debug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "mysql.xs do() async %d\n", (async ? 1 : 0)); if (async) { if (disable_fallback_for_server_prepare) { mariadb_dr_do_error(dbh, ER_UNSUPPORTED_PS, "Async option not supported with server side prepare", "HY000"); return -2; } use_server_side_prepare = FALSE; /* for now */ imp_dbh->async_query_in_flight = imp_dbh; } while ((next_result_rc = mysql_next_result(imp_dbh->pmysql)) == 0) { result = mysql_store_result(imp_dbh->pmysql); if (!result) { if (mysql_errno(imp_dbh->pmysql)) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return -2; } imp_dbh->insertid = mysql_insert_id(imp_dbh->pmysql); } if (result) { mysql_free_result(result); result = NULL; } } if (next_result_rc > 0) { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif /* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */ error = mysql_errno(imp_dbh->pmysql); if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == CR_UNKNOWN_ERROR) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return -2; } } if (use_server_side_prepare) { stmt = mysql_stmt_init(imp_dbh->pmysql); if (stmt && mysql_stmt_prepare(stmt, statement, statement_len)) { if (mariadb_db_reconnect(dbh, stmt)) { mysql_stmt_close(stmt); stmt = mysql_stmt_init(imp_dbh->pmysql); if (stmt && mysql_stmt_prepare(stmt, statement, statement_len)) failed = TRUE; } else { failed = TRUE; } } if (!stmt) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); retval = (my_ulonglong)-1; } else if (failed) { /* For commands that are not supported by server side prepared statement mechanism lets try to pass them through regular API */ if (!disable_fallback_for_server_prepare && (mysql_stmt_errno(stmt) == ER_UNSUPPORTED_PS || /* And also fallback when placeholder is used in unsupported * construction with old server versions (e.g. LIMIT ?) */ (mysql_stmt_errno(stmt) == ER_PARSE_ERROR && mysql_get_server_version(imp_dbh->pmysql) < 50007 && strstr(mysql_stmt_error(stmt), "'?")))) { use_server_side_prepare = FALSE; } else { mariadb_dr_do_error(dbh, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt)); retval = (my_ulonglong)-1; } mysql_stmt_close(stmt); stmt = NULL; } else { num_params = mysql_stmt_param_count(stmt); if (num_params > INT_MAX) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Statement contains too many placeholders", "HY000"); mysql_stmt_close(stmt); return -2; } else if ((int)num_params != items) { mariadb_dr_do_error(dbh, ER_WRONG_ARGUMENTS, "Wrong number of bind parameters", "HY000"); mysql_stmt_close(stmt); return -2; } if (items > 0) { Newz(0, bind, items, MYSQL_BIND); for (i = 0; i < items; i++) { SV *param = ST(i); if (SvOK(param)) { bind[i].buffer = SvPVutf8_nomg(param, blen); bind[i].buffer_length = blen; bind[i].buffer_type = MYSQL_TYPE_STRING; } else { bind[i].buffer = NULL; bind[i].buffer_length = 0; bind[i].buffer_type = MYSQL_TYPE_NULL; } } } retval = mariadb_st_internal_execute41(dbh, statement, statement_len, !!(items > 0), &result, &stmt, bind, &imp_dbh->pmysql, &has_been_bound); if (bind) Safefree(bind); mysql_stmt_close(stmt); stmt = NULL; if (retval == (my_ulonglong)-1) /* -1 means error */ { SV *err = DBIc_ERR(imp_dbh); if (!disable_fallback_for_server_prepare && SvIV(err) == ER_UNSUPPORTED_PS) { use_server_side_prepare = FALSE; } } } } if (!use_server_side_prepare) { num_params = count_params(imp_dbh, aTHX_ statement, statement_len, imp_dbh->bind_comment_placeholders); if (num_params > INT_MAX || num_params == ULONG_MAX) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Statement contains too many placeholders", "HY000"); return -2; } else if ((int)num_params != items) { mariadb_dr_do_error(dbh, ER_WRONG_ARGUMENTS, "Wrong number of bind parameters", "HY000"); return -2; } if (items > 0) { Newz(0, params, items, struct imp_sth_ph_st); for (i = 0; i < items; i++) { SV *param = ST(i); if (SvOK(param)) params[i].value = SvPVutf8_nomg(param, params[i].len); else params[i].value = NULL; params[i].type = SQL_VARCHAR; } } retval = mariadb_st_internal_execute(dbh, statement, statement_len, items, params, &result, &imp_dbh->pmysql, FALSE); } if (params) Safefree(params); /* Some MySQL client versions return correct value from mysql_insert_id() * function only after non-SELECT operation. So store insert id into dbh * cache and later read it only from cache. */ if (retval != (my_ulonglong)-1 && !async && !result) imp_dbh->insertid = mysql_insert_id(imp_dbh->pmysql); if (result) { mysql_free_result(result); result = NULL; } if (retval != (my_ulonglong)-1 && !async) /* -1 means error */ { /* more results? -1 = no, >0 = error, 0 = yes (keep looping) */ while ((next_result_rc = mysql_next_result(imp_dbh->pmysql)) == 0) { result = mysql_store_result(imp_dbh->pmysql); if (mysql_errno(imp_dbh->pmysql)) { next_result_rc = 1; break; } if (!result) /* Next statement without result set, new insert id */ imp_dbh->insertid = mysql_insert_id(imp_dbh->pmysql); if (result) mysql_free_result(result); result = NULL; } if (next_result_rc > 0) { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif if (DBIc_DBISTATE(imp_dbh)->debug >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "\t<- do() ERROR: %s\n", mysql_error(imp_dbh->pmysql)); mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); retval = (my_ulonglong)-1; } } if (retval == (my_ulonglong)-1) return -2; else if (retval <= IV_MAX) return retval; else return -1; } /*************************************************************************** * * Name: mariadb_db_commit * mariadb_db_rollback * * Purpose: You guess what they should do. * * Input: dbh - database handle being committed or rolled back * imp_dbh - drivers private database handle data * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error has already * been called in the latter case * **************************************************************************/ int mariadb_db_commit(SV* dbh, imp_dbh_t* imp_dbh) { if (DBIc_has(imp_dbh, DBIcf_AutoCommit)) return 0; ASYNC_CHECK_RETURN(dbh, 0); if (!imp_dbh->pmysql) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "No connection to server", "HY000"); return 0; } if (mysql_commit(imp_dbh->pmysql)) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql) ,mysql_sqlstate(imp_dbh->pmysql)); return 0; } return 1; } /* mariadb_db_rollback */ int mariadb_db_rollback(SV* dbh, imp_dbh_t* imp_dbh) { /* report error, if not in AutoCommit mode */ if (DBIc_has(imp_dbh, DBIcf_AutoCommit)) return 0; ASYNC_CHECK_RETURN(dbh, 0); /* No connection to server, nothing to rollback */ if (!imp_dbh->pmysql) return 1; if (mysql_rollback(imp_dbh->pmysql)) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql) ,mysql_sqlstate(imp_dbh->pmysql)); return 0; } return 1; } static void mariadb_dr_close_mysql(pTHX_ imp_drh_t *imp_drh, MYSQL *pmysql) { if (pmysql) { mysql_close(pmysql); imp_drh->instances--; } if (imp_drh->instances == 0) { /* * Some MariaDB and MySQL clients have a bug which cause: * - inability to successfully initialize a new network connection, even after mysql_server_init() * - infinite loop when calling mysql_server_end() more then once in case Embedded server was not started * Therefore do not call mysql_server_end() when Embedded server was not in used. * These bugs were fixed in MariaDB Connector/C 3.0.5, see: https://jira.mariadb.org/browse/CONC-336 * But remains in MariaDB Embedded server, see: https://jira.mariadb.org/browse/MDEV-16578 */ #if !defined(HAVE_BROKEN_INIT) && (defined(HAVE_DEINITIALIZE_SSL) || !defined(HAVE_PROBLEM_WITH_OPENSSL)) if (imp_drh->non_embedded_started) { mysql_server_end(); imp_drh->non_embedded_started = FALSE; } #endif if (imp_drh->embedded_started) { mysql_server_end(); imp_drh->embedded_started = FALSE; #if !defined(HAVE_DEINITIALIZE_SSL) && defined(HAVE_PROBLEM_WITH_OPENSSL) warn("DBD::MariaDB disconnect: Client library deinitialized OpenSSL library functions and module Net::SSLeay is now broken"); #endif } if (imp_drh->embedded_args) { (void)SvREFCNT_dec(imp_drh->embedded_args); imp_drh->embedded_args = NULL; } if (imp_drh->embedded_groups) { (void)SvREFCNT_dec(imp_drh->embedded_groups); imp_drh->embedded_groups = NULL; } } } static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh) { AV *av; I32 i; MAGIC *mg; SV **svp; SV *sv; SV *sth; imp_sth_t *imp_sth; if (DBIc_TRACE_LEVEL(imp_dbh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "\tmariadb_db_close_mysql: imp_dbh=%p pmysql=%p\n", imp_dbh, imp_dbh->pmysql); DBIc_ACTIVE_off(imp_dbh); if (imp_dbh->list_entry) mariadb_list_remove(imp_drh->active_imp_dbhs, imp_dbh->list_entry); if (imp_dbh->pmysql) { mariadb_dr_close_mysql(aTHX_ imp_drh, imp_dbh->pmysql); imp_dbh->pmysql = NULL; svp = hv_fetchs((HV*)DBIc_MY_H(imp_dbh), "ChildHandles", FALSE); if (svp && *svp) { SvGETMAGIC(*svp); if (SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) { av = (AV *)SvRV(*svp); for (i = AvFILL(av); i >= 0; --i) { svp = av_fetch(av, i, FALSE); if (!svp || !*svp || !sv_isobject(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) continue; sv = SvRV(*svp); /* get inner DBI handle (sth) from outer DBI handle (sv) */ if (!SvMAGICAL(sv)) continue; mg = mg_find(sv, 'P'); if (!mg) continue; sth = mg->mg_obj; imp_sth = (imp_sth_t *)DBIh_COM(sth); if (DBIc_TYPE(imp_sth) != DBIt_ST) continue; /* mysql_close() should properly invalidates MYSQL* pointers in * MYSQL_STMT structures. But MariaDB and MySQL clients affected by * CVE 2017-3302 do not do it. So do it manually to prevent crash. */ if (imp_sth->stmt && imp_sth->stmt->mysql) { if (DBIc_TRACE_LEVEL(imp_dbh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_dbh), "Applying CVE 2017-3302 workaround for sth=%p\n", imp_sth); imp_sth->stmt->mysql = NULL; } } } } } } /* *************************************************************************** * * Name: mariadb_db_disconnect * * Purpose: Disconnect a database handle from its database * * Input: dbh - database handle being disconnected * imp_dbh - drivers private database handle data * * Returns: 1 for success (always) * **************************************************************************/ int mariadb_db_disconnect(SV* dbh, imp_dbh_t* imp_dbh) { dTHX; D_imp_drh_from_dbh; PERL_UNUSED_ARG(dbh); /* We assume that disconnect will always work */ /* since most errors imply already disconnected. */ mariadb_db_close_mysql(aTHX_ imp_drh, imp_dbh); /* We don't free imp_dbh since a reference still exists */ /* The DESTROY method is the only one to 'free' memory. */ return 1; } /*************************************************************************** * * Name: mariadb_dr_discon_all * * Purpose: Disconnect all database handles at shutdown time * * Input: dbh - database handle being disconnected * imp_dbh - drivers private database handle data * * Returns: 1 for success, 0 otherwise * **************************************************************************/ int mariadb_dr_discon_all (SV *drh, imp_drh_t *imp_drh) { dTHX; int ret; struct mariadb_list_entry *entry; PERL_UNUSED_ARG(drh); while ((entry = imp_drh->taken_pmysqls)) { mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data); mariadb_list_remove(imp_drh->taken_pmysqls, entry); } while (imp_drh->active_imp_dbhs) mariadb_db_close_mysql(aTHX_ imp_drh, (imp_dbh_t *)imp_drh->active_imp_dbhs->data); ret = 1; if (imp_drh->instances) { warn("DBD::MariaDB disconnect_all: %lu database handlers were not released (possible bug in driver)", imp_drh->instances); ret = 0; } if (imp_drh->embedded_started) { warn("DBD::MariaDB disconnect_all: Embedded server was not properly stopped (possible bug in driver)"); ret = 0; } /* Some MariaDB and MySQL clients with Embedded server support have a bug which cause segfault * when trying to call mysql_server_end() when Embedded server was not started. So do not call * mysql_server_end() for normal connections when we have Embedded server support. */ #ifndef HAVE_EMBEDDED if (imp_drh->non_embedded_started) { #if defined(HAVE_DEINITIALIZE_SSL) || !defined(HAVE_PROBLEM_WITH_OPENSSL) #ifndef HAVE_BROKEN_INIT warn("DBD::MariaDB disconnect_all: Client library was not properly deinitialized (possible bug in driver)"); ret = 0; #else mysql_server_end(); imp_drh->non_embedded_started = FALSE; imp_drh->non_embedded_finished = TRUE; #endif #endif } #endif if (imp_drh->embedded_args) { warn("DBD::MariaDB disconnect_all: mariadb_embedded_options was not released (possible bug in driver)"); ret = 0; } if (imp_drh->embedded_groups) { warn("DBD::MariaDB disconnect_all: mariadb_embedded_groups was not released (possible bug in driver)"); ret = 0; } return ret; } /**************************************************************************** * * Name: mariadb_db_destroy * * Purpose: Our part of the dbh destructor * * Input: dbh - database handle being destroyed * imp_dbh - drivers private database handle data * * Returns: Nothing * **************************************************************************/ void mariadb_db_destroy(SV* dbh, imp_dbh_t* imp_dbh) { /* * Being on the safe side never hurts ... */ if (DBIc_ACTIVE(imp_dbh)) { if (!DBIc_has(imp_dbh, DBIcf_AutoCommit) && imp_dbh->pmysql) if (mysql_rollback(imp_dbh->pmysql)) mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); mariadb_db_disconnect(dbh, imp_dbh); } /* Tell DBI, that dbh->destroy must no longer be called */ DBIc_off(imp_dbh, DBIcf_IMPSET); } /* *************************************************************************** * * Name: mariadb_db_STORE_attrib * * Purpose: Function for storing dbh attributes; we currently support * just nothing. :-) * * Input: dbh - database handle being modified * imp_dbh - drivers private database handle data * keysv - the attribute name * valuesv - the attribute value * * Returns: 1 for success, 0 otherwise * **************************************************************************/ int mariadb_db_STORE_attrib( SV* dbh, imp_dbh_t* imp_dbh, SV* keysv, SV* valuesv ) { dTHX; STRLEN kl; char *key = SvPV(keysv, kl); /* needs to process get magic */ const bool bool_value = SvTRUE_nomg(valuesv); if (!imp_dbh->pmysql && !mariadb_db_reconnect(dbh, NULL)) { mariadb_dr_do_error(dbh, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return 0; } if (memEQs(key, kl, "AutoCommit")) { bool oldval = DBIc_has(imp_dbh, DBIcf_AutoCommit) ? TRUE : FALSE; if (bool_value == oldval) return 1; /* if setting AutoCommit on ... */ if (!imp_dbh->no_autocommit_cmd) { if ( mysql_autocommit(imp_dbh->pmysql, bool_value) ) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return 1; /* 1 means we handled it - important to avoid spurious errors */ } } DBIc_set(imp_dbh, DBIcf_AutoCommit, bool_value); } else if (strBEGINs(key, "mariadb_")) { if (memEQs(key, kl, "mariadb_use_result")) imp_dbh->use_mysql_use_result = bool_value; else if (memEQs(key, kl, "mariadb_auto_reconnect")) imp_dbh->auto_reconnect = bool_value; else if (memEQs(key, kl, "mariadb_server_prepare")) { if (bool_value && imp_dbh->bind_type_guessing) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "mariadb_bind_type_guessing and mariadb_server_prepare cannot be enabled together", "HY000"); return 0; } imp_dbh->use_server_side_prepare = bool_value; } else if (memEQs(key, kl, "mariadb_server_prepare_disable_fallback")) imp_dbh->disable_fallback_for_server_prepare = bool_value; else if (memEQs(key, kl, "mariadb_no_autocommit_cmd")) imp_dbh->no_autocommit_cmd = bool_value; else if (memEQs(key, kl, "mariadb_bind_type_guessing")) { if (bool_value && imp_dbh->use_server_side_prepare) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "mariadb_bind_type_guessing and mariadb_server_prepare cannot be enabled together", "HY000"); return 0; } imp_dbh->bind_type_guessing = bool_value; } else if (memEQs(key, kl, "mariadb_bind_comment_placeholders")) imp_dbh->bind_comment_placeholders = bool_value; #ifdef HAVE_FABRIC else if (memEQs(key, kl, "mariadb_fabric_opt_group")) { STRLEN len; char *str = SvPVutf8_nomg(valuesv, len); if (strlen(str) != len) { error_nul_character(dbh, "mariadb_fabric_opt_group"); return 0; } mysql_options(imp_dbh->pmysql, FABRIC_OPT_GROUP, str); } else if (memEQs(key, kl, "mariadb_fabric_opt_default_mode")) { if (SvOK(valuesv)) { STRLEN len; const char *str = SvPV_nomg(valuesv, len); if (len == 0 || memEQs(str, len, "ro") || memEQs(str, len, "rw")) mysql_options(imp_dbh->pmysql, FABRIC_OPT_DEFAULT_MODE, len == 0 ? NULL : str); else { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Valid settings for FABRIC_OPT_DEFAULT_MODE are 'ro', 'rw', or undef/empty string", "HY000"); return 0; } } else { mysql_options(imp_dbh->pmysql, FABRIC_OPT_DEFAULT_MODE, NULL); } } else if (memEQs(key, kl, "mariadb_fabric_opt_mode")) { STRLEN len; const char *str = SvPV_nomg(valuesv, len); if (!memEQs(str, len, "ro") && !memEQs(str, len, "rw")) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Valid settings for FABRIC_OPT_MODE are 'ro' or 'rw'", "HY000"); return 0; } mysql_options(imp_dbh->pmysql, FABRIC_OPT_MODE, str); } else if (memEQs(key, kl, "mariadb_fabric_opt_group_credentials")) { mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "'fabric_opt_group_credentials' is not supported", "HY000"); return 0; } #endif else if (memEQs(key, kl, "mariadb_max_allowed_packet")) { #if (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50709 && MYSQL_VERSION_ID != 60000) || (defined(MARIADB_VERSION_ID) && MARIADB_VERSION_ID >= 100202) /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in mysql 5.7.9 */ /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in MariaDB 10.2.2 */ UV uv = SvUV_nomg(valuesv); unsigned long packet_size = (uv <= ULONG_MAX ? uv : ULONG_MAX); mysql_options(imp_dbh->pmysql, MYSQL_OPT_MAX_ALLOWED_PACKET, &packet_size); #else /* before MySQL 5.7.9 and MariaDB 10.2.2 it is not possible to change max_allowed_packet after connection was established */ if (imp_dbh->connected) mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Changing mariadb_max_allowed_packet is not supported after connection was established", "HY000"); return 0; #endif } else { if (imp_dbh->connected) /* Ignore unknown attributes passed by DBI->connect, they are handled in mariadb_dr_connect() */ error_unknown_attribute(dbh, key); return 0; } } else { if (!skip_attribute(key)) /* Not handled by this driver */ error_unknown_attribute(dbh, key); return 0; } return 1; } #if IVSIZE < 8 static char * my_ulonglong2str(my_ulonglong val, char *buf, STRLEN *len) { char *ptr = buf + *len - 1; if (*len < 2) { *len = 0; return NULL; } if (val == 0) { buf[0] = '0'; buf[1] = '\0'; *len = 1; return buf; } *ptr = '\0'; while (val > 0) { if (ptr == buf) { *len = 0; return NULL; } *(--ptr) = ('0' + (val % 10)); val = val / 10; } *len = (buf + *len - 1) - ptr; return ptr; } static char* signed_my_ulonglong2str(my_ulonglong val, char *buf, STRLEN *len) { char *ptr; if (val <= (~(my_ulonglong)0 >> 1)) return my_ulonglong2str(val, buf, len); ptr = my_ulonglong2str(-val, buf, len); if (!ptr || ptr == buf) { *len = 0; return NULL; } *(--ptr) = '-'; *len += 1; return ptr; } #endif SV* mariadb_dr_my_ulonglong2sv(pTHX_ my_ulonglong val) { #if IVSIZE >= 8 return newSVuv(val); #else if (val <= UV_MAX) { return newSVuv(val); } else { char buf[64]; STRLEN len = sizeof(buf); char *ptr = my_ulonglong2str(val, buf, &len); return newSVpvn(ptr, len); } #endif } /*************************************************************************** * * Name: mariadb_db_FETCH_attrib * * Purpose: Function for fetching dbh attributes * * Input: dbh - database handle being queried * imp_dbh - drivers private database handle data * keysv - the attribute name * * Returns: An SV*, if successful; NULL otherwise * * Notes: Do not forget to call sv_2mortal in the former case! * **************************************************************************/ SV* mariadb_db_FETCH_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv) { dTHX; STRLEN kl; char *key = SvPV(keysv, kl); /* needs to process get magic */ SV* result = NULL; PERL_UNUSED_ARG(dbh); switch (*key) { case 'A': if (memEQs(key, kl, "AutoCommit")) return sv_2mortal(boolSV(DBIc_has(imp_dbh,DBIcf_AutoCommit))); break; } if (!strBEGINs(key, "mariadb_")) { if (!skip_attribute(key)) /* Not handled by this driver */ error_unknown_attribute(dbh, key); return Nullsv; } else { if (memEQs(key, kl, "mariadb_auto_reconnect")) result = boolSV(imp_dbh->auto_reconnect); else if (memEQs(key, kl, "mariadb_bind_type_guessing")) result = boolSV(imp_dbh->bind_type_guessing); else if (memEQs(key, kl, "mariadb_bind_comment_placeholders")) result = boolSV(imp_dbh->bind_comment_placeholders); else if (memEQs(key, kl, "mariadb_clientinfo")) { const char* clientinfo = mysql_get_client_info(); result = clientinfo ? sv_2mortal(newSVpv(clientinfo, 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_clientversion")) result= sv_2mortal(newSVuv(mysql_get_client_version())); else if (memEQs(key, kl, "mariadb_errno")) result = imp_dbh->pmysql ? sv_2mortal(newSVuv(mysql_errno(imp_dbh->pmysql))) : &PL_sv_undef; else if (memEQs(key, kl, "mariadb_error")) { result = imp_dbh->pmysql ? sv_2mortal(newSVpv(mysql_error(imp_dbh->pmysql), 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_dbd_stats")) { HV* hv = newHV(); result = sv_2mortal((newRV_noinc((SV*)hv))); (void)hv_stores(hv, "auto_reconnects_ok", newSViv(imp_dbh->stats.auto_reconnects_ok)); (void)hv_stores(hv, "auto_reconnects_failed", newSViv(imp_dbh->stats.auto_reconnects_failed)); } else if (memEQs(key, kl, "mariadb_hostinfo")) { const char *hostinfo = imp_dbh->pmysql ? mysql_get_host_info(imp_dbh->pmysql) : NULL; result = hostinfo ? sv_2mortal(newSVpv(hostinfo, 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_info")) { const char *info = imp_dbh->pmysql ? mysql_info(imp_dbh->pmysql) : NULL; result = info ? sv_2mortal(newSVpv(info, 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_insertid")) { /* We cannot return an IV, because the insertid is a long. */ result = sv_2mortal(my_ulonglong2sv(imp_dbh->insertid)); } else if (memEQs(key, kl, "mariadb_max_allowed_packet")) { unsigned long packet_size; #if (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50709 && MYSQL_VERSION_ID != 60000) || (defined(MARIADB_VERSION_ID) && MARIADB_VERSION_ID >= 100202) /* mysql_get_option() is not available in all versions */ /* if we do not have mysql_get_option() we cannot retrieve max_allowed_packet */ /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in mysql 5.7.9 */ /* MYSQL_OPT_MAX_ALLOWED_PACKET was added in MariaDB 10.2.2 */ #ifdef HAVE_GET_OPTION mysql_get_option(imp_dbh->pmysql, MYSQL_OPT_MAX_ALLOWED_PACKET, &packet_size); #else mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Fetching mariadb_max_allowed_packet is not supported", "HY000"); return Nullsv; #endif #else /* before MySQL 5.7.9 and MariaDB 10.2.2 use max_allowed_packet macro */ packet_size = max_allowed_packet; #endif result = sv_2mortal(newSVuv(packet_size)); } else if (memEQs(key, kl, "mariadb_no_autocommit_cmd")) result = boolSV(imp_dbh->no_autocommit_cmd); else if (memEQs(key, kl, "mariadb_protoinfo")) result = imp_dbh->pmysql ? sv_2mortal(newSViv(mysql_get_proto_info(imp_dbh->pmysql))) : &PL_sv_undef; else if (memEQs(key, kl, "mariadb_serverinfo")) { const char *serverinfo = imp_dbh->pmysql ? mysql_get_server_info(imp_dbh->pmysql) : NULL; #ifndef MARIADB_BASE_VERSION /* serverinfo for MariaDB server from MySQL client is prefixed by string 5.5.5- */ if (serverinfo && strBEGINs(serverinfo, "5.5.5-")) serverinfo += sizeof("5.5.5-")-1; #endif result = serverinfo ? sv_2mortal(newSVpv(serverinfo, 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_ssl_cipher")) { #if ((MYSQL_VERSION_ID >= 50023 && MYSQL_VERSION_ID < 50100) || MYSQL_VERSION_ID >= 50111) const char *ssl_cipher = imp_dbh->pmysql ? mysql_get_ssl_cipher(imp_dbh->pmysql) : NULL; result = ssl_cipher ? sv_2mortal(newSVpv(ssl_cipher, 0)) : &PL_sv_undef; sv_utf8_decode(result); #else mariadb_dr_do_error(dbh, CR_UNKNOWN_ERROR, "Fetching mariadb_ssl_cipher is not supported", "HY000"); return Nullsv; #endif } else if (memEQs(key, kl, "mariadb_serverversion")) { #ifndef MARIADB_BASE_VERSION unsigned int major, minor, patch; const char *serverinfo = imp_dbh->pmysql ? mysql_get_server_info(imp_dbh->pmysql) : NULL; /* serverinfo for MariaDB server from MySQL client is prefixed by string 5.5.5- */ if (serverinfo && strBEGINs(serverinfo, "5.5.5-")) { /* And in this case mysql_get_server_version() returns just 50505 and not correct * MariaDB server version. So parse serverversion manually from serverinfo. */ serverinfo += sizeof("5.5.5-")-1; if (sscanf(serverinfo, "%u.%u.%u", &major, &minor, &patch) == 3) result = sv_2mortal(newSVuv(10000UL * major + 100UL * minor + patch)); } #endif if (!result) result = imp_dbh->pmysql ? sv_2mortal(newSVuv(mysql_get_server_version(imp_dbh->pmysql))) : &PL_sv_undef; } else if (memEQs(key, kl, "mariadb_sock")) result = sv_2mortal(newSViv(PTR2IV(imp_dbh->pmysql))); else if (memEQs(key, kl, "mariadb_sockfd")) result = imp_dbh->pmysql ? sv_2mortal(newSViv(imp_dbh->pmysql->net.fd)) : &PL_sv_undef; else if (memEQs(key, kl, "mariadb_stat")) { const char *stats = imp_dbh->pmysql ? mysql_stat(imp_dbh->pmysql) : NULL; result = stats ? sv_2mortal(newSVpv(stats, 0)) : &PL_sv_undef; sv_utf8_decode(result); } else if (memEQs(key, kl, "mariadb_server_prepare")) result = boolSV(imp_dbh->use_server_side_prepare); else if (memEQs(key, kl, "mariadb_server_prepare_disable_fallback")) result = boolSV(imp_dbh->disable_fallback_for_server_prepare); else if (memEQs(key, kl, "mariadb_thread_id")) result = imp_dbh->pmysql ? sv_2mortal(newSVuv(mysql_thread_id(imp_dbh->pmysql))) : &PL_sv_undef; else if (memEQs(key, kl, "mariadb_warning_count")) result = imp_dbh->pmysql ? sv_2mortal(newSVuv(mysql_warning_count(imp_dbh->pmysql))) : &PL_sv_undef; else if (memEQs(key, kl, "mariadb_use_result")) result = boolSV(imp_dbh->use_mysql_use_result); else { error_unknown_attribute(dbh, key); return Nullsv; } } return result; } AV *mariadb_db_data_sources(SV *dbh, imp_dbh_t *imp_dbh, SV *attr) { dTHX; SV *sv; AV *av; SSize_t i; MYSQL_RES *res; MYSQL_ROW row; MYSQL_FIELD* field; my_ulonglong num_rows; unsigned long *lengths; const char *prefix = "DBI:MariaDB:"; const Size_t prefix_len = strlen(prefix); PERL_UNUSED_ARG(attr); ASYNC_CHECK_RETURN(dbh, NULL); if (!imp_dbh->pmysql && !mariadb_db_reconnect(dbh, NULL)) { mariadb_dr_do_error(dbh, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return NULL; } av = newAV(); sv_2mortal((SV *)av); res = mysql_list_dbs(imp_dbh->pmysql, NULL); if (!res && mariadb_db_reconnect(dbh, NULL)) res = mysql_list_dbs(imp_dbh->pmysql, NULL); if (!res) { mariadb_dr_do_error(dbh, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return NULL; } field = mysql_fetch_field(res); if (!field) { mariadb_dr_do_error(dbh, CR_NO_RESULT_SET, "No result list of databases", "HY000"); return NULL; } num_rows = mysql_num_rows(res); if (num_rows == 0) return av; /* av_extend() extends array to size: arg+1 */ --num_rows; /* Truncate list when is too big */ if (num_rows > SSize_t_MAX) num_rows = SSize_t_MAX; av_extend(av, num_rows); i = 0; while ((row = mysql_fetch_row(res))) { if (!row[0]) continue; lengths = mysql_fetch_lengths(res); /* newSV automatically adds extra byte for '\0' and does not set POK */ sv = newSV(prefix_len + lengths[0]); av_store(av, i, sv); memcpy(SvPVX(sv), prefix, prefix_len); memcpy(SvPVX(sv)+prefix_len, row[0], lengths[0]); *(SvPVX(sv)+prefix_len+lengths[0]) = '\0'; SvPOK_on(sv); SvCUR_set(sv, prefix_len + lengths[0]); if (mysql_charsetnr_is_utf8(field->charsetnr)) sv_utf8_decode(sv); if ((my_ulonglong)i == num_rows+1) break; i++; } mysql_free_result(res); return av; } static bool mariadb_st_free_result_sets(SV *sth, imp_sth_t *imp_sth, bool free_last); /* ************************************************************************** * * Name: mariadb_st_prepare_sv * * Purpose: Called for preparing an SQL statement; our part of the * statement handle constructor * * Input: sth - statement handle being initialized * imp_sth - drivers private statement handle data * statement - pointer to string with SQL statement * attribs - statement attributes * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error will * be called in the latter case * **************************************************************************/ int mariadb_st_prepare_sv( SV *sth, imp_sth_t *imp_sth, SV *statement_sv, SV *attribs) { int i; HV *hv; HE *he; SV **svp; HV *processed; char *statement; STRLEN statement_len; dTHX; int prepare_retval; MYSQL_BIND *bind, *bind_end; imp_sth_phb_t *fbind; unsigned long int num_params; D_imp_xxh(sth); D_imp_dbh_from_sth; if (imp_sth->statement) { mariadb_dr_do_error(sth, CR_UNKNOWN_ERROR, "Statement is already prepared", "HY000"); return 0; } if (!imp_dbh->pmysql && !mariadb_db_reconnect(sth, NULL)) { mariadb_dr_do_error(sth, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return 0; } statement = SvPVutf8_nomg(statement_sv, statement_len); imp_sth->statement = savepvn(statement, statement_len); imp_sth->statement_len = statement_len; /* Set default value of 'mariadb_server_prepare' attribute for sth from dbh */ imp_sth->use_mysql_use_result = imp_dbh->use_mysql_use_result; imp_sth->use_server_side_prepare = imp_dbh->use_server_side_prepare; imp_sth->disable_fallback_for_server_prepare = imp_dbh->disable_fallback_for_server_prepare; imp_sth->done_desc = FALSE; imp_sth->result = NULL; imp_sth->currow = 0; imp_sth->row_num = (my_ulonglong)-1; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t-> mariadb_st_prepare_sv MYSQL_VERSION_ID %d, SQL statement: %.1000s%s\n", MYSQL_VERSION_ID, statement, statement_len > 1000 ? "..." : ""); if (attribs) { processed = newHV(); sv_2mortal(newRV_noinc((SV *)processed)); /* Automatically free HV processed */ /* Automatically processed by DBI */ (void)hv_stores(processed, "Slice", &PL_sv_yes); (void)hv_stores(processed, "Columns", &PL_sv_yes); (void)hv_stores(processed, "MaxRows", &PL_sv_yes); (void)hv_stores(processed, "mariadb_server_prepare", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_server_prepare"); imp_sth->use_server_side_prepare = (svp) ? SvTRUE(*svp) : imp_dbh->use_server_side_prepare; (void)hv_stores(processed, "mariadb_server_prepare_disable_fallback", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_server_prepare_disable_fallback"); imp_sth->disable_fallback_for_server_prepare = (svp) ? SvTRUE(*svp) : imp_dbh->disable_fallback_for_server_prepare; (void)hv_stores(processed, "mariadb_async", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_async"); if(svp && SvTRUE(*svp)) { imp_sth->is_async = TRUE; if (imp_sth->disable_fallback_for_server_prepare) { mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "Async option not supported with server side prepare", "HY000"); return 0; } imp_sth->use_server_side_prepare = FALSE; } /* Set default value of 'mariadb_use_result' attribute for sth from dbh */ (void)hv_stores(processed, "mariadb_use_result", &PL_sv_yes); svp = MARIADB_DR_ATTRIB_GET_SVPS(attribs, "mariadb_use_result"); imp_sth->use_mysql_use_result= svp ? SvTRUE(*svp) : imp_dbh->use_mysql_use_result; hv = (HV*) SvRV(attribs); hv_iterinit(hv); while ((he = hv_iternext(hv)) != NULL) { I32 len; const char *key; key = hv_iterkey(he, &len); if (hv_exists(processed, key, len)) continue; error_unknown_attribute(sth, key); return 0; } } for (i= 0; i < AV_ATTRIB_LAST; i++) imp_sth->av_attr[i]= Nullav; /* Clean-up previous result set(s) for sth to prevent 'Commands out of sync' error */ if (!mariadb_st_free_result_sets(sth, imp_sth, TRUE)) return 0; if (imp_sth->use_server_side_prepare) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tuse_server_side_prepare set\n"); imp_sth->stmt= mysql_stmt_init(imp_dbh->pmysql); if (! imp_sth->stmt) { mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return 0; } prepare_retval= mysql_stmt_prepare(imp_sth->stmt, statement, statement_len); if (prepare_retval && mariadb_db_reconnect(sth, imp_sth->stmt)) { mysql_stmt_close(imp_sth->stmt); imp_sth->stmt = mysql_stmt_init(imp_dbh->pmysql); if (!imp_sth->stmt) { mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return 0; } prepare_retval= mysql_stmt_prepare(imp_sth->stmt, statement, statement_len); } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmysql_stmt_prepare returned %d\n", prepare_retval); if (prepare_retval) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmysql_stmt_prepare %d %s\n", mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt)); /* For commands that are not supported by server side prepared statement mechanism lets try to pass them through regular API */ if (!imp_sth->disable_fallback_for_server_prepare && (mysql_stmt_errno(imp_sth->stmt) == ER_UNSUPPORTED_PS || /* And also fallback when placeholder is used in unsupported * construction with old server versions (e.g. LIMIT ?) */ (mysql_stmt_errno(imp_sth->stmt) == ER_PARSE_ERROR && mysql_get_server_version(imp_dbh->pmysql) < 50007 && strstr(mysql_stmt_error(imp_sth->stmt), "'?")))) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tSETTING imp_sth->use_server_side_prepare to FALSE\n"); mysql_stmt_close(imp_sth->stmt); imp_sth->stmt = NULL; imp_sth->use_server_side_prepare = FALSE; } else { mariadb_dr_do_error(sth, mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt), mysql_sqlstate(imp_dbh->pmysql)); mysql_stmt_close(imp_sth->stmt); imp_sth->stmt= NULL; return 0; } } else { num_params = mysql_stmt_param_count(imp_sth->stmt); if (num_params > INT_MAX) { mariadb_dr_do_error(sth, CR_UNKNOWN_ERROR, "Prepared statement contains too many placeholders", "HY000"); mysql_stmt_close(imp_sth->stmt); imp_sth->stmt = NULL; return 0; } DBIc_NUM_PARAMS(imp_sth) = num_params; if (DBIc_NUM_PARAMS(imp_sth) > 0) { /* Allocate memory for bind variables */ imp_sth->bind= alloc_bind(DBIc_NUM_PARAMS(imp_sth)); imp_sth->fbind= alloc_fbind(DBIc_NUM_PARAMS(imp_sth)); imp_sth->has_been_bound = FALSE; /* Initialize ph variables with NULL values */ for (i= 0, bind= imp_sth->bind, fbind= imp_sth->fbind, bind_end= bind+DBIc_NUM_PARAMS(imp_sth); bind < bind_end ; bind++, fbind++, i++ ) { bind->buffer_type= MYSQL_TYPE_STRING; bind->buffer= NULL; bind->length= &(fbind->length); bind->is_null= &(fbind->is_null); fbind->is_null= TRUE; fbind->length= 0; } } } } /* Count the number of parameters (driver, vs server-side) */ if (!imp_sth->use_server_side_prepare) { num_params = count_params(imp_dbh, aTHX_ statement, statement_len, imp_dbh->bind_comment_placeholders); if (num_params > INT_MAX || num_params == ULONG_MAX) { mariadb_dr_do_error(sth, CR_UNKNOWN_ERROR, "Prepared statement contains too many placeholders", "HY000"); mysql_stmt_close(imp_sth->stmt); imp_sth->stmt = NULL; return 0; } DBIc_NUM_PARAMS(imp_sth) = num_params; } /* Allocate memory for parameters */ if (DBIc_NUM_PARAMS(imp_sth) > 0) imp_sth->params = alloc_param(DBIc_NUM_PARAMS(imp_sth)); DBIc_IMPSET_on(imp_sth); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_prepare_sv\n"); return 1; } /*************************************************************************** * Name: mariadb_st_free_result_sets * * Purpose: Clean-up single or multiple result sets (if any) * * Inputs: sth - Statement handle * imp_sth - driver's private statement handle * free_last - free also the last result set * * Returns: TRUE ok * FALSE error; mariadb_dr_do_error will be called *************************************************************************/ static bool mariadb_st_free_result_sets(SV *sth, imp_sth_t *imp_sth, bool free_last) { dTHX; D_imp_dbh_from_sth; D_imp_xxh(sth); int next_result_rc= -1; unsigned int error; /* No connection, nothing to clean, no error */ if (!imp_dbh->pmysql) return TRUE; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t>- mariadb_st_free_result_sets\n"); do { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_free_result_sets RC %d\n", next_result_rc); if (next_result_rc == 0) { if (!(imp_sth->result = mysql_store_result(imp_dbh->pmysql))) { /* Check for possible error */ if (mysql_errno(imp_dbh->pmysql)) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_free_result_sets ERROR: %s\n", mysql_error(imp_dbh->pmysql)); mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return FALSE; } imp_dbh->insertid = imp_sth->insertid = mysql_insert_id(imp_dbh->pmysql); } } if (imp_sth->result && (mysql_more_results(imp_dbh->pmysql) || free_last)) { mysql_free_result(imp_sth->result); imp_sth->result=NULL; } } while ((next_result_rc=mysql_next_result(imp_dbh->pmysql))==0); if (next_result_rc > 0) { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_free_result_sets: Error while processing multi-result set: %s\n", mysql_error(imp_dbh->pmysql)); /* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */ error = mysql_errno(imp_dbh->pmysql); if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == CR_UNKNOWN_ERROR) { mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return FALSE; } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_free_result_sets\n"); return TRUE; } /*************************************************************************** * Name: mariadb_st_more_results * * Purpose: Move onto the next result set (if any) * * Inputs: sth - Statement handle * imp_sth - driver's private statement handle * * Returns: TRUE if there are more results sets * FALSE if there are not *************************************************************************/ bool mariadb_st_more_results(SV* sth, imp_sth_t* imp_sth) { dTHX; D_imp_dbh_from_sth; D_imp_xxh(sth); bool use_mysql_use_result = imp_sth->use_mysql_use_result; int next_result_return_code, i; if (!SvROK(sth) || SvTYPE(SvRV(sth)) != SVt_PVHV) croak("Expected hash array"); if (imp_sth->use_server_side_prepare) { mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "Processing of multiple result set is not possible with server side prepare", "HY000"); return FALSE; } if (imp_dbh->async_query_in_flight && imp_dbh->async_query_in_flight != imp_sth) { mariadb_dr_do_error(sth, CR_UNKNOWN_ERROR, "Gathering async_query_in_flight results for the wrong handle", "HY000"); return FALSE; } imp_dbh->async_query_in_flight = NULL; DBIc_ACTIVE_off(imp_sth); if (!imp_dbh->pmysql && !mariadb_db_reconnect(sth, NULL)) { mariadb_dr_do_error(sth, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return FALSE; } if (!mysql_more_results(imp_dbh->pmysql)) { /* No more pending result set(s)*/ if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\n <- mariadb_st_more_results no more results\n"); return FALSE; } /* * Free cached array attributes */ for (i= 0; i < AV_ATTRIB_LAST; i++) { if (imp_sth->av_attr[i]) SvREFCNT_dec(imp_sth->av_attr[i]); imp_sth->av_attr[i]= Nullav; } /* Release previous MySQL result*/ if (imp_sth->result) { mysql_free_result(imp_sth->result); imp_sth->result= NULL; } imp_sth->done_desc = FALSE; imp_sth->currow = 0; imp_sth->row_num = (my_ulonglong)-1; /* clear NUM_OF_FIELDS attribute */ DBIc_DBISTATE(imp_sth)->set_attr_k(sth, sv_2mortal(newSVpvs("NUM_OF_FIELDS")), 0, sv_2mortal(newSViv(0))); /* delete cached handle attributes */ /* XXX should be driven by a list to ease maintenance */ (void)hv_deletes((HV*)SvRV(sth), "NAME", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "NULLABLE", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "NUM_OF_FIELDS", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "PRECISION", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "SCALE", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "TYPE", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_insertid", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_is_auto_increment", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_is_blob", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_is_key", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_is_num", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_is_pri_key", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_length", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_max_length", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_table", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_type", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_type_name", G_DISCARD); (void)hv_deletes((HV*)SvRV(sth), "mariadb_warning_count", G_DISCARD); next_result_return_code= mysql_next_result(imp_dbh->pmysql); imp_sth->warning_count = mysql_warning_count(imp_dbh->pmysql); /* mysql_next_result returns 0 if there are more results -1 if there are no more results >0 if there was an error */ if (next_result_return_code > 0) { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return FALSE; } else if(next_result_return_code == -1) { return FALSE; } else { /* Store the result from the Query */ imp_sth->result = use_mysql_use_result ? mysql_use_result(imp_dbh->pmysql) : mysql_store_result(imp_dbh->pmysql); if (mysql_errno(imp_dbh->pmysql)) { mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); return FALSE; } if (imp_sth->result == NULL) { imp_sth->row_num = mysql_affected_rows(imp_dbh->pmysql); imp_dbh->insertid = imp_sth->insertid = mysql_insert_id(imp_dbh->pmysql); if (mysql_more_results(imp_dbh->pmysql)) DBIc_ACTIVE_on(imp_sth); } else { /* We have a new rowset */ imp_sth->row_num = mysql_num_rows(imp_sth->result); /* Adjust NUM_OF_FIELDS - which also adjusts the row buffer size */ DBIc_DBISTATE(imp_sth)->set_attr_k(sth, sv_2mortal(newSVpvs("NUM_OF_FIELDS")), 0, sv_2mortal(newSVuv(mysql_num_fields(imp_sth->result))) ); if (imp_sth->row_num) DBIc_ACTIVE_on(imp_sth); } if (imp_sth->is_async && mysql_more_results(imp_dbh->pmysql)) imp_dbh->async_query_in_flight = imp_sth; imp_dbh->pmysql->net.last_errno= 0; return TRUE; } } /************************************************************************** * * Name: mariadb_st_internal_execute * * Purpose: Internal version for executing a statement, called both from * within the "do" and the "execute" method. * * Inputs: h - object handle, for storing error messages * statement - query being executed * attribs - statement attributes, currently ignored * num_params - number of parameters being bound * params - parameter array * result - where to store results, if any * svsock - socket connected to the database * **************************************************************************/ static my_ulonglong mariadb_st_internal_execute( SV *h, /* could be sth or dbh */ char *sbuf, STRLEN slen, int num_params, imp_sth_ph_t *params, MYSQL_RES **result, MYSQL **svsock, bool use_mysql_use_result ) { dTHX; bool bind_type_guessing= FALSE; bool bind_comment_placeholders= TRUE; char *salloc; int htype; bool async = FALSE; my_ulonglong rows= 0; /* thank you DBI.c for this info! */ D_imp_xxh(h); htype= DBIc_TYPE(imp_xxh); /* It is important to import imp_dbh properly according to the htype that it is! Also, one might ask why bind_type_guessing is assigned in each block. Well, it's because D_imp_ macros called in these blocks make it so imp_dbh is not "visible" or defined outside of the if/else (when compiled, it fails for imp_dbh not being defined). */ /* h is a dbh */ if (htype == DBIt_DB) { D_imp_dbh(h); /* if imp_dbh is not available, it causes segfault (proper) on OpenBSD */ if (imp_dbh) { bind_type_guessing= imp_dbh->bind_type_guessing; bind_comment_placeholders= imp_dbh->bind_comment_placeholders; } async = imp_dbh->async_query_in_flight ? TRUE : FALSE; } /* h is a sth */ else { D_imp_sth(h); D_imp_dbh_from_sth; /* if imp_dbh is not available, it causes segfault (proper) on OpenBSD */ if (imp_dbh) { bind_type_guessing= imp_dbh->bind_type_guessing; bind_comment_placeholders= imp_dbh->bind_comment_placeholders; } async = imp_sth->is_async; imp_dbh->async_query_in_flight = async ? imp_sth : NULL; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "mariadb_st_internal_execute MYSQL_VERSION_ID %d\n", MYSQL_VERSION_ID ); if (!*svsock && !mariadb_db_reconnect(h, NULL)) { mariadb_dr_do_error(h, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return -1; } salloc= parse_params(imp_xxh, aTHX_ *svsock, sbuf, &slen, params, num_params, bind_type_guessing, bind_comment_placeholders); if (salloc) { sbuf= salloc; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "Binding parameters: %.1000s%s\n", sbuf, slen > 1000 ? "..." : ""); } if(async) { if((mysql_send_query(*svsock, sbuf, slen)) && (!mariadb_db_reconnect(h, NULL) || (mysql_send_query(*svsock, sbuf, slen)))) { rows = -1; } else { rows = 0; } } else { if ((mysql_real_query(*svsock, sbuf, slen)) && (!mariadb_db_reconnect(h, NULL) || (mysql_real_query(*svsock, sbuf, slen)))) { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ (*svsock)->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif rows = -1; } else { /** Store the result from the Query */ *result= use_mysql_use_result ? mysql_use_result(*svsock) : mysql_store_result(*svsock); if (mysql_errno(*svsock)) rows = -1; else if (*result) rows = mysql_num_rows(*result); else { rows = mysql_affected_rows(*svsock); } } } if (salloc) Safefree(salloc); if (rows == (my_ulonglong)-1) mariadb_dr_do_error(h, mysql_errno(*svsock), mysql_error(*svsock), mysql_sqlstate(*svsock)); return(rows); } /************************************************************************** * * Name: mariadb_st_internal_execute41 * * Purpose: Internal version for executing a prepared statement, called both * from within the "do" and the "execute" method. * MYSQL 4.1 API * * * Inputs: h - object handle, for storing error messages * statement - query being executed * attribs - statement attributes, currently ignored * has_params - non-zero parameters being bound * params - parameter array * result - where to store results, if any * svsock - socket connected to the database * **************************************************************************/ static my_ulonglong mariadb_st_internal_execute41( SV *h, char *sbuf, STRLEN slen, bool has_params, MYSQL_RES **result, MYSQL_STMT **stmt_ptr, MYSQL_BIND *bind, MYSQL **svsock, bool *has_been_bound ) { dTHX; int store_retval; int execute_retval; unsigned int i, num_fields; MYSQL_STMT *stmt = *stmt_ptr; my_ulonglong rows=0; bool reconnected = FALSE; D_imp_xxh(h); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t-> mariadb_st_internal_execute41\n"); /* free result if exists */ if (*result) { mysql_free_result(*result); *result = NULL; } if (!*svsock) { if (!mariadb_db_reconnect(h, NULL)) { mariadb_dr_do_error(h, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return -1; } reconnected = TRUE; } /* If were performed any changes with ph variables we have to rebind them */ if (!reconnected && has_params && !(*has_been_bound)) { if (mysql_stmt_bind_param(stmt,bind) == 0) { *has_been_bound = TRUE; } else { if (!mariadb_db_reconnect(h, stmt)) goto error; reconnected = TRUE; } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_internal_execute41 calling mysql_execute\n"); if (!reconnected) { execute_retval = mysql_stmt_execute(stmt); if (execute_retval && mariadb_db_reconnect(h, stmt)) reconnected = TRUE; } if (reconnected) { *has_been_bound = FALSE; stmt = mysql_stmt_init(*svsock); if (!stmt) { mariadb_dr_do_error(h, mysql_errno(*svsock), mysql_error(*svsock), mysql_sqlstate(*svsock)); return -1; } if (mysql_stmt_prepare(stmt, sbuf, slen)) { mariadb_dr_do_error(h, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt)); mysql_stmt_close(stmt); return -1; } mysql_stmt_close(*stmt_ptr); *stmt_ptr = stmt; if (has_params) { if (mysql_stmt_bind_param(stmt,bind)) goto error; *has_been_bound = TRUE; } execute_retval= mysql_stmt_execute(stmt); } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmysql_stmt_execute returned %d\n", execute_retval); if (execute_retval) goto error; /* This statement does not return a result set (INSERT, UPDATE...) */ if (!(*result= mysql_stmt_result_metadata(stmt))) { if (mysql_stmt_errno(stmt)) goto error; rows= mysql_stmt_affected_rows(stmt); /* mysql_stmt_affected_rows(): -1 indicates that the query returned an error */ if (rows == (my_ulonglong)-1) goto error; } /* This statement returns a result set (SELECT...) */ else { num_fields = mysql_stmt_field_count(stmt); for (i = 0; i < num_fields; ++i) { MYSQL_FIELD *field = mysql_fetch_field_direct(*result, i); if (field && mysql_field_needs_allocated_buffer(field)) { /* mysql_stmt_store_result to update MYSQL_FIELD->max_length */ my_bool on = TRUE; mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &on); break; } } store_retval = mysql_stmt_store_result(stmt); if (store_retval) goto error; /* Get the total rows affected and return */ rows = mysql_stmt_num_rows(stmt); } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mysql_internal_execute_41 returning %" SVf " rows\n", SVfARG(sv_2mortal(my_ulonglong2sv(rows)))); return(rows); error: if (*result) { mysql_free_result(*result); *result = NULL; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " errno %d err message %s\n", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); mariadb_dr_do_error(h, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt)); mysql_stmt_reset(stmt); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_internal_execute41\n"); return -1; } /*************************************************************************** * * Name: mariadb_st_execute_iv * * Purpose: Called for preparing an SQL statement; our part of the * statement handle constructor * * Input: sth - statement handle being initialized * imp_sth - drivers private statement handle data * * Returns: -2 for errors, -1 for unknown number of rows, otherwise number * of rows; mariadb_dr_do_error will be called for errors * **************************************************************************/ IV mariadb_st_execute_iv(SV* sth, imp_sth_t* imp_sth) { dTHX; int i; unsigned int num_fields; D_imp_dbh_from_sth; D_imp_xxh(sth); bool use_server_side_prepare = imp_sth->use_server_side_prepare; bool disable_fallback_for_server_prepare = imp_sth->disable_fallback_for_server_prepare; ASYNC_CHECK_RETURN(sth, -2); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " -> mariadb_st_execute_iv for %p\n", sth); if (!SvROK(sth) || SvTYPE(SvRV(sth)) != SVt_PVHV) croak("Expected hash array"); for (i = 0; i < DBIc_NUM_PARAMS(imp_sth); ++i) { if (!imp_sth->params[i].bound) { mariadb_dr_do_error(sth, ER_WRONG_ARGUMENTS, "Wrong number of bind parameters", "HY000"); return -2; } } /* Free cached array attributes */ for (i= 0; i < AV_ATTRIB_LAST; i++) { if (imp_sth->av_attr[i]) SvREFCNT_dec(imp_sth->av_attr[i]); imp_sth->av_attr[i]= Nullav; } /* Clean-up previous result set(s) for sth to prevent 'Commands out of sync' error */ if (!mariadb_st_free_result_sets(sth, imp_sth, TRUE)) return -2; imp_sth->currow = 0; if (use_server_side_prepare) { if (imp_sth->use_mysql_use_result) { if (disable_fallback_for_server_prepare) { mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "\"mariadb_use_result\" not supported with server side prepare", "HY000"); return -2; } use_server_side_prepare = FALSE; } if (use_server_side_prepare) { imp_sth->row_num= mariadb_st_internal_execute41( sth, imp_sth->statement, imp_sth->statement_len, !!(DBIc_NUM_PARAMS(imp_sth) > 0), &imp_sth->result, &imp_sth->stmt, imp_sth->bind, &imp_dbh->pmysql, &imp_sth->has_been_bound ); if (imp_sth->row_num == (my_ulonglong)-1) /* -1 means error */ { SV *err = DBIc_ERR(imp_xxh); if (!disable_fallback_for_server_prepare && SvIV(err) == ER_UNSUPPORTED_PS) { use_server_side_prepare = FALSE; } } } } if (!use_server_side_prepare) { imp_sth->row_num= mariadb_st_internal_execute( sth, imp_sth->statement, imp_sth->statement_len, DBIc_NUM_PARAMS(imp_sth), imp_sth->params, &imp_sth->result, &imp_dbh->pmysql, imp_sth->use_mysql_use_result ); if(imp_dbh->async_query_in_flight) { DBIc_ACTIVE_on(imp_sth); return 0; } } if (imp_sth->row_num != (my_ulonglong)-1) { if (!imp_sth->result) { /* Some MySQL client versions return correct value from mysql_insert_id() * function only after non-SELECT operation. So store insert id into dbh * cache and later read it only from cache. */ imp_dbh->insertid = imp_sth->insertid = mysql_insert_id(imp_dbh->pmysql); if (mysql_more_results(imp_dbh->pmysql)) DBIc_ACTIVE_on(imp_sth); } else { /** Store the result in the current statement handle */ num_fields = mysql_num_fields(imp_sth->result); DBIc_NUM_FIELDS(imp_sth) = (num_fields <= INT_MAX) ? num_fields : INT_MAX; if (imp_sth->row_num) DBIc_ACTIVE_on(imp_sth); if (!use_server_side_prepare) imp_sth->done_desc = FALSE; } } imp_sth->warning_count = mysql_warning_count(imp_dbh->pmysql); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), " <- mariadb_st_execute_iv returning imp_sth->row_num %" SVf "\n", SVfARG(sv_2mortal(my_ulonglong2sv(imp_sth->row_num)))); } if (imp_sth->row_num == (my_ulonglong)-1) return -2; /* -2 is error */ else if (imp_sth->row_num <= IV_MAX) return imp_sth->row_num; else /* overflow */ return -1; /* -1 is unknown number of rows */ } /************************************************************************** * * Name: mariadb_st_describe * * Purpose: Called from within the fetch method to describe the result * * Input: sth - statement handle being initialized * imp_sth - our part of the statement handle, there's no * need for supplying both; Tim just doesn't remove it * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error will * be called in the latter case * **************************************************************************/ static int mariadb_st_describe(SV* sth, imp_sth_t* imp_sth) { dTHX; D_imp_xxh(sth); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t--> mariadb_st_describe\n"); if (imp_sth->done_desc) return 1; if (imp_sth->use_server_side_prepare) { int i; int num_fields= DBIc_NUM_FIELDS(imp_sth); imp_sth_fbh_t *fbh; MYSQL_BIND *buffer; MYSQL_FIELD *fields; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_describe() num_fields %d\n", num_fields); if (num_fields <= 0 || !imp_sth->result) { /* no metadata */ mariadb_dr_do_error(sth, CR_NO_STMT_METADATA, "Prepared statement contains no metadata", "HY000"); return 0; } /* allocate fields buffers */ if ( !(imp_sth->fbh= alloc_fbuffer(num_fields)) || !(imp_sth->buffer= alloc_bind(num_fields)) ) { /* Out of memory */ mariadb_dr_do_error(sth, CR_OUT_OF_MEMORY, "Out of memory in mariadb_st_describe()", "HY000"); return 0; } fields= mysql_fetch_fields(imp_sth->result); for ( fbh= imp_sth->fbh, buffer= (MYSQL_BIND*)imp_sth->buffer, i= 0; i < num_fields; i++, fbh++, buffer++ ) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh),"\t\ti %d fbh->length %lu\n", i, fbh->length); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tfields[i].length %lu fields[i].max_length %lu fields[i].type %d fields[i].flags %d fields[i].charsetnr %d\n", fields[i].length, fields[i].max_length, fields[i].type, fields[i].flags, fields[i].charsetnr); } fbh->is_utf8 = mysql_charsetnr_is_utf8(fields[i].charsetnr); buffer->buffer_type= fields[i].type; buffer->is_unsigned= (fields[i].flags & UNSIGNED_FLAG) ? TRUE : FALSE; buffer->length= &(fbh->length); buffer->is_null= &(fbh->is_null); #if MYSQL_VERSION_ID >= NEW_DATATYPE_VERSION buffer->error= &(fbh->error); #endif if (mysql_field_needs_string_type(&fields[i])) buffer->buffer_type = MYSQL_TYPE_STRING; switch (buffer->buffer_type) { case MYSQL_TYPE_NULL: buffer->buffer_length= 0; buffer->buffer= NULL; case MYSQL_TYPE_TINY: buffer->buffer_length= sizeof(fbh->numeric_val.tval); buffer->buffer= (char*) &fbh->numeric_val.tval; break; case MYSQL_TYPE_SHORT: buffer->buffer_length= sizeof(fbh->numeric_val.sval); buffer->buffer= (char*) &fbh->numeric_val.sval; break; case MYSQL_TYPE_LONG: buffer->buffer_length= sizeof(fbh->numeric_val.lval); buffer->buffer= (char*) &fbh->numeric_val.lval; break; case MYSQL_TYPE_LONGLONG: buffer->buffer_length= sizeof(fbh->numeric_val.llval); buffer->buffer= (char*) &fbh->numeric_val.llval; break; case MYSQL_TYPE_FLOAT: buffer->buffer_length= sizeof(fbh->numeric_val.fval); buffer->buffer= (char*) &fbh->numeric_val.fval; break; case MYSQL_TYPE_DOUBLE: buffer->buffer_length= sizeof(fbh->numeric_val.dval); buffer->buffer= (char*) &fbh->numeric_val.dval; break; /* TODO: datetime structures */ #if 0 case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: break; #endif default: if (buffer->buffer_type != MYSQL_TYPE_BLOB) buffer->buffer_type= MYSQL_TYPE_STRING; buffer->buffer_length= fields[i].max_length ? fields[i].max_length : 1; Newz(908, fbh->data, buffer->buffer_length, char); buffer->buffer= (char *) fbh->data; break; } } if (mysql_stmt_bind_result(imp_sth->stmt, imp_sth->buffer)) { mariadb_dr_do_error(sth, mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt), mysql_stmt_sqlstate(imp_sth->stmt)); return 0; } } imp_sth->done_desc = TRUE; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_describe\n"); return 1; } /************************************************************************** * * Name: mariadb_st_fetch * * Purpose: Called for fetching a result row * * Input: sth - statement handle being initialized * imp_sth - drivers private statement handle data * * Returns: array of columns; the array is allocated by DBI via * DBIc_DBISTATE(imp_sth)->get_fbav(imp_sth), even the values * of the array are prepared, we just need to modify them * appropriately * **************************************************************************/ AV* mariadb_st_fetch(SV *sth, imp_sth_t* imp_sth) { dTHX; bool ChopBlanks; int rc; unsigned int i, num_fields; unsigned long *lengths; AV *av; unsigned int av_length; bool av_readonly; MYSQL_ROW cols; D_imp_dbh_from_sth; imp_sth_fbh_t *fbh; D_imp_xxh(sth); MYSQL_BIND *buffer; IV int_val; const char *int_type; MYSQL_FIELD *fields; bool rebind_result; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t-> mariadb_st_fetch\n"); if (!imp_dbh->pmysql) { mariadb_dr_do_error(sth, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return Nullav; } if (imp_dbh->async_query_in_flight) { if (!DBIc_ACTIVE(imp_sth)) return Nullav; if (mariadb_db_async_result(sth, &imp_sth->result) == (my_ulonglong)-1) return Nullav; } else { if (!imp_sth->result) { mariadb_dr_do_error(sth, CR_UNKNOWN_ERROR, "fetch() without execute()", "HY000"); return Nullav; } if (!DBIc_ACTIVE(imp_sth)) return Nullav; } ChopBlanks = DBIc_is(imp_sth, DBIcf_ChopBlanks) ? TRUE : FALSE; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_fetch for %p, chopblanks %d\n", sth, ChopBlanks ? 1 : 0); /* fix from 2.9008 */ imp_dbh->pmysql->net.last_errno = 0; if (imp_sth->use_server_side_prepare) { if (!mariadb_st_describe(sth, imp_sth)) return Nullav; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_fetch calling mysql_stmt_fetch\n"); if ((rc= mysql_stmt_fetch(imp_sth->stmt))) { #if MYSQL_VERSION_ID >= 50003 if (rc == MYSQL_DATA_TRUNCATED) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_fetch data truncated\n"); goto process; } #endif if (rc == MYSQL_NO_DATA) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_fetch no data\n"); } else if (rc == 1) { mariadb_dr_do_error(sth, mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt), mysql_stmt_sqlstate(imp_sth->stmt)); } DBIc_ACTIVE_off(imp_sth); return Nullav; } process: imp_sth->currow++; if (imp_sth->currow >= imp_sth->row_num) DBIc_ACTIVE_off(imp_sth); av= DBIc_DBISTATE(imp_sth)->get_fbav(imp_sth); num_fields=mysql_stmt_field_count(imp_sth->stmt); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tmariadb_st_fetch called mysql_fetch, rc %d num_fields %u\n", rc, num_fields); rebind_result = FALSE; for ( buffer= imp_sth->buffer, fbh= imp_sth->fbh, i= 0; i < num_fields; i++, fbh++, buffer++ ) { /* In case of BLOB/TEXT fields we allocate only few bytes in mariadb_st_describe() for data. Here we know real size of field so we should increase buffer size and refetch column value */ if (!fbh->is_null && mysql_type_needs_allocated_buffer(buffer->buffer_type) && (fbh->length > buffer->buffer_length || fbh->error)) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tRefetch BLOB/TEXT column: %d, length: %lu, error: %d\n", i, fbh->length, fbh->error ? 1 : 0); Renew(fbh->data, fbh->length, char); buffer->buffer_length= fbh->length; buffer->buffer= (char *) fbh->data; /* We invalidated fbh->data, therefore we must call mysql_stmt_bind_result() * prior exiting this function. But we cannot call mysql_stmt_bind_result() * before all remaining mysql_stmt_fetch_column() calls because we would get * again truncated data. */ rebind_result = TRUE; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { char *ptr = (char*)buffer->buffer; unsigned long int j, m; m = buffer->buffer_length; if (m > *buffer->length) m = *buffer->length; PerlIO_printf(DBIc_LOGPIO(imp_xxh),"\t\tbefore buffer->buffer: "); for (j = 0; j < m; j++) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "%c", *ptr++); } PerlIO_printf(DBIc_LOGPIO(imp_xxh),"\n"); } /*TODO: Use offset instead of 0 to fetch only remain part of data*/ if (mysql_stmt_fetch_column(imp_sth->stmt, buffer , i, 0)) { mariadb_dr_do_error(sth, mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt), mysql_stmt_sqlstate(imp_sth->stmt)); mysql_stmt_bind_result(imp_sth->stmt, imp_sth->buffer); return Nullav; } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { char *ptr = (char*)buffer->buffer; unsigned long int j, m; m = buffer->buffer_length; if (m > *buffer->length) m = *buffer->length; PerlIO_printf(DBIc_LOGPIO(imp_xxh),"\t\tafter buffer->buffer: "); for (j = 0; j < m; j++) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "%c", *ptr++); } PerlIO_printf(DBIc_LOGPIO(imp_xxh),"\n"); } } } if (rebind_result) { if (mysql_stmt_bind_result(imp_sth->stmt, imp_sth->buffer)) { mariadb_dr_do_error(sth, mysql_stmt_errno(imp_sth->stmt), mysql_stmt_error(imp_sth->stmt), mysql_stmt_sqlstate(imp_sth->stmt)); return Nullav; } } for ( buffer= imp_sth->buffer, fbh= imp_sth->fbh, i= 0; i < num_fields; i++, fbh++, buffer++ ) { SV *sv= AvARRAY(av)[i]; /* Note: we (re)use the SV in the AV */ STRLEN len; if (fbh->is_null) (void) SvOK_off(sv); /* Field is NULL, return undef */ else { switch (buffer->buffer_type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: #if IVSIZE >= 8 case MYSQL_TYPE_LONGLONG: #endif switch (buffer->buffer_type) { case MYSQL_TYPE_TINY: if (buffer->is_unsigned) int_val= (unsigned char)fbh->numeric_val.tval; else int_val= (signed char)fbh->numeric_val.tval; int_type= "TINY INT"; break; case MYSQL_TYPE_SHORT: if (buffer->is_unsigned) int_val= (unsigned short)fbh->numeric_val.sval; else int_val= (signed short)fbh->numeric_val.sval; int_type= "SHORT INT"; break; case MYSQL_TYPE_LONG: if (buffer->is_unsigned) int_val= (uint32_t)fbh->numeric_val.lval; else int_val= (int32_t)fbh->numeric_val.lval; int_type= "LONG INT"; break; #if IVSIZE >= 8 case MYSQL_TYPE_LONGLONG: if (buffer->is_unsigned) int_val= fbh->numeric_val.llval; else int_val= fbh->numeric_val.llval; int_type= "LONGLONG INT"; break; #endif default: NOT_REACHED; int_val = 0; int_type = ""; break; } if (buffer->is_unsigned) sv_setuv(sv, (UV)int_val); else sv_setiv(sv, (IV)int_val); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { if (buffer->is_unsigned) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tst_fetch AN UNSIGNED %s NUMBER %"UVuf"\n", int_type, (UV)int_val); else PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tst_fetch A SIGNED %s NUMBER %"IVdf"\n", int_type, (IV)int_val); } break; #if IVSIZE < 8 case MYSQL_TYPE_LONGLONG: { char buf[64]; STRLEN len = sizeof(buf); char *ptr; if (buffer->is_unsigned) ptr = my_ulonglong2str(fbh->numeric_val.llval, buf, &len); else ptr = signed_my_ulonglong2str(fbh->numeric_val.llval, buf, &len); SvUTF8_off(sv); sv_setpvn(sv, ptr, len); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tst_fetch %s LONGLONG INT NUMBER %s\n", (buffer->is_unsigned ? "AN UNSIGNED" : "A SIGNED"), ptr); } break; #endif case MYSQL_TYPE_FLOAT: if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tst_fetch A FLOAT NUMBER %f\n", fbh->numeric_val.fval); sv_setnv(sv, fbh->numeric_val.fval); break; case MYSQL_TYPE_DOUBLE: if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tst_fetch A DOUBLE NUMBER %f\n", fbh->numeric_val.dval); sv_setnv(sv, fbh->numeric_val.dval); break; /* TODO: datetime structures */ #if 0 case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: break; #endif case MYSQL_TYPE_NULL: (void) SvOK_off(sv); /* Field is NULL, return undef */ break; default: /* TEXT columns can be returned as MYSQL_TYPE_BLOB, so always check for charset */ len= fbh->length; /* ChopBlanks server-side prepared statement */ if (ChopBlanks) { if (fbh->is_utf8) while (len && fbh->data[len-1] == ' ') { --len; } } /* END OF ChopBlanks */ SvUTF8_off(sv); sv_setpvn(sv, fbh->data, len); if (fbh->is_utf8) sv_utf8_decode(sv); break; } } } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_fetch, %u cols\n", num_fields); return av; } else { imp_sth->currow++; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmariadb_st_fetch result set details\n"); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\timp_sth->result=%p\n", imp_sth->result); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmysql_num_fields=%u\n", mysql_num_fields(imp_sth->result)); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmysql_num_rows=%" SVf "\n", SVfARG(sv_2mortal(my_ulonglong2sv(mysql_num_rows(imp_sth->result))))); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmysql_affected_rows=%" SVf "\n", SVfARG(sv_2mortal(my_ulonglong2sv(mysql_affected_rows(imp_dbh->pmysql))))); PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmariadb_st_fetch for %p, currow=%" SVf "\n", sth, SVfARG(sv_2mortal(my_ulonglong2sv(imp_sth->currow)))); } if (!(cols= mysql_fetch_row(imp_sth->result))) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tmariadb_st_fetch, no more rows to fetch"); } if (mysql_errno(imp_dbh->pmysql)) mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql)); if (!mysql_more_results(imp_dbh->pmysql)) DBIc_ACTIVE_off(imp_sth); return Nullav; } if (imp_sth->currow >= imp_sth->row_num && !mysql_more_results(imp_dbh->pmysql)) DBIc_ACTIVE_off(imp_sth); num_fields= mysql_num_fields(imp_sth->result); fields= mysql_fetch_fields(imp_sth->result); lengths= mysql_fetch_lengths(imp_sth->result); if ((av= DBIc_FIELDS_AV(imp_sth)) != Nullav) { av_length= av_len(av)+1; if (av_length != num_fields) /* Resize array if necessary */ { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_fetch, size of results array(%u) != num_fields(%u)\n", av_length, num_fields); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_fetch, result fields(%d)\n", DBIc_NUM_FIELDS(imp_sth)); av_readonly = SvREADONLY(av) ? TRUE : FALSE; if (av_readonly) SvREADONLY_off( av ); /* DBI sets this readonly */ while (av_length < num_fields) { av_store(av, av_length++, newSV(0)); } while (av_length > num_fields) { SvREFCNT_dec(av_pop(av)); av_length--; } if (av_readonly) SvREADONLY_on(av); } } av= DBIc_DBISTATE(imp_sth)->get_fbav(imp_sth); for (i= 0; i < num_fields; ++i) { char *col= cols[i]; SV *sv= AvARRAY(av)[i]; /* Note: we (re)use the SV in the AV */ if (col) { STRLEN len= lengths[i]; if (ChopBlanks) { if (mysql_charsetnr_is_utf8(fields[i].charsetnr)) while (len && col[len-1] == ' ') { --len; } } /* Set string value returned from mysql server */ SvUTF8_off(sv); sv_setpvn(sv, col, len); switch (mysql_to_perl_type(fields[i].type)) { case PERL_TYPE_NUMERIC: if (!mysql_field_needs_string_type(&fields[i])) { /* Coerce to dobule and set scalar as NV */ sv_setnv(sv, SvNV(sv)); } break; case PERL_TYPE_INTEGER: if (!mysql_field_needs_string_type(&fields[i])) { /* Coerce to integer and set scalar as UV resp. IV */ if (fields[i].flags & UNSIGNED_FLAG) sv_setuv(sv, SvUV_nomg(sv)); else sv_setiv(sv, SvIV_nomg(sv)); } break; case PERL_TYPE_UNDEF: /* Field is NULL, return undef */ (void) SvOK_off(sv); break; default: /* TEXT columns can be returned as MYSQL_TYPE_BLOB, so always check for charset */ if (mysql_charsetnr_is_utf8(fields[i].charsetnr)) sv_utf8_decode(sv); break; } } else (void) SvOK_off(sv); /* Field is NULL, return undef */ } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_fetch, %u cols\n", num_fields); return av; } } /*************************************************************************** * * Name: mariadb_st_finish * * Purpose: Called for freeing a mysql result * * Input: sth - statement handle being finished * imp_sth - drivers private statement handle data * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error() will * be called in the latter case * **************************************************************************/ int mariadb_st_finish(SV* sth, imp_sth_t* imp_sth) { dTHX; D_imp_xxh(sth); D_imp_dbh_from_sth; if(imp_dbh->async_query_in_flight) { mariadb_db_async_result(sth, &imp_sth->result); } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\n--> mariadb_st_finish\n"); } if (imp_sth->use_server_side_prepare && imp_sth->stmt) mysql_stmt_free_result(imp_sth->stmt); /* Clean-up previous result set(s) for sth to prevent 'Commands out of sync' error */ if (!mariadb_st_free_result_sets(sth, imp_sth, FALSE)) return 0; /* Cancel further fetches from this cursor. We don't close the cursor till DESTROY. The application may re execute it. */ DBIc_ACTIVE_off(imp_sth); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\n<-- mariadb_st_finish\n"); } return 1; } /************************************************************************** * * Name: mariadb_st_destroy * * Purpose: Our part of the statement handles destructor * * Input: sth - statement handle being destroyed * imp_sth - drivers private statement handle data * * Returns: Nothing * **************************************************************************/ void mariadb_st_destroy(SV *sth, imp_sth_t *imp_sth) { dTHX; D_imp_xxh(sth); int i; imp_sth_fbh_t *fbh; int num_params; int num_fields; if (!PL_dirty) { /* During global destruction, DBI objects are destroyed in random order * and therefore imp_dbh may be already freed. So do not access it. */ mariadb_st_finish(sth, imp_sth); mariadb_st_free_result_sets(sth, imp_sth, TRUE); } DBIc_ACTIVE_off(imp_sth); if (imp_sth->statement) Safefree(imp_sth->statement); num_params = DBIc_NUM_PARAMS(imp_sth); if (num_params > 0) { if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\tFreeing %d parameters, bind %p fbind %p\n", num_params, imp_sth->bind, imp_sth->fbind); free_bind(imp_sth->bind); free_fbind(imp_sth->fbind); } fbh= imp_sth->fbh; if (fbh) { num_fields = DBIc_NUM_FIELDS(imp_sth); i = 0; while (i < num_fields) { if (fbh[i].data) Safefree(fbh[i].data); ++i; } free_fbuffer(fbh); if (imp_sth->buffer) free_bind(imp_sth->buffer); } if (imp_sth->stmt) { mysql_stmt_close(imp_sth->stmt); imp_sth->stmt= NULL; } /* Free values allocated by mariadb_st_bind_ph */ if (imp_sth->params) { free_param(aTHX_ imp_sth->params, num_params); imp_sth->params= NULL; } /* Free cached array attributes */ for (i= 0; i < AV_ATTRIB_LAST; i++) { if (imp_sth->av_attr[i]) SvREFCNT_dec(imp_sth->av_attr[i]); imp_sth->av_attr[i]= Nullav; } /* let DBI know we've done it */ DBIc_IMPSET_off(imp_sth); } /* ************************************************************************** * * Name: mariadb_st_STORE_attrib * * Purpose: Modifies a statement handles attributes; we currently * support just nothing * * Input: sth - statement handle being destroyed * imp_sth - drivers private statement handle data * keysv - attribute name * valuesv - attribute value * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error will * be called in the latter case * **************************************************************************/ int mariadb_st_STORE_attrib( SV *sth, imp_sth_t *imp_sth, SV *keysv, SV *valuesv ) { dTHX; STRLEN(kl); char *key= SvPV(keysv, kl); /* needs to process get magic */ int retval = 0; D_imp_xxh(sth); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\t-> mariadb_st_STORE_attrib for %p, key %s\n", sth, key); if (memEQs(key, kl, "mariadb_use_result")) { imp_sth->use_mysql_use_result= SvTRUE_nomg(valuesv); retval = 1; } else { if (!skip_attribute(key)) /* Not handled by this driver */ error_unknown_attribute(sth, key); } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\t<- mariadb_st_STORE_attrib for %p, result %d\n", sth, retval); return retval; } /* ************************************************************************** * * Name: mariadb_st_fetch_internal * * Purpose: Retrieves a statement handles array attributes; we use * a separate function, because creating the array * attributes shares much code and it aids in supporting * enhanced features like caching. * * Input: sth - statement handle; may even be a database handle, * in which case this will be used for storing error * messages only. This is only valid, if cacheit (the * last argument) is set to TRUE. * what - internal attribute number * res - pointer to a DBMS result * cacheit - TRUE, if results may be cached in the sth. * * Returns: RV pointing to result array in case of success, NULL * otherwise; mariadb_dr_do_error has already been called in the latter * case. * **************************************************************************/ #define IS_KEY(A) (((A) & (PRI_KEY_FLAG | UNIQUE_KEY_FLAG | MULTIPLE_KEY_FLAG)) != 0) #define IS_AUTO_INCREMENT(A) (((A) & AUTO_INCREMENT_FLAG) != 0) static SV* mariadb_st_fetch_internal( SV *sth, int what, MYSQL_RES *res, bool cacheit ) { dTHX; D_imp_sth(sth); AV *av= Nullav; MYSQL_FIELD *curField; unsigned int length; /* Are we asking for a legal value? */ if (what < 0 || what >= AV_ATTRIB_LAST) mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "Not implemented", "HY000"); /* Return cached value, if possible */ else if (cacheit && imp_sth->av_attr[what]) av= imp_sth->av_attr[what]; /* Does this sth really have a result? */ else if (!res) mariadb_dr_do_error(sth, CR_NO_RESULT_SET, "No result set associated with the statement", "HY000"); /* Do the real work. */ else { av= newAV(); mysql_field_seek(res, 0); while ((curField= mysql_fetch_field(res))) { SV *sv; switch(what) { case AV_ATTRIB_NAME: length = curField->name_length; #if MYSQL_VERSION_ID < 50500 || (defined(MARIADB_BASE_VERSION) && ((MYSQL_VERSION_ID >= 100204 && MYSQL_VERSION_ID < 100219) || (MYSQL_VERSION_ID >= 100300 && MYSQL_VERSION_ID < 100309))) || (defined(MARIADB_PACKAGE_VERSION) && (!defined(MARIADB_PACKAGE_VERSION_ID) || MARIADB_PACKAGE_VERSION_ID < 20306 || (MARIADB_PACKAGE_VERSION_ID >= 30000 && MARIADB_PACKAGE_VERSION_ID < 30005))) /* MySQL clients prior to 5.5.0, MariaDB clients 10.2.4+ prior to 10.2.19 and 10.3.9 and MariaDB Connector/C clients prior to 2.3.6 and 3.0.5 * fill uninitialized value for length in prepared statements, so calculate length it manually * See: https://jira.mariadb.org/browse/CONC-334 */ if (imp_sth->stmt) length = strlen(curField->name); #endif sv= newSVpvn(curField->name, length); if (mysql_charsetnr_is_utf8(curField->charsetnr)) sv_utf8_decode(sv); break; case AV_ATTRIB_TABLE: length = curField->table_length; #if MYSQL_VERSION_ID < 50500 || (defined(MARIADB_BASE_VERSION) && ((MYSQL_VERSION_ID >= 100204 && MYSQL_VERSION_ID < 100219) || (MYSQL_VERSION_ID >= 100300 && MYSQL_VERSION_ID < 100309))) || (defined(MARIADB_PACKAGE_VERSION) && (!defined(MARIADB_PACKAGE_VERSION_ID) || MARIADB_PACKAGE_VERSION_ID < 20306 || (MARIADB_PACKAGE_VERSION_ID >= 30000 && MARIADB_PACKAGE_VERSION_ID < 30005))) /* MySQL clients prior to 5.5.0, MariaDB clients 10.2.4+ prior to 10.2.19 and 10.3.9 and MariaDB Connector/C clients prior to 2.3.6 and 3.0.5 * fill uninitialized value for length in prepared statements, so calculate length it manually * See: https://jira.mariadb.org/browse/CONC-334 */ if (imp_sth->stmt) length = strlen(curField->table); #endif sv= newSVpvn(curField->table, length); if (mysql_charsetnr_is_utf8(curField->charsetnr)) sv_utf8_decode(sv); break; case AV_ATTRIB_TYPE: sv= newSVuv(curField->type); break; case AV_ATTRIB_SQL_TYPE: sv= newSViv(native2sql(curField->type)->data_type); break; case AV_ATTRIB_IS_PRI_KEY: sv= boolSV(IS_PRI_KEY(curField->flags)); break; case AV_ATTRIB_IS_NOT_NULL: sv= boolSV(IS_NOT_NULL(curField->flags)); break; case AV_ATTRIB_NULLABLE: sv= boolSV(!IS_NOT_NULL(curField->flags)); break; case AV_ATTRIB_LENGTH: sv= newSVuv(curField->length); break; case AV_ATTRIB_IS_NUM: sv= boolSV(native2sql(curField->type)->is_num); break; case AV_ATTRIB_TYPE_NAME: sv= newSVpv(native2sql(curField->type)->type_name, 0); break; case AV_ATTRIB_MAX_LENGTH: sv= newSVuv(curField->max_length); break; case AV_ATTRIB_IS_AUTO_INCREMENT: sv= boolSV(IS_AUTO_INCREMENT(curField->flags)); break; case AV_ATTRIB_IS_KEY: sv= boolSV(IS_KEY(curField->flags)); break; case AV_ATTRIB_IS_BLOB: sv= boolSV(IS_BLOB(curField->flags)); break; case AV_ATTRIB_SCALE: sv= newSVuv(curField->decimals); break; case AV_ATTRIB_PRECISION: sv= newSVuv((curField->length > curField->max_length) ? curField->length : curField->max_length); break; default: sv= &PL_sv_undef; break; } av_push(av, sv); } /* Ensure that this value is kept, decremented in * mariadb_st_destroy and mariadb_st_execute_iv. */ if (!cacheit) return sv_2mortal(newRV_noinc((SV*)av)); imp_sth->av_attr[what]= av; } if (av == Nullav) return &PL_sv_undef; return sv_2mortal(newRV_inc((SV*)av)); } /* ************************************************************************** * * Name: mariadb_st_FETCH_attrib * * Purpose: Retrieves a statement handles attributes * * Input: sth - statement handle being destroyed * imp_sth - drivers private statement handle data * keysv - attribute name * * Returns: NULL for an unknown attribute, "undef" for error, * attribute value otherwise. * **************************************************************************/ #define ST_FETCH_AV(what) \ mariadb_st_fetch_internal(sth, (what), imp_sth->result, TRUE) SV* mariadb_st_FETCH_attrib( SV *sth, imp_sth_t *imp_sth, SV *keysv ) { dTHX; STRLEN(kl); char *key= SvPV(keysv, kl); /* needs to process get magic */ SV *retsv= Nullsv; D_imp_xxh(sth); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " -> mariadb_st_FETCH_attrib for %p, key %s\n", sth, key); switch (*key) { case 'N': if (memEQs(key, kl, "NAME")) retsv= ST_FETCH_AV(AV_ATTRIB_NAME); else if (memEQs(key, kl, "NULLABLE")) retsv= ST_FETCH_AV(AV_ATTRIB_NULLABLE); break; case 'P': if (memEQs(key, kl, "PRECISION")) retsv= ST_FETCH_AV(AV_ATTRIB_PRECISION); else if (memEQs(key, kl, "ParamValues")) { HV *pvhv= newHV(); if (DBIc_NUM_PARAMS(imp_sth) > 0) { int i; char key[100]; I32 keylen; SV *sv; for (i = 0; i < DBIc_NUM_PARAMS(imp_sth); i++) { keylen = sprintf(key, "%d", i); sv = newSVpvn(imp_sth->params[i].value, imp_sth->params[i].len); if (!sql_type_is_binary(imp_sth->params[i].type)) sv_utf8_decode(sv); (void)hv_store(pvhv, key, keylen, sv, 0); } } retsv= sv_2mortal(newRV_noinc((SV*)pvhv)); } break; case 'S': if (memEQs(key, kl, "SCALE")) retsv= ST_FETCH_AV(AV_ATTRIB_SCALE); break; case 'T': if (memEQs(key, kl, "TYPE")) retsv= ST_FETCH_AV(AV_ATTRIB_SQL_TYPE); break; case 'm': if (memEQs(key, kl, "mariadb_type")) retsv= ST_FETCH_AV(AV_ATTRIB_TYPE); else if (memEQs(key, kl, "mariadb_sock")) retsv= (imp_sth->stmt) ? sv_2mortal(newSViv(PTR2IV(imp_sth->stmt->mysql))) : boolSV(0); else if (memEQs(key, kl, "mariadb_table")) retsv= ST_FETCH_AV(AV_ATTRIB_TABLE); else if (memEQs(key, kl, "mariadb_is_key")) retsv= ST_FETCH_AV(AV_ATTRIB_IS_KEY); else if (memEQs(key, kl, "mariadb_is_num")) retsv= ST_FETCH_AV(AV_ATTRIB_IS_NUM); else if (memEQs(key, kl, "mariadb_length")) retsv= ST_FETCH_AV(AV_ATTRIB_LENGTH); else if (memEQs(key, kl, "mariadb_result")) retsv= sv_2mortal(newSViv(PTR2IV(imp_sth->result))); else if (memEQs(key, kl, "mariadb_is_blob")) retsv= ST_FETCH_AV(AV_ATTRIB_IS_BLOB); else if (memEQs(key, kl, "mariadb_insertid")) { /* We cannot return an IV, because the insertid is a long. */ retsv= sv_2mortal(my_ulonglong2sv(imp_sth->insertid)); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "INSERT ID %" SVf "\n", SVfARG(retsv)); } else if (memEQs(key, kl, "mariadb_type_name")) retsv = ST_FETCH_AV(AV_ATTRIB_TYPE_NAME); else if (memEQs(key, kl, "mariadb_is_pri_key")) retsv= ST_FETCH_AV(AV_ATTRIB_IS_PRI_KEY); else if (memEQs(key, kl, "mariadb_max_length")) retsv= ST_FETCH_AV(AV_ATTRIB_MAX_LENGTH); else if (memEQs(key, kl, "mariadb_use_result")) retsv= boolSV(imp_sth->use_mysql_use_result); else if (memEQs(key, kl, "mariadb_warning_count")) retsv= sv_2mortal(newSVuv(imp_sth->warning_count)); else if (memEQs(key, kl, "mariadb_server_prepare")) retsv= boolSV(imp_sth->use_server_side_prepare); else if (memEQs(key, kl, "mariadb_is_auto_increment")) retsv = ST_FETCH_AV(AV_ATTRIB_IS_AUTO_INCREMENT); else if (memEQs(key, kl, "mariadb_server_prepare_disable_fallback")) retsv= boolSV(imp_sth->disable_fallback_for_server_prepare); break; } if (retsv == Nullsv) { if (!skip_attribute(key)) /* Not handled by this driver */ error_unknown_attribute(sth, key); } return retsv; } SV *mariadb_st_last_insert_id(SV *sth, imp_sth_t *imp_sth, SV *catalog, SV *schema, SV *table, SV *field, SV *attr) { dTHX; PERL_UNUSED_ARG(sth); PERL_UNUSED_ARG(catalog); PERL_UNUSED_ARG(schema); PERL_UNUSED_ARG(table); PERL_UNUSED_ARG(field); PERL_UNUSED_ARG(attr); return sv_2mortal(my_ulonglong2sv(imp_sth->insertid)); } /*************************************************************************** * * Name: mariadb_st_blob_read * * Purpose: Used for blob reads if the statement handles "LongTruncOk" * attribute (currently not supported by DBD::MariaDB) * * Input: SV* - statement handle from which a blob will be fetched * imp_sth - drivers private statement handle data * field - field number of the blob (note, that a row may * contain more than one blob) * offset - the offset of the field, where to start reading * len - maximum number of bytes to read * destrv - RV* that tells us where to store * destoffset - destination offset * * Returns: 1 for success, 0 otherwise; mariadb_dr_do_error will * be called in the latter case * **************************************************************************/ int mariadb_st_blob_read ( SV *sth, imp_sth_t *imp_sth, int field, long offset, long len, SV *destrv, long destoffset) { PERL_UNUSED_ARG(sth); PERL_UNUSED_ARG(imp_sth); PERL_UNUSED_ARG(field); PERL_UNUSED_ARG(offset); PERL_UNUSED_ARG(len); PERL_UNUSED_ARG(destrv); PERL_UNUSED_ARG(destoffset); mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "blob_read not implemented", "HY000"); return 0; } /*************************************************************************** * * Name: mariadb_st_bind_ph * * Purpose: Binds a statement value to a parameter * * Input: sth - statement handle * imp_sth - drivers private statement handle data * param - parameter number, counting starts with 1 * value - value being inserted for parameter "param" * sql_type - SQL type of the value * attribs - bind parameter attributes, currently this must be * one of the values SQL_CHAR, ... * inout - TRUE, if parameter is an output variable (currently * this is not supported) * maxlen - ??? * * Returns: 1 for success, 0 otherwise * **************************************************************************/ int mariadb_st_bind_ph(SV *sth, imp_sth_t *imp_sth, SV *param, SV *value, IV sql_type, SV *attribs, int is_inout, IV maxlen) { dTHX; IV param_num = SvIV(param); /* needs to process get magic */ int idx; char *err_msg; D_imp_xxh(sth); D_imp_dbh_from_sth; PERL_UNUSED_ARG(attribs); PERL_UNUSED_ARG(maxlen); char *buffer= NULL; my_bool buffer_is_null = FALSE; my_bool buffer_is_unsigned = FALSE; unsigned long int buffer_length = 0; unsigned int buffer_type= 0; IV int_val= 0; const char *int_type = ""; ASYNC_CHECK_RETURN(sth, FALSE); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " Called: mariadb_st_bind_ph\n"); if (param_num <= 0 || param_num > DBIc_NUM_PARAMS(imp_sth)) { mariadb_dr_do_error(sth, CR_INVALID_PARAMETER_NO, "Illegal parameter number", "HY000"); return 0; } idx = param_num - 1; /* This fixes the bug whereby no warning was issued upon binding a defined non-numeric as numeric */ if (SvOK(value) && sql_type_is_numeric(sql_type)) { if (! looks_like_number(value)) { err_msg = SvPVX(sv_2mortal(newSVpvf( "Binding non-numeric field %" IVdf ", value %s as a numeric!", param_num, neatsvpv(value,0)))); mariadb_dr_do_error(sth, CR_INVALID_PARAMETER_NO, err_msg, "HY000"); return 0; } } if (is_inout) { mariadb_dr_do_error(sth, CR_NOT_IMPLEMENTED, "Output parameters not implemented", "HY000"); return 0; } bind_param(&imp_sth->params[idx], value, sql_type); if (imp_sth->use_server_side_prepare) { buffer_is_null = !imp_sth->params[idx].value; if (!buffer_is_null) { buffer_type= sql_to_mysql_type(sql_type); switch (buffer_type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: #if IVSIZE >= 8 case MYSQL_TYPE_LONGLONG: #endif if (!SvIOK(value) && DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tTRY TO BIND AN INT NUMBER\n"); int_val= SvIV_nomg(value); /* SvIV and SvUV may modify SvIsUV flag, on overflow maximal value is returned */ if (SvIsUV(value) || int_val == IV_MAX) { int_val = SvUV_nomg(value); buffer_is_unsigned = TRUE; } switch (buffer_type) { case MYSQL_TYPE_TINY: buffer_length= sizeof(imp_sth->fbind[idx].numeric_val.tval); if (int_val > SCHAR_MAX) buffer_is_unsigned = TRUE; if (buffer_is_unsigned) imp_sth->fbind[idx].numeric_val.tval= (unsigned char)((UV)int_val); else imp_sth->fbind[idx].numeric_val.tval= (signed char)((IV)int_val); buffer= (void*)&(imp_sth->fbind[idx].numeric_val.tval); int_val= imp_sth->fbind[idx].numeric_val.tval; int_type= "TINY INT"; break; case MYSQL_TYPE_SHORT: buffer_length= sizeof(imp_sth->fbind[idx].numeric_val.sval); if (int_val > SHRT_MAX) buffer_is_unsigned = TRUE; if (buffer_is_unsigned) imp_sth->fbind[idx].numeric_val.sval= (unsigned short)((UV)int_val); else imp_sth->fbind[idx].numeric_val.sval= (signed short)((IV)int_val); buffer= (void*)&(imp_sth->fbind[idx].numeric_val.sval); int_val= imp_sth->fbind[idx].numeric_val.sval; int_type= "SHORT INT"; break; case MYSQL_TYPE_LONG: buffer_length= sizeof(imp_sth->fbind[idx].numeric_val.lval); if (int_val > INT32_MAX) buffer_is_unsigned = TRUE; if (buffer_is_unsigned) imp_sth->fbind[idx].numeric_val.lval= (uint32_t)((UV)int_val); else imp_sth->fbind[idx].numeric_val.lval= (int32_t)((IV)int_val); buffer= (void*)&(imp_sth->fbind[idx].numeric_val.lval); int_val= imp_sth->fbind[idx].numeric_val.lval; int_type= "LONG INT"; break; #if IVSIZE >= 8 case MYSQL_TYPE_LONGLONG: buffer_length= sizeof(imp_sth->fbind[idx].numeric_val.llval); if (int_val >= 0 && (UV)int_val > (~(my_ulonglong)0 >> 1)) buffer_is_unsigned = TRUE; if (buffer_is_unsigned) imp_sth->fbind[idx].numeric_val.llval= (UV)int_val; else imp_sth->fbind[idx].numeric_val.llval= (IV)int_val; int_val= imp_sth->fbind[idx].numeric_val.llval; int_type= "LONGLONG INT"; buffer= (void*)&(imp_sth->fbind[idx].numeric_val.llval); break; #endif } if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { if (buffer_is_unsigned) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" ->%"UVuf"<- IS AN UNSIGNED %s NUMBER\n", sql_type, (UV)int_val, int_type); else PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" ->%"IVdf"<- IS A SIGNED %s NUMBER\n", sql_type, (IV)int_val, int_type); } break; #if IVSIZE < 8 case MYSQL_TYPE_LONGLONG: { char *buf; my_ulonglong val; buffer_length= sizeof(imp_sth->fbind[idx].numeric_val.llval); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tTRY TO BIND AN LONGLONG INT NUMBER FROM STRING\n"); buf= SvPV_nomg_nolen(value); val= strtoll(buf, NULL, 10); if (val == (~(my_ulonglong)0 >> 1)) { val= strtoull(buf, NULL, 10); buffer_is_unsigned = TRUE; } imp_sth->fbind[idx].numeric_val.llval= val; buffer= (void*)&(imp_sth->fbind[idx].numeric_val.llval); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) { PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %" IVdf " ->%s<- IS %s LONGLONG INT NUMBER\n", sql_type, buf, buffer_is_unsigned ? "AN UNSIGNED" : "A SIGNED"); } } break; #endif case MYSQL_TYPE_FLOAT: if (!SvNOK(value) && DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tTRY TO BIND A FLOAT NUMBER\n"); buffer_length = sizeof(imp_sth->fbind[idx].numeric_val.fval); imp_sth->fbind[idx].numeric_val.fval= SvNV_nomg(value); buffer=(char*)&(imp_sth->fbind[idx].numeric_val.fval); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" ->%f<- IS A FLOAT NUMBER\n", sql_type, *(float *)buffer); break; case MYSQL_TYPE_DOUBLE: if (!SvNOK(value) && DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\tTRY TO BIND A DOUBLE NUMBER\n"); buffer_length = sizeof(imp_sth->fbind[idx].numeric_val.dval); #if NVSIZE >= 8 imp_sth->fbind[idx].numeric_val.dval= SvNV_nomg(value); #else imp_sth->fbind[idx].numeric_val.dval= atof(SvPV_nomg_nolen(value)); #endif buffer=(char*)&(imp_sth->fbind[idx].numeric_val.dval); if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" ->%f<- IS A DOUBLE NUMBER\n", sql_type, *(double *)buffer); break; /* TODO: datetime structures */ #if 0 case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: break; #endif case MYSQL_TYPE_BLOB: buffer= imp_sth->params[idx].value; buffer_length= imp_sth->params[idx].len; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %" IVdf " ->length %lu<- IS A BLOB\n", sql_type, buffer_length); break; default: buffer_type= MYSQL_TYPE_STRING; buffer= imp_sth->params[idx].value; buffer_length= imp_sth->params[idx].len; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" ->%.1000s%s<- IS A STRING\n", sql_type, buffer, buffer_length > 1000 ? "..." : ""); break; } } else { buffer= NULL; buffer_type= MYSQL_TYPE_NULL; buffer_length= 0; if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), " SCALAR sql_type %"IVdf" IS A NULL VALUE", sql_type); } /* Column was changed, force rebind */ imp_sth->has_been_bound = FALSE; imp_sth->bind[idx].buffer_type= buffer_type; imp_sth->bind[idx].buffer= buffer; imp_sth->bind[idx].buffer_length= buffer_length; imp_sth->bind[idx].is_unsigned= buffer_is_unsigned; imp_sth->fbind[idx].length= buffer_length; imp_sth->fbind[idx].is_null= buffer_is_null; } return 1; } /*************************************************************************** * * Name: mariadb_db_reconnect * * Purpose: If the server has disconnected, try to reconnect. * * Input: h - database or statement handle * stmt - MYSQL statement pointer (or NULL) * * Returns: TRUE for success, FALSE otherwise * **************************************************************************/ bool mariadb_db_reconnect(SV *h, MYSQL_STMT *stmt) { dTHX; SV *dbh; D_imp_xxh(h); imp_dbh_t* imp_dbh; if (DBIc_TYPE(imp_xxh) == DBIt_ST) { dbh = DBIc_PARENT_H(imp_xxh); imp_dbh = (imp_dbh_t*) DBIc_PARENT_COM(imp_xxh); } else { dbh = h; imp_dbh= (imp_dbh_t*) imp_xxh; } if (imp_dbh->pmysql && mysql_errno(imp_dbh->pmysql) != CR_SERVER_GONE_ERROR && mysql_errno(imp_dbh->pmysql) != CR_SERVER_LOST && (!stmt || (mysql_stmt_errno(stmt) != CR_SERVER_GONE_ERROR && mysql_stmt_errno(stmt) != CR_SERVER_LOST && mysql_stmt_errno(stmt) != CR_STMT_CLOSED))) { /* Other error */ return FALSE; } if (!DBIc_has(imp_dbh, DBIcf_AutoCommit) || !imp_dbh->auto_reconnect) { /* We never reconnect if AutoCommit is turned off. * Otherwise we might get an inconsistent transaction * state. */ return FALSE; } /* we should disconnect the db handle before reconnecting, this will * prevent mariadb_db_my_login from thinking it's adopting an active child which * would prevent the handle from actually reconnecting */ mariadb_db_disconnect(dbh, imp_dbh); if (!mariadb_db_my_login(aTHX_ dbh, imp_dbh)) { ++imp_dbh->stats.auto_reconnects_failed; return FALSE; } /* * Tell DBI, that dbh->disconnect should be called for this handle */ DBIc_ACTIVE_on(imp_dbh); ++imp_dbh->stats.auto_reconnects_ok; return TRUE; } /************************************************************************** * * Name: mariadb_db_type_info_all * * Purpose: Implements $dbh->type_info_all * * Returns: RV to AV of types * **************************************************************************/ #define PV_PUSH(c) \ if (c) { \ sv= newSVpv((char*) (c), 0); \ SvREADONLY_on(sv); \ } else { \ sv= &PL_sv_undef; \ } \ av_push(row, sv); #define IV_PUSH(i) sv= newSViv((i)); SvREADONLY_on(sv); av_push(row, sv); AV *mariadb_db_type_info_all(void) { dTHX; AV *av= newAV(); AV *row; HV *hv; SV *sv; size_t i; const char *cols[] = { "TYPE_NAME", "DATA_TYPE", "COLUMN_SIZE", "LITERAL_PREFIX", "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_UNIQUE_VALUE", "LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE", "NUM_PREC_RADIX", "SQL_DATATYPE", "SQL_DATETIME_SUB", "INTERVAL_PRECISION", "mariadb_native_type", "mariadb_is_num" }; hv= newHV(); av_push(av, newRV_noinc((SV*) hv)); for (i = 0; i < sizeof(cols) / sizeof(const char*); i++) { if (!hv_store(hv, (char*) cols[i], strlen(cols[i]), newSVuv(i), 0)) { SvREFCNT_dec((SV*) av); return Nullav; } } for (i = 0; i < SQL_GET_TYPE_INFO_num; i++) { const sql_type_info_t *t= &SQL_GET_TYPE_INFO_values[i]; row= newAV(); av_push(av, newRV_noinc((SV*) row)); PV_PUSH(t->type_name); IV_PUSH(t->data_type); IV_PUSH(t->column_size); PV_PUSH(t->literal_prefix); PV_PUSH(t->literal_suffix); PV_PUSH(t->create_params); IV_PUSH(t->nullable); IV_PUSH(t->case_sensitive); IV_PUSH(t->searchable); IV_PUSH(t->unsigned_attribute); IV_PUSH(t->fixed_prec_scale); IV_PUSH(t->auto_unique_value); PV_PUSH(t->local_type_name); IV_PUSH(t->minimum_scale); IV_PUSH(t->maximum_scale); if (t->num_prec_radix) { IV_PUSH(t->num_prec_radix); } else av_push(row, &PL_sv_undef); IV_PUSH(t->sql_datatype); /* SQL_DATATYPE*/ IV_PUSH(t->sql_datetime_sub); /* SQL_DATETIME_SUB*/ IV_PUSH(t->interval_precision); /* INTERVAL_PRECISION */ IV_PUSH(t->native_type); av_push(row, boolSV(t->is_num)); } return av; } /* mariadb_db_quote Properly quotes a value */ SV* mariadb_db_quote(SV *dbh, SV *str, SV *type) { dTHX; SV *result; if (SvGMAGICAL(str)) mg_get(str); if (!SvOK(str)) result= newSVpvs("NULL"); else { char *ptr, *sptr; STRLEN len; bool is_binary = FALSE; D_imp_dbh(dbh); if (type && SvGMAGICAL(type)) mg_get(type); if (type && SvOK(type)) { size_t i; IV tp = SvIV_nomg(type); is_binary = sql_type_is_binary(tp); for (i = 0; i < SQL_GET_TYPE_INFO_num; i++) { const sql_type_info_t *t= &SQL_GET_TYPE_INFO_values[i]; if (t->data_type == tp) { if (!t->literal_prefix) return Nullsv; break; } } } if (is_binary) { ptr = SvPVbyte_nomg(str, len); result = newSV(len*2+4); sptr = SvPVX(result); *sptr++ = 'X'; *sptr++ = '\''; sptr += mysql_hex_string(sptr, ptr, len); *sptr++ = '\''; } else { if (!imp_dbh->pmysql && !mariadb_db_reconnect(dbh, NULL)) { mariadb_dr_do_error(dbh, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return Nullsv; } ptr = SvPVutf8_nomg(str, len); result = newSV(len*2+4); sptr = SvPVX(result); #if MYSQL_VERSION_ID < 50001 if (imp_dbh->pmysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) { *sptr++ = '\''; sptr += string_escape_quotes(sptr, ptr, len); *sptr++ = '\''; } else #endif { *sptr++ = '\''; #if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50706 && MYSQL_VERSION_ID != 60000 sptr += mysql_real_escape_string_quote(imp_dbh->pmysql, sptr, ptr, len, '\''); #else sptr += mysql_real_escape_string(imp_dbh->pmysql, sptr, ptr, len); #endif *sptr++ = '\''; } } SvPOK_on(result); SvCUR_set(result, sptr - SvPVX(result)); /* Never hurts NUL terminating a Per string */ *sptr++= '\0'; if (!is_binary) sv_utf8_decode(result); } return result; } SV *mariadb_db_last_insert_id(SV *dbh, imp_dbh_t *imp_dbh, SV *catalog, SV *schema, SV *table, SV *field, SV *attr) { dTHX; PERL_UNUSED_ARG(dbh); PERL_UNUSED_ARG(catalog); PERL_UNUSED_ARG(schema); PERL_UNUSED_ARG(table); PERL_UNUSED_ARG(field); PERL_UNUSED_ARG(attr); return sv_2mortal(my_ulonglong2sv(imp_dbh->insertid)); } my_ulonglong mariadb_db_async_result(SV* h, MYSQL_RES** resp) { dTHX; D_imp_xxh(h); imp_dbh_t* dbh; MYSQL* svsock = NULL; MYSQL_RES* _res = NULL; my_ulonglong retval = 0; unsigned int num_fields; int htype; bool async_sth = FALSE; if(! resp) { resp = &_res; } htype = DBIc_TYPE(imp_xxh); if(htype == DBIt_DB) { D_imp_dbh(h); dbh = imp_dbh; } else { D_imp_sth(h); D_imp_dbh_from_sth; dbh = imp_dbh; async_sth = imp_sth->is_async; retval = imp_sth->row_num; } if(! dbh->async_query_in_flight) { if (async_sth) return retval; mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Gathering asynchronous results for a synchronous handle", "HY000"); return -1; } if(dbh->async_query_in_flight != imp_xxh) { mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Gathering async_query_in_flight results for the wrong handle", "HY000"); return -1; } dbh->async_query_in_flight = NULL; if (htype == DBIt_ST) { D_imp_sth(h); DBIc_ACTIVE_off(imp_sth); } svsock= dbh->pmysql; if (!svsock) { mariadb_dr_do_error(h, CR_SERVER_GONE_ERROR, "MySQL server has gone away", "HY000"); return -1; } if (*resp) { mysql_free_result(*resp); *resp = NULL; } if (!mysql_read_query_result(svsock)) { *resp= mysql_store_result(svsock); if (mysql_errno(svsock)) { mariadb_dr_do_error(h, mysql_errno(svsock), mysql_error(svsock), mysql_sqlstate(svsock)); return -1; } if (!*resp) retval= mysql_affected_rows(svsock); else retval= mysql_num_rows(*resp); /* Some MySQL client versions return correct value from mysql_insert_id() * function only after non-SELECT operation. So store insert id into dbh * cache and later read it only from cache. */ if (!*resp) dbh->insertid = mysql_insert_id(svsock); if(htype == DBIt_ST) { D_imp_sth(h); D_imp_dbh_from_sth; imp_sth->row_num = retval; if(! *resp) { imp_sth->insertid = dbh->insertid; if (mysql_more_results(svsock)) DBIc_ACTIVE_on(imp_sth); } else { num_fields = mysql_num_fields(imp_sth->result); DBIc_NUM_FIELDS(imp_sth) = (num_fields <= INT_MAX) ? num_fields : INT_MAX; if (imp_sth->row_num) DBIc_ACTIVE_on(imp_sth); } imp_sth->warning_count = mysql_warning_count(imp_dbh->pmysql); } if (*resp && resp == &_res) { mysql_free_result(*resp); *resp = NULL; } if (mysql_more_results(svsock)) dbh->async_query_in_flight = imp_xxh; } else { #if MYSQL_VERSION_ID < 50025 /* Cover a protocol design error: error packet does not contain the server status. * Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */ svsock->server_status &= ~SERVER_MORE_RESULTS_EXISTS; #endif mariadb_dr_do_error(h, mysql_errno(svsock), mysql_error(svsock), mysql_sqlstate(svsock)); return (my_ulonglong)-1; } return retval; } int mariadb_db_async_ready(SV* h) { dTHX; D_imp_xxh(h); imp_dbh_t* dbh; int htype; bool async_sth = FALSE; bool async_active = FALSE; htype = DBIc_TYPE(imp_xxh); if(htype == DBIt_DB) { D_imp_dbh(h); dbh = imp_dbh; } else { D_imp_sth(h); D_imp_dbh_from_sth; dbh = imp_dbh; async_sth = imp_sth->is_async; async_active = !!DBIc_ACTIVE(imp_sth); } if (!dbh->pmysql) return -1; if(dbh->async_query_in_flight) { if (dbh->async_query_in_flight == imp_xxh) { int retval = mariadb_dr_socket_ready(dbh->pmysql->net.fd); if(retval < 0) { mariadb_dr_do_error(h, -retval, strerror(-retval), "HY000"); } return retval; } else { mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Calling mariadb_async_ready on the wrong handle", "HY000"); return -1; } } else { if (async_sth) { if (async_active) return 1; mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Asynchronous handle was not executed yet", "HY000"); return -1; } mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Handle is not in asynchronous mode", "HY000"); return -1; } } static bool is_mysql_number(char *string, STRLEN len) { char *cp = string; bool number_found = FALSE; /* Skip leading MySQL utf8mb4 whitespaces */ while (*cp == ' ' || (*cp >= 9 && *cp <= 13)) cp++; /* Optional '+' or '-' */ if (*cp == '-' || *cp == '+') cp++; /* Number before '.' */ while (*cp >= '0' && *cp <= '9') { cp++; number_found = TRUE; } /* Optional '.' */ if (*cp == '.') { cp++; /* Number after '.' */ while (*cp >= '0' && *cp <= '9') { cp++; number_found = TRUE; } } /* No number found - error */ if (!number_found) return FALSE; /* Optional exponent */ if (*cp == 'e' || *cp == 'E') { cp++; /* Search for number also in exponent */ number_found = FALSE; /* Optional '+' or '-' in exponent */ if (*cp == '-' || *cp == '+') cp++; /* Exponent number */ while (*cp >= '0' && *cp <= '9') { cp++; number_found = TRUE; } } /* Skip trailing MySQL utf8mb4 whitespaces */ while (*cp == ' ' || (*cp >= 9 && *cp <= 13)) cp++; /* Check that we processed all characters */ if (string + len != cp) return FALSE; return number_found; } DBD-MariaDB-1.22/MANIFEST0000644000175000017500000000404414230360635013055 0ustar palipaliChanges Changes.historic dbdimp.c dbdimp.h lib/DBD/MariaDB.pm lib/DBD/MariaDB.pod lib/DBD/MariaDB/INSTALL.pod LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP MariaDB.xs README.pod socket.c t/testrules.yml t/00base.t t/05dbcreate.t t/10connect.t t/11data_sources.t t/12embedded.t t/13disconnect.t t/14destruct.t t/15reconnect.t t/16dbi-get_info.t t/20createdrop.t t/25lockunlock.t t/29warnings.t t/30insertfetch.t t/31insertid.t t/32insert_error.t t/35limit.t t/35prepare.t t/40bindparam.t t/40bindparam2.t t/40bit.t t/40blobs.t t/40catalog.t t/40invalid_attributes.t t/40keyinfo.t t/40listfields.t t/40nulls.t t/40nulls_prepare.t t/40numrows.t t/40server_prepare.t t/40server_prepare_crash.t t/40server_prepare_error.t t/40sth_attr.t t/40types.t t/41bindparam.t t/41blobs_prepare.t t/41int_min_max.t t/42bindparam.t t/43count_params.t t/44call_placeholder.t t/44limit_placeholder.t t/45bind_no_backslash_escapes.t t/50chopblanks.t t/50commit.t t/51bind_type_guessing.t t/52comment.t t/53comment.t t/55unicode.t t/55utf8.t t/55utf8mb4.t t/55utf8_jp.t t/56connattr.t t/60leaks.t t/65segfault.t t/65types.t t/70takeimp.t t/71impdata.t t/75supported_sql.t t/76multi_statement.t t/77max_allowed_packet.t t/80procs.t t/81procs.t t/85init_command.t t/86_bug_36972.t t/87async.t t/88async-multi-stmts.t t/89async-method-check.t t/90utf8_params.t t/91errcheck.t t/92ssl_connection.t t/92ssl_optional.t t/92ssl_backronym_vulnerability.t t/92ssl_riddle_vulnerability.t t/93net_ssleay.t t/99_bug_server_prepare_blob_null.t t/cve-2017-3302.t t/lib.pl t/magic.t t/manifest.t t/pod.t t/rt110983-valid-mysqlfd.t t/rt118977-zerofill.t t/rt122541-decimals.t t/rt25389-bin-case.t t/rt50304-column_info_parentheses.t t/rt61849-bind-param-buffer-overflow.t t/rt75353-innodb-lock-timeout.t t/rt83494-quotes-comments.t t/rt85919-fetch-lost-connection.t t/rt86153-reconnect-fail-memory.t t/rt88006-bit-prepare.t t/rt91715.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) DBD-MariaDB-1.22/Makefile.PL0000644000175000017500000010306114230360604013671 0ustar palipali# -*- cperl -*- use strict; use warnings; use utf8; use 5.008_001; use Config; use Getopt::Long; use ExtUtils::MakeMaker; use Data::Dumper; use Devel::CheckLib 1.12; use File::Spec; require DBI; require DBI::DBD; my $TESTDB = "test"; # On WIN32 windows.h and winsock.h need to be included before mysql.h # Otherwise SOCKET type which is needed for mysql.h is not defined my @mysql_headers; push @mysql_headers, 'windows.h', 'winsock.h' if $^O eq 'MSWin32'; push @mysql_headers, 'mysql.h'; our $opt = { "help" => \&Usage, }; my ($test_host, $test_port, $test_socket); { local ($::test_host, $::test_port, $::test_user, $::test_socket, $::test_password, $::test_db, $::test_mysql_config, $::test_cflags, $::test_libs); eval { require "./t/MariaDB.mtest" } and do { $opt->{'testuser'} = $::test_user; $opt->{'testpassword'} = $::test_password; $opt->{'testdb'} = $::test_db; $opt->{'mysql_config'} = $::test_mysql_config; $opt->{'cflags'} = $::test_cflags; $opt->{'libs'} = $::test_libs; $test_host = $::test_host; $test_port = $::test_port; $test_socket = $::test_socket; } } Getopt::Long::GetOptions( $opt, "help", "testdb:s", "testhost:s", "testport:s", "testuser:s", "testpassword:s", "testsocket:s", "cflags:s", "libs:s", "mysql_config:s", "mariadb_config:s", ) || die Usage(); $opt->{mysql_config} = delete $opt->{mariadb_config} if exists $opt->{mariadb_config}; my $source = {}; #Check for mysql_config first $source->{'mysql_config'} = "guessed"; if ($opt->{'mysql_config'}) { $source->{'mysql_config'} = "User's choice"; } if (!$opt->{'mysql_config'} && $ENV{DBD_MARIADB_CONFIG}) { $opt->{'mysql_config'} = $ENV{DBD_MARIADB_CONFIG}; $source->{'mysql_config'} = 'environment'; } if ($opt->{'mysql_config'}) { if ($opt->{'mysql_config'} ne 'skip') { $opt->{'mysql_config'} = Win32::GetShortPathName($opt->{'mysql_config'}) if $^O eq 'MSWin32'; if (!CanExecute($opt->{'mysql_config'})) { die <<"MSG"; Specified mysql configuration script '$opt->{'mysql_config'}' doesn't exist. Please check path/permissions. MSG } } } else { if (CanExecute("mariadb_config")) { $opt->{'mysql_config'} = "mariadb_config"; } elsif (CanExecute("mysql_config")) { $opt->{'mysql_config'} = "mysql_config"; } else { print <{testport} && (!$opt->{testhost} || $opt->{testhost} eq 'localhost') && !defined $opt->{testsocket} && $test_socket) { $opt->{testsocket} = $test_socket; $source->{testsocket} = "User's choice"; } if (!$opt->{testsocket}) { if (!defined $opt->{testhost} && $test_host && (!$opt->{testport} || $test_host ne 'localhost')) { $opt->{testhost} = $test_host; $source->{testhost} = "User's choice"; } if (!defined $opt->{testport} && $test_port && (!$opt->{testhost} || $opt->{testhost} ne 'localhost')) { $opt->{testport} = $test_port; $source->{testport} = "User's choice"; } } else { if (!defined $opt->{testhost} && $test_host && $test_host eq 'localhost') { $opt->{testhost} = 'localhost'; $source->{testhost} = "User's choice"; } } #if we have a testport but no host, assume 127.0.0.1 if ( $opt->{testport} && !$opt->{testhost} ) { $opt->{testhost} = '127.0.0.1'; $source->{testhost} = 'guessed'; } foreach (qw(testhost testport testsocket)) { next if defined $opt->{$_}; $opt->{$_} = ''; $source->{$_} = 'default'; } # testsocket makes sense only when testhost is localhost if ($opt->{testsocket} && $opt->{testhost} && $opt->{testhost} ne 'localhost') { die << "MSG"; Option --testport or --testhost different from localhost cannot be specified together with option --testsocket. MSG } # testport cannot be specified when host is localhost if ($opt->{testport} && $opt->{testhost} && $opt->{testhost} eq 'localhost') { die << "MSG"; Option --testport cannot be specified when --testhost is localhost. MSG } # testhost cannot be embedded if ($opt->{testhost} && $opt->{testhost} eq 'embedded') { die << "MSG"; Option --testhost cannot be embedded. MSG } # Separate libs and libdirs from ldflags # When linking libdirs must be specified before libs due to runtime linking problems my ($main_lib, @libs, @libdirs, @ldflags); for (split ' ', $opt->{libs}) { if (not defined $main_lib and /^-l(?:.*mariadb.*|.*mysql.*)$/) { $main_lib = $_; } elsif (/^-l/) { push @libs, $_; } elsif (/^-L/) { push @libdirs, $_; } else { push @ldflags, $_; } } if (not defined $main_lib) { $main_lib = shift @libs; } if (not defined $main_lib) { die <<"MSG"; No MariaDB or MySQL client library was specified. Use perl Makefile.PL --libs="-L -l" to set directory and client library. For details see the DBD::MariaDB::INSTALL, section "Linker flags" or type perl Makefile.PL --help 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::MariaDB::INSTALL'. MSG print "Checking if libs and header files are available for compiling...\n"; assert_lib( LIBS => (join ' ', @libdirs, $main_lib, @libs), ccflags => (join ' ', $opt->{cflags}, ($Config{usedl} ? $Config{cccdlflags} : ())), ldflags => (join ' ', @libdirs, @ldflags, ($Config{usedl} ? $Config{lddlflags} : ())), header => \@mysql_headers, not_execute => 1, ); print "Checking if correct version of MariaDB or MySQL client is present...\n"; check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags), header => \@mysql_headers, function => "\n#ifndef MYSQL_VERSION_ID\n#include \n#endif\nreturn (MYSQL_VERSION_ID >= 40108) ? 0 : 1;\n", ) or die <<"MSG"; ERROR: Wrong version or unable to check version of MariaDB/MySQL include files. To build DBD::MariaDB it is needed MariaDB or MySQL client >= 4.1.8. MSG print "Looks good.\n\n"; my $have_embedded = check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags), header => \@mysql_headers, function => 'return mysql_embedded() ? 0 : 1;', ); print "Embedded server: " . ($have_embedded ? "supported" : "not supported by client library") . "\n\n"; my $have_get_charset_number = check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags), header => \@mysql_headers, function => 'unsigned int get_charset_number(const char *cs_name, unsigned int cs_flags); mysql_server_init(-1, 0, 0); get_charset_number("utf8", 32); return 0;', ); my $have_get_option = check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags), header => \@mysql_headers, function => 'MYSQL mysql; char buf[1024]; mysql_server_init(-1, 0, 0); mysql_init(&mysql); mysql_get_option(&mysql, 0, &buf); return 0;', ); my $have_deinitialize_ssl = check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags), header => \@mysql_headers, function => 'mariadb_deinitialize_ssl = 0; return 0;', ); # Check if mysql_server_end() deinitialize OpenSSL library functions # See: https://github.com/gooddata/DBD-MariaDB/issues/119 my $have_problem_with_openssl = !check_lib( LIBS => (join ' ', @libdirs, $main_lib), ccflags => $opt->{cflags}, ldflags => (join ' ', @libdirs, @libs, @ldflags, $Config{perllibs}), header => \@mysql_headers, function => << 'EOF' #ifndef _WIN32 #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #ifndef RTLD_DEFAULT #define RTLD_DEFAULT ((void *)0) #endif #endif int (*OPENSSL_init_ssl_func)(unsigned long long, const void *); void (*SSL_load_error_strings_func)(void); int (*SSL_library_init_func)(void); void *(*SSL_CTX_new_func)(const void *method); void (*SSL_CTX_free_func)(void *ctx); const void *(*TLS_method_func)(void); const void *method1; const void *method2; void *ctx1; void *ctx2; #ifdef _WIN32 BOOL (WINAPI *EnumProcessModules_func)(HANDLE, HMODULE *, DWORD, LPDWORD); HMODULE psapi_lib; DWORD size, i; HMODULE *modules; modules = NULL; psapi_lib = LoadLibraryA("Psapi.dll"); if (psapi_lib) { EnumProcessModules_func = (BOOL (WINAPI *)(HANDLE, HMODULE *, DWORD, LPDWORD))GetProcAddress(psapi_lib, "EnumProcessModules"); if (EnumProcessModules_func) { if (EnumProcessModules_func((HANDLE)-1, NULL, 0, &size)) { modules = (HMODULE *)GlobalAlloc(GPTR, size); if (modules && !EnumProcessModules_func((HANDLE)-1, modules, size, &size)) modules = NULL; } } } #define SYMBOL(var, type, sym) do { \ var = (type)GetProcAddress(GetModuleHandle(NULL), sym); \ if (!var) { \ if (!modules) \ return 1; \ for (i = 0; i < size/sizeof(*modules); ++i) { \ var = (type)GetProcAddress(modules[i], sym); \ if (var) \ break; \ } \ } \ } while (0) #else #define SYMBOL(var, type, sym) do { var = (type)dlsym(RTLD_DEFAULT, sym); } while (0) #endif SYMBOL(OPENSSL_init_ssl_func, int (*)(unsigned long long, const void *), "OPENSSL_init_ssl"); SYMBOL(SSL_library_init_func, int (*)(void), "SSL_library_init"); if (!OPENSSL_init_ssl_func && !SSL_library_init_func) return 0; SYMBOL(SSL_load_error_strings_func, void (*)(void), "SSL_load_error_strings"); if (!OPENSSL_init_ssl_func && !SSL_load_error_strings_func) return 0; SYMBOL(SSL_CTX_new_func, void *(*)(const void *), "SSL_CTX_new"); if (!SSL_CTX_new_func) return 0; SYMBOL(SSL_CTX_free_func, void (*)(void *), "SSL_CTX_free"); if (!SSL_CTX_free_func) return 0; SYMBOL(TLS_method_func, const void *(*)(void), "TLS_method"); if (!TLS_method_func) SYMBOL(TLS_method_func, const void *(*)(void), "TLSv1_2_method"); if (!TLS_method_func) SYMBOL(TLS_method_func, const void *(*)(void), "TLSv1_1_method"); if (!TLS_method_func) SYMBOL(TLS_method_func, const void *(*)(void), "TLSv1_method"); if (!TLS_method_func) return 0; if (OPENSSL_init_ssl_func) { OPENSSL_init_ssl_func(0, (void *)0); } else { SSL_library_init_func(); SSL_load_error_strings_func(); } method1 = TLS_method_func(); if (!method1) return 1; ctx1 = SSL_CTX_new_func(method1); if (!ctx1) return 1; mysql_server_init(-1, 0, 0); mysql_server_end(); method2 = TLS_method_func(); if (!method2) return 1; ctx2 = SSL_CTX_new_func(method2); if (!ctx2) return 1; SSL_CTX_free_func(ctx1); SSL_CTX_free_func(ctx2); return 0; EOF ); print "Client library deinitialize OpenSSL library functions: " . ($have_problem_with_openssl ? "yes" : "no") . "\n\n"; my $fileName = File::Spec->catfile("t", "MariaDB.mtest"); (open(FILE, ">$fileName") && (print FILE ("{ local " . Data::Dumper->Dump([$opt], ["opt"]) . " local " . Data::Dumper->Dump([$source], ["source"]) . "\$::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:MariaDB:\$::test_db\";\n" . "\$::test_dsn .= \":\$::test_host\" if \$::test_host;\n" . "\$::test_dsn .= \":\$::test_port\" if \$::test_port;\n". "\$::test_dsn .= \";mariadb_socket=\$::test_socket\" if \$::test_socket;\n" . "\$::test_dsn .= \";mariadb_connect_timeout=120;mariadb_read_timeout=120;mariadb_write_timeout=120\";\n" . "\$::test_mysql_config = \$opt->{'mysql_config'} if \$source->{'mysql_config'} eq 'User\\'s choice';\n" . "\$::test_cflags = \$opt->{'cflags'} if \$source->{'cflags'} eq 'User\\'s choice';\n" . "\$::test_libs = \$opt->{'libs'} if \$source->{'libs'} eq 'User\\'s choice';\n" . "} 1;\n")) && close(FILE)) || die "Failed to create $fileName: $!"; my $cflags = "-I\$(DBI_INSTARCH_DIR) $opt->{'cflags'}"; $cflags .= " -DHAVE_DBI_1_634" if eval { DBI->VERSION(1.634) }; $cflags .= " -DHAVE_DBI_1_642" if eval { DBI->VERSION(1.642) }; $cflags .= " -DHAVE_EMBEDDED" if $have_embedded; $cflags .= " -DHAVE_GET_CHARSET_NUMBER" if $have_get_charset_number; $cflags .= " -DHAVE_GET_OPTION" if $have_get_option; $cflags .= " -DHAVE_DEINITIALIZE_SSL" if $have_deinitialize_ssl; $cflags .= " -DHAVE_PROBLEM_WITH_OPENSSL" if $have_problem_with_openssl; my %o = ( 'NAME' => 'DBD::MariaDB', 'INC' => $cflags, 'dist' => { 'SUFFIX' => ".gz", 'DIST_DEFAULT' => 'all tardist', 'COMPRESS' => "gzip -9f" }, 'clean' => { 'FILES' => '*.xsi' }, 'realclean' => { 'FILES' => 't/MariaDB.mtest' }, 'C' => ["dbdimp.c", "MariaDB.c", "socket.c"], 'XS' => {'MariaDB.xs' => 'MariaDB.c'}, 'PM' => { 'lib/DBD/MariaDB.pm' => '$(INST_LIB)/DBD/MariaDB.pm', 'lib/DBD/MariaDB.pod' => '$(INST_LIB)/DBD/MariaDB.pod', 'lib/DBD/MariaDB/INSTALL.pod' => '$(INST_LIB)/DBD/MariaDB/INSTALL.pod', 'README.pod' => '$(INST_LIB)/DBD/MariaDB/README.pod', }, 'MAN3PODS' => { 'lib/DBD/MariaDB.pod' => '$(INST_MAN3DIR)/DBD::MariaDB.$(MAN3EXT)', 'lib/DBD/MariaDB/INSTALL.pod' => '$(INST_MAN3DIR)/DBD::MariaDB::INSTALL.$(MAN3EXT)', 'README.pod' => '$(INST_MAN3DIR)/DBD::MariaDB::README.$(MAN3EXT)', }, 'OBJECT' => '$(O_FILES)', 'LIBS' => (join ' ', @libdirs, $main_lib, @libs), @ldflags ? (dynamic_lib => { OTHERLDFLAGS => (join ' ', @ldflags) }) : (), 'VERSION_FROM' => 'lib/DBD/MariaDB.pm' ); if (eval { ExtUtils::MakeMaker->VERSION(5.43) }) { %o=(%o, ABSTRACT => 'MariaDB and MySQL driver for the Perl5 Database Interface (DBI)', AUTHOR => 'Pali ', LICENSE => 'perl', MIN_PERL_VERSION => '5.008001', META_MERGE => { 'meta-spec' => { version => 2, }, dynamic_config => 0, resources => { repository => { url => 'git://github.com/gooddata/DBD-MariaDB.git', web => 'https://github.com/gooddata/DBD-MariaDB', type => 'git', }, bugtracker => { web => 'https://github.com/gooddata/DBD-MariaDB/issues', }, x_MailingList => 'mailto:dbi-dev@perl.org', license => [ 'http://dev.perl.org/licenses/' ], homepage => 'https://github.com/gooddata/DBD-MariaDB', x_IRC => 'irc://irc.perl.org/#dbi', }, x_contributors => [ # a list of our awesome contributors generated from git # using the command: # git shortlog -se | cut -f2- | sed "s/^/ '/;s/$/',/" 'Alexandr Ciornii ', 'Alexey Molchanov ', 'Amiri Barksdale at Home ', 'Andrew Miller ', 'Aran Deltac ', 'Bernt M. Johnsen ', 'Branislav Zahradník ', 'Chase Whitener ', 'Chip Salzenberg ', 'Chris Hammond ', 'Chris Weyl ', 'Christian Walde ', 'Dagfinn Ilmari Mannsåker ', 'Daisuke Murase ', 'Damyan Ivanov ', 'Dan Book ', 'Daniël van Eeden ', 'Dave Lambley ', 'David Farrell ', 'David Steinbrunner ', 'Dominik Sauer ', 'Giovanni Bechis ', 'Graham Ollis ', 'H.Merijn Brand - Tux ', 'Hanno ', 'James McCoy ', 'Jan Holcapek ', 'Jim Winstead ', 'Juergen Weigert ', 'Kenny Gryp ', 'Lu Shengliang ', 'Masahiro Chiba ', 'Matthew Horsfall (alh) ', 'Michiel Beijen ', 'Mike Pomraning ', 'Mohammad S Anwar ', 'Pali ', 'Patrick Galbraith ', 'Perlover ', 'Peter Botha ', 'Petr Písař ', 'Reini Urban ', 'Rob Hoelz ', 'Rob Van Dam ', 'Rudy Lippan ', 'Scimon ', 'Sergey Zhuravlev ', 'Sergiy Borodych ', 'Sharif Nassar ', 'Steffen Mueller ', 'Steven Hartland ', 'Taro Kobayashi <9re.3000@gmail.com>', 'Tatsuhiko Miyagawa ', 'Tim Mullin ', 'Ville Skyttä ', 'Vladimir Marek ', 'katyavoid ', 'kmx ', 'tokuhirom ', 'zefram ', 'zentooo ', ], prereqs => { test => { recommends => { 'Net::SSLeay' => '1.43', 'Proc::ProcessTable' => 0, 'TAP::Harness' => '3.31', 'CPAN::Meta::YAML' => 0, }, suggests => { 'Storable' => 0, 'Test::Pod' => '1.41', 'Test::DistManifest' => 0, }, }, }, }, CONFIGURE_REQUIRES => { 'strict' => 0, 'utf8' => 0, 'warnings' => 0, 'Config' => 0, 'Data::Dumper' => 0, 'DBI' => '1.608', 'Devel::CheckLib' => '1.12', 'ExtUtils::MakeMaker' => 0, 'File::Spec' => 0, 'Getopt::Long' => 0, }, PREREQ_PM => { 'strict' => 0, 'warnings' => 0, 'DBI' => 1.608, 'DynaLoader' => 0, }, TEST_REQUIRES => { 'bigint' => 0, 'lib' => 0, 'strict' => 0, 'utf8' => 0, 'vars' => 0, 'warnings' => 0, 'B' => 0, 'DBI' => 0, 'DBI::Const::GetInfoType' => 0, 'Data::Dumper' => 0, 'Encode' => 0, 'File::Temp' => 0, 'FindBin' => 0, 'Test::Deep' => 0, 'Test::More' => '0.90', 'Time::HiRes' => 0, }, ); } 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 "mariadb_config --cflags" or a guessed value --libs= Use for running the linker; defaults to the value of "mariadb_config --libs" or a guessed value --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 chosen from the mariadb/mysqlclient library; ignored when --testhost is set to "localhost" --testsocket= Use as a unix socket for connecting to the database server; by default unix socket is chosen by mariadb/mysqlclient library; takes effect only when --testhost is set to "localhost" --mariadb_config Synonym for --mysql_config, override it --mysql_config= Specify for mariadb_config or mysql_config script --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 mariadb_config is called (if it can be found): mariadb_config --cflags mariadb_config --libs and so on. See DBD::MariaDB::INSTALL for details. USAGE exit 1; } sub CanExecute { my ($command) = @_; return MM->maybe_command($command) if File::Spec->file_name_is_absolute($command); foreach my $dir (File::Spec->path) { return 1 if MM->maybe_command(File::Spec->catfile($dir, $command)); } return 0; } my %ParsedCache; sub ParseMySQLConfig { my ($opt, $param) = @_; return $ParsedCache{$param} if exists $ParsedCache{$param}; return undef unless $opt->{'mysql_config'} and $opt->{'mysql_config'} ne 'skip'; my $output = `$opt->{'mysql_config'} --$param 2>&1`; if ($? == 0 and defined $output and $output !~ /Options:|Usage:|unrecognized option/) { $output =~ s/\s+$//s; $output =~ s/^\s+//s; $ParsedCache{$param} = $output; } else { $ParsedCache{$param} = undef; } return $ParsedCache{$param}; } ############################################################################ # # 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 (defined($opt->{$param})) { $source->{$param} = "User's choice"; return; } # First try to get options values from mysql_config if ($param eq 'cflags') { my $str = ParseMySQLConfig($opt, 'cflags'); if (defined $str) { $opt->{$param} = $str; $source->{$param} = "mysql_config"; return; } } elsif ($param eq 'libs') { foreach (qw(libmysqld-libs libs_r libs)) { my $str = ParseMySQLConfig($opt, $_); next unless defined $str; # Unfortunately ExtUtils::MakeMaker doesn't deal very well with -L'...' $str =~ s/\-L\'(.*?)\'/-L$1/sg; $str =~ s/\-L\"(.*?)\"/-L$1/sg; # libmysqld-libs and libs_r do not have to be always installed # check that we use correct library, sometimes library reported # by mysql_config is not present but linker find different # version in system wide location; so check that version in # header file matches version in library my ($main_lib, @libdirs, @ldflags); for (split ' ', $str) { if (not defined $main_lib and /^-l(?:.*mariadb.*|.*mysql.*)$/) { $main_lib = $_; } elsif (/^-L/) { push @libdirs, $_; } else { push @ldflags, $_; } } my $check_passed; if (defined $main_lib) { my $function = "\n#ifndef MYSQL_VERSION_ID\n#include \n#endif\n"; if ($_ eq 'libmysqld-libs') { # libmariadbd.so from MariaDB 10.3.1 - 10.3.7 is broken, unusable # and always crash in mysql_real_connect() function, so avoid its usage # https://jira.mariadb.org/browse/MDEV-16478 $function .= "\n#if defined(MARIADB_BASE_VERSION) || defined(MARIADB_PACKAGE_VERSION)\nif (mysql_get_client_version() >= 100301 && mysql_get_client_version() < 100308) return 1;\n#endif\n"; # libmysqld.a from MySQL 8.x is broken too $function .= "\n#if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_PACKAGE_VERSION)\nif (mysql_get_client_version() >= 80000) return 1;\n#endif\n"; } # MariaDB Connector/C 3.1.10+ has broken mysql_get_client_version() function, so use mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) instead $function .= "size_t version;\n"; $function .= "#if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000\n"; $function .= "if (mariadb_get_infov((void *)0, MARIADB_CLIENT_VERSION_ID, &version) != 0)\n"; $function .= "#endif\n"; $function .= "version = mysql_get_client_version();\n"; $function .= 'return (version == MYSQL_VERSION_ID) ? 0 : 1;'; # libmysqld is built using g++ rather than gcc and sometimes # we have to use libstdc++ to resolve linking problems foreach my $add_ldflags (undef, '-lstdc++') { my $ldflags = join ' ', @ldflags, (defined $add_ldflags ? $add_ldflags : ()); if ($Config{usedl}) { # check that we can create a shared library (not executable) check_lib( LIBS => (join ' ', @libdirs, $main_lib), ldflags => (join ' ', @libdirs, $ldflags, $Config{lddlflags}), ccflags => (join ' ', $opt->{cflags}, $Config{cccdlflags}), header => \@mysql_headers, function => $function, not_execute => 1, ) or next; } # and now create executable and do real version check check_lib( LIBS => (join ' ', @libdirs, $main_lib), ldflags => (join ' ', @libdirs, $ldflags), ccflags => $opt->{cflags}, header => \@mysql_headers, function => $function, ) or next; $str .= ' ' . $add_ldflags if defined $add_ldflags; $check_passed = 1; last; } } # libs param is checked as last, so ensure that mysql_config # error is reported back to the caller next unless $_ eq 'libs' or $check_passed; $opt->{$param} = $str; $source->{$param} = "mysql_config"; return; } } # Ok, mysql_config doesn't work. We need to do our best # First check environment variables my $normparam = uc($param); $normparam =~ tr/-/_/; if (defined($ENV{'DBD_MARIADB_'.$normparam})) { $opt->{$param} = $ENV{'DBD_MARIADB_'.$normparam}; $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 MariaDB or 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 "testdb") { $source->{$param} = "default"; $opt->{$param} = $TESTDB; } elsif ($param eq "testpassword") { $source->{$param} = "default"; $opt->{$param} = ""; } elsif ($param eq "cflags") { $source->{$param} = "guessed"; my ($dir, $file) = 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::MariaDB::INSTALL, section "C Compiler flags" or type perl Makefile.PL --help MSG } elsif ($param eq "libs") { $source->{$param} = "guessed"; my @files = qw(mariadb.lib libmariadb.lib mariadbclient.lib mysqlclient.lib libmysqld.so libmysqld.a libmariadb.so libmariadb.a libmysqlclient.so libmysqlclient.a); my ($dir, $file) = SearchFor('lib', @files); if ($dir) { my $lib = $file; $lib =~ s/\.[^.]+$//; $lib =~ s/^lib//; $opt->{$param} = "-L$dir -l$lib"; return; } die <<"MSG"; Failed to determine directory of MariaDB or MySQL client library. Use perl Makefile.PL --libs="-L -l" to set directory and client library. For details see the DBD::MariaDB::INSTALL, section "Linker flags" or type perl Makefile.PL --help MSG } elsif ($param eq "testhost" || $param eq "testport" || $param eq "testsocket") { # known parameter, but do nothing } else { die "Unknown configuration parameter: $param"; } } } sub SearchFor { my($subdir, @files) = @_; my @dirs = ($^O eq 'MSWin32') ? qw(C:) : qw(/usr/local /usr /opt); for my $f (@files) { for my $dir (@dirs) { my $try1 = File::Spec->catdir($dir, $subdir); my $try2 = File::Spec->catdir($try1, "mariadb"); my $try3 = File::Spec->catdir($try1, "mysql"); for my $path ($try1, $try2, $try3) { my $file = File::Spec->catfile($path, $f); if (-f $file) { my (undef, undef, $file) = File::Spec->splitpath($file); return ($path, $file); } } } } } package MY; sub postamble { return DBI::DBD::dbd_postamble(@_); } 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{META_MERGE} and $params{META_MERGE}->{'meta-spec'}->{version} >= 2 and $eumm_version < 6.68) { #EUMM 6.68 has problems with meta-spec 2 delete $params{META_MERGE}->{'meta-spec'}; if ($params{META_MERGE}->{resources}) { foreach (values %{$params{META_MERGE}->{resources}}) { $_ = $_->{url} || $_->{web} if ref $_ eq 'HASH'; } } if ($params{META_MERGE}->{prereqs}) { $params{CONFIGURE_REQUIRES} = { %{$params{CONFIGURE_REQUIRES} || {'ExtUtils::MakeMaker' => 0}}, %{$params{META_MERGE}->{prereqs}->{configure}->{requires} || {}} }; $params{BUILD_REQUIRES} = { %{$params{BUILD_REQUIRES} || {'ExtUtils::MakeMaker' => 0}}, %{$params{META_MERGE}->{prereqs}->{build}->{requires} || {}} }; $params{TEST_REQUIRES} = { %{$params{TEST_REQUIRES} || {}}, %{$params{META_MERGE}->{prereqs}->{test}->{requires} || {}} }; $params{PREREQ_PM} = { %{$params{PREREQ_PM} || {}}, %{$params{META_MERGE}->{prereqs}->{runtime}->{requires} || {}} }; my @recommends = ( %{$params{META_MERGE}->{prereqs}->{configure}->{recommends} || {}}, %{$params{META_MERGE}->{prereqs}->{configure}->{suggests} || {}}, %{$params{META_MERGE}->{prereqs}->{build}->{recommends} || {}}, %{$params{META_MERGE}->{prereqs}->{build}->{suggests} || {}}, %{$params{META_MERGE}->{prereqs}->{test}->{recommends} || {}}, %{$params{META_MERGE}->{prereqs}->{test}->{suggests} || {}}, %{$params{META_MERGE}->{prereqs}->{runtime}->{recommends} || {}}, %{$params{META_MERGE}->{prereqs}->{runtime}->{suggests} || {}}, ); $params{META_MERGE}->{recommends} = { %{$params{META_MERGE}->{recommends} || {}}, @recommends } if @recommends; delete $params{META_MERGE}->{prereqs}; } } 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}; } if ($params{TEST_REQUIRES} and $eumm_version < 6.64) { #EUMM 6.64 has problems with TEST_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{TEST_REQUIRES}} }; delete $params{TEST_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); } DBD-MariaDB-1.22/README.pod0000644000175000017500000000305414230360604013361 0ustar palipali=head1 DBD::MariaDB - database driver for Perl =begin html

Travis CI Build Status AppVeyor Build Status

=end html This is the Perl L driver for access to MariaDB and MySQL databases. The goal of our effort was to fix MariaDB compatibility, Perl Unicode support and security related bugs. This Perl DBI driver is a fork of the L driver and was created because said issues in the original DBD::mysql have not been addressed for more than a year. =head2 Usage Usage of this Perl DBI driver is described in L. =head2 Installation Installation is described in L. =head2 Support This module comes with no warranty and is distributed as is. To participate in a general discussion about Perl DBI with other DBI users, subscribe to the mailing list by sending an email to L|mailto:dbi-users-subscribe@perl.org>. Mailing list archives are available at the L. =head2 License This module is released under the same license as Perl itself. See L for details. =head2 Contributing Contributions are welcome. DBD-MariaDB-1.22/socket.c0000644000175000017500000000217414230360604013356 0ustar palipali/* * On WIN32 windows.h and winsock.h need to be included before mysql.h * Otherwise SOCKET type which is needed for mysql.h is not defined */ #ifdef _WIN32 #include #include #endif #include #include #include #ifndef _WIN32 #include #include #include #endif #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) /* Do not export non-static functions from driver library */ #pragma GCC visibility push(hidden) #endif /* * Warning: Native socket code must be outside of dbdimp.c and dbdimp.h because * perl header files redefine socket function. This file must not * include any perl header files! */ int mariadb_dr_socket_ready(my_socket fd) { struct timeval timeout; fd_set fds; int retval; FD_ZERO(&fds); FD_SET(fd, &fds); timeout.tv_sec = 0; timeout.tv_usec = 0; retval = select(fd+1, &fds, NULL, NULL, &timeout); if (retval < 0) { #ifdef _WIN32 /* Windows does not update errno */ return -WSAGetLastError(); #else return -errno; #endif } return retval; } DBD-MariaDB-1.22/MANIFEST.SKIP0000644000175000017500000000044314230360604013615 0ustar palipali^.*\.exe$ ^.*\.o$ ^DBD-MariaDB-.*\.tar\.gz$ ^MYMETA\.json$ ^MYMETA\.yml$ ^Makefile$ ^Makefile\.old$ ^MariaDB\.bs$ ^MariaDB\.c$ ^MariaDB\.def$ ^MariaDB\.xsi$ ^\.git/.*$ ^\.gitignore$ ^\.mailmap$ ^\.travis\.yml$ ^appveyor\.yml$ ^blib/.*$ ^dll\.base$ ^dll\.exp$ ^pm_to_blib$ ^t/MariaDB\.mtest$ DBD-MariaDB-1.22/dbdimp.h0000644000175000017500000005356014230360604013337 0ustar palipali/* * DBD::MariaDB - DBI driver for the MariaDB and MySQL database * * Copyright (c) 2005 Patrick Galbraith * Copyright (c) 2003 Rudolf Lippan * Copyright (c) 1997-2003 Jochen Wiedmann * * Based on DBD::Oracle; DBD::Oracle is * * Copyright (c) 1994,1995 Tim Bunce * * You may distribute this under the terms of either the GNU General Public * License or the Artistic License, as specified in the Perl README file. */ #define PERL_NO_GET_CONTEXT /* * Header files we use */ /* * On WIN32 windows.h and winsock.h need to be included before mysql.h * Otherwise SOCKET type which is needed for mysql.h is not defined */ #ifdef _WIN32 #include #include #endif #include /* Comes with MySQL-devel */ #include /* Comes MySQL */ #include /* Comes with MySQL-devel */ #ifndef MYSQL_VERSION_ID #include /* Comes with MySQL-devel */ #endif #include /* installed by the DBI module */ #include /* For uint32_t */ #if !defined(MARIADB_BASE_VERSION) && defined(MARIADB_PACKAGE_VERSION) #define MARIADB_BASE_VERSION #endif /* Macro is available in my_global.h which is not included or present in some versions of MariaDB */ #ifndef NOT_FIXED_DEC #define NOT_FIXED_DEC 31 #endif /* Macro is available in m_ctype.h which is not included in some versions of MySQL */ #ifndef MY_CS_PRIMARY #define MY_CS_PRIMARY 32 #endif /* Macro is available in mysql_com.h, but not defined in older MySQL versions */ #ifndef SERVER_STATUS_NO_BACKSLASH_ESCAPES #define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512 #endif /* Macro is not defined in older MySQL versions */ #ifndef CR_NO_STMT_METADATA #define CR_NO_STMT_METADATA 2052 #endif /* Macro is not defined in some MariaDB versions */ #ifndef CR_NO_RESULT_SET #define CR_NO_RESULT_SET 2053 #endif /* Macro is not defined in older MySQL versions */ #ifndef CR_NOT_IMPLEMENTED #define CR_NOT_IMPLEMENTED 2054 #endif /* Macro is not defined in older MySQL versions */ #ifndef CR_STMT_CLOSED #define CR_STMT_CLOSED 2056 #endif #ifndef PERL_STATIC_INLINE #define PERL_STATIC_INLINE static #endif #ifndef NOT_REACHED #define NOT_REACHED assert(0) #endif #ifndef SVfARG #define SVfARG(p) ((void*)(p)) #endif #ifndef SSize_t_MAX #define SSize_t_MAX (SSize_t)(~(Size_t)0 >> 1) #endif /* PERL_UNUSED_ARG does not exist prior to perl 5.9.3 */ #ifndef PERL_UNUSED_ARG # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ # include # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) # else # define PERL_UNUSED_ARG(x) ((void)x) # endif #endif /* assert_not_ROK is broken prior to perl 5.8.2 */ #if PERL_VERSION < 8 || (PERL_VERSION == 8 && PERL_SUBVERSION < 2) #undef assert_not_ROK #define assert_not_ROK(sv) #endif #ifndef SvPV_nomg_nolen #define SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK ? SvPVX(sv) : sv_2pv_flags(sv, &PL_na, 0)) #endif /* looks_like_number() process get magic prior to perl 5.15.4, so reimplement it */ #if PERL_VERSION < 15 || (PERL_VERSION == 15 && PERL_SUBVERSION < 4) #undef looks_like_number PERL_STATIC_INLINE I32 looks_like_number(pTHX_ SV *sv) { char *sbegin; STRLEN len; if (!SvPOK(sv) && !SvPOKp(sv)) return SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK); sbegin = SvPV_nomg(sv, len); return grok_number(sbegin, len, NULL); } #define looks_like_number(sv) looks_like_number(aTHX_ (sv)) #endif #ifndef SvPVutf8_nomg PERL_STATIC_INLINE char * SvPVutf8_nomg(pTHX_ SV *sv, STRLEN *len) { char *buf = SvPV_nomg(sv, *len); if (SvUTF8(sv)) return buf; if (SvGMAGICAL(sv)) sv = sv_2mortal(newSVpvn(buf, *len)); /* There is sv_utf8_upgrade_nomg(), but it is broken prior to Perl version 5.13.10 */ return SvPVutf8(sv, *len); } #define SvPVutf8_nomg(sv, len) SvPVutf8_nomg(aTHX_ (sv), &(len)) #endif #ifndef SvPVbyte_nomg PERL_STATIC_INLINE char * SvPVbyte_nomg(pTHX_ SV *sv, STRLEN *len) { char *buf = SvPV_nomg(sv, *len); if (!SvUTF8(sv)) return buf; if (SvGMAGICAL(sv)) { sv = sv_2mortal(newSVpvn(buf, *len)); SvUTF8_on(sv); } return SvPVbyte(sv, *len); } #define SvPVbyte_nomg(sv, len) SvPVbyte_nomg(aTHX_ (sv), &(len)) #endif #ifndef SvTRUE_nomg #define SvTRUE_nomg SvTRUE /* SvTRUE does not process get magic for scalars with already cached values, so we are safe */ #endif /* Sorry, there is no way to handle integer magic scalars properly prior to perl 5.9.1 */ /* Remove wrong SvIV_nomg macro defined by ppport.h */ #if defined(SvIV_nomg) && (PERL_VERSION < 9 | (PERL_VERSION == 9 && PERL_SUBVERSION < 1)) #undef SvIV_nomg #endif #ifndef SvIV_nomg PERL_STATIC_INLINE IV SvIV_nomg(pTHX_ SV *sv) { UV uv; char *str; STRLEN len; int num_type; if (SvIOK(sv) || SvIOKp(sv)) { if (!SvIsUV(sv)) return SvIVX(sv); uv = SvUVX(sv); if (uv > (UV)IV_MAX) return IV_MAX; return (IV)uv; } if (SvNOK(sv) || SvNOKp(sv)) return (IV)SvNVX(sv); str = SvPV_nomg(sv, len); num_type = grok_number(str, len, &uv); if (!(num_type & (IS_NUMBER_IN_UV)) || (num_type & IS_NUMBER_NOT_INT)) { warner(packWARN(WARN_NUMERIC), "Argument \"%s\" isn't numeric", str); return 0; } if (num_type & IS_NUMBER_NEG) { if (uv > (UV)IV_MAX+1) return IV_MIN; return -(IV)uv; } else { if (uv > (UV)IV_MAX) return IV_MAX; return (IV)uv; } } #define SvIV_nomg(sv) SvIV_nomg(aTHX_ sv) #endif /* Remove wrong SvUV_nomg macro defined by ppport.h */ #if defined(SvUV_nomg) && (PERL_VERSION < 9 | (PERL_VERSION == 9 && PERL_SUBVERSION < 1)) #undef SvUV_nomg #endif #ifndef SvUV_nomg PERL_STATIC_INLINE UV SvUV_nomg(pTHX_ SV *sv) { IV iv; UV uv; char *str; STRLEN len; int num_type; if (SvIOK(sv) || SvIOKp(sv)) { if (SvIsUV(sv)) return SvUVX(sv); iv = SvIVX(sv); if (iv < 0) return 0; return (UV)iv; } if (SvNOK(sv) || SvNOKp(sv)) return (UV)SvNVX(sv); str = SvPV_nomg(sv, len); num_type = grok_number(str, len, &uv); if (!(num_type & (IS_NUMBER_IN_UV)) || (num_type & IS_NUMBER_NOT_INT)) { warner(packWARN(WARN_NUMERIC), "Argument \"%s\" isn't numeric", str); return 0; } if (num_type & IS_NUMBER_NEG) return 0; return uv; } #define SvUV_nomg(sv) SvUV_nomg(aTHX_ sv) #endif /* Sorry, there is no way to handle numeric magic scalars properly prior to perl 5.13.2 */ #ifndef SvNV_nomg #define SvNV_nomg(sv) \ ((SvNOK(sv) || SvNOKp(sv)) \ ? SvNVX(sv) \ : (SvIOK(sv) || SvIOKp(sv)) \ ? (SvIsUV(sv) \ ? ((NV)SvUVX(sv)) \ : ((NV)SvIVX(sv))) \ : (SvPOK(sv) || SvPOKp(sv)) \ ? ((NV)Atof(SvPVX(sv))) \ : ((NV)Atof(SvPV_nomg_nolen(sv)))) #endif #ifndef sv_cmp_flags #define sv_cmp_flags(a,b,c) sv_cmp(a,b) /* Sorry, there is no way to compare magic scalars properly prior to perl 5.13.6 */ #endif #ifndef gv_stashpvs #define gv_stashpvs(str, flags) gv_stashpvn("" str "", sizeof((str))-1, (flags)) #endif #ifndef newSVpvs #define newSVpvs(str) newSVpvn("" str "", sizeof((str)) - 1) #endif #ifndef hv_fetchs #define hv_fetchs(hv, key, lval) hv_fetch((hv), "" key "", sizeof((key))-1, (lval)) #endif #ifndef hv_stores #define hv_stores(hv, key, val) hv_store((hv), "" key "", sizeof((key))-1, (val), 0) #endif #ifndef hv_deletes #define hv_deletes(hv, key, flags) hv_delete((hv), "" key "", sizeof((key))-1, (flags)) #endif #ifndef memEQs #define memEQs(s1, l, s2) (sizeof((s2))-1 == (l) && memEQ((s1), "" s2 "", sizeof((s2))-1)) #endif #ifndef strBEGINs #define strBEGINs(s1, s2) strnEQ((s1), "" s2 "", sizeof((s2))-1) #endif #define GEO_DATATYPE_VERSION 50007 #define NEW_DATATYPE_VERSION 50003 #if MYSQL_VERSION_ID < NEW_DATATYPE_VERSION #define MYSQL_TYPE_VARCHAR 15 #define MYSQL_TYPE_BIT 16 #define MYSQL_TYPE_NEWDECIMAL 246 #endif #if MYSQL_VERSION_ID < GEO_DATATYPE_VERSION #define MYSQL_TYPE_GEOMETRY 255 #endif /* * This is the versions of libmysql that supports MySQL Fabric. * We need to check for special macro LIBMYSQL_VERSION_ID. */ #ifdef LIBMYSQL_VERSION_ID #if LIBMYSQL_VERSION_ID >= 60200 && LIBMYSQL_VERSION_ID < 70000 #define HAVE_FABRIC #endif #endif #if !defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 80001 #define my_bool bool #endif /* * MariaDB Connector/C 3.1.10 changed API of mysql_get_client_version() * function. Before that release it returned client version. With that release * it started returning Connector/C package version. * * So when compiling with MariaDB Connector/C client library, redefine * mysql_get_client_version() to always returns client version via function * mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) call. * * Driver code expects for a long time that mysql_get_client_version() call * returns client version and not something different. * * Function mariadb_get_infov() is supported since MariaDB Connector/C 3.0+. */ #if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000 PERL_STATIC_INLINE unsigned long mariadb_get_client_version(void) { /* MARIADB_CLIENT_VERSION_ID really expects size_t type, documentation is wrong and says unsigned int. */ size_t version; if (mariadb_get_infov(NULL, MARIADB_CLIENT_VERSION_ID, &version) != 0) version = mysql_get_client_version(); /* On error fallback to mysql_get_client_version() */ return version; } #define mysql_get_client_version() mariadb_get_client_version() #endif /* MYSQL_SECURE_AUTH became a no-op from MySQL 5.7.5 and is removed from MySQL 8.0.3 */ #if defined(MARIADB_BASE_VERSION) || MYSQL_VERSION_ID <= 50704 #define HAVE_SECURE_AUTH #endif /* mysql_error(NULL) returns last error message, needs MySQL 5.0.60+ or 5.1.24+; does not work with MariaDB Connector/C yet */ #if ((MYSQL_VERSION_ID >= 50060 && MYSQL_VERSION_ID < 50100) || MYSQL_VERSION_ID >= 50124) && !defined(MARIADB_PACKAGE_VERSION) #define HAVE_LAST_ERROR #endif /* * MySQL and MariaDB Embedded are affected by https://jira.mariadb.org/browse/MDEV-16578 * MariaDB 10.2.2+ prior to 10.2.19 and 10.3.9 and MariaDB Connector/C prior to 3.0.5 are affected by https://jira.mariadb.org/browse/CONC-336 * MySQL 8.0.4+ is affected too by https://bugs.mysql.com/bug.php?id=93276 */ #if defined(HAVE_EMBEDDED) || (!defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 80004) || (defined(MARIADB_PACKAGE_VERSION) && (!defined(MARIADB_PACKAGE_VERSION_ID) || MARIADB_PACKAGE_VERSION_ID < 30005)) || (defined(MARIADB_VERSION_ID) && ((MARIADB_VERSION_ID >= 100202 && MARIADB_VERSION_ID < 100219) || (MARIADB_VERSION_ID >= 100300 && MARIADB_VERSION_ID < 100309))) #define HAVE_BROKEN_INIT #endif /* * Check which SSL settings are supported by API at compile time */ /* Use mysql_options with MYSQL_OPT_SSL_VERIFY_SERVER_CERT */ #if ((MYSQL_VERSION_ID >= 50023 && MYSQL_VERSION_ID < 50100) || MYSQL_VERSION_ID >= 50111) && (MYSQL_VERSION_ID < 80000 || defined(MARIADB_BASE_VERSION)) #define HAVE_SSL_VERIFY #endif /* Use mysql_options with MYSQL_OPT_SSL_ENFORCE (CVE-2015-3152, fix for MySQL) */ #if !defined(MARIADB_BASE_VERSION) && !defined(HAVE_EMBEDDED) && MYSQL_VERSION_ID >= 50703 && MYSQL_VERSION_ID < 80000 && MYSQL_VERSION_ID != 60000 #define HAVE_SSL_ENFORCE #endif /* Use mysql_options with MYSQL_OPT_SSL_MODE (CVE-2015-3152, fix for MySQL) */ #if !defined(MARIADB_BASE_VERSION) && !defined(HAVE_EMBEDDED) && MYSQL_VERSION_ID >= 50711 && MYSQL_VERSION_ID != 60000 #define HAVE_SSL_MODE #endif /* Use mysql_options with MYSQL_OPT_SSL_MODE, but only SSL_MODE_REQUIRED is supported (CVE-2017-3305, fix for MySQL) */ #if !defined(MARIADB_BASE_VERSION) && !defined(HAVE_EMBEDDED) && ((MYSQL_VERSION_ID >= 50636 && MYSQL_VERSION_ID < 50700) || (MYSQL_VERSION_ID >= 50555 && MYSQL_VERSION_ID < 50600)) #define HAVE_SSL_MODE_ONLY_REQUIRED #endif /* * Check which SSL settings are supported by API at runtime */ /* MYSQL_OPT_SSL_VERIFY_SERVER_CERT automatically enforce SSL mode (CVE-2015-3152 and CVE-2017-3305 and CVE-2018-2767, fix for MariaDB) */ PERL_STATIC_INLINE bool ssl_verify_also_enforce_ssl(void) { #ifdef MARIADB_BASE_VERSION unsigned long version = mysql_get_client_version(); #ifdef HAVE_EMBEDDED return ((version >= 50560 && version < 50600) || (version >= 100035 && version < 100100) || (version >= 100133 && version < 100200) || (version >= 100215 && version < 100300) || version >= 100307); #else return ((version >= 50556 && version < 50600) || (version >= 100031 && version < 100100) || (version >= 100123 && version < 100200) || (version >= 100206 && version < 100300) || version >= 100301); #endif #else return FALSE; #endif } /* MYSQL_OPT_SSL_VERIFY_SERVER_CERT is not vulnerable (CVE-2016-2047) and can be used */ PERL_STATIC_INLINE bool ssl_verify_usable(void) { unsigned long version = mysql_get_client_version(); #ifdef MARIADB_BASE_VERSION return ((version >= 50547 && version < 50600) || (version >= 100023 && version < 100100) || version >= 100110); #else return ((version >= 50549 && version < 50600) || (version >= 50630 && version < 50700) || version >= 50712); #endif } /* * Internal constants, used for fetching array attributes */ enum av_attribs { AV_ATTRIB_NAME = 0, AV_ATTRIB_TABLE, AV_ATTRIB_TYPE, AV_ATTRIB_SQL_TYPE, AV_ATTRIB_IS_PRI_KEY, AV_ATTRIB_IS_NOT_NULL, AV_ATTRIB_NULLABLE, AV_ATTRIB_LENGTH, AV_ATTRIB_IS_NUM, AV_ATTRIB_TYPE_NAME, AV_ATTRIB_PRECISION, AV_ATTRIB_SCALE, AV_ATTRIB_MAX_LENGTH, AV_ATTRIB_IS_KEY, AV_ATTRIB_IS_BLOB, AV_ATTRIB_IS_AUTO_INCREMENT, AV_ATTRIB_LAST /* Dummy attribute, never used, for allocation */ }; /* purposes only */ /* Double linked list */ struct mariadb_list_entry { void *data; struct mariadb_list_entry *prev; struct mariadb_list_entry *next; }; #define mariadb_list_add(list, entry, ptr) \ STMT_START { \ Newz(0, (entry), 1, struct mariadb_list_entry); \ (entry)->data = (ptr); \ (entry)->prev = NULL; \ (entry)->next = (list); \ if ((list)) \ (list)->prev = (entry); \ (list) = (entry); \ } STMT_END #define mariadb_list_remove(list, entry) \ STMT_START { \ if ((entry)->prev) \ (entry)->prev->next = (entry)->next; \ if ((entry)->next) \ (entry)->next->prev = (entry)->prev; \ if ((list) == (entry)) \ (list) = (entry)->next; \ Safefree((entry)); \ (entry) = NULL; \ } STMT_END /* * This is our part of the driver handle. We receive the handle as * an "SV*", say "drh", and receive a pointer to the structure below * by declaring * * D_imp_drh(drh); * * This declares a variable called "imp_drh" of type * "struct imp_drh_st *". */ struct imp_drh_st { dbih_drc_t com; /* MUST be first element in structure */ struct mariadb_list_entry *active_imp_dbhs; /* List of imp_dbh structures with active MYSQL* */ struct mariadb_list_entry *taken_pmysqls; /* List of active MYSQL* from take_imp_data() */ unsigned long int instances; bool non_embedded_started; #if !defined(HAVE_EMBEDDED) && defined(HAVE_BROKEN_INIT) bool non_embedded_finished; #endif bool embedded_started; SV *embedded_args; SV *embedded_groups; }; /* * Likewise, this is our part of the database handle, as returned * by DBI->connect. We receive the handle as an "SV*", say "dbh", * and receive a pointer to the structure below by declaring * * D_imp_dbh(dbh); * * This declares a variable called "imp_dbh" of type * "struct imp_dbh_st *". */ struct imp_dbh_st { dbih_dbc_t com; /* MUST be first element in structure */ struct mariadb_list_entry *list_entry; /* Entry of imp_drh->active_imp_dbhs list */ MYSQL *pmysql; bool connected; /* Set to true after DBI->connect finished */ bool auto_reconnect; bool bind_type_guessing; bool bind_comment_placeholders; bool no_autocommit_cmd; bool use_mysql_use_result; /* TRUE if execute should use * mysql_use_result rather than * mysql_store_result */ bool use_server_side_prepare; bool disable_fallback_for_server_prepare; void* async_query_in_flight; my_ulonglong insertid; struct { unsigned int auto_reconnects_ok; unsigned int auto_reconnects_failed; } stats; }; /* * The bind_param method internally uses this structure for storing * parameters. */ typedef struct imp_sth_ph_st { char* value; STRLEN len; int type; bool bound; } imp_sth_ph_t; /* * Storage for numeric value in prepared statement */ typedef union numeric_val_u { unsigned char tval; unsigned short sval; uint32_t lval; my_ulonglong llval; float fval; double dval; } numeric_val_t; /* * The bind_param method internally uses this structure for storing * parameters. */ typedef struct imp_sth_phb_st { numeric_val_t numeric_val; unsigned long length; my_bool is_null; } imp_sth_phb_t; /* * The mariadb_st_describe uses this structure for storing * fields meta info. */ typedef struct imp_sth_fbh_st { unsigned long length; my_bool is_null; my_bool error; char *data; numeric_val_t numeric_val; bool is_utf8; } imp_sth_fbh_t; typedef struct imp_sth_fbind_st { unsigned long * length; my_bool * is_null; } imp_sth_fbind_t; /* * Finally our part of the statement handle. We receive the handle as * an "SV*", say "dbh", and receive a pointer to the structure below * by declaring * * D_imp_sth(sth); * * This declares a variable called "imp_sth" of type * "struct imp_sth_st *". */ struct imp_sth_st { dbih_stc_t com; /* MUST be first element in structure */ char *statement; STRLEN statement_len; MYSQL_STMT *stmt; MYSQL_BIND *bind; MYSQL_BIND *buffer; imp_sth_phb_t *fbind; imp_sth_fbh_t *fbh; bool has_been_bound; bool use_server_side_prepare; /* server side prepare statements? */ bool disable_fallback_for_server_prepare; MYSQL_RES* result; /* result */ my_ulonglong currow; /* number of current row */ my_ulonglong row_num; /* total number of rows */ bool done_desc; /* have we described this sth yet ? */ long long_buflen; /* length for long/longraw (if >0) */ bool long_trunc_ok; /* is truncating a long an error */ my_ulonglong insertid; /* ID of auto insert */ unsigned int warning_count; /* Number of warnings after execute() */ imp_sth_ph_t* params; /* Pointer to parameter array */ AV* av_attr[AV_ATTRIB_LAST];/* For caching array attributes */ bool use_mysql_use_result; /* TRUE if execute should use */ /* mysql_use_result rather than */ /* mysql_store_result */ bool is_async; }; /* * And last, not least: The prototype definitions. * * These defines avoid name clashes for multiple statically linked DBD's */ #define dbd_init mariadb_dr_init #define dbd_discon_all mariadb_dr_discon_all #define dbd_take_imp_data mariadb_db_take_imp_data #define dbd_db_login6_sv mariadb_db_login6_sv #define dbd_db_do6 mariadb_db_do6 #define dbd_db_commit mariadb_db_commit #define dbd_db_rollback mariadb_db_rollback #define dbd_db_disconnect mariadb_db_disconnect #define dbd_db_destroy mariadb_db_destroy #define dbd_db_STORE_attrib mariadb_db_STORE_attrib #define dbd_db_FETCH_attrib mariadb_db_FETCH_attrib #define dbd_db_last_insert_id mariadb_db_last_insert_id #define dbd_db_data_sources mariadb_db_data_sources #define dbd_st_prepare_sv mariadb_st_prepare_sv #define dbd_st_execute_iv mariadb_st_execute_iv #define dbd_st_fetch mariadb_st_fetch #define dbd_st_finish mariadb_st_finish #define dbd_st_destroy mariadb_st_destroy #define dbd_st_blob_read mariadb_st_blob_read #define dbd_st_STORE_attrib mariadb_st_STORE_attrib #define dbd_st_FETCH_attrib mariadb_st_FETCH_attrib #define dbd_st_last_insert_id mariadb_st_last_insert_id #define dbd_bind_ph mariadb_st_bind_ph #include /* Compatibility for DBI version prior to 1.634 which do not support dbd_st_execute_iv API */ #ifndef HAVE_DBI_1_634 #define dbd_st_execute mariadb_st_execute IV dbd_st_execute_iv(SV *sth, imp_sth_t *imp_sth); PERL_STATIC_INLINE int dbd_st_execute(SV *sth, imp_sth_t *imp_sth) { IV ret = dbd_st_execute_iv(sth, imp_sth); if (ret >= INT_MIN && ret <= INT_MAX) return ret; else /* overflow */ return -1; /* -1 is unknown number of rows */ } #endif #ifndef HAVE_DBI_1_642 IV mariadb_db_do6(SV *dbh, imp_dbh_t *imp_dbh, SV *statement, SV *attribs, I32 items, I32 ax); SV *mariadb_st_last_insert_id(SV *sth, imp_sth_t *imp_sth, SV *catalog, SV *schema, SV *table, SV *field, SV *attr); #endif #define MARIADB_DR_ATTRIB_GET_SVPS(attribs, key) DBD_ATTRIB_GET_SVP((attribs), "" key "", sizeof((key))-1) SV* mariadb_dr_my_ulonglong2sv(pTHX_ my_ulonglong val); #define my_ulonglong2sv(val) mariadb_dr_my_ulonglong2sv(aTHX_ val) void mariadb_dr_do_error (SV* h, unsigned int rc, const char *what, const char *sqlstate); bool mariadb_st_more_results(SV*, imp_sth_t*); AV* mariadb_db_type_info_all(void); SV* mariadb_db_quote(SV*, SV*, SV*); bool mariadb_db_reconnect(SV *h, MYSQL_STMT *stmt); my_ulonglong mariadb_db_async_result(SV* h, MYSQL_RES** resp); int mariadb_db_async_ready(SV* h); int mariadb_dr_socket_ready(my_socket fd); DBD-MariaDB-1.22/lib/0000755000175000017500000000000014230360635012470 5ustar palipaliDBD-MariaDB-1.22/lib/DBD/0000755000175000017500000000000014230360635013061 5ustar palipaliDBD-MariaDB-1.22/lib/DBD/MariaDB.pm0000644000175000017500000010557314230360604014665 0ustar palipali#!/usr/bin/perl use strict; use warnings; require 5.008_001; # just as DBI package DBD::MariaDB; use DBI; use DynaLoader(); our @ISA = qw(DynaLoader); our $VERSION = '1.22'; bootstrap DBD::MariaDB $VERSION; our $err = 0; # holds error code for DBI::err our $errstr = ""; # holds error string for DBI::errstr our $sqlstate = ""; # holds five character SQLSTATE code 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' => 'MariaDB', 'Version' => $VERSION, 'Err' => \$DBD::MariaDB::err, 'Errstr' => \$DBD::MariaDB::errstr, 'State' => \$DBD::MariaDB::sqlstate, 'Attribution' => "DBD::MariaDB $VERSION by Pali and others", }); if (!$methods_are_installed) { # for older DBI versions disable warning: method name prefix 'mariadb_' is not associated with a registered driver local $SIG{__WARN__} = sub {} unless eval { DBI->VERSION(1.640) }; DBD::MariaDB::db->install_method('mariadb_sockfd'); DBD::MariaDB::db->install_method('mariadb_async_result'); DBD::MariaDB::db->install_method('mariadb_async_ready'); DBD::MariaDB::st->install_method('mariadb_async_result'); DBD::MariaDB::st->install_method('mariadb_async_ready'); # for older DBI versions register our last_insert_id statement method if (not eval { DBI->VERSION(1.642) }) { # disable warning: method name prefix 'last_' is not associated with a registered driver local $SIG{__WARN__} = sub {}; DBD::MariaDB::st->install_method('last_insert_id'); } $methods_are_installed++; } $drh; } sub CLONE { undef $drh; } sub parse_dsn { my ($class, $dsn) = @_; my $hash = {}; my($var, $val); if (!defined($dsn)) { return $hash; } 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 (qw(database host port)) { if (!defined($hash->{$var})) { $hash->{$var} = $val; last; } } } } return $hash; } # ====== DRIVER ====== package # hide from PAUSE DBD::MariaDB::dr; use strict; use DBI qw(:sql_types); sub connect { my($drh, $dsn, $username, $password, $attrhash) = @_; my($port); my($cWarn); my $connect_ref= { 'Name' => $dsn }; $attrhash = {} unless defined $attrhash; # create a 'blank' dbh my $attr_dsn = DBD::MariaDB->parse_dsn($dsn); my($this, $privateAttrHash) = (undef, $attrhash); $privateAttrHash = { %$attr_dsn, %$privateAttrHash, 'Name' => $dsn, 'user' => $username, 'password' => $password }; if (exists $attrhash->{dbi_imp_data}) { $connect_ref->{'dbi_imp_data'} = $attrhash->{dbi_imp_data}; } if (!defined($this = DBI::_new_dbh($drh, $connect_ref, $privateAttrHash))) { return undef; } DBD::MariaDB::db::_login($this, $dsn, $username, $password) or $this = undef; $this; } sub data_sources { my ($self, $attributes) = @_; my ($host, $port, $username, $password); if (defined $attributes) { %{$attributes} = %{$attributes}; $host = delete $attributes->{host}; $port = delete $attributes->{port}; $username = delete $attributes->{user}; $password = delete $attributes->{password}; } my $dsn = ''; $dsn .= ";host=$host" if defined $host; $dsn .= ";port=$port" if defined $port; my $dbh = $self->connect($dsn, $username, $password, $attributes); return unless defined $dbh; return $dbh->data_sources(); } # ====== DATABASE ====== package # hide from PAUSE DBD::MariaDB::db; use strict; use DBI qw(:sql_types); 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::MariaDB::st::_prepare($sth, $statement, $attribs)) { $sth = undef; } $sth; } sub table_info { my ($dbh, $catalog, $schema, $table, $type, $attr) = @_; return unless $dbh->func('_async_check'); local $dbh->{mariadb_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 return undef; $sth->execute() or 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 return undef; $sth->execute() or 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 return undef; $sth->execute() or 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 return $dbh->DBI::set_err($sponge->err(), $sponge->errstr()); return $sth; } sub column_info { my ($dbh, $catalog, $schema, $table, $column) = @_; return unless $dbh->func('_async_check'); local $dbh->{mariadb_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 $ER_BAD_FIELD_ERROR = 1054; 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 mariadb_is_pri_key mariadb_type_name mariadb_values mariadb_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) { 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, mariadb_is_pri_key => ($row->{key} eq 'PRI'), mariadb_type_name => $row->{type}, mariadb_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->{"mariadb_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 { return $dbh->DBI::set_err($ER_BAD_FIELD_ERROR, "column_info: unrecognized column type '$basetype' of $table_id.$row->{field} treated as varchar"); } $info->{SQL_DATA_TYPE} ||= $info->{DATA_TYPE}; } my $sponge = DBI->connect("DBI:Sponge:", '','') or 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->DBI::set_err($sponge->err(), $sponge->errstr()); return $sth; } sub primary_key_info { my ($dbh, $catalog, $schema, $table) = @_; return unless $dbh->func('_async_check'); local $dbh->{mariadb_server_prepare} = 0; 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 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 return $dbh->DBI::set_err($sponge->err(), $sponge->errstr()); 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 return if $dbh->FETCH('mariadb_serverversion') < 50006; 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 return if $dbh->FETCH('mariadb_serverversion') < 50006; 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; } #################### # get_info() # SQL_DRIVER_VER should be formatted as ##.##.#### my $odbc_driver_ver = $DBD::MariaDB::VERSION; $odbc_driver_ver .= '_00' if $odbc_driver_ver =~ /^\d+\.\d+$/; $odbc_driver_ver = sprintf("%02u.%02u.%04u", split(/[\._]/, $odbc_driver_ver)); my @odbc_keywords = qw( BIGINT BLOB DEFAULT KEYS LIMIT LONGBLOB MEDIMUMBLOB MEDIUMINT MEDIUMTEXT PROCEDURE REGEXP RLIKE SHOW TABLES TINYBLOB TINYTEXT UNIQUE UNSIGNED ZEROFILL ); my %odbc_info_constants = ( 20 => 'N', # SQL_ACCESSIBLE_PROCEDURES 19 => 'Y', # SQL_ACCESSIBLE_TABLES 116 => 0, # SQL_ACTIVE_ENVIRONMENTS 169 => 127, # SQL_AGGREGATE_FUNCTIONS 117 => 0, # SQL_ALTER_DOMAIN 86 => 3, # SQL_ALTER_TABLE 10021 => 2, # 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 => '.', # SQL_CATALOG_NAME_SEPARATOR 42 => 'database', # SQL_CATALOG_TERM 92 => 29, # SQL_CATALOG_USAGE 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 25 => 'N', # SQL_DATA_SOURCE_READ_ONLY 119 => 7, # SQL_DATETIME_LITERALS 170 => 3, # SQL_DDL_INDEX 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 => 'DBD/MariaDB.pm', # SQL_DRIVER_NAME 77 => '03.51', # SQL_DRIVER_ODBC_VER 7 => $odbc_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 => '`', # 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 => (join ',', @odbc_keywords), # SQL_KEYWORDS 113 => 'Y', # SQL_LIKE_ESCAPE_CLAUSE 78 => 0, # SQL_LOCK_TYPES # 20000 => undef, # SQL_MAXIMUM_STMT_OCTETS # 20001 => undef, # SQL_MAXIMUM_STMT_OCTETS_DATA # 20002 => undef, # SQL_MAXIMUM_STMT_OCTETS_SCHEMA 10022 => 1, # 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 33 => 0, # SQL_MAX_PROCEDURE_NAME_LEN 104 => 0, # SQL_MAX_ROW_SIZE 103 => 'Y', # SQL_MAX_ROW_SIZE_INCLUDES_LONG 32 => 0, # SQL_MAX_SCHEMA_NAME_LEN 35 => 64, # 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 10 => '03.80', # SQL_ODBC_VER 115 => 123, # SQL_OJ_CAPABILITIES 90 => 'Y', # SQL_ORDER_BY_COLUMNS_IN_SELECT 38 => 'Y', # SQL_OUTER_JOINS 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 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 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_TXN_CAPABLE 72 => 15, # SQL_TXN_ISOLATION_OPTION 96 => 0, # SQL_UNION 10000 => 1992, # SQL_XOPEN_CLI_YEAR ); my %odbc_info_subs = ( 2 => sub { "DBI:MariaDB:" . $_[0]->{Name} }, # SQL_DATA_SOURCE_NAME 17 => sub { ($_[0]->FETCH('mariadb_serverinfo') =~ /MariaDB|-maria-/) ? 'MariaDB' : 'MySQL' }, # SQL_DBMS_NAME 18 => sub { my $ver = $_[0]->FETCH('mariadb_serverversion'); sprintf("%02u.%02u.%02u00", $ver/10000, ($ver%10000)/100, $ver%100) }, # SQL_DBMS_VER 105 => sub { $_[0]->FETCH('mariadb_max_allowed_packet') }, # SQL_MAX_STATEMENT_LEN 106 => sub { $_[0]->FETCH('mariadb_serverversion') >= 50000 ? 63 : 31 }, # SQL_MAX_TABLES_IN_SELECT 13 => sub { $_[0]->FETCH('mariadb_hostinfo') }, # SQL_SERVER_NAME 47 => sub { $_[0]->{Username} }, # SQL_USER_NAME ); sub get_info { my ($dbh, $type) = @_; return $odbc_info_constants{$type} if exists $odbc_info_constants{$type}; return $odbc_info_subs{$type}->($dbh) if exists $odbc_info_subs{$type}; return undef; } BEGIN { my @needs_async_check = qw/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(@_); }; } } # ====== STATEMENT ====== package # hide from PAUSE DBD::MariaDB::st; 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->mariadb_async_ready) { return unless $sth->mariadb_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; DBD-MariaDB-1.22/lib/DBD/MariaDB.pod0000644000175000017500000014362314230360604015031 0ustar palipali=encoding utf8 =head1 NAME DBD::MariaDB - MariaDB and MySQL driver for the Perl5 Database Interface (DBI) =head1 SYNOPSIS use DBI; my $dsn = "DBI:MariaDB:database=$database;host=$hostname;port=$port"; my $dbh = DBI->connect($dsn, $user, $password); my $sth = $dbh->prepare( 'SELECT id, first_name, last_name FROM authors WHERE last_name = ?' ) or die 'prepare statement failed: ' . $dbh->errstr(); $sth->execute('Eggers') or die 'execution failed: ' . $dbh->errstr(); print $sth->rows() . " rows found.\n"; while (my $ref = $sth->fetchrow_hashref()) { print "Found a row: id = $ref->{'id'}, fn = $ref->{'first_name'}\n"; } =head1 EXAMPLE #!/usr/bin/perl use strict; use warnings; use DBI; # Connect to the database. my $dbh = DBI->connect('DBI:MariaDB:database=test;host=localhost', 'joe', q(joe's password), { RaiseError => 1, PrintError => 0 }); # Drop table 'foo'. This may fail, if 'foo' doesn't exist # Thus we put an eval around it. eval { $dbh->do('DROP TABLE foo'); } or do { print 'Dropping foo failed: ' . $dbh->errstr() . "\n"; }; # 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' using placeholders $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"; } # Disconnect from the database. $dbh->disconnect(); =head1 DESCRIPTION B is the Perl5 Database Interface driver for MariaDB and MySQL databases. In other words: DBD::MariaDB is an interface between the Perl programming language and the MariaDB/MySQL programming API that comes with the MariaDB/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::MariaDB, 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 MariaDB and 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: my $dbh = DBI->connect("DBI:MariaDB:database=$db;host=$host", $user, $password, { RaiseError => 1, PrintError => 0 }); Once you have connected to a database, you can execute SQL statements with: $dbh->do('INSERT INTO foo VALUES (?, ?)', undef, $number, $name); See DBI L method for details. See also the L 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: my $sth = $dbh->prepare('SELECT * FROM ' . $dbh->quote_identifier($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 C and C, then C<$row> will be hash ref with keys C and C. See L below for more details on statement handles. But now for a more formal approach: =head2 Class Methods =over =item connect use DBI; my $dsn = "DBI:MariaDB:$database"; my $dsn = "DBI:MariaDB:database=$database;host=$hostname"; my $dsn = "DBI:MariaDB:database=$database;host=$hostname;port=$port"; my $dsn = "DBI:MariaDB:database=$database;mariadb_socket=$socket"; my $dbh = DBI->connect($dsn, $user, $password); The I is not a required attribute, but please note that MariaDB and MySQL has no such thing as a default database. If you don't specify the database at connection time your active database will be null and you'd need to prefix your tables with the database name; i.e. C will return the current database active for the handle. =over =item host =item port The I, if not specified or specified as empty string or C, will default to a MariaDB or MySQL server running on the local machine using the default for the UNIX socket. To connect to a MariaDB or MySQL server on the local machine via TCP, you must specify the loopback IP address C<127.0.0.1> as the I. Should the MariaDB or MySQL server be running on a non-standard port number, you may explicitly state the C to connect to in the I argument, by concatenating the C and C together separated by a colon (C<:>) character or by using the I argument. To connect to a MariaDB or MySQL server on localhost using TCP/IP, you must specify the I as C<127.0.0.1> with the optional I, e.g. C<3306>. When connecting to a MariaDB or MySQL Server with IPv6, a bracketed IPv6 address should be used. Example DSN: my $dsn = 'DBI:MariaDB:;host=[1a12:2800:6f2:85::f20:8cf];port=3306'; =item mariadb_client_found_rows Enables (logical true value) or disables (logical false value) the flag C while connecting to the MariaDB or MySQL server. This has a somewhat funny effect. Without I, if you perform a query like UPDATE t SET id = 1 WHERE id = 1; then the MariaDB or MySQL engine will always return 0, because no rows have changed. With I 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. By default I is enabled. =item mariadb_compression If your DSN contains the option C, then the communication between client and server will be compressed. =item mariadb_connect_timeout If your DSN contains the option C, the connect request to the server will timeout if it has not been successful after the given number of seconds. Zero value means infinite timeout. =item mariadb_write_timeout If your DSN contains the option C, the write operation to the server will timeout if it has not been successful after the given number of seconds. Zero value means infinite timeout. =item mariadb_read_timeout If your DSN contains the option C, the read operation to the server will timeout if it has not been successful after the given number of seconds. Zero value means infinite timeout. =item mariadb_init_command If your DSN contains the option C, then this C statement is executed when connecting to the MariaDB or MySQL server. It is automatically re-executed if reconnection occurs. =item mariadb_skip_secure_auth This option is for older MySQL databases that don't have secure auth set. =item mariadb_read_default_file =item mariadb_read_default_group These options can be used to read a config file like F or F<~/.my.cnf>. By default MariaDB's and 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 my $dsn = 'DBI:MariaDB:test;mariadb_read_default_file=/home/joe/my.cnf'; my $dbh = DBI->connect($dsn, $user, $password); The option I can be used to specify the default group in the config file: Usually this is the C 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 C<[client]> and C<[perl]> sections!) If you read this config file, then you'll be typically connected to C. However, by using my $dsn = 'DBI:MariaDB:test;mariadb_read_default_group=perl;' . 'mariadb_read_default_file=/home/joe/my.cnf'; my $dbh = DBI->connect($dsn, $user, $password); you'll be connected to C. 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 C for details. =item mariadb_socket It is possible to choose the Unix socket that is used for connecting to the server. This is done, for example, with my $dsn = 'DBI:MariaDB:database=test;' . 'mariadb_socket=/var/run/mysqld/mysqld.sock'; Usually there's no need for this option, unless you are using another location for the socket than that built into the client. =item mariadb_ssl A true value turns on the C flag when connecting to the MariaDB or MySQL server and enforce SSL encryption. A false value (which is default) disable SSL encryption with the MariaDB or MySQL server. When enabling SSL encryption you should set also other SSL options, at least L|/mariadb_ssl_ca_file> or L|/mariadb_ssl_ca_path>. my $dsn = 'DBI:MariaDB:database=test;host=hostname;port=3306;' . 'mariadb_ssl=1;mariadb_ssl_verify_server_cert=1;' . 'mariadb_ssl_ca_file=/path/to/ca_cert.pem'; This means that your communication with the server will be encrypted. =item mariadb_ssl_ca_file The path to a file in PEM format that contains a list of trusted SSL certificate authorities. When set MariaDB or MySQL server certificate is checked that it is signed by some CA certificate in the list. I value is not verified unless L|/mariadb_ssl_verify_server_cert> is enabled. =item mariadb_ssl_ca_path The path to a directory that contains trusted SSL certificate authority certificates in PEM format. When set MariaDB or MySQL server certificate is checked that it is signed by some CA certificate in the list. I value is not verified unless L|/mariadb_ssl_verify_server_cert> is enabled. Please note that this option is supported only if your MariaDB or MySQL client was compiled with OpenSSL library, and not with default yaSSL library. =item mariadb_ssl_verify_server_cert Checks the server's I value in the certificate that the server sends to the client. The client verifies that name against the host name the client uses for connecting to the server, and the connection fails if there is a mismatch. For encrypted connections, this option helps prevent man-in-the-middle attacks. Verification of the host name is disabled by default. =item mariadb_ssl_client_key The name of the SSL key file in PEM format to use for establishing a secure connection. =item mariadb_ssl_client_cert The name of the SSL certificate file in PEM format to use for establishing a secure connection. =item mariadb_ssl_cipher A list of permissible ciphers to use for connection encryption. If no cipher in the list is supported, encrypted connections will not work. mariadb_ssl_cipher=AES128-SHA mariadb_ssl_cipher=DHE-RSA-AES256-SHA:AES128-SHA =item mariadb_ssl_optional Setting I to true disables strict SSL enforcement and makes SSL connection optional. This option opens security hole for man-in-the-middle attacks. Default value is false which means that L|/mariadb_ssl> set to true enforces SSL encryption. Due to L and L vulnerabilities in libmariadb and libmysqlclient libraries, enforcement of SSL encryption was not possible and therefore C was effectively set for old DBD::mysql driver prior DBD::MariaDB fork was created. DBD::MariaDB with C could refuse connection to MariaDB or MySQL server if underlying libmariadb or libmysqlclient library is vulnerable. Option I can be used to make SSL connection vulnerable. =item mariadb_local_infile The C capability for C may be disabled in the MariaDB or MySQL client library by default. If your DSN contains the option C, C will be enabled. However, this option is B if the server has also been configured to disallow C. =item mariadb_multi_statements Support for multiple statements separated by a semicolon (C<;>) may be enabled by using this option. Enabling this option may cause problems if server-side prepared statements are also enabled. =item mariadb_server_prepare This option is used to enable server side prepared statements. By default prepared statements are not used and placeholder replacement is done by DBD::MariaDB prior to sending SQL statement to MariaDB or MySQL server. This default behavior may change in the future. To use server side prepared statements, all you need to do is set the variable I in the connect: my $dbh = DBI->connect( 'DBI:MariaDB:database=test;host=localhost;mariadb_server_prepare=1', 'user', 'password', { RaiseError => 1, PrintError => 0 }, ); or: my $dbh = DBI->connect( 'DBI:MariaDB:database=test;host=localhost', 'user', 'password', { RaiseError => 1, PrintError => 0, mariadb_server_prepare => 1 }, ); There are many benefits to using server side prepare statements, mostly if you are using SQL statements with placeholders or performing many inserts because of that fact that a single statement is prepared to accept multiple insert values. Please note that MariaDB or MySQL server cannot prepare or execute some prepared statements. In this case DBD::MariaDB fallbacks to normal non-prepared statement and tries again. =item mariadb_server_prepare_disable_fallback This option disable fallback to normal non-prepared statement when MariaDB or MySQL server does not support execution of current statement as prepared. Useful when you want to be sure that the statement is going to be executed as server side prepared. Error message and code in case of failure is propagated back to DBI. This default behavior may change in the future. =item mariadb_embedded_options The option I can be used to pass command line options to the embedded server. When you want to start and connect embedded server, use C in dsn as connection parameter. Example: use DBI; my $datadir = '/var/lib/mysql/'; my $langdir = '/usr/share/mysql/english'; my $dsn = 'DBI:MariaDB:host=embedded;database=test;' . "mariadb_embedded_options=--datadir=$datadir,--language=$langdir"; my $dbh = DBI->connect($dsn, undef, undef); This would start embedded server with language directory C<$langdir>, database directory C<$datadir> and connects to database C. Embedded server does not have to be supported by configured MariaDB or MySQL library. In that case Lconnect() >>|/connect> returns an error. =item mariadb_embedded_groups The option I can be used to specify the groups in the config file (F) which will be used to get options for the embedded server. If not specified C<[server]> and C<[embedded]> groups will be used. Example: my $dsn = 'DBI:MariaDB:host=embedded;database=test;' . 'mariadb_embedded_groups=embedded_server,common'; =item mariadb_conn_attrs The option I is a hash of attribute names and values which can be used to send custom connection attributes to the server. Some attributes like C<_os>, C<_platform>, C<_client_name> and C<_client_version> are added by libmariadb or libmysqlclient. 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 both server and client at least in version MariaDB 10.0.5 or MySQL 5.6 to leverage this feature. It is a good idea to provides additional C attribute. my $dbh= DBI->connect($dsn, $user, $password, { AutoCommit => 0, mariadb_conn_attrs => { program_name => $0, 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 I my $results = $dbh->selectall_hashref( 'SELECT * FROM performance_schema.session_connect_attrs', 'ATTR_NAME' ); This returns: $result = { '_client_name' => { 'ATTR_VALUE' => 'libmysql', 'ATTR_NAME' => '_client_name', 'ORDINAL_POSITION' => '1', 'PROCESSLIST_ID' => '3', }, '_client_version' => { 'ATTR_VALUE' => '5.6.24', 'ATTR_NAME' => '_client_version', 'ORDINAL_POSITION' => '7', 'PROCESSLIST_ID' => '3', }, '_os' => { 'ATTR_VALUE' => 'osx10.8', 'ATTR_NAME' => '_os', 'ORDINAL_POSITION' => '0', 'PROCESSLIST_ID' => '3', }, '_pid' => { 'ATTR_VALUE' => '59860', 'ATTR_NAME' => '_pid', 'ORDINAL_POSITION' => '2', 'PROCESSLIST_ID' => '3', }, '_platform' => { 'ATTR_VALUE' => 'x86_64', 'ATTR_NAME' => '_platform', 'ORDINAL_POSITION' => '4', 'PROCESSLIST_ID' => '3', }, 'foo' => { 'ATTR_NAME' => 'foo', 'ATTR_VALUE' => 'bar', 'ORDINAL_POSITION' => '6', 'PROCESSLIST_ID' => '3', }, 'program_name' => { 'ATTR_VALUE' => './foo.pl', 'ATTR_NAME' => 'program_name', 'ORDINAL_POSITION' => '5', 'PROCESSLIST_ID' => '3', }, 'wiz' => { 'ATTR_VALUE' => 'bang', 'ATTR_NAME' => 'wiz', 'ORDINAL_POSITION' => '3', 'PROCESSLIST_ID' => '3', }, }; =back =item data_sources use DBI; my @dsns = DBI->data_sources('MariaDB', { host => $hostname, port => $port, user => $username, password => $password, ... }); Returns a list of all databases in dsn format suitable for L method, managed by the MariaDB or MySQL server. It accepts all attributes from L method. =back =head1 DATABASE HANDLES The DBD::MariaDB driver supports the following attributes of database handles (read only): my $errno = $dbh->{'mariadb_errno'}; my $error = $dbh->{'mariadb_error'}; my $hostinfo = $dbh->{'mariadb_hostinfo'}; my $info = $dbh->{'mariadb_info'}; my $insertid = $dbh->{'mariadb_insertid'}; my $protoinfo = $dbh->{'mariadb_protoinfo'}; my $serverinfo = $dbh->{'mariadb_serverinfo'}; my $ssl_cipher = $dbh->{'mariadb_ssl_cipher'}; my $stat = $dbh->{'mariadb_stat'}; my $thread_id = $dbh->{'mariadb_thread_id'}; These correspond to C, C, C, C, C, C, C, C, C and C respectively. Portable DBI applications should not use them. Instead they should use standard DBI methods: Lerr() >>|DBI/err> and Lerrstr() >>|DBI/errstr> for error number and string, C<< $dbh->get_info($GetInfoType{SQL_SERVER_NAME}) >> for server host name, C<< $dbh->get_info($GetInfoType{SQL_DBMS_NAME}) >> and C<< $dbh->get_info($GetInfoType{SQL_DBMS_VER}) >> for server database name and version, Llast_insert_id() >>|DBI/last_insert_id> or C<< $sth->last_insert_id() >> for insert id. =over 2 =item mariadb_clientinfo =item mariadb_clientversion List information of the MariaDB or MySQL client library that DBD::MariaDB was built against: print "$dbh->{mariadb_clientinfo}\n"; 5.2.0-MariaDB print "$dbh->{mariadb_clientversion}\n"; 50200 Portable DBI applications should not be interested in version of underlying client library. DBD::MariaDB is there to hide any possible incompatibility and works correctly with any available version. =item mariadb_serverversion print "$dbh->{mariadb_serverversion}\n"; 50200 Portable DBI applications should use C<< $dbh->get_info($GetInfoType{SQL_DBMS_NAME}) >> and C<< $dbh->get_info($GetInfoType{SQL_DBMS_VER}) >> for server database name and version instead. =item mariadb_ssl_cipher Returns the SSL encryption cipher used for the given connection to the server. In case SSL encryption was not enabled with L|/mariadb_ssl> or was not established returns C. my $ssl_cipher = $dbh->{mariadb_ssl_cipher}; if (defined $ssl_cipher) { print "Connection with server is encrypted with cipher: $ssl_cipher\n"; } else { print "Connection with server is not encrypted\n"; } =item mariadb_dbd_stats my $info_hashref = $dbh->{mariadb_dbd_stats}; DBD::MariaDB keeps track of some statistics in the I attribute. The following stats are being maintained: =over 8 =item auto_reconnects_ok The number of times that DBD::MariaDB successfully reconnected to the MariaDB or MySQL server. =item auto_reconnects_failed The number of times that DBD::MariaDB tried to reconnect to MariaDB or MySQL but failed. =back =back The DBD::MariaDB driver also supports the following attributes of database handles (read/write): =over =item mariadb_auto_reconnect This attribute determines whether DBD::MariaDB will automatically reconnect to MariaDB or MySQL server if the connection be lost. This feature defaults to off. Setting I to C<1> is not advised if C is used because if DBD::MariaDB reconnect to MariaDB or MySQL server all table locks will be lost. This attribute is ignored when L is turned off, and when L is turned off, DBD::MariaDB will not automatically reconnect to the server. It is also possible to set the default value of the I attribute for the C<$dbh> by passing it in the C<\%attr> hash for Lconnect >>|/connect>. $dbh->{mariadb_auto_reconnect} = 1; or my $dbh = DBI->connect($dsn, $user, $password, { mariadb_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 C<0>. =item mariadb_use_result This attribute forces the driver to use C rather than C library function. The former is faster and less memory consuming, but tends to block other processes. C 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 I attribute for the C<$dbh> via the DSN: my $dbh = DBI->connect('DBI:MariaDB:test;mariadb_use_result=1', $user, $pass); You can also set it after creation of the database handle: $dbh->{mariadb_use_result} = 0; # disable $dbh->{mariadb_use_result} = 1; # enable You can also set or unset the I setting on your statement handle, when creating the statement handle or after it has been created. See L. =item mariadb_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. 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: L I can be turned on via - through DSN my $dbh = DBI->connect('DBI:MariaDB:test', 'username', 'pass', { mariadb_bind_type_guessing => 1 }); - OR after handle creation $dbh->{mariadb_bind_type_guessing} = 1; =item mariadb_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. =item mariadb_no_autocommit_cmd This attribute causes the driver to not issue C either through explicit or using C. This is particularly useful in the case of using MySQL Proxy. See the bug report: L I can be turned on when creating the database handle: my $dbh = DBI->connect('DBI:MariaDB:test', 'username', 'pass', { mariadb_no_autocommit_cmd => 1 }); or using an existing database handle: $dbh->{mariadb_no_autocommit_cmd} = 1; =item mariadb_max_allowed_packet This attribute controls the maximum size of one packet, any generated or intermediate string and any bind parameter. Default value depends on client MariaDB/MySQL library and should be 1GB. $dbh->{mariadb_max_allowed_packet} = 32*1024*1024; # limit max size to 32MB =back Documentation for some DBD::MariaDB methods of database handles: =over 2 =item ping This can be used to send a ping to the server. See DBI L. my $rc = $dbh->ping(); =item get_info This method can be used to retrieve information about MariaDB or MySQL server. See DBI L. Some useful information: C returns server database name, either C or C. C returns server database version and C returns server host name. use DBI::Const::GetInfoType; print $dbh->get_info($GetInfoType{SQL_DBMS_NAME}); MariaDB print $dbh->get_info($GetInfoType{SQL_DBMS_VER}); 10.01.2600 print $dbh->get_info($GetInfoType{SQL_SERVER_NAME}); Localhost via UNIX socket =back =head1 STATEMENT HANDLES The statement handles of DBD::MariaDB 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 L. An C value will returned otherwise. The most important exception is the L|/mariadb_use_result> attribute. To set the L|/mariadb_use_result> attribute on statement handle C<$sth>, use either of the following: my $sth = $dbh->prepare($sql, { mariadb_use_result => 1}); or my $sth = $dbh->prepare($sql); $sth->{mariadb_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 L 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 t') or die 'Error: ' . $dbh->errstr() . "\n"; $sth->execute() or 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::MariaDB. The attribute list includes: =over =item ChopBlanks This attribute determines whether a L will chop preceding and trailing blanks off the column values. Chopping blanks does not have impact on the L|/mariadb_max_length> attribute. =item mariadb_insertid If the statement you executed performs an C, and there is an C column in the table you inserted in, this attribute holds the value stored into the C column, if that value is automatically generated, by storing C or C<0> or was specified as an explicit value. Typically, you'd access the value via C<< $sth->{mariadb_insertid} >>. The value can also be accessed via C<< $dbh->{mariadb_insertid} >> but this can easily produce incorrect results in case one database handle is shared. Portable DBI applications should not use I. Instead they should use DBI method Llast_insert_id() >>|DBI/last_insert_id> or statement DBI method C<< $sth->last_insert_id() >>. Statement method was introduced in DBI version 1.642, but DBD::MariaDB implements it also for older DBI versions. =item mariadb_is_blob Reference to an array of boolean values; Logical true value indicates, that the respective column is a blob. =item mariadb_is_key Reference to an array of boolean values; Logical true value indicates, that the respective column is a key. =item mariadb_is_num Reference to an array of boolean values; Logical true value indicates, that the respective column contains numeric values. =item mariadb_is_pri_key Reference to an array of boolean values; Logical true value indicates, that the respective column is a primary key. =item mariadb_is_auto_increment Reference to an array of boolean values; Logical true value indicates that the respective column is an C column. =item mariadb_length =item mariadb_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. For string orientated variable types (char, varchar, text and similar types) both attributes return value in bytes. If you are interested in number of characters then instead of I use C via standard DBI method L and instead of I issue SQL query C statement. You may use this for checking whether a statement returned a result: A zero value indicates a non-C