├── .fossil-settings ├── binary-glob └── crlf-glob ├── Bakefiles.bkgen ├── CONTRIBUTING.md ├── COPYING.txt ├── CREDITS.txt ├── ChangeLog.md ├── INSTALL.txt ├── LICENSE.txt ├── README-Cygwin.txt ├── README-Linux.txt ├── README-MinGW.txt ├── README-Solaris.txt ├── README-Unix.txt ├── README-Visual-C++.txt ├── README-examples.txt ├── README-macOS.txt ├── README.md ├── RELEASE-CHECKLIST.md ├── abi.xml.in ├── bmark.txt ├── bootstrap ├── bootstrap.bat ├── cleanmf ├── config ├── acx_pthread.m4 ├── ax_cxx_compile_stdcxx.m4 ├── libm.m4 ├── localtime_r.m4 ├── mysql++.m4 ├── mysql_loc.m4 ├── mysql_ssl.m4 ├── socket_nsl.m4 └── stl_slist.m4 ├── configure.ac ├── doc ├── README-devel-RPM.txt ├── README-manuals-RPM.txt ├── html │ ├── refman │ │ └── _header.html │ └── userman │ │ └── tangentsoft.css ├── ssqls-pretty └── userman │ ├── LICENSE.txt │ ├── Makefile │ ├── Makefile.hello.mingw │ ├── Makefile.hello.posix │ ├── README.md │ ├── breakages.dbx │ ├── common.xsl │ ├── configuration.dbx │ ├── fo.xsl │ ├── fo2pdf │ ├── hello.txt │ ├── html.xsl │ ├── incorporating.dbx │ ├── intro.dbx │ ├── licenses.dbx │ ├── mktxt │ ├── overview.dbx │ ├── section-template.dbx │ ├── ssqls.dbx │ ├── threads.dbx │ ├── tquery.dbx │ ├── tutorial.dbx │ ├── unicode.dbx │ ├── userman.dbx.in │ └── xinclude.mod ├── dtest ├── examples ├── cgi_jpeg.cpp ├── common.ssqls ├── cpool.cpp ├── dbinfo.cpp ├── deadlock.cpp ├── fieldinf.cpp ├── for_each.cpp ├── images.h ├── load_jpeg.cpp ├── logo.jpg ├── multiquery.cpp ├── printdata.cpp ├── printdata.h ├── resetdb.cpp ├── simple1.cpp ├── simple2.cpp ├── simple3.cpp ├── ssqls1.cpp ├── ssqls2.cpp ├── ssqls3.cpp ├── ssqls4.cpp ├── ssqls5.cpp ├── ssqls6.cpp ├── stock.h ├── stock.ssqls ├── stock.txt ├── store_if.cpp ├── threads.h ├── tquery1.cpp ├── tquery2.cpp ├── tquery3.cpp ├── tquery4.cpp ├── transaction.cpp └── vstudio │ ├── mfc │ ├── mfc.cpp │ ├── mfc.h │ ├── mfc.rc │ ├── mfc_dlg.cpp │ ├── mfc_dlg.h │ ├── resource.h │ └── stdafx.h │ └── wforms │ ├── AssemblyInfo.cpp │ ├── MainForm.h │ ├── MainForm.resX │ ├── resource.h │ └── wforms.cpp ├── exrun ├── exrun.bat ├── install.hta.in ├── lib ├── Doxyfile.in ├── autoflag.h ├── beemutex.cpp ├── beemutex.h ├── cmdline.cpp ├── cmdline.h ├── common.h ├── comparable.h ├── connection.cpp ├── connection.h ├── cpool.cpp ├── cpool.h ├── datetime.cpp ├── datetime.h ├── dbdriver.cpp ├── dbdriver.h ├── exceptions.h ├── field.h ├── field_names.cpp ├── field_names.h ├── field_types.cpp ├── field_types.h ├── insertpolicy.h ├── manip.cpp ├── manip.h ├── myset.cpp ├── myset.h ├── mysql++.cpp ├── mysql++.h.in ├── mystring.cpp ├── mystring.h ├── noexceptions.h ├── null.cpp ├── null.h ├── options.cpp ├── options.h ├── qparms.cpp ├── qparms.h ├── query.cpp ├── query.h ├── querydef.pl ├── refcounted.h ├── result.cpp ├── result.h ├── row.cpp ├── row.h ├── scopedconnection.cpp ├── scopedconnection.h ├── sql_buffer.cpp ├── sql_buffer.h ├── sql_types.h ├── sqlstream.cpp ├── sqlstream.h ├── ssqls.pl ├── ssqls2.cpp ├── ssqls2.h ├── stadapter.cpp ├── stadapter.h ├── stream2string.h ├── tcp_connection.cpp ├── tcp_connection.h ├── tiny_int.h ├── transaction.cpp ├── transaction.h ├── type_info.cpp ├── type_info.h ├── uds_connection.cpp ├── uds_connection.h ├── utility.cpp ├── utility.h ├── vallist.cpp ├── vallist.h ├── wnp_connection.cpp └── wnp_connection.h ├── mysql++.bkl ├── mysql++.ebuild ├── mysql++.spec.in ├── osver ├── rebake.bat ├── ssx ├── Doxyfile.in ├── genv2.cpp ├── genv2.h ├── main.cpp ├── parsev2.cpp └── parsev2.h ├── static ├── logo-large.jpg ├── logo-small.jpg └── prism.js ├── test ├── array_index.cpp ├── cpool.cpp ├── datetime.cpp ├── insertpolicy.cpp ├── inttypes.cpp ├── manip.cpp ├── null_comparison.cpp ├── null_uniqueness.cpp ├── qssqls.cpp ├── qstream.cpp ├── query_copy.cpp ├── sqlstream.cpp ├── ssqls2.cpp ├── string.cpp ├── tcp.cpp ├── test1.ssqls ├── test2.ssqls ├── uds.cpp └── wnp.cpp └── tools ├── corecount ├── mkrel ├── mmake ├── print-version.in ├── tarballs-to-fossil └── tb-ignore-glob /.fossil-settings/binary-glob: -------------------------------------------------------------------------------- 1 | static/*.jpg 2 | -------------------------------------------------------------------------------- /.fossil-settings/crlf-glob: -------------------------------------------------------------------------------- 1 | *.md 2 | *.txt 3 | -------------------------------------------------------------------------------- /Bakefiles.bkgen: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ./mysql++.bkl 5 | 6 | 7 | 8 | 9 | autoconf,mingw,msvs2003prj,msvs2005prj,msvs2008prj,xcode2 10 | 11 | 12 | 13 | -o$(INPUT_FILE_DIR)/Makefile.mingw 14 | 15 | 16 | -ovc2003/mysql++.sln 17 | 18 | 19 | -ovc2005/mysql++.sln 20 | 21 | 22 | -ovc2008/mysql++.sln -DMSVS_PLATFORMS=win64 23 | 24 | 25 | -------------------------------------------------------------------------------- /COPYING.txt: -------------------------------------------------------------------------------- 1 | The MySQL++ library proper and the reference manual derived from 2 | comments in the library source code are licensed under the GNU Lesser 3 | General Public License. A copy is provided in this directory, in the 4 | file LICENSE.txt. 5 | 6 | The MySQL++ User Manual is licensed under a unique license derived from 7 | the Linux Documentation Project License. (The only changes are due to 8 | the fact that the User Manual isn't actually part of the LDP, so a lot 9 | of the language in the LDPL doesn't make sense when applied to the user 10 | manual.) This license is provided in the file doc/userman/LICENSE.txt. 11 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | The installation procedure depends on the compiler you use to build 2 | MySQL++ and the OS you build it on. There are platform-specific 3 | instructions for all popular platforms: 4 | 5 | README-Cygwin.txt - for Cygwin 6 | README-Linux.txt - for Linux 7 | README-macOS.txt - for macOS 8 | README-MinGW.txt - for MinGW 9 | README-Solaris.txt - for Solaris 10 | README-Visual-C++.txt - for Visual C++ 11 | 12 | If you're on some Unix variant (Linux, OS X, *BSD, Solaris, Cygwin...) 13 | there are additional general instructions in README-Unix.txt. 14 | 15 | See the main README.txt file for high-level instructions that apply 16 | to all platforms MySQL++ works on. 17 | -------------------------------------------------------------------------------- /README-Cygwin.txt: -------------------------------------------------------------------------------- 1 | Prerequisite: Install MySQL 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | Before you can build MySQL++, you need to install the 4 | libmysqlclient-devel package with Cygwin's setup.exe. 5 | 6 | In the past, you had to build MySQL from source, since 7 | there was no reliable place to get a binary version of the 8 | client library for Cygwin. If you must still do this for 9 | some reason, here's a hint on how to build just the client 10 | library, since you probably will be running either a native 11 | Windows version of the server, or have the server installed 12 | on another machine entirely: 13 | 14 | $ ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \ 15 | --infodir=/usr/share/info --mandir=/usr/share/man \ 16 | --disable-shared --without-{debug,readline,libedit,server} 17 | 18 | 19 | Building the Library and Example Programs 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | Having done that, Cygwin behaves like any other Unixy system. 22 | See the instructions in README-Unix.txt. 23 | -------------------------------------------------------------------------------- /README-Solaris.txt: -------------------------------------------------------------------------------- 1 | For the most part, Solaris is just another Unix variant as far as 2 | MySQL++ is concerned. See README-Unix.txt for most of what you need 3 | to know to build and use MySQL++. 4 | 5 | 6 | Prerequisite: Install the MySQL Development Files 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | MySQL++ is built on top of the MySQL C API library, so it needs the 9 | C API development files to build against. 10 | 11 | With the current version of Solaris, at least, a MySQL package 12 | is included on the operating system disk, but not installed 13 | by default. To install it, oull down the GNOME System menu, 14 | go to Administration, and then to Package Manager. Search for 15 | "mysql5" and install those packages. While there, you may also 16 | need to install the gcc packages, if you haven't done that already. 17 | I'm not sure, but you may need to install Perl as well. 18 | 19 | Don't search for just "mysql" in Package Manager, as that will also 20 | bring up legacy MySQL 4.0 packages. MySQL++ may build against 4.0 21 | still; it's been a while since we've tested it. What is certain 22 | is that the examples won't run against 4.0 without modification, 23 | as they assume the availability of UTF-8 character set support, 24 | which was added in 4.1. 25 | 26 | It's no doubt possible to use the official binaries from mysql.com 27 | instead, or to build from source. We don't do that ourselves, 28 | though, and don't have reports from those who have, so we can't 29 | advise on how to do it. 30 | 31 | 32 | C API Development File Directories 33 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 | Sun's MySQL package installs the development files in relatively 35 | uncommon locations. The libraries are in /usr/mysql/lib/mysql, 36 | and the headers are in /usr/mysql/include/mysql. Way to be 37 | redundant, guys. :) 38 | -------------------------------------------------------------------------------- /RELEASE-CHECKLIST.md: -------------------------------------------------------------------------------- 1 | - Update `ChangeLog.md`. 2 | 3 | - Change version number in `configure.ac`, `mysql++.bkl`, and 4 | `~/tangentsoft.com/mysqlpp/GNUmakefile` 5 | 6 | All other places the version number occurs are generated from the 7 | first two. If there’s a corresponding `*.in` file for the one you’re 8 | looking at, the version number was substituted in by autoconf from 9 | `configure.ac`. Otherwise, the file was most likely created by the 10 | build system using the version number in `mysql++.bkl`. 11 | 12 | - Run “`make abicheck`”. There should be no changes. 13 | 14 | You may have to run the following command in the current “stable” 15 | directory before this will succeed, since it depends on there being 16 | an ACC dump file in place already. 17 | 18 | $ abi-compliance-checker -lib mysqlpp -dump abi.xml 19 | 20 | (“Stable” is assumed to be in ../3.3.0 relative to the trunk 21 | checkout, as I write this.) 22 | 23 | This dependence on an existing ABI dump file is deemed reasonable 24 | since the ABI of the stable version had better not be changing! 25 | Plus, it saves some processing time, since ACC can load the stable 26 | ABI info without re-parsing its headers and library file. 27 | 28 | - Re-bootstrap the system in pedantic mode, then do a clean rebuild. 29 | Fix any new errors and warnings. 30 | 31 | Known bogus warnings: 32 | 33 | - The base class `std::basic_ios<>` for `class Query` is not being 34 | initialized. Yes, we know. We don’t care. The same basic 35 | thing occurs in a few other places where we derive from core C++ 36 | classes. The problem is, how do we call these parent class ctors 37 | portably? It isn’t the same everywhere! 38 | 39 | - The float equality comparisons in `lib/stadapter.cpp` are 40 | harmless. They’re comparisons against special NaN and infinity 41 | constants, which are safe. 42 | 43 | - If building in C++98 mode (which includes `-Wpedantic` on some 44 | compilers) the argument-less calls to `MAY_THROW()` are 45 | harmless. All still-supported C++98 compilers cope with this 46 | usage. 47 | 48 | - Re-bootstrap it again without “pedantic” to avoid shipping the 49 | pedantic build files. 50 | 51 | - Run `tools/mkrel` to check the new `ChangeLog.md`, `configure.ac`, and 52 | `mysql++.bkl` files in with the proper version tag and to merge it into 53 | the release branch. This also creates `mysql++-$(VERSION).tar.gz` and 54 | synchs it up to tangentsoft.com in the MySQL++ releases directory. 55 | 56 | - On a CentOS 8 box, say “`make rpm`” from the “release” branch tree. 57 | Copy the resulting `~/rpmbuild/SRPMS/mysql++-$(VERSION)-1.el8.src.rpm` 58 | to that same releases directory. 59 | 60 | - Update “MySQL++” wiki document to point to new release packages. 61 | 62 | - Send an announcement update via the public repo: 63 | [](https://tangentsoft.com/mysqlpp/announce). 64 | -------------------------------------------------------------------------------- /abi.xml.in: -------------------------------------------------------------------------------- 1 | 2 | @MYSQLPP_VERSION_MAJOR@.@MYSQLPP_VERSION_MINOR@.@MYSQLPP_VERSION_BUGFIX@ 3 | 4 | 5 | lib 6 | 7 | 8 | . 9 | 10 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ARGS=1 4 | BF_OPTIONS= 5 | MAINT_FLAGS="--cache-file=config.cache" 6 | while [ $ARGS != 0 ] 7 | do 8 | case "$1" in 9 | bat) 10 | cmd /c bootstrap.bat $BF_OPTIONS 11 | exit 0 12 | ;; 13 | 14 | nodoc) 15 | BF_OPTIONS="-DBUILDDOCS=no $BF_OPTIONS" 16 | shift 17 | ;; 18 | 19 | noex) 20 | BF_OPTIONS="-DBUILDEXAMPLES=no $BF_OPTIONS" 21 | shift 22 | ;; 23 | 24 | nolib) 25 | BF_OPTIONS="-DBUILDLIBRARY=no $BF_OPTIONS" 26 | shift 27 | ;; 28 | 29 | nomaint) 30 | MAINT_FLAGS= 31 | shift 32 | ;; 33 | 34 | noopt) 35 | export CXXFLAGS="-g -O0" 36 | shift 37 | ;; 38 | 39 | pedantic) 40 | export CXXFLAGS="-g -O2 -ansi -pedantic -Wall -Wextra -W -Wold-style-cast -Wfloat-equal -Wwrite-strings -Wno-overloaded-virtual -Wno-long-long -Wno-variadic-macros -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC" 41 | shift 42 | ;; 43 | 44 | *) 45 | ARGS=0 46 | ;; 47 | esac 48 | done 49 | 50 | # Find location of Bakefile stuff. 51 | bakefilize=bakefilize 52 | for d in /usr/share/aclocal /usr/local/share/aclocal \ 53 | '/c/Program Files (x86)/Bakefile/autoconf' 54 | do 55 | BAKEFILE_M4="$d" 56 | if [ -e "$BAKEFILE_M4/bakefile.m4" ] 57 | then 58 | if [ -x "$d/bakefilize" ] 59 | then 60 | bakefilize="$d/bakefilize" 61 | fi 62 | break 63 | fi 64 | done 65 | if [ ! -e "$BAKEFILE_M4/bakefile.m4" ] 66 | then 67 | echo 68 | echo "Failed to find bakefile.m4. Add the directory containing" 69 | echo "this to the bootstrap script." 70 | echo 71 | exit 1 72 | fi 73 | if [ ! -x "$bakefilize" ] && ! type -p "$bakefilize" > /dev/null 74 | then 75 | echo 76 | echo "Failed to find the bakefilize script. Is Bakefile installed?" 77 | echo 78 | exit 1 79 | fi 80 | 81 | # Check for existence of needed tools, so we can give a better error 82 | # message than the shell will. 83 | tools="make" # POSIX 84 | tools="$tools aclocal autoconf autoheader autoreconf libtoolize" # Autotools 85 | tools="$tools bakefile bakefile_gen" # Bakefile 86 | for tool in $tools 87 | do 88 | if ! type -p $tool > /dev/null 89 | then 90 | echo "FAILED to find build tool '$tool'!" 91 | echo 92 | echo BOOTSTRAP FAILED! 93 | echo 94 | exit 1 95 | fi 96 | done 97 | 98 | # Do Bakefile stuff first. Autoconf can't succeed without 99 | # autoconf_in.m4, which Bakefile creates. 100 | success= 101 | set -x && 102 | for d in 3 5 8 ; do mkdir -p vc200$d ; done && 103 | "$bakefilize" && 104 | rm -f INSTALL && 105 | bakefile_gen $BF_OPTIONS && 106 | bakefile -f gnu -o Makefile.simple -DBUILDLIBRARY=no mysql++.bkl && 107 | set +x && 108 | success=shonuff 109 | 110 | # Do the autotools stuff if Bakefile steps succeeded 111 | # 112 | # We're calling automake only because autoconf depends on install-sh or 113 | # similar, and it *ass*umes you're using automake as well, so it 114 | # delegates installation of that to automake! This is why we ignore its 115 | # errors: it fails because configure.ac doesn't refer to AM_* and there 116 | # is no Makefile.am file, but it does still copy over the missing files. 117 | if [ -n "$success" ] 118 | then 119 | # autoreconf from old Autoconf doesn't pass -I to aclocal properly. 120 | export ACLOCAL="aclocal -I config -I '${BAKEFILE_M4}'" 121 | rm -f config.cache 122 | mv autoconf_inc.m4 config > /dev/null 2>&1 # don't care if it fails 123 | set -x && 124 | automake --add-missing --force-missing > /dev/null 2>&1 ; 125 | autoreconf -i && 126 | ./configure $MAINT_FLAGS $* && 127 | make lib/querydef.h lib/ssqls.h && 128 | set +x && 129 | success=awyeah 130 | fi 131 | 132 | # Detect failure in any part of above 133 | if [ -z "$success" ] 134 | then 135 | echo 136 | echo BOOTSTRAP FAILED! 137 | echo 138 | exit 1 139 | fi 140 | 141 | -------------------------------------------------------------------------------- /bootstrap.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if not exist vc2003 mkdir vc2003 3 | if not exist vc2005 mkdir vc2005 4 | if not exist vc2008 mkdir vc2008 5 | 6 | bakefile_gen %* 7 | if errorlevel 1 exit 8 | if not exist vc2003\mysql++.sln goto no_bakefile 9 | if not exist vc2005\mysql++.sln goto no_bakefile 10 | if not exist vc2008\mysql++.sln goto no_bakefile 11 | 12 | cd lib 13 | perl querydef.pl 14 | if errorlevel 1 exit 15 | if not exist querydef.h goto no_perl 16 | perl ssqls.pl 17 | if errorlevel 1 exit 18 | if not exist ssqls.h goto no_perl 19 | 20 | if not exist mysql++.h goto no_mysqlpp_h 21 | cd .. 22 | 23 | exit 24 | 25 | :no_bakefile 26 | echo. 27 | echo Bakefile doesn't seem to be installed on this system. Download it 28 | echo from http://bakefile.org/ You need version 0.2.3 or newer. 29 | echo. 30 | exit 31 | 32 | :no_perl 33 | echo. 34 | echo You need a Perl interpreter installed on your system, somewhere in 35 | echo the PATH. Any recent version or flavor should work; we don't use 36 | echo any special extensions. The easiest to install on Windows would be 37 | echo ActivePerl, from http://activestate.com/Products/activeperl/ 38 | echo If you're familiar with Unix, you might like Cygwin better instead: 39 | echo http://cygwin.com/setup.exe 40 | echo. 41 | cd .. 42 | exit 43 | 44 | :no_mysqlpp_h 45 | echo. 46 | echo WARNING: Can't make lib/mysql++.h 47 | echo. 48 | echo On Unixy systems, autoconf creates lib/mysql++.h from lib/mysql++.h.in 49 | echo but there is no easy way to do this on Windows. You can do it manually: 50 | echo just copy the file to the new name, and edit the MYSQLPP_HEADER_VERSION 51 | echo definition to put the proper version number parts into the macro. It 52 | echo needs to look something like this: 53 | echo. 54 | echo #define MYSQLPP_HEADER_VERSION MYSQLPP_VERSION(3, 0, 0) 55 | echo. 56 | echo It's important that the three numbers match the actual library version 57 | echo number, or else programs that check this (like resetdb) will fail. 58 | echo. 59 | echo Alternately, if you've also got MySQL++ installed on some Unixy type 60 | echo system, you can let its bootstrap procedure create mysql++.h and then 61 | echo copy it to the Windows machine. 62 | echo. 63 | cd .. 64 | -------------------------------------------------------------------------------- /cleanmf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -f Makefile* 3 | rm -rf *.xcodeproj vc200? 4 | -------------------------------------------------------------------------------- /config/libm.m4: -------------------------------------------------------------------------------- 1 | dnl @synopsis LIB_MATH 2 | dnl 3 | dnl This macro figures out how whether programs using C's math routines 4 | dnl need to link to libm or not. This is common on SysV Unices. 5 | dnl 6 | dnl @category C 7 | dnl @author Warren Young 8 | dnl @version 1.2, 2006-03-06 9 | 10 | AC_DEFUN([LIB_MATH], 11 | [ 12 | AC_MSG_CHECKING([whether -lm is needed to use C math functions]) 13 | 14 | MYSQLPP_EXTRA_LIBS= 15 | TRY_LIBM=no 16 | AC_TRY_LINK( 17 | [ #include ], 18 | [ floor(0); ], AC_MSG_RESULT(no), TRY_LIBM=yes) 19 | 20 | if test "x$TRY_LIBM" = "xyes" 21 | then 22 | save_LIBS=$LIBS 23 | LIBS="$LIBS -lm" 24 | AC_TRY_LINK( 25 | [ #include ], 26 | [ floor(0); ], 27 | [ 28 | MYSQLPP_EXTRA_LIBS=-lm 29 | AC_MSG_RESULT(yes) 30 | ], 31 | AC_MSG_ERROR([Failed to build program containing math functions!])) 32 | LIBS="$save_LIBS" 33 | fi 34 | 35 | AC_SUBST(MYSQLPP_EXTRA_LIBS) 36 | ]) 37 | 38 | -------------------------------------------------------------------------------- /config/localtime_r.m4: -------------------------------------------------------------------------------- 1 | dnl @synopsis AX_C_LOCALTIME_R 2 | dnl 3 | dnl This macro determines whether the C runtime library contains 4 | dnl localtime_r(), a thread-safe replacement for localtime(). 5 | dnl 6 | dnl @version 1.0, 2007/02/20 7 | dnl @author Warren Young 8 | AC_DEFUN([AX_C_LOCALTIME_R], 9 | [ 10 | AC_MSG_CHECKING([for localtime_r()]) 11 | 12 | AC_TRY_RUN([ 13 | #include 14 | int main(void) 15 | { 16 | time_t tt; 17 | struct tm stm; 18 | localtime_r(&tt, &stm); 19 | return 0; 20 | } 21 | ], [localtime_r_found=yes], [localtime_r_found=no], [localtime_r_found=no]) 22 | 23 | AC_MSG_RESULT([$localtime_r_found]) 24 | if test x"$localtime_r_found" = xyes 25 | then 26 | AC_DEFINE(HAVE_LOCALTIME_R, 1, 27 | [Define if you have the localtime_r() facility]) 28 | fi 29 | ]) dnl AX_C_LOCALTIME_R 30 | 31 | -------------------------------------------------------------------------------- /config/mysql_ssl.m4: -------------------------------------------------------------------------------- 1 | dnl @synopsis MYSQL_WITH_SSL 2 | dnl 3 | dnl This macro determines whether mysql_ssl_set() API call exists. 4 | dnl Requires at least MySQL 4.0.1. 5 | dnl 6 | dnl @version $Id$, $Date$ 7 | dnl @author Ovidiu Bivolaru 8 | AC_DEFUN([MYSQL_WITH_SSL], 9 | [ 10 | # 11 | # Check for mysql_ssl_set() in libmysqlclient(_r) 12 | # 13 | AC_CHECK_LIB($MYSQL_C_LIB_NAME, mysql_ssl_set, [ 14 | AC_DEFINE(HAVE_MYSQL_SSL_SET,, Define if your MySQL library has SSL functions) 15 | ]) dnl AC_CHECK_LIB(mysqlclient, mysql_ssl_set) 16 | ]) dnl MYSQL_WITH_SSL 17 | 18 | -------------------------------------------------------------------------------- /config/socket_nsl.m4: -------------------------------------------------------------------------------- 1 | dnl @synopsis LIB_SOCKET_NSL 2 | dnl 3 | dnl This macro figures out what libraries are required on this platform 4 | dnl to link sockets programs. 5 | dnl 6 | dnl The common cases are not to need any extra libraries, or to need 7 | dnl -lsocket and -lnsl. We need to avoid linking with libnsl unless 8 | dnl we need it, though, since on some OSes where it isn't necessary it 9 | dnl will totally break networking. Unisys also includes gethostbyname() 10 | dnl in libsocket but needs libnsl for socket(). 11 | dnl 12 | dnl @category Misc 13 | dnl @author Warren Young 14 | dnl @version 1.5, 2006-03-06 15 | 16 | AC_DEFUN([LIB_SOCKET_NSL], 17 | [ 18 | save_LIBS="$LIBS" 19 | 20 | AC_MSG_CHECKING([whether -lsocket is needed]) 21 | TRY_LSOCKET=no 22 | AC_TRY_LINK( 23 | [ 24 | #include 25 | #include 26 | #include 27 | #include 28 | ], 29 | [ socket(AF_INET, SOCK_STREAM, 0); ], 30 | AC_MSG_RESULT(no), TRY_LSOCKET=yes) 31 | 32 | if test "x$TRY_LSOCKET" = "xyes" 33 | then 34 | LIBS="-lsocket $LIBS" 35 | AC_TRY_LINK( 36 | [ 37 | #include 38 | #include 39 | #include 40 | #include 41 | ], 42 | [ socket(AF_INET, SOCK_STREAM, 0); ], 43 | [ 44 | MYSQLPP_EXTRA_LIBS="-lsocket $MYSQLPP_EXTRA_LIBS" 45 | AC_MSG_RESULT(yes) 46 | ], 47 | AC_MSG_ERROR([failed to link using -lsocket!])) 48 | fi 49 | 50 | AC_MSG_CHECKING([whether -lnsl is needed]) 51 | TRY_LNSL=no 52 | AC_TRY_LINK( 53 | [ #include ], 54 | [ gethostbyname("gna.org"); ], 55 | AC_MSG_RESULT(no), TRY_LNSL=yes) 56 | 57 | if test "x$TRY_LNSL" = "xyes" 58 | then 59 | LIBS="-lnsl $LIBS" 60 | AC_TRY_LINK( 61 | [ #include ], 62 | [ gethostbyname("gna.org"); ], 63 | [ 64 | MYSQLPP_EXTRA_LIBS="-lnsl $MYSQLPP_EXTRA_LIBS" 65 | AC_MSG_RESULT(yes) 66 | ], 67 | AC_MSG_ERROR([failed to link using -lnsl!])) 68 | fi 69 | 70 | AC_SUBST(MYSQLPP_EXTRA_LIBS) 71 | ]) 72 | 73 | -------------------------------------------------------------------------------- /config/stl_slist.m4: -------------------------------------------------------------------------------- 1 | dnl @synopsis STL_SLIST_EXTENSION 2 | dnl 3 | dnl This macro determines whether the local STL implementation includes 4 | dnl a singly-linked list template, slist, and if so, where it is. 5 | dnl 6 | dnl @version 1.2, 2005/07/22 7 | dnl @author Warren Young 8 | AC_DEFUN([STL_SLIST_EXTENSION], 9 | [ 10 | AC_MSG_CHECKING([for STL slist extension]) 11 | 12 | AC_COMPILE_IFELSE( 13 | [AC_LANG_PROGRAM( 14 | [#include ], 15 | [slist l])], 16 | AC_DEFINE(HAVE_GLOBAL_SLIST, 1, 17 | [ Define if you have ::slist container in ]), 18 | TRY_NEXT=yes) 19 | 20 | if test -z "$TRY_NEXT" 21 | then 22 | SLIST_LOC=", global scope" 23 | else 24 | TRY_NEXT="" 25 | AC_COMPILE_IFELSE( 26 | [AC_LANG_PROGRAM( 27 | [#include ], 28 | [std::slist l])], 29 | AC_DEFINE(HAVE_STD_SLIST, 1, 30 | [ Define if you have std::slist container in ]), 31 | TRY_NEXT=yes) 32 | 33 | if test -z "$TRY_NEXT" 34 | then 35 | SLIST_LOC=", namespace std" 36 | else 37 | TRY_NEXT="" 38 | AC_COMPILE_IFELSE( 39 | [AC_LANG_PROGRAM( 40 | [#include ], 41 | [__gnu_cxx::slist l])], 42 | AC_DEFINE(HAVE_EXT_SLIST, 1, 43 | [ Define if you have __gnu_cxx:slist container in ]), 44 | SLIST_LOC="not found") 45 | 46 | if test -z "$SLIST_LOC" 47 | then 48 | SLIST_LOC=", namespace __gnu_cxx" 49 | fi 50 | fi 51 | fi 52 | 53 | AC_MSG_RESULT([$SLIST_LOC]) 54 | ]) dnl STL_SLIST_EXTENSION 55 | 56 | -------------------------------------------------------------------------------- /doc/README-devel-RPM.txt: -------------------------------------------------------------------------------- 1 | mysql++-devel RPM installs the files you need when building your own 2 | MySQL++ based programs, as well as documentation and examples that 3 | can help you learn how to use the library. 4 | 5 | The MySQL++ header files are in /usr/include/mysql++, the library 6 | is in /usr/lib, and the example programs' source code is in 7 | /usr/share/doc/mysql++-devel-*/examples. For more information on 8 | the examples, see the README-examples.txt file in the directory 9 | containing the examples. 10 | 11 | -------------------------------------------------------------------------------- /doc/README-manuals-RPM.txt: -------------------------------------------------------------------------------- 1 | For more information about MySQL++, see its home page: 2 | 3 | http://tangentsoft.net/mysql++/ 4 | 5 | See the LICENSE file in this directory for the library's license. 6 | -------------------------------------------------------------------------------- /doc/html/refman/_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MySQL++ Reference Manual 5 | 6 | 7 | 8 | 9 | $projectname: $title 10 | $title 11 | 12 | 13 | 14 | 15 | $treeview 16 | $search 17 | $mathjax 18 | 19 | $extrastylesheet 20 | 21 | 22 | 23 |
24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
34 |
$projectname 35 |  $projectnumber 36 |
37 |
$projectbrief
38 |
43 |
$projectbrief
44 |
$searchbox
55 |
56 | 57 | 58 | -------------------------------------------------------------------------------- /doc/html/userman/tangentsoft.css: -------------------------------------------------------------------------------- 1 | BODY { 2 | background-color: #FFFFEE; 3 | font-family: 4 | "Georgia", 5 | "Luxi Serif", 6 | "New Century Schoolbook", 7 | "Times New Roman", 8 | "Times", 9 | serif; 10 | margin-left: 30pt; 11 | margin-right: 30pt; 12 | } 13 | 14 | a:link { 15 | color: #491E00; 16 | } 17 | 18 | a:visited { 19 | color: #7D2E01; 20 | } 21 | 22 | a:hover { 23 | color: #CC5500; 24 | text-decoration: none; 25 | } 26 | 27 | a:active { 28 | color: #DA7417; 29 | } 30 | 31 | DIV.footnote > P { 32 | font-size: 85%; 33 | } 34 | 35 | EM.phrase { 36 | /* Georgia's great, but oldstyle numerals make math hard to read */ 37 | font-family: "Times", "Times New Roman", serif; 38 | } 39 | 40 | H1, H2, H3, H4, H5, H6, DIV.navheader > TABLE > TBODY > TR > TH { 41 | color: #501000; 42 | font-family: 43 | "Verdana", 44 | "Luxi Sans", 45 | "Helvetica Narrow", 46 | "Arial", 47 | "Univers", 48 | sans-serif; 49 | font-weight: bold; 50 | } 51 | 52 | H1 { 53 | font-size: 20pt; 54 | } 55 | 56 | H2 { 57 | font-size: 18pt; 58 | } 59 | 60 | H3 { 61 | font-size: 14pt; 62 | } 63 | 64 | H4 { 65 | font-size: 10pt; 66 | } 67 | H4.subtitle { 68 | margin-left: 20pt; 69 | } 70 | 71 | H5 { 72 | font-size: 10pt; 73 | margin-left: 20pt; 74 | } 75 | 76 | P { 77 | line-height: 140%; 78 | margin-left: 20pt; 79 | } 80 | 81 | div.sect3 { 82 | margin-left: 20pt; 83 | } 84 | 85 | li { 86 | margin-left: 30pt; 87 | } 88 | 89 | li p { 90 | margin-left: 0pt; 91 | } 92 | 93 | pre.programlisting, pre.screen { 94 | border: 1px solid #882200; 95 | margin: 10pt; 96 | margin-left: 40pt; 97 | padding: 10pt; 98 | background-color: #FFFFCC; 99 | } 100 | 101 | .type { 102 | font-family: monospace; 103 | } 104 | 105 | .symbol { 106 | font-family: monospace; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /doc/ssqls-pretty: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use FileHandle; 3 | use IPC::Open2; 4 | 5 | if ($ARGV[0] =~ /^--command\=(.+)/) { 6 | $command = $1; 7 | } else { 8 | $command = "g++ -E -I /usr/include/mysql"; 9 | } 10 | 11 | if (-e 'lib/mysql++.h') { 12 | $command .= " -I lib"; 13 | } 14 | else { 15 | $command .= " -I /usr/include/mysql++/"; 16 | } 17 | 18 | $/ = undef; 19 | $orgcode = ; 20 | 21 | ($macro) = $orgcode =~ /(sql_create_.+? *\(.+?\))/s; 22 | 23 | $out = << "---"; 24 | 25 | #include 26 | 27 | $macro 28 | 29 | --- 30 | 31 | $/ = "\n"; 32 | 33 | $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP}; 34 | 35 | #print $out; 36 | 37 | open OUT, ">$temp_dir/${$}.cc"; 38 | print OUT $out; 39 | close OUT; 40 | 41 | system "$command $temp_dir/${$}.cc > $temp_dir/${$}.ii"; 42 | 43 | open IN, "$temp_dir/${$}.ii"; 44 | while () { 45 | next if /^\#/; 46 | $code .= $_; 47 | } 48 | close IN; 49 | 50 | unlink "$temp_dir/${$}.cc","$temp_dir/${$}.ii"; 51 | 52 | $_ = $code; 53 | s/\s+/ /g; 54 | s/ *public: */public:\n/g; 55 | s/ *private: */public:\n/g; 56 | s/ *\; */\;\n/g; 57 | s/ *\{ */ \{\n/g; 58 | s/ *\} */ \}\n\n/g; 59 | s/ *\n */\n/g; 60 | s/\{\s+}/\{\}/g; 61 | s/\}\s+\;/\}\;\n/g; 62 | 63 | $code = ""; 64 | foreach (split /\n/) { 65 | if (/\}/ && !/\{\}/ ) { 66 | $indent -= 2; 67 | $ind = ' 'x$indent; 68 | } 69 | $code .= "$ind$_\n" unless /\:$/; 70 | $code .= "$_\n" if /\:$/; 71 | if (/\{/ && !/\{\}/ ) { 72 | $indent += 2; 73 | $ind = ' 'x$indent; 74 | } 75 | } 76 | 77 | $orgcode =~ s/(sql_create_.+? *\(.+?\))/\n$code\n/s; 78 | 79 | print $orgcode; 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /doc/userman/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MySQL++ User Manual License 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | 4 | I. COPYRIGHT 5 | 6 | The copyright to the MySQL++ User Manual is owned by its authors. 7 | 8 | 9 | II. LICENSE 10 | 11 | The MySQL++ User Manual may be reproduced and distributed in whole 12 | or in part, in any medium physical or electronic, provided that 13 | this license notice is displayed in the reproduction. Commercial 14 | redistribution is permitted and encouraged. Thirty days advance 15 | notice via email to the authors of redistribution is appreciated, 16 | to give the authors time to provide updated documents. 17 | 18 | 19 | A. REQUIREMENTS OF MODIFIED WORKS 20 | 21 | All modified documents, including translations, 22 | anthologies, and partial documents, must meet the 23 | following requirements: 24 | 25 | 1. The modified version must be labeled as such. 26 | 27 | 2. The person making the modifications must be 28 | identified. 29 | 30 | 3. Acknowledgement of the original author must be 31 | retained. 32 | 33 | 4. The location of the original unmodified 34 | document be identified. 35 | 36 | 5. The original authors' names may not be used 37 | to assert or imply endorsement of the 38 | resulting document without the original 39 | authors' permission. 40 | 41 | In addition it is requested that: 42 | 43 | 1. The modifications (including deletions) 44 | be noted. 45 | 46 | 2. The authors be notified by email of the 47 | modification in advance of redistribution, 48 | if an email address is provided in 49 | the document. 50 | 51 | Mere aggregation of the MySQL++ User Manual with other 52 | documents or programs on the same media shall not cause 53 | this license to apply to those other works. 54 | 55 | All translations, derivative documents, or modified 56 | documents that incorporate the MySQL++ User Manual may 57 | not have more restrictive license terms than these, 58 | except that you may require distributors to make the 59 | resulting document available in source format. 60 | -------------------------------------------------------------------------------- /doc/userman/Makefile: -------------------------------------------------------------------------------- 1 | ## ------------------------ 2 | ## Input files 3 | ## ------------------------ 4 | 5 | HTML_DIR=../html/userman 6 | BASENAME=userman 7 | DOCFILE=$(BASENAME).dbx 8 | PDFFILE=../pdf/$(BASENAME).pdf 9 | FOFILE=$(BASENAME).fo 10 | COMMON_SS=common.xsl 11 | FO_SS=fo.xsl 12 | HTML_SS=html.xsl 13 | EX_TXT=cgi_jpeg.txt cpool.txt deadlock.txt fieldinf.txt for_each.txt \ 14 | load_jpeg.txt multiquery.txt resetdb.txt simple1.txt \ 15 | simple2.txt simple3.txt ssqls1.txt ssqls2.txt ssqls3.txt \ 16 | ssqls4.txt ssqls5.txt ssqls6.txt stock.txt store_if.txt \ 17 | tquery1.txt transaction.txt 18 | 19 | 20 | ## ------------------------ 21 | ## Major output rules 22 | ## ------------------------ 23 | 24 | html: $(EX_TXT) $(HTML_DIR)/index.html 25 | 26 | pdf: $(EX_TXT) $(PDFFILE) 27 | 28 | 29 | ## ------------------------ 30 | ## Standard Makefile targets 31 | ## ------------------------ 32 | 33 | # Notice that this is not the first target in the file, as is standard. 34 | # PDF generation takes longer than HTML generation, so to keep the code- 35 | # test-debug-rebuild cycle short, we generate only the HTML manual by 36 | # default. You can explicitly say "make pdf" or "make all" when you're 37 | # sure the DocBook file's contents are correct. 38 | all: html pdf 39 | 40 | clean: 41 | @rm -f tags *.fo $(HTML_DIR)/*.html *.log *.out *.pdf $(EX_TXT) $(PDFFILE) 42 | 43 | 44 | ## ------------------------ 45 | ## How to make output files 46 | ## ------------------------ 47 | 48 | $(PDFFILE): *.dbx *.in $(FO_SS) $(COMMON_SS) 49 | xsltproc --xinclude $(FO_SS) $(DOCFILE) > $(FOFILE) 50 | mkdir -p ../pdf 51 | ./fo2pdf $(FOFILE) $(PDFFILE) 52 | 53 | $(HTML_DIR)/index.html: *.dbx *.in *.mod *.txt *.xsl 54 | @xmllint --xinclude --nonet --postvalid --noent --noout $(DOCFILE) 55 | xsltproc --xinclude --nonet -o $(HTML_DIR)/ $(HTML_SS) $(DOCFILE) 56 | 57 | 58 | ## ------------------------ 59 | ## Dependency rules 60 | ## ------------------------ 61 | 62 | $(EX_TXT): 63 | @./mktxt $@ 64 | 65 | userman.dbx: userman.dbx.in 66 | ( cd ../.. ; ./config.status ) 67 | -------------------------------------------------------------------------------- /doc/userman/Makefile.hello.mingw: -------------------------------------------------------------------------------- 1 | SHELL := $(COMSPEC) 2 | MYSQL_DIR := "c:/Program Files/MySQL/MySQL Connector C 6.1" 3 | CXXFLAGS := -I$(MYSQL_DIR)/include -Ic:/MySQL++/include 4 | LDFLAGS := -L$(MYSQL_DIR)/lib -Lc:/MySQL++/lib/MinGW 5 | LDLIBS := -lmysql -lmysqlpp 6 | EXECUTABLE := hello 7 | 8 | all: $(EXECUTABLE) 9 | 10 | clean: 11 | del $(EXECUTABLE) 12 | -------------------------------------------------------------------------------- /doc/userman/Makefile.hello.posix: -------------------------------------------------------------------------------- 1 | CXXFLAGS := -I/usr/include/mysql -I/usr/local/include/mysql++ 2 | LDFLAGS := -L/usr/local/lib 3 | LDLIBS := -lmysqlpp -lmysqlclient 4 | EXECUTABLE := hello 5 | 6 | all: $(EXECUTABLE) 7 | 8 | clean: 9 | rm -f $(EXECUTABLE) *.o 10 | -------------------------------------------------------------------------------- /doc/userman/common.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/userman/fo.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | page 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | false 52 | 53 | 54 | 55 | 56 | left 57 | 58 | 59 | 62 | 63 | 85% 64 | 65 | 66 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /doc/userman/fo2pdf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | AHCMD=/usr/XSLFormatterV42/run.sh 3 | FOPCMD=$(type -p fop) 4 | XEPCMD=/usr/local/xep/xep 5 | 6 | FOFILE=$1 7 | PDFFILE=$2 8 | if [ -n "$FOFILE" -a -r "$FOFILE" -a -n "$PDFFILE" ] 9 | then 10 | if [ -x "$XEPCMD" ] 11 | then 12 | echo Rendering $FOFILE to $PDFFILE with RenderX XEP... 13 | $XEPCMD -quiet -fo $FOFILE -pdf $PDFFILE 14 | elif [ -x "$AHCMD" ] 15 | then 16 | echo Rendering $FOFILE to $PDFFILE with Antenna House XSL Formatter... 17 | $AHCMD -silent -d $FOFILE -o $PDFFILE 18 | elif [ -x "$FOPCMD" ] 19 | then 20 | echo "Rendering $FOFILE to $PDFFILE with Apache FOP ($FOPCMD)..." 21 | $FOPCMD -q -fo $FOFILE $PDFFILE 22 | else 23 | echo 'Cannot find a working XSL-FO processor on your system! See' 24 | echo 'doc/usrman/README.txt for instructions on installing one.' 25 | echo 26 | exit 1 27 | fi 28 | else 29 | if [ -n "$FOFILE" ] 30 | then 31 | echo "XSL-FO file $FOFILE does not exist." 32 | echo 33 | fi 34 | echo "usage: $0 fofile pdffile" 35 | echo 36 | echo ' Translates XSL-FO in fofile to PDF output in pdffile.' 37 | echo 38 | exit 1 39 | fi 40 | -------------------------------------------------------------------------------- /doc/userman/hello.txt: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | mysqlpp::String greeting("Hello, world!"); 6 | std::cout << greeting << std::endl; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /doc/userman/html.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | http://dev.mysql.com/doc/mysql/en/ 43 | 44 | .html 45 | 46 | 47 | () 48 | 49 | 50 | 51 | 52 | 54 | 55 | 56 | 57 | 58 | ../refman/classmysqlpp_1_1 59 | 60 | .html 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 76 | 77 | 78 | 79 | 80 | ../refman/structmysqlpp_1_1 81 | 82 | .html 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /doc/userman/mktxt: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Script to convert C++ source files to a text format, with 4 spaces for 3 | # every tab, and with the leading block comment removed. Used to 4 | # reformat the example programs so they can be xincluded directly into 5 | # the DocBook during XSLT processing. 6 | 7 | TXTFILE=$1 8 | SRCFILE=`echo ../../examples/$TXTFILE | sed -e s/\\\\.txt/.cpp/` 9 | if [ ! -e $SRCFILE ] 10 | then 11 | SRCFILE=`echo ../../examples/$TXTFILE | sed -e s/\\\\.txt/.h/` 12 | fi 13 | CLINE=`grep -n '\*\*/' $SRCFILE |cut -f1 -d:` 14 | LINE=`echo $CLINE + 2 |bc` 15 | 16 | #echo Converting $SRCFILE to $TXTFILE, starting at line $LINE... 17 | 18 | expand -t4 $SRCFILE | tail -n +$LINE > $TXTFILE 19 | 20 | -------------------------------------------------------------------------------- /doc/userman/section-template.dbx: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | SECTION TITLE 7 | 8 | FIRST PARAGRAPH 9 | 10 | -------------------------------------------------------------------------------- /doc/userman/userman.dbx.in: -------------------------------------------------------------------------------- 1 | 2 | 5 | %xinclude; 6 | ]> 7 |
8 | 9 | MySQL++ v@MYSQLPP_VERSION_MAJOR@.@MYSQLPP_VERSION_MINOR@.@MYSQLPP_VERSION_BUGFIX@ User Manual 10 | 11 | 12 | 13 | Kevin 14 | Atkinson 15 | 16 | 17 | 18 | Sinisa 19 | Milivojevic 20 | 21 | 22 | 23 | Monty 24 | Widenius 25 | 26 | 27 | 28 | Warren 29 | Young 30 | 31 | 32 | 33 | 34 | 1998-2001, 2005-2019 35 | Kevin Atkinson (original author) 36 | MySQL AB 37 | Educational Technology Resources 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
55 | -------------------------------------------------------------------------------- /doc/userman/xinclude.mod: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /dtest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TMP=`mktemp bmXXXXXX` 4 | 5 | # Run simple unit tests first. 6 | typeset -i count=0 7 | echo -n 'Running unit tests:' 8 | for t in test_* 9 | do 10 | if [ -x "$t" ] 11 | then 12 | errmsg=`./exrun "$t" 2>&1` 13 | errno=$? 14 | if [ "$errno" = 0 ] 15 | then 16 | count=count+1 17 | else 18 | rm -f $TMP 19 | echo " $t FAILED ($errno)" 20 | echo 21 | echo "$errmsg" 22 | exit $? 23 | fi 24 | fi 25 | done 26 | echo " $count tests succeeded" 27 | echo 'All unit tests passed' >> $TMP 28 | 29 | # Assume AUTO_INCREMENT id column in images table will get 1 in 30 | # load_jpeg call below, since we reset the DB before doing it. 31 | export QUERY_STRING=id=1 32 | 33 | # Now run examples to test high-level behavior. The repeated use of 34 | # resetdb is intentional! It's run after each example that changes 35 | # the database in a way that will cause a subsequent example to fail 36 | # because data it expects isn't present. 37 | echo -n 'Running examples:' 38 | for t in \ 39 | resetdb simple[0-9] store_if for_each multiquery tquery1 \ 40 | resetdb tquery[2-9] \ 41 | resetdb ssqls[0-9] \ 42 | load_jpeg cgi_jpeg 43 | do 44 | if [ -x $t ] 45 | then 46 | if [ "$t" = "resetdb" ] 47 | then 48 | echo 49 | echo -n " " 50 | fi 51 | 52 | echo -n "$t " 53 | echo "---------------- BEGIN $t OUTPUT ----------------" >> $TMP 54 | if ! ./exrun $t -D $* >> $TMP 55 | then 56 | echo 57 | echo 'TESTING ABORTED.' 58 | rm -f $TMP 59 | exit $? 60 | fi 61 | echo "================ END $t OUTPUT ================" >> $TMP 62 | echo >> $TMP 63 | fi 64 | done 65 | echo 66 | 67 | # Test ssqlsxlat -o. Note that it suppresses stdout but keeps stderr 68 | # so warnings about directives and line elements it doesn't understand 69 | # aren't suppressed. We run the first pass's output back through 70 | # ssqlsxlat to deal with comments, whitespace differences, line element 71 | # ordering, boolean value and type canonicalization, and other niggly 72 | # differences we really don't care about. diff -w isn't enough. 73 | for f in {examples,test}/*.ssqls 74 | do 75 | echo -n "Testing ssqlsxlat -i $f -o..." 76 | echo "--- BEGIN ssqlsxlat -i $f -o ERROR OUTPUT ---" >> $TMP 77 | pass1=/tmp/dtest-ssxgv2-pass1-$bnf 78 | pass2=/tmp/dtest-ssxgv2-pass2-$bnf 79 | echo -n "pass 1" 80 | ./exrun ssqlsxlat -i $f -o $pass1 > /dev/null 2>> $TMP 81 | echo -n ", pass 2" 82 | ./exrun ssqlsxlat -i $pass1 -o $pass2 > /dev/null 2>> $TMP 83 | echo -n ", diff" 84 | diff $pass1 $pass2 > /dev/null >> $TMP 85 | echo "==== END ssqlsxlat -i $f -o ERROR OUTPUT ====" >> $TMP 86 | echo 87 | done 88 | 89 | # Check for any changes 90 | BFILE=bmark.txt 91 | if [ -f $BFILE ] 92 | then 93 | if diff -u -w $BFILE $TMP 94 | then 95 | echo 96 | echo 'All tests passed.' 97 | fi 98 | rm -f $TMP 99 | else 100 | mv $TMP $BFILE 101 | chmod -w $BFILE 102 | echo 103 | echo 'BENCHMARK FILE REGENERATED.' 104 | echo 105 | fi 106 | -------------------------------------------------------------------------------- /examples/common.ssqls: -------------------------------------------------------------------------------- 1 | option implementation_extension cc 2 | option header_extension hh 3 | option accessor_style getX 4 | option exception_on_schema_mismatch true 5 | -------------------------------------------------------------------------------- /examples/for_each.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | for_each.cpp - Demonstrates Query::for_each(), showing how to perform 3 | an arbitrary action on each row in a result set. 4 | 5 | Copyright (c) 2005-2009 by Educational Technology Resources, Inc. and 6 | (c) 2007 by Switchplane, Ltd. Others may also hold copyrights on 7 | code in this file. See the CREDITS.txt file in the top directory 8 | of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | #include "stock.h" 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | 38 | 39 | // Define a functor to collect statistics about the stock table 40 | class gather_stock_stats 41 | { 42 | public: 43 | gather_stock_stats() : 44 | items_(0), 45 | weight_(0), 46 | cost_(0) 47 | { 48 | } 49 | 50 | void operator()(const stock& s) 51 | { 52 | items_ += s.num; 53 | weight_ += (s.num * s.weight); 54 | cost_ += (s.num * s.price.data); 55 | } 56 | 57 | private: 58 | mysqlpp::sql_bigint items_; 59 | mysqlpp::sql_double weight_, cost_; 60 | 61 | friend std::ostream& operator<<(std::ostream& os, 62 | const gather_stock_stats& ss); 63 | }; 64 | 65 | 66 | // Dump the contents of gather_stock_stats to a stream in human-readable 67 | // form. 68 | std::ostream& 69 | operator<<(std::ostream& os, const gather_stock_stats& ss) 70 | { 71 | os << ss.items_ << " items " << 72 | "weighing " << ss.weight_ << " stone and " << 73 | "costing " << ss.cost_ << " cowrie shells"; 74 | return os; 75 | } 76 | 77 | 78 | int 79 | main(int argc, char *argv[]) 80 | { 81 | // Get database access parameters from command line 82 | mysqlpp::examples::CommandLine cmdline(argc, argv); 83 | if (!cmdline) { 84 | return 1; 85 | } 86 | 87 | try { 88 | // Establish the connection to the database server. 89 | mysqlpp::Connection con(mysqlpp::examples::db_name, 90 | cmdline.server(), cmdline.user(), cmdline.pass()); 91 | 92 | // Gather and display the stats for the entire stock table 93 | mysqlpp::Query query = con.query(); 94 | std::cout << "There are " << query.for_each(stock(), 95 | gather_stock_stats()) << '.' << std::endl; 96 | } 97 | catch (const mysqlpp::BadQuery& e) { 98 | // Something went wrong with the SQL query. 99 | std::cerr << "Query failed: " << e.what() << std::endl; 100 | return 1; 101 | } 102 | catch (const mysqlpp::Exception& er) { 103 | // Catch-all for any other MySQL++ exceptions 104 | std::cerr << "Error: " << er.what() << std::endl; 105 | return 1; 106 | } 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /examples/images.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | images.h - Declares the images table SSQLS. 3 | 4 | Copyright (c) 2008-2010 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include 27 | #include 28 | 29 | sql_create_2(images, 30 | 1, 2, 31 | mysqlpp::sql_int_unsigned_null, id, 32 | mysqlpp::sql_blob_null, data) 33 | -------------------------------------------------------------------------------- /examples/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangentsoft/mysqlpp/f40d94c4eddbad5ff319d8886bcf68dbf14528cf/examples/logo.jpg -------------------------------------------------------------------------------- /examples/printdata.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | printdata.h - Declares utility routines for printing out data in 3 | common forms, used by most of the example programs. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #if !defined(MYSQLPP_PRINTDATA_H) 29 | #define MYSQLPP_PRINTDATA_H 30 | 31 | #include 32 | 33 | void print_stock_header(size_t rows); 34 | void print_stock_row(const mysqlpp::Row& r); 35 | void print_stock_row(const mysqlpp::sql_char& item, 36 | mysqlpp::sql_bigint num, mysqlpp::sql_double weight, 37 | mysqlpp::sql_decimal_null price, const mysqlpp::sql_date& date); 38 | void print_stock_rows(mysqlpp::StoreQueryResult& res); 39 | void print_stock_table(mysqlpp::Query& query); 40 | 41 | #endif // !defined(MYSQLPP_PRINTDATA_H) 42 | 43 | -------------------------------------------------------------------------------- /examples/simple1.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | simple1.cpp - Example showing the simplest way to get data from a MySQL 3 | table with MySQL++. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | // Connect to the sample database. 48 | mysqlpp::Connection conn(false); 49 | if (conn.connect(mysqlpp::examples::db_name, cmdline.server(), 50 | cmdline.user(), cmdline.pass())) { 51 | // Retrieve a subset of the sample stock table set up by resetdb 52 | // and display it. 53 | mysqlpp::Query query = conn.query("select item from stock"); 54 | if (mysqlpp::StoreQueryResult res = query.store()) { 55 | cout << "We have:" << endl; 56 | mysqlpp::StoreQueryResult::const_iterator it; 57 | for (it = res.begin(); it != res.end(); ++it) { 58 | mysqlpp::Row row = *it; 59 | cout << '\t' << row[0] << endl; 60 | } 61 | } 62 | else { 63 | cerr << "Failed to get item list: " << query.error() << endl; 64 | return 1; 65 | } 66 | 67 | return 0; 68 | } 69 | else { 70 | cerr << "DB connection failed: " << conn.error() << endl; 71 | return 1; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /examples/simple2.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | simple2.cpp - Retrieves the entire contents of the sample stock table 3 | using a "store" query, and prints it out. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | // Connect to the sample database. 48 | mysqlpp::Connection conn(false); 49 | if (conn.connect(mysqlpp::examples::db_name, cmdline.server(), 50 | cmdline.user(), cmdline.pass())) { 51 | // Retrieve the sample stock table set up by resetdb 52 | mysqlpp::Query query = conn.query("select * from stock"); 53 | mysqlpp::StoreQueryResult res = query.store(); 54 | 55 | // Display results 56 | if (res) { 57 | // Display header 58 | cout.setf(ios::left); 59 | cout << setw(31) << "Item" << 60 | setw(10) << "Num" << 61 | setw(10) << "Weight" << 62 | setw(10) << "Price" << 63 | "Date" << endl << endl; 64 | 65 | // Get each row in result set, and print its contents 66 | for (size_t i = 0; i < res.num_rows(); ++i) { 67 | cout << setw(30) << res[i]["item"] << ' ' << 68 | setw(9) << res[i]["num"] << ' ' << 69 | setw(9) << res[i]["weight"] << ' ' << 70 | setw(9) << res[i]["price"] << ' ' << 71 | setw(9) << res[i]["sdate"] << 72 | endl; 73 | } 74 | } 75 | else { 76 | cerr << "Failed to get stock table: " << query.error() << endl; 77 | return 1; 78 | } 79 | 80 | return 0; 81 | } 82 | else { 83 | cerr << "DB connection failed: " << conn.error() << endl; 84 | return 1; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /examples/simple3.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | simple3.cpp - Example showing how to use the 'use' method of retrieving 3 | a table, as opposed to the more common 'store' method illustrated 4 | by the simple2 example. 5 | 6 | Copyright (c) 2005-2009 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the CREDITS 8 | file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | // Connect to the sample database. 48 | mysqlpp::Connection conn(false); 49 | if (conn.connect(mysqlpp::examples::db_name, cmdline.server(), 50 | cmdline.user(), cmdline.pass())) { 51 | // Ask for all rows from the sample stock table and display 52 | // them. Unlike simple2 example, we retreive each row one at 53 | // a time instead of storing the entire result set in memory 54 | // and then iterating over it. 55 | mysqlpp::Query query = conn.query("select * from stock"); 56 | if (mysqlpp::UseQueryResult res = query.use()) { 57 | // Display header 58 | cout.setf(ios::left); 59 | cout << setw(31) << "Item" << 60 | setw(10) << "Num" << 61 | setw(10) << "Weight" << 62 | setw(10) << "Price" << 63 | "Date" << endl << endl; 64 | 65 | // Get each row in result set, and print its contents 66 | while (mysqlpp::Row row = res.fetch_row()) { 67 | cout << setw(30) << row["item"] << ' ' << 68 | setw(9) << row["num"] << ' ' << 69 | setw(9) << row["weight"] << ' ' << 70 | setw(9) << row["price"] << ' ' << 71 | setw(9) << row["sdate"] << 72 | endl; 73 | } 74 | 75 | // Check for error: can't distinguish "end of results" and 76 | // error cases in return from fetch_row() otherwise. 77 | if (conn.errnum()) { 78 | cerr << "Error received in fetching a row: " << 79 | conn.error() << endl; 80 | return 1; 81 | } 82 | return 0; 83 | } 84 | else { 85 | cerr << "Failed to get stock item: " << query.error() << endl; 86 | return 1; 87 | } 88 | } 89 | else { 90 | cerr << "DB connection failed: " << conn.error() << endl; 91 | return 1; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/ssqls1.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssqls1.cpp - Example that produces the same results as simple1, but it 3 | uses a Specialized SQL Structure to store the results instead of a 4 | MySQL++ Result object. 5 | 6 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 7 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 8 | also hold copyrights on code in this file. See the CREDITS.txt file 9 | in the top directory of the distribution for details. 10 | 11 | This file is part of MySQL++. 12 | 13 | MySQL++ is free software; you can redistribute it and/or modify it 14 | under the terms of the GNU Lesser General Public License as published 15 | by the Free Software Foundation; either version 2.1 of the License, or 16 | (at your option) any later version. 17 | 18 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 | License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with MySQL++; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | USA 27 | ***********************************************************************/ 28 | 29 | #include "cmdline.h" 30 | #include "printdata.h" 31 | #include "stock.h" 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | try { 48 | // Establish the connection to the database server. 49 | mysqlpp::Connection con(mysqlpp::examples::db_name, 50 | cmdline.server(), cmdline.user(), cmdline.pass()); 51 | 52 | // Retrieve a subset of the stock table's columns, and store 53 | // the data in a vector of 'stock' SSQLS structures. See the 54 | // user manual for the consequences arising from this quiet 55 | // ability to store a subset of the table in the stock SSQLS. 56 | mysqlpp::Query query = con.query("select item,description from stock"); 57 | vector res; 58 | query.storein(res); 59 | 60 | // Display the items 61 | cout << "We have:" << endl; 62 | vector::iterator it; 63 | for (it = res.begin(); it != res.end(); ++it) { 64 | cout << '\t' << it->item; 65 | if (it->description != mysqlpp::null) { 66 | cout << " (" << it->description << ")"; 67 | } 68 | cout << endl; 69 | } 70 | } 71 | catch (const mysqlpp::BadQuery& er) { 72 | // Handle any query errors 73 | cerr << "Query error: " << er.what() << endl; 74 | return -1; 75 | } 76 | catch (const mysqlpp::BadConversion& er) { 77 | // Handle bad conversions; e.g. type mismatch populating 'stock' 78 | cerr << "Conversion error: " << er.what() << endl << 79 | "\tretrieved data size: " << er.retrieved << 80 | ", actual size: " << er.actual_size << endl; 81 | return -1; 82 | } 83 | catch (const mysqlpp::Exception& er) { 84 | // Catch-all for any other MySQL++ exceptions 85 | cerr << "Error: " << er.what() << endl; 86 | return -1; 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /examples/ssqls2.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssqls2.cpp - Example showing how to insert a row using the Specialized 3 | SQL Structures feature of MySQL++. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | #include "stock.h" 31 | 32 | #include 33 | #include 34 | 35 | using namespace std; 36 | 37 | int 38 | main(int argc, char *argv[]) 39 | { 40 | // Get database access parameters from command line 41 | mysqlpp::examples::CommandLine cmdline(argc, argv); 42 | if (!cmdline) { 43 | return 1; 44 | } 45 | 46 | try { 47 | // Establish the connection to the database server. 48 | mysqlpp::Connection con(mysqlpp::examples::db_name, 49 | cmdline.server(), cmdline.user(), cmdline.pass()); 50 | 51 | // Create and populate a stock object. We could also have used 52 | // the set() member, which takes the same parameters as this 53 | // constructor. 54 | stock row("Hot Dogs", 100, 1.5, 55 | numeric_limits::infinity(), // "priceless," ha! 56 | mysqlpp::sql_date("1998-09-25"), mysqlpp::null); 57 | 58 | // Form the query to insert the row into the stock table. 59 | mysqlpp::Query query = con.query(); 60 | query.insert(row); 61 | 62 | // Show the query about to be executed. 63 | cout << "Query: " << query << endl; 64 | 65 | // Execute the query. We use execute() because INSERT doesn't 66 | // return a result set. 67 | query.execute(); 68 | 69 | // Retrieve and print out the new table contents. 70 | print_stock_table(query); 71 | } 72 | catch (const mysqlpp::BadQuery& er) { 73 | // Handle any query errors 74 | cerr << "Query error: " << er.what() << endl; 75 | return -1; 76 | } 77 | catch (const mysqlpp::BadConversion& er) { 78 | // Handle bad conversions 79 | cerr << "Conversion error: " << er.what() << endl << 80 | "\tretrieved data size: " << er.retrieved << 81 | ", actual size: " << er.actual_size << endl; 82 | return -1; 83 | } 84 | catch (const mysqlpp::Exception& er) { 85 | // Catch-all for any other MySQL++ exceptions 86 | cerr << "Error: " << er.what() << endl; 87 | return -1; 88 | } 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /examples/ssqls4.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssqls4.cpp - Example very similar to ssqls1.cpp, except that it 3 | stores its result set in an STL set container. This demonstrates 4 | how one can manipulate MySQL++ result sets in a very natural C++ 5 | style. 6 | 7 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 8 | (c) 2004-2010 by Educational Technology Resources, Inc. Others may 9 | also hold copyrights on code in this file. See the CREDITS.txt file 10 | in the top directory of the distribution for details. 11 | 12 | This file is part of MySQL++. 13 | 14 | MySQL++ is free software; you can redistribute it and/or modify it 15 | under the terms of the GNU Lesser General Public License as published 16 | by the Free Software Foundation; either version 2.1 of the License, or 17 | (at your option) any later version. 18 | 19 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with MySQL++; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 27 | USA 28 | ***********************************************************************/ 29 | 30 | #include "cmdline.h" 31 | #include "printdata.h" 32 | #include "stock.h" 33 | 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | try { 48 | // Establish the connection to the database server. 49 | mysqlpp::Connection con(mysqlpp::examples::db_name, 50 | cmdline.server(), cmdline.user(), cmdline.pass()); 51 | 52 | // Retrieve all rows from the stock table and put them in an 53 | // STL set. Notice that this works just as well as storing them 54 | // in a vector, which we did in ssqls1.cpp. It works because 55 | // SSQLS objects are less-than comparable. 56 | mysqlpp::Query query = con.query("select * from stock"); 57 | set res; 58 | query.storein(res); 59 | 60 | // Display the result set. Since it is an STL set and we set up 61 | // the SSQLS to compare based on the item column, the rows will 62 | // be sorted by item. 63 | print_stock_header(res.size()); 64 | set::iterator it; 65 | cout.precision(3); 66 | for (it = res.begin(); it != res.end(); ++it) { 67 | print_stock_row(it->item.c_str(), it->num, it->weight, 68 | it->price, it->sDate); 69 | } 70 | 71 | // Use set's find method to look up a stock item by item name. 72 | // This also uses the SSQLS comparison setup. 73 | it = res.find(stock("Hotdog Buns")); 74 | if (it != res.end()) { 75 | cout << endl << "Currently " << it->num << 76 | " hotdog buns in stock." << endl; 77 | } 78 | else { 79 | cout << endl << "Sorry, no hotdog buns in stock." << endl; 80 | } 81 | } 82 | catch (const mysqlpp::BadQuery& er) { 83 | // Handle any query errors 84 | cerr << "Query error: " << er.what() << endl; 85 | return -1; 86 | } 87 | catch (const mysqlpp::BadConversion& er) { 88 | // Handle bad conversions 89 | cerr << "Conversion error: " << er.what() << endl << 90 | "\tretrieved data size: " << er.retrieved << 91 | ", actual size: " << er.actual_size << endl; 92 | return -1; 93 | } 94 | catch (const mysqlpp::Exception& er) { 95 | // Catch-all for any other MySQL++ exceptions 96 | cerr << "Error: " << er.what() << endl; 97 | return -1; 98 | } 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /examples/ssqls5.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssqls5.cpp - Example showing how to use the equal_list() member of 3 | some SSQLS types to build SELECT queries with custom WHERE clauses. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, (c) 6 | 2004-2009 by Educational Technology Resources, Inc., and (c) 2005 by 7 | Chris Frey. Others may also hold copyrights on code in this file. 8 | See the CREDITS.txt file in the top directory of the distribution 9 | for details. 10 | 11 | This file is part of MySQL++. 12 | 13 | MySQL++ is free software; you can redistribute it and/or modify it 14 | under the terms of the GNU Lesser General Public License as published 15 | by the Free Software Foundation; either version 2.1 of the License, or 16 | (at your option) any later version. 17 | 18 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 | License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with MySQL++; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | USA 27 | ***********************************************************************/ 28 | 29 | #include "cmdline.h" 30 | #include "printdata.h" 31 | #include "stock.h" 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | try { 48 | // Establish the connection to the database server. 49 | mysqlpp::Connection con(mysqlpp::examples::db_name, 50 | cmdline.server(), cmdline.user(), cmdline.pass()); 51 | 52 | // Get all the rows in the stock table. 53 | mysqlpp::Query query = con.query("select * from stock"); 54 | vector res; 55 | query.storein(res); 56 | 57 | if (res.size() > 0) { 58 | // Build a select query using the data from the first row 59 | // returned by our previous query. 60 | query << "select * from stock where " << 61 | res[0].equal_list(" and ", stock_weight, stock_price); 62 | 63 | // Display the finished query. 64 | cout << "Custom query:\n" << query << endl; 65 | } 66 | } 67 | catch (const mysqlpp::BadQuery& er) { 68 | // Handle any query errors 69 | cerr << "Query error: " << er.what() << endl; 70 | return -1; 71 | } 72 | catch (const mysqlpp::BadConversion& er) { 73 | // Handle bad conversions 74 | cerr << "Conversion error: " << er.what() << endl << 75 | "\tretrieved data size: " << er.retrieved << 76 | ", actual size: " << er.actual_size << endl; 77 | return -1; 78 | } 79 | catch (const mysqlpp::Exception& er) { 80 | // Catch-all for any other MySQL++ exceptions 81 | cerr << "Error: " << er.what() << endl; 82 | return -1; 83 | } 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /examples/stock.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | stock.h - Declares the stock SSQLS used by several of the examples. 3 | 4 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 5 | (c) 2004-2010 by Educational Technology Resources, Inc. Others may 6 | also hold copyrights on code in this file. See the CREDITS.txt file 7 | in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | // The following is calling a very complex macro which will create 31 | // "struct stock", which has the member variables: 32 | // 33 | // sql_char item; 34 | // ... 35 | // sql_mediumtext_null description; 36 | // 37 | // plus methods to help populate the class from a MySQL row. See the 38 | // SSQLS sections in the user manual for further details. 39 | sql_create_6(stock, 40 | 1, 6, // The meaning of these values is covered in the user manual 41 | mysqlpp::sql_char, item, 42 | mysqlpp::sql_bigint, num, 43 | mysqlpp::sql_double, weight, 44 | mysqlpp::sql_double_null, price, 45 | mysqlpp::sql_date, sDate, // SSQLS isn't case-sensitive! 46 | mysqlpp::sql_mediumtext_null, description) 47 | 48 | -------------------------------------------------------------------------------- /examples/stock.ssqls: -------------------------------------------------------------------------------- 1 | include common.ssqls 2 | 3 | table stock alias SQLStock filebase ssqls_stock 4 | field item type bigint alias id is autoinc is key 5 | field num type bigint 6 | field weight type double 7 | field price type double 8 | field sdate type date 9 | field description type mediumtext is null 10 | 11 | -------------------------------------------------------------------------------- /examples/stock.txt: -------------------------------------------------------------------------------- 1 | Tiny Screws 1000 0.01 0.05 2008-11-11 All those tiny, indistinguishable, but slighly different screws like the ones it the bottom of your computer desk drawer. 2 | Needle-nose Pliers 50 0.5 5.95 2008-11-12 Drop-forged steel, rubberized grip 3 | Small Soldering Iron 40 0.5 15.95 2008-09-01 20-watt model, assorted tips, UL approved 4 | Large Soldering Iron 35 0.75 24.95 2008-08-01 40-watt model, assorted tips, UL approved, stand included 5 | Solder Wick 100 0.1 2.95 2008-04-01 25 feet, braided copper 6 | Mini Screwdrivers, 3 pc. 30 0.4 8.95 2008-03-25 3-piece mini-screwdriver set in plastic case, 2 Phillips, 1 standard slot 7 | Mini Screwdrivers, 6 pc. 40 0.6 12.95 2008-04-01 6-piece mini-screwdriver set in plastic case, 3 Phillips, 3 standard slot 8 | Wire-wrapping Tool 25 0.2 4.95 2008-04-23 wire-wrapping tool with rubberied grip 9 | Red LED, 5mm, 3000mcd 300 0.01 0.29 2008-10-02 Max forward current 20mA continuous. Max Forward Drop: 2.1V. Max reverse Voltage:5VDC. 10 | Orange LED, 5mm, 2500mcd 250 0.01 0.29 2008-07-31 Max forward current 20mA continuous, 5VDC Max reverse Voltage. 2VDC (typ) Forward voltage drop. 30 Deg. view angle. 1" leads. 11 | Yellow LED, 5mm, 3000mcd 400 0.01 0.25 2008-09-30 Max forward current 20mA continuous, 5VDC Max reverse Voltage. 2.2VDC (typ) Forward voltage drop. 30 Deg. view angle. 1" leads. 12 | Green LED, 5mm, 1000mcd 350 0.01 0.45 2008-09-27 Max forward current 20mA continuous, 5VDC Max reverse Voltage. 2VDC (typ) Forward voltage drop. 30 Deg. view angle. 1" leads. 13 | Blue LED, 5mm, 3900mcd 500 0.01 0.34 2007-12-01 Max forward current 20mA continuous, 5VDC Max reverse Voltage. 2.2VDC (typ) Forward voltage drop. 30 Deg. view angle. 1" leads. 14 | White LED, 5mm, 15000mcd 750 0.01 0.43 2008-02-01 Max forward current 30mA continuous, 20mA recommended. 5VDC Max reverse Voltage. 3.8VDC typ. 4.5V max. Forward voltage drop. 15deg. View angle. 1" leads. 15 | AA Battery, single 220 0.05 0.50 2007-09-19 1.5 v, alkaline 16 | AA Battery, 4-pack 60 0.20 1.79 2007-08-03 1.5 v, alkaline 17 | AA Battery, 24-pack 8 1.2 9.99 2007-04-25 1.5 v, alkaline, includes tester 18 | C Battery, single 100 0.075 0.65 2007-11-14 1.5 v, alkaline 19 | C Battery, 4-pack 25 0.3 2.29 2007-06-05 1.5 v, alkaline 20 | C Battery, 24-pack 5 1.8 10.99 2007-06-13 1.5 v, alkaline, includes tester 21 | D Battery, single 180 0.08 0.70 2007-12-03 1.5 v, alkaline 22 | D Battery, 4-pack 45 0.3 2.59 2007-04-01 1.5 v, alkaline 23 | D Battery, 24-pack 12 1.9 11.99 2007-05-15 1.5 v, alkaline, includes tester 24 | 9-volt Battery, single 90 0.06 0.75 2008-01-02 alkaline 25 | 9-volt Battery, 3-pack 17 0.2 1.99 2008-02-28 alkaline 26 | 9-volt Batter, 20-pack 12 1.2 12.99 2007-12-28 alkaline, no tester needed (just use your tongue) 27 | -------------------------------------------------------------------------------- /examples/store_if.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | store_if.cpp - Demonstrates Query::store_if(), showing only the rows 3 | from the sample table with prime quantities. This isn't intended 4 | to be useful, only to show how you can do result set filtering that 5 | outstrips the power of SQL. 6 | 7 | Copyright (c) 2005-2010 by Educational Technology Resources, Inc. 8 | Others may also hold copyrights on code in this file. See the CREDITS 9 | file in the top directory of the distribution for details. 10 | 11 | This file is part of MySQL++. 12 | 13 | MySQL++ is free software; you can redistribute it and/or modify it 14 | under the terms of the GNU Lesser General Public License as published 15 | by the Free Software Foundation; either version 2.1 of the License, or 16 | (at your option) any later version. 17 | 18 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 | License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with MySQL++; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | USA 27 | ***********************************************************************/ 28 | 29 | #include "cmdline.h" 30 | #include "printdata.h" 31 | #include "stock.h" 32 | 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | 39 | 40 | // Define a functor for testing primality. 41 | struct is_prime 42 | { 43 | bool operator()(const stock& s) 44 | { 45 | if ((s.num == 2) || (s.num == 3)) { 46 | return true; // 2 and 3 are trivial cases 47 | } 48 | else if ((s.num < 2) || ((s.num % 2) == 0)) { 49 | return false; // can't be prime if < 2 or even 50 | } 51 | else { 52 | // The only possibility left is that it's divisible by an 53 | // odd number that's less than or equal to its square root. 54 | for (int i = 3; i <= sqrt(double(s.num)); i += 2) { 55 | if ((s.num % i) == 0) { 56 | return false; 57 | } 58 | } 59 | return true; 60 | } 61 | } 62 | }; 63 | 64 | 65 | int 66 | main(int argc, char *argv[]) 67 | { 68 | // Get database access parameters from command line 69 | mysqlpp::examples::CommandLine cmdline(argc, argv); 70 | if (!cmdline) { 71 | return 1; 72 | } 73 | 74 | try { 75 | // Establish the connection to the database server. 76 | mysqlpp::Connection con(mysqlpp::examples::db_name, 77 | cmdline.server(), cmdline.user(), cmdline.pass()); 78 | 79 | // Collect the stock items with prime quantities 80 | std::vector results; 81 | mysqlpp::Query query = con.query(); 82 | query.store_if(results, stock(), is_prime()); 83 | 84 | // Show the results 85 | print_stock_header(results.size()); 86 | std::vector::const_iterator it; 87 | for (it = results.begin(); it != results.end(); ++it) { 88 | print_stock_row(it->item.c_str(), it->num, it->weight, 89 | it->price, it->sDate); 90 | } 91 | } 92 | catch (const mysqlpp::BadQuery& e) { 93 | // Something went wrong with the SQL query. 94 | std::cerr << "Query failed: " << e.what() << std::endl; 95 | return 1; 96 | } 97 | catch (const mysqlpp::Exception& er) { 98 | // Catch-all for any other MySQL++ exceptions 99 | std::cerr << "Error: " << er.what() << std::endl; 100 | return 1; 101 | } 102 | 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /examples/threads.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | threads.h - Abstracts away the differences between POSIX threads and 3 | Windows native threads. Used by the cpool example only; we could 4 | keep this code inline there, but it's really just unimportant 5 | details. 6 | 7 | Copyright (c) 2008 by Educational Technology Resources, Inc. 8 | Others may also hold copyrights on code in this file. See the 9 | CREDITS.txt file in the top directory of the distribution for details. 10 | 11 | This file is part of MySQL++. 12 | 13 | MySQL++ is free software; you can redistribute it and/or modify it 14 | under the terms of the GNU Lesser General Public License as published 15 | by the Free Software Foundation; either version 2.1 of the License, or 16 | (at your option) any later version. 17 | 18 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 | License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with MySQL++; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | USA 27 | ***********************************************************************/ 28 | 29 | #if !defined(MYSQLPP_THREADS_H) 30 | #define MYSQLPP_THREADS_H 31 | 32 | #include 33 | 34 | #if defined(MYSQLPP_PLATFORM_WINDOWS) 35 | # define HAVE_THREADS 36 | # define CALLBACK_SPECIFIER WINAPI 37 | typedef DWORD thread_return_t; 38 | typedef LPVOID thread_arg_t; 39 | static int create_thread(LPTHREAD_START_ROUTINE worker, thread_arg_t arg) 40 | { 41 | return CreateThread(0, 0, worker, arg, 0, 0) ? 0 : GetLastError(); 42 | } 43 | static void sleep(int s) { Sleep(s * 1000); } 44 | #else 45 | # include "../config.h" 46 | # if defined(HAVE_UNISTD_H) 47 | # include 48 | # endif 49 | # if defined(HAVE_PTHREAD) 50 | # define HAVE_THREADS 51 | # define CALLBACK_SPECIFIER 52 | typedef void* thread_return_t; 53 | typedef void* thread_arg_t; 54 | static int create_thread(thread_return_t(*worker)(thread_arg_t), 55 | thread_arg_t arg) 56 | { 57 | pthread_t pt; 58 | return pthread_create(&pt, 0, worker, arg); 59 | } 60 | # endif 61 | #endif 62 | 63 | #endif // !defined(MYSQLPP_THREADS_H) 64 | -------------------------------------------------------------------------------- /examples/tquery1.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | tquery1.cpp - Example similar to ssqls3.cpp, except that it uses 3 | template queries instead of SSQLS. 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "cmdline.h" 29 | #include "printdata.h" 30 | 31 | #include 32 | 33 | using namespace std; 34 | 35 | int 36 | main(int argc, char *argv[]) 37 | { 38 | // Get database access parameters from command line 39 | mysqlpp::examples::CommandLine cmdline(argc, argv); 40 | if (!cmdline) { 41 | return 1; 42 | } 43 | 44 | try { 45 | // Establish the connection to the database server. 46 | mysqlpp::Connection con(mysqlpp::examples::db_name, 47 | cmdline.server(), cmdline.user(), cmdline.pass()); 48 | 49 | // Build a template query to retrieve a stock item given by 50 | // item name. 51 | mysqlpp::Query query = con.query( 52 | "select * from stock where item = %0q"); 53 | query.parse(); 54 | 55 | // Retrieve an item added by resetdb; it won't be there if 56 | // tquery* or ssqls3 is run since resetdb. 57 | mysqlpp::StoreQueryResult res1 = query.store("Nürnberger Brats"); 58 | if (res1.empty()) { 59 | throw mysqlpp::BadQuery("UTF-8 bratwurst item not found in " 60 | "table, run resetdb"); 61 | } 62 | 63 | // Replace the proper German name with a 7-bit ASCII 64 | // approximation using a different template query. 65 | query.reset(); // forget previous template query data 66 | query << "update stock set item = %0q where item = %1q"; 67 | query.parse(); 68 | mysqlpp::SimpleResult res2 = query.execute("Nuerenberger Bratwurst", 69 | res1[0][0].c_str()); 70 | 71 | // Print the new table contents. 72 | print_stock_table(query); 73 | } 74 | catch (const mysqlpp::BadQuery& er) { 75 | // Handle any query errors 76 | cerr << "Query error: " << er.what() << endl; 77 | return -1; 78 | } 79 | catch (const mysqlpp::BadConversion& er) { 80 | // Handle bad conversions 81 | cerr << "Conversion error: " << er.what() << endl << 82 | "\tretrieved data size: " << er.retrieved << 83 | ", actual size: " << er.actual_size << endl; 84 | return -1; 85 | } 86 | catch (const mysqlpp::Exception& er) { 87 | // Catch-all for any other MySQL++ exceptions 88 | cerr << "Error: " << er.what() << endl; 89 | return -1; 90 | } 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /examples/tquery2.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | tquery2.cpp - Same as tquery1.cpp, except that it passes the template 3 | query parameters in a SQLQueryParms object, instead of separately. 4 | This is useful when the calling code doesn't know in advance how 5 | many parameters there will be. This is most likely because the 6 | templates are coming from somewhere else, or being generated. 7 | 8 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 9 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 10 | also hold copyrights on code in this file. See the CREDITS.txt file 11 | in the top directory of the distribution for details. 12 | 13 | This file is part of MySQL++. 14 | 15 | MySQL++ is free software; you can redistribute it and/or modify it 16 | under the terms of the GNU Lesser General Public License as published 17 | by the Free Software Foundation; either version 2.1 of the License, or 18 | (at your option) any later version. 19 | 20 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 21 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with MySQL++; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 28 | USA 29 | ***********************************************************************/ 30 | 31 | #include "cmdline.h" 32 | #include "printdata.h" 33 | 34 | #include 35 | 36 | using namespace std; 37 | 38 | int 39 | main(int argc, char *argv[]) 40 | { 41 | // Get database access parameters from command line 42 | mysqlpp::examples::CommandLine cmdline(argc, argv); 43 | if (!cmdline) { 44 | return 1; 45 | } 46 | 47 | try { 48 | // Establish the connection to the database server. 49 | mysqlpp::Connection con(mysqlpp::examples::db_name, 50 | cmdline.server(), cmdline.user(), cmdline.pass()); 51 | 52 | // Build a template query to retrieve a stock item given by 53 | // item name. 54 | mysqlpp::Query query = con.query( 55 | "select * from stock where item = %0q"); 56 | query.parse(); 57 | 58 | // Retrieve an item added by resetdb; it won't be there if 59 | // tquery* or ssqls3 is run since resetdb. 60 | mysqlpp::SQLQueryParms sqp; 61 | sqp << "Nürnberger Brats"; 62 | mysqlpp::StoreQueryResult res1 = query.store(sqp); 63 | if (res1.empty()) { 64 | throw mysqlpp::BadQuery("UTF-8 bratwurst item not found in " 65 | "table, run resetdb"); 66 | } 67 | 68 | // Replace the proper German name with a 7-bit ASCII 69 | // approximation using a different template query. 70 | query.reset(); // forget previous template query info 71 | query << "update stock set item = %0q where item = %1q"; 72 | query.parse(); 73 | sqp.clear(); 74 | sqp << "Nuerenberger Bratwurst" << res1[0][0].c_str(); 75 | mysqlpp::SimpleResult res2 = query.execute(sqp); 76 | 77 | // Print the new table contents. 78 | print_stock_table(query); 79 | } 80 | catch (const mysqlpp::BadQuery& er) { 81 | // Handle any query errors 82 | cerr << "Query error: " << er.what() << endl; 83 | return -1; 84 | } 85 | catch (const mysqlpp::BadConversion& er) { 86 | // Handle bad conversions 87 | cerr << "Conversion error: " << er.what() << endl << 88 | "\tretrieved data size: " << er.retrieved << 89 | ", actual size: " << er.actual_size << endl; 90 | return -1; 91 | } 92 | catch (const mysqlpp::Exception& er) { 93 | // Catch-all for any other MySQL++ exceptions 94 | cerr << "Error: " << er.what() << endl; 95 | return -1; 96 | } 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /examples/tquery3.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | tquery3.cpp - Similar to tquery1.cpp but uses unquoted parameters. 3 | It's here more for code test coverage than because it shows 4 | something interesting. We've historically had a problem with 5 | tqueries with just one parameter; we cover the quoted case in 6 | resetdb and the other tquery examples, so we get the unquoted 7 | one here. 8 | 9 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 10 | (c) 2004-2009 by Educational Technology Resources, Inc. Others may 11 | also hold copyrights on code in this file. See the CREDITS.txt file 12 | in the top directory of the distribution for details. 13 | 14 | This file is part of MySQL++. 15 | 16 | MySQL++ is free software; you can redistribute it and/or modify it 17 | under the terms of the GNU Lesser General Public License as published 18 | by the Free Software Foundation; either version 2.1 of the License, or 19 | (at your option) any later version. 20 | 21 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | License for more details. 25 | 26 | You should have received a copy of the GNU Lesser General Public 27 | License along with MySQL++; if not, write to the Free Software 28 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 29 | USA 30 | ***********************************************************************/ 31 | 32 | #include "cmdline.h" 33 | #include "printdata.h" 34 | 35 | #include 36 | 37 | using namespace std; 38 | 39 | int 40 | main(int argc, char *argv[]) 41 | { 42 | // Get database access parameters from command line 43 | mysqlpp::examples::CommandLine cmdline(argc, argv); 44 | if (!cmdline) { 45 | return 1; 46 | } 47 | 48 | try { 49 | // Establish the connection to the database server. 50 | mysqlpp::Connection con(mysqlpp::examples::db_name, 51 | cmdline.server(), cmdline.user(), cmdline.pass()); 52 | 53 | // Build a template query to retrieve item names for stock 54 | // entries with a quantity over some threshold. 55 | mysqlpp::Query query = con.query( 56 | "select item from stock where num > %0"); 57 | query.parse(); 58 | 59 | // Get a list of things we have lots of in stock 60 | if (mysqlpp::StoreQueryResult res = query.store(80)) { 61 | cout << "Stuff we have a lot of in stock:" << endl; 62 | for (size_t i = 0; i < res.num_rows(); ++i) { 63 | cout << '\t' << res[i]["item"] << endl; 64 | } 65 | } 66 | else { 67 | cerr << "Failed to get item list: " << query.error() << endl; 68 | return 1; 69 | } 70 | } 71 | catch (const mysqlpp::BadQuery& er) { 72 | // Handle any query errors 73 | cerr << "Query error: " << er.what() << endl; 74 | return 2; 75 | } 76 | catch (const mysqlpp::Exception& er) { 77 | // Catch-all for any other MySQL++ exceptions 78 | cerr << "Error: " << er.what() << endl; 79 | return 2; 80 | } 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /examples/tquery4.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | tquery4.cpp - Tests other details about template queries, like unquoted 3 | parameters, multiple parameters, and preventing problems with LIKE 4 | patterns. This exists more for code coverage than to demonstrate 5 | the library. 6 | 7 | Copyright (c) 2009 by Martin Gallwey and (c) 2009 by Educational 8 | Technology Resources, Inc. Others may also hold copyrights on code 9 | in this file. See the CREDITS.txt file in the top directory of the 10 | distribution for details. 11 | 12 | This file is part of MySQL++. 13 | 14 | MySQL++ is free software; you can redistribute it and/or modify it 15 | under the terms of the GNU Lesser General Public License as published 16 | by the Free Software Foundation; either version 2.1 of the License, or 17 | (at your option) any later version. 18 | 19 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with MySQL++; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 27 | USA 28 | ***********************************************************************/ 29 | 30 | #include "cmdline.h" 31 | #include "printdata.h" 32 | 33 | #include 34 | 35 | using namespace std; 36 | 37 | int 38 | main(int argc, char *argv[]) 39 | { 40 | // Get database access parameters from command line 41 | mysqlpp::examples::CommandLine cmdline(argc, argv); 42 | if (!cmdline) { 43 | return 1; 44 | } 45 | 46 | try { 47 | // Establish the connection to the database server. 48 | mysqlpp::Connection con(mysqlpp::examples::db_name, 49 | cmdline.server(), cmdline.user(), cmdline.pass()); 50 | 51 | // Modify an item using two named template query parameters 52 | mysqlpp::Query query = con.query("update stock " 53 | "set num = %0:quantity where num < %0:quantity"); 54 | query.parse(); 55 | query.template_defaults["quantity"] = 70; 56 | cout << "Query: " << query << endl; 57 | mysqlpp::SimpleResult result = query.execute(); 58 | 59 | // Print the new table contents. 60 | print_stock_table(query); 61 | 62 | // Now let's check multiple dissimilar parameter types, and show 63 | // how to avoid conflicts between '%' as used in tqueries vs in 64 | // LIKE patterns. 65 | query.reset(); 66 | query << "select * from stock where weight > %0q or " 67 | "description like '%%%1%%'"; 68 | query.parse(); 69 | cout << "\nQuery: " << query.str(1.2, "Mustard") << endl; 70 | mysqlpp::StoreQueryResult res = query.store(1.2, "Mustard"); 71 | 72 | // Show what second tquery found 73 | print_stock_rows(res); 74 | } 75 | catch (const mysqlpp::BadQuery& er) { 76 | // Handle any query errors 77 | cerr << "Query error: " << er.what() << endl; 78 | return -1; 79 | } 80 | catch (const mysqlpp::BadConversion& er) { 81 | // Handle bad conversions 82 | cerr << "Conversion error: " << er.what() << endl << 83 | "\tretrieved data size: " << er.retrieved << 84 | ", actual size: " << er.actual_size << endl; 85 | return -1; 86 | } 87 | catch (const mysqlpp::Exception& er) { 88 | // Catch-all for any other MySQL++ exceptions 89 | cerr << "Error: " << er.what() << endl; 90 | return -1; 91 | } 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /examples/vstudio/mfc/mfc.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | mfc.cpp - Skeletal main module of the MySQL++ MFC example program. 3 | Nothing interesting to see here. Move along to mfc_dlg.cpp, folks. 4 | 5 | Copyright (c) 2007 by Educational Technology Resources, Inc. Others 6 | may also hold copyrights on code in this file. See the CREDITS.txt 7 | file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include "stdafx.h" 28 | #include "mfc.h" 29 | #include "mfc_dlg.h" 30 | 31 | CApp gApplication; 32 | 33 | BOOL CApp::InitInstance() 34 | { 35 | // Set up Windows commomn controls 36 | INITCOMMONCONTROLSEX InitCtrls; 37 | InitCtrls.dwSize = sizeof(InitCtrls); 38 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 39 | InitCommonControlsEx(&InitCtrls); 40 | 41 | CWinApp::InitInstance(); 42 | 43 | // Initialize Winsock for MySQL communication, start GUI 44 | if (AfxSocketInit()) { 45 | CExampleDlg dlg; 46 | m_pMainWnd = &dlg; 47 | dlg.DoModal(); 48 | } 49 | else { 50 | AfxMessageBox(IDP_SOCKETS_INIT_FAILED); 51 | } 52 | 53 | return FALSE; 54 | } 55 | -------------------------------------------------------------------------------- /examples/vstudio/mfc/mfc.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | mfc.cpp - Declares the MFC application object. Nothing interesting to 3 | see here. Move along to mfc_dlg.cpp, folks. 4 | 5 | Copyright (c) 2007 by Educational Technology Resources, Inc. Others 6 | may also hold copyrights on code in this file. See the CREDITS.txt 7 | file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #pragma once 28 | 29 | class CApp : public CWinApp 30 | { 31 | public: 32 | CApp() { } 33 | virtual BOOL InitInstance(); 34 | }; 35 | -------------------------------------------------------------------------------- /examples/vstudio/mfc/mfc_dlg.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | mfc_dlg.h - Declares the dialog class for the MySQL++ MFC example. 3 | 4 | Copyright (c) 2007 by Educational Technology Resources, Inc. Others 5 | may also hold copyrights on code in this file. See the CREDITS.txt 6 | file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #pragma once 27 | #include "afxwin.h" 28 | #include "resource.h" 29 | 30 | class CExampleDlg : public CDialog 31 | { 32 | public: 33 | //// Public interface 34 | CExampleDlg(CWnd* pParent = 0); 35 | 36 | //// Public data 37 | CString sServerAddress; 38 | CString sUserName; 39 | CString sPassword; 40 | CListBox ResultsList; 41 | 42 | protected: 43 | //// Internal support functions 44 | void AddMessage(LPCTSTR pcMessage); 45 | void DoDataExchange(CDataExchange* pDX); 46 | void LoadDefaults(); 47 | bool LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue, 48 | DWORD nValueSize); 49 | HKEY OpenSettingsRegistryKey(); 50 | bool SaveInputs(); 51 | bool SaveSetting(HKEY key, LPCTSTR pcName, LPCTSTR pcValue); 52 | bool ToUCS2(LPTSTR pcOut, int nOutLen, const char* kpcIn); 53 | bool ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn); 54 | 55 | //// Message map 56 | afx_msg void OnBnClickedConnectButton(); 57 | DECLARE_MESSAGE_MAP() 58 | }; 59 | -------------------------------------------------------------------------------- /examples/vstudio/mfc/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by mfc.rc 4 | // 5 | #define IDD_MFC_DIALOG 102 6 | #define IDP_SOCKETS_INIT_FAILED 103 7 | #define IDC_SERVER_EDIT 1000 8 | #define IDC_PASSWORD_EDIT 1001 9 | #define IDC_USER_EDIT 1002 10 | #define IDC_RESULTS_LIST 1003 11 | #define IDC_CONNECT_BUTTON 1004 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 129 18 | #define _APS_NEXT_COMMAND_VALUE 32771 19 | #define _APS_NEXT_CONTROL_VALUE 1005 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /examples/vstudio/mfc/stdafx.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | stdafx.h - Common include file to bring in MFC support and other 3 | basics. 4 | 5 | Copyright (c) 2007 by Educational Technology Resources, Inc. Others 6 | may also hold copyrights on code in this file. See the CREDITS.txt 7 | file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #pragma once 28 | 29 | #ifndef VC_EXTRALEAN 30 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 31 | #endif 32 | 33 | // Modify the following defines if you have to target a platform prior to the ones specified below. 34 | // Refer to MSDN for the latest info on corresponding values for different platforms. 35 | #ifndef WINVER // Allow use of features specific to Windows XP or later. 36 | #define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. 37 | #endif 38 | 39 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 40 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 41 | #endif 42 | 43 | #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. 44 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 45 | #endif 46 | 47 | // turns off MFC's hiding of some common and often safely ignored warning messages 48 | #define _AFX_ALL_WARNINGS 49 | 50 | #include // MFC core and standard components 51 | #include // MFC extensions 52 | #include // MFC support for Windows Common Controls 53 | #include // MFC socket extensions 54 | 55 | -------------------------------------------------------------------------------- /examples/vstudio/wforms/AssemblyInfo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangentsoft/mysqlpp/f40d94c4eddbad5ff319d8886bcf68dbf14528cf/examples/vstudio/wforms/AssemblyInfo.cpp -------------------------------------------------------------------------------- /examples/vstudio/wforms/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by app.rc 4 | -------------------------------------------------------------------------------- /examples/vstudio/wforms/wforms.cpp: -------------------------------------------------------------------------------- 1 | // wforms.cpp : main project file. 2 | 3 | #include "MainForm.h" 4 | 5 | using namespace wforms; 6 | 7 | [STAThreadAttribute] 8 | int main(array ^args) 9 | { 10 | // Enabling Windows XP visual effects before any controls are created 11 | Application::EnableVisualStyles(); 12 | Application::SetCompatibleTextRenderingDefault(false); 13 | 14 | // Create the main window and run it 15 | Application::Run(gcnew MainForm()); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /exrun: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "$1" ] 3 | then 4 | echo "usage: $0 [TOOL] [args...]" 5 | echo 6 | echo " Runs the given example, using the library in the current directory" 7 | echo " instead of using the system library search mechanism. Accepts an " 8 | echo " arbitrary number of arguments." 9 | echo 10 | echo " TOOL can be 'valgrind', 'gdb', or 'ldd', which causes exrun to" 11 | echo " run the example program under the given tool." 12 | echo 13 | exit 1 14 | fi 15 | 16 | TOOL= 17 | PROG=$1 18 | if [ "$PROG" = 'valgrind' ] 19 | then 20 | TOOL='valgrind' 21 | shift 22 | PROG=$1 23 | elif [ "$PROG" = 'gdb' ] 24 | then 25 | TOOL='gdb --args' 26 | shift 27 | PROG=$1 28 | elif [ "$PROG" = 'ldd' ] 29 | then 30 | TOOL='ldd' 31 | shift 32 | PROG=$1 33 | fi 34 | 35 | shift 36 | if [ -e "$PROG" ] 37 | then 38 | if [ `uname -s` = 'Darwin' ] 39 | then 40 | DYLD_LIBRARY_PATH=. $TOOL ./$PROG $* 41 | elif [ `uname -o` = 'Cygwin' ] 42 | then 43 | # Cygwin build case; see below for bash-as-DOS-shell case 44 | PATH=. $TOOL ./$PROG $* 45 | elif [ -e /usr/bin/ldd ] 46 | then 47 | if [ `uname -s` = 'SunOS' ] 48 | then 49 | LD_LIBRARY_PATH=.:/usr/mysql/lib/mysql $TOOL ./$PROG $* 50 | else 51 | LD_LIBRARY_PATH=. $TOOL ./$PROG $* 52 | fi 53 | else 54 | echo "ERROR: I don't grok this system's dynamic linkage system." 55 | fi 56 | elif [ `uname -o` = 'Cygwin' ] 57 | then 58 | # VC++ build, but using Cygwin's bash as shell to run programs 59 | cmd.exe /c exrun.bat $PROG $* 60 | else 61 | echo "usage: $0 [TOOL] [args...]" 62 | echo 63 | echo " Run $0 without arguments for more detailed usage info." 64 | echo 65 | exit 1 66 | fi 67 | -------------------------------------------------------------------------------- /exrun.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set PROG=%1 3 | if not exist %PROG% set PROG=%1.exe 4 | if not exist %PROG% set PROG=Debug\%1 5 | if not exist %PROG% set PROG=vc2008\x64\Debug\%1.exe 6 | if not exist %PROG% set PROG=vc2008\Debug\%1.exe 7 | if not exist %PROG% set PROG=vc2005\Debug\%1.exe 8 | if not exist %PROG% set PROG=vc2003\Debug\%1.exe 9 | if not exist %PROG% exit 10 | shift 11 | 12 | set PATH=Debug;vc2008\x64\Debug;vc2008\Debug;vc2005\Debug;vc2003\Debug;%PATH% 13 | echo Running %PROG%... 14 | %PROG% %1 %2 %3 %4 %5 %6 %7 %8 %9 15 | -------------------------------------------------------------------------------- /lib/autoflag.h: -------------------------------------------------------------------------------- 1 | /// \file autoflag.h 2 | /// \brief Defines a template for setting a flag within a given variable 3 | /// scope, and resetting it when exiting that scope. 4 | 5 | /*********************************************************************** 6 | Copyright © 2007 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the 8 | CREDITS.txt file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #if !defined(MYSQLPP_AUTOFLAG_H) 29 | #define MYSQLPP_AUTOFLAG_H 30 | 31 | namespace mysqlpp { 32 | 33 | /// \brief A template for setting a flag on a variable as long as the 34 | /// object that set it is in scope. Flag resets when object goes 35 | /// out of scope. Works on anything that looks like bool. 36 | 37 | template 38 | class AutoFlag 39 | { 40 | public: 41 | /// \brief Constructor: sets ref to true. 42 | AutoFlag(T& ref) : 43 | referent_(ref) 44 | { 45 | referent_ = true; 46 | } 47 | 48 | /// \brief Destructor: sets referent passed to ctor to false. 49 | ~AutoFlag() 50 | { 51 | referent_ = false; 52 | } 53 | 54 | private: 55 | T& referent_; 56 | }; 57 | 58 | } // end namespace mysqlpp 59 | 60 | #endif // !defined(MYSQLPP_AUTOFLAG_H) 61 | 62 | -------------------------------------------------------------------------------- /lib/comparable.h: -------------------------------------------------------------------------------- 1 | /// \file comparable.h 2 | /// \brief Declares the Comparable mixin 3 | 4 | /*********************************************************************** 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2008 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #if !defined(MYSQLPP_COMPARABLE_H) 29 | #define MYSQLPP_COMPARABLE_H 30 | 31 | namespace mysqlpp { 32 | 33 | /// \brief Mix-in that gives its subclass a full set of comparison 34 | /// operators. 35 | /// 36 | /// Simply by inheriting publically from this and implementing 37 | /// compare(), the subclass gains a full set of comparison operators, 38 | /// because all of the operators are implemented in terms of compare(). 39 | template 40 | class Comparable 41 | { 42 | public: 43 | /// \brief Returns true if "other" is equal to this object 44 | bool operator ==(const T& other) const 45 | { 46 | return !compare(other); 47 | } 48 | 49 | /// \brief Returns true if "other" is not equal to this object 50 | bool operator !=(const T& other) const 51 | { 52 | return compare(other); 53 | } 54 | 55 | /// \brief Returns true if "other" is less than this object 56 | bool operator <(const T& other) const 57 | { 58 | return compare(other) < 0; 59 | } 60 | 61 | /// \brief Returns true if "other" is less than or equal to this object 62 | bool operator <=(const T& other) const 63 | { 64 | return compare(other) <= 0; 65 | } 66 | 67 | /// \brief Returns true if "other" is greater than this object 68 | bool operator >(const T& other) const 69 | { 70 | return compare(other) > 0; 71 | } 72 | 73 | /// \brief Returns true if "other" is greater than or equal to this object 74 | bool operator >=(const T& other) const 75 | { 76 | return compare(other) >= 0; 77 | } 78 | 79 | protected: 80 | /// \brief Destroy object 81 | /// 82 | /// This class has nothing to destroy, but declaring the dtor 83 | /// virtual placates some compilers set to high warning levels. 84 | /// Protecting it ensures you can't delete subclasses through base 85 | /// class pointers, which makes no sense because this class isn't 86 | /// made for polymorphism. It's just a mixin. 87 | virtual ~Comparable() { } 88 | 89 | /// \brief Compare this object to another of the same type 90 | /// 91 | /// Returns < 0 if this object is "before" the other, 0 of they are 92 | /// equal, and > 0 if this object is "after" the other. 93 | virtual int compare(const T& other) const = 0; 94 | }; 95 | 96 | } 97 | 98 | #endif // !defined(MYSQLPP_COMPARABLE_H) 99 | -------------------------------------------------------------------------------- /lib/field_names.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | field_names.cpp - Implements the FieldNames class. 3 | 4 | Copyright © 5 | 1998 by Kevin Atkinson 6 | 1999-2001 by MySQL AB 7 | 2004-2010 by Educational Technology Resources, Inc. 8 | 2021 by Warren Young 9 | 10 | Others may also hold copyrights on code in this file. See the 11 | CREDITS.txt file in the top directory of the distribution for details. 12 | 13 | This file is part of MySQL++. 14 | 15 | MySQL++ is free software; you can redistribute it and/or modify it 16 | under the terms of the GNU Lesser General Public License as published 17 | by the Free Software Foundation; either version 2.1 of the License, or 18 | (at your option) any later version. 19 | 20 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 21 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with MySQL++; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 28 | USA 29 | ***********************************************************************/ 30 | 31 | #define MYSQLPP_NOT_HEADER 32 | #include "common.h" 33 | 34 | #include "field_names.h" 35 | #include "result.h" 36 | 37 | #include 38 | 39 | namespace mysqlpp { 40 | 41 | namespace internal { extern void str_to_lwr(std::string& s); } 42 | 43 | void 44 | FieldNames::init(const ResultBase* res) 45 | { 46 | size_t num = res->num_fields(); 47 | reserve(num); 48 | 49 | for (size_t i = 0; i < num; i++) { 50 | push_back(res->fields().at(i).name()); 51 | } 52 | } 53 | 54 | 55 | unsigned int 56 | FieldNames::operator [](const std::string& s) const 57 | { 58 | std::string temp1(s); 59 | internal::str_to_lwr(temp1); 60 | for (const_iterator it = begin(); it != end(); ++it) { 61 | std::string temp2(*it); 62 | internal::str_to_lwr(temp2); 63 | #if __cplusplus < 201703L 64 | if (temp2.compare(temp1) == 0) { 65 | #else 66 | if (temp1 == temp2) { // faster: https://godbolt.org/z/xs114s 67 | #endif 68 | // The cast is necessary for compilers where sizeof(int) != 69 | // sizeof (void*) with sufficiently good warnings. Yes, 70 | // technically this does risk data loss, but for that to 71 | // happen you'd have to have more than 2^(sizeof(int)*8)-1 72 | // fields in your table. If you do that, you deserve to 73 | // lose anyway. 74 | return static_cast(it - begin()); 75 | } 76 | } 77 | 78 | return static_cast(end() - begin()); // same as above 79 | } 80 | 81 | } // end namespace mysqlpp 82 | -------------------------------------------------------------------------------- /lib/field_names.h: -------------------------------------------------------------------------------- 1 | /// \file field_names.h 2 | /// \brief Declares a class to hold a list of field names. 3 | 4 | /*********************************************************************** 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 6 | (c) 2004-2008 by Educational Technology Resources, Inc. Others may 7 | also hold copyrights on code in this file. See the CREDITS.txt file 8 | in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #ifndef MYSQLPP_FIELD_NAMES_H 29 | #define MYSQLPP_FIELD_NAMES_H 30 | 31 | #include 32 | #include 33 | 34 | namespace mysqlpp { 35 | 36 | #if !defined(DOXYGEN_IGNORE) 37 | // Make Doxygen ignore this 38 | class MYSQLPP_EXPORT ResultBase; 39 | #endif 40 | 41 | /// \brief Holds a list of SQL field names 42 | class FieldNames : public std::vector 43 | { 44 | public: 45 | /// \brief Default constructor 46 | FieldNames() { } 47 | 48 | /// \brief Copy constructor 49 | FieldNames(const FieldNames& other) : 50 | std::vector() 51 | { 52 | assign(other.begin(), other.end()); 53 | } 54 | 55 | /// \brief Create field name list from a result set 56 | FieldNames(const ResultBase* res) : 57 | std::vector() 58 | { 59 | init(res); 60 | } 61 | 62 | /// \brief Create empty field name list, reserving space for 63 | /// a fixed number of field names. 64 | FieldNames(int i) : 65 | std::vector(i) 66 | { 67 | } 68 | 69 | /// \brief Initializes the field list from a result set 70 | FieldNames& operator =(const ResultBase* res) 71 | { 72 | init(res); 73 | return *this; 74 | } 75 | 76 | /// \brief Insert \c i empty field names at beginning of list 77 | FieldNames& operator =(int i) 78 | { 79 | insert(begin(), i, ""); 80 | return *this; 81 | } 82 | 83 | /// \brief Get the name of a field given its index. 84 | std::string& operator [](int i) 85 | { 86 | return at(i); 87 | } 88 | 89 | /// \brief Get the name of a field given its index, in const 90 | /// context. 91 | const std::string& operator [](int i) const 92 | { 93 | return at(i); 94 | } 95 | 96 | /// \brief Get the name of a field given its index. 97 | std::string& operator [](size_type i) 98 | { 99 | return at(i); 100 | } 101 | 102 | /// \brief Get the name of a field given its index, in const 103 | /// context. 104 | const std::string& operator [](size_type i) const 105 | { 106 | return at(i); 107 | } 108 | 109 | /// \brief Get the index number of a field given its name 110 | unsigned int operator [](const std::string& s) const; 111 | 112 | private: 113 | void init(const ResultBase* res); 114 | }; 115 | 116 | } // end namespace mysqlpp 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /lib/field_types.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | field_types.cpp - Implements the FieldTypes class. 3 | 4 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 5 | (c) 2004-2007 by Educational Technology Resources, Inc. Others may 6 | also hold copyrights on code in this file. See the CREDITS.txt file 7 | in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #define MYSQLPP_NOT_HEADER 28 | #include "common.h" 29 | 30 | #include "field_types.h" 31 | 32 | #include "result.h" 33 | 34 | namespace mysqlpp { 35 | 36 | void FieldTypes::init(const ResultBase* res) 37 | { 38 | size_t num = res->num_fields(); 39 | reserve(num); 40 | for (size_t i = 0; i < num; i++) { 41 | push_back(res->field(unsigned(i)).type()); 42 | } 43 | } 44 | 45 | } // end namespace mysqlpp 46 | -------------------------------------------------------------------------------- /lib/field_types.h: -------------------------------------------------------------------------------- 1 | /// \file field_types.h 2 | /// \brief Declares a class to hold a list of SQL field type info. 3 | 4 | /*********************************************************************** 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by 6 | MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the CREDITS 8 | file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #ifndef MYSQLPP_FIELD_TYPES_H 29 | #define MYSQLPP_FIELD_TYPES_H 30 | 31 | #include "type_info.h" 32 | 33 | #include 34 | 35 | namespace mysqlpp { 36 | 37 | #if !defined(DOXYGEN_IGNORE) 38 | // Make Doxygen ignore this 39 | class MYSQLPP_EXPORT ResultBase; 40 | #endif 41 | 42 | /// \brief A vector of SQL field types. 43 | class FieldTypes : public std::vector 44 | { 45 | public: 46 | /// \brief Default constructor 47 | FieldTypes() { } 48 | 49 | /// \brief Create list of field types from a result set 50 | FieldTypes(const ResultBase* res) 51 | { 52 | init(res); 53 | } 54 | 55 | /// \brief Create fixed-size list of uninitialized field types 56 | FieldTypes(int i) : 57 | std::vector(i) 58 | { 59 | } 60 | 61 | /// \brief Initialize field list based on a result set 62 | FieldTypes& operator =(const ResultBase* res) 63 | { 64 | init(res); 65 | return *this; 66 | } 67 | 68 | /// \brief Insert a given number of uninitialized field type 69 | /// objects at the beginning of the list 70 | /// 71 | /// \param i number of field type objects to insert 72 | FieldTypes& operator =(int i) 73 | { 74 | insert(begin(), i, mysql_type_info()); 75 | return *this; 76 | } 77 | 78 | private: 79 | void init(const ResultBase* res); 80 | }; 81 | 82 | } // end namespace mysqlpp 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /lib/myset.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | myset.cpp - Implements the Set template. (Not to be confused with 3 | std::set, which this template wraps.) 4 | 5 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by 6 | MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the CREDITS 8 | file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include "myset.h" 29 | 30 | namespace mysqlpp { 31 | 32 | template class Set >; 33 | 34 | } // end namespace mysqlpp 35 | 36 | -------------------------------------------------------------------------------- /lib/mysql++.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | mysql++.cpp - Implements functions dealing with the library itself, 3 | as opposed to individual features of the library. 4 | 5 | Copyright (c) 2007 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the CREDITS 7 | file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include "mysql++.h" 28 | 29 | namespace mysqlpp { 30 | 31 | unsigned int 32 | get_library_version() 33 | { 34 | return MYSQLPP_HEADER_VERSION; 35 | } 36 | 37 | } // end namespace mysqlpp 38 | 39 | -------------------------------------------------------------------------------- /lib/null.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | null.cpp - Defines a few things declared in null.h 3 | 4 | Copyright (c) 2007 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include "null.h" 27 | 28 | namespace mysqlpp { 29 | /// \brief "NULL" string constant used in many places within MySQL++ 30 | const std::string null_str("NULL"); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /lib/qparms.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | qparms.cpp - Implements the SQLQueryParms class. 3 | 4 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by 5 | MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the CREDITS 7 | file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include "qparms.h" 28 | 29 | #include "query.h" 30 | 31 | using namespace std; 32 | 33 | namespace mysqlpp { 34 | 35 | size_t 36 | SQLQueryParms::escape_string(std::string* ps, const char* original, 37 | size_t length) const 38 | { 39 | return parent_ ? parent_->escape_string(ps, original, length) : 0; 40 | } 41 | 42 | size_t 43 | SQLQueryParms::escape_string(char* escaped, const char* original, 44 | size_t length) const 45 | { 46 | return parent_ ? parent_->escape_string(escaped, original, length) : 0; 47 | } 48 | 49 | SQLTypeAdapter& 50 | SQLQueryParms::operator [](const char* str) 51 | { 52 | if (parent_) { 53 | return operator [](parent_->parsed_nums_[str]); 54 | } 55 | throw ObjectNotInitialized("SQLQueryParms object has no parent!"); 56 | } 57 | 58 | const SQLTypeAdapter& 59 | SQLQueryParms::operator[] (const char* str) const 60 | { 61 | if (parent_) { 62 | return operator [](parent_->parsed_nums_[str]); 63 | } 64 | throw ObjectNotInitialized("SQLQueryParms object has no parent!"); 65 | } 66 | 67 | SQLQueryParms 68 | SQLQueryParms::operator +(const SQLQueryParms& other) const 69 | { 70 | if (other.size() <= size()) { 71 | return *this; 72 | } 73 | SQLQueryParms New = *this; 74 | size_t i; 75 | for (i = size(); i < other.size(); i++) { 76 | New.push_back(other[i]); 77 | } 78 | 79 | return New; 80 | } 81 | 82 | 83 | } // end namespace mysqlpp 84 | -------------------------------------------------------------------------------- /lib/querydef.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | ######################################################################## 4 | # querydef.pl - Generates querydef.h, which defines a number of macros 5 | # used in query.h that differ only in the number of arguments. That 6 | # number limits the number of parameters a MySQL++ template query can 7 | # accept. This value can be changed from its default, below. 8 | # 9 | # Copyright (c) 2006-2010 by Educational Technology Resources, Inc. 10 | # Others may also hold copyrights on code in this file. See the CREDITS 11 | # file in the top directory of the distribution for details. 12 | # 13 | # This file is part of MySQL++. 14 | # 15 | # MySQL++ is free software; you can redistribute it and/or modify it 16 | # under the terms of the GNU Lesser General Public License as published 17 | # by the Free Software Foundation; either version 2.1 of the License, or 18 | # (at your option) any later version. 19 | # 20 | # MySQL++ is distributed in the hope that it will be useful, but WITHOUT 21 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | # License for more details. 24 | # 25 | # You should have received a copy of the GNU Lesser General Public 26 | # License along with MySQL++; if not, write to the Free Software 27 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 28 | # USA 29 | ######################################################################## 30 | 31 | 32 | # The number of parameters a template query can accept. Make this value 33 | # larger only at need, as it adds code to the library proportionally. 34 | # You should not reduce this value if programs you did not write may 35 | # link to the library, as that would constitute an ABI breakage. 36 | my $max_parameters = 25; 37 | 38 | 39 | # No user-serviceable parts below. 40 | 41 | use strict; 42 | use Getopt::Std; 43 | 44 | our $opt_f; 45 | getopts('f:') or die "usage: $0 [-f fields]\n\n"; 46 | $max_parameters = int($opt_f) if defined $opt_f; 47 | 48 | open (OUT, ">querydef.h"); 49 | 50 | print OUT << "---"; 51 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 52 | // This file is generated by the Perl script querydef.pl. Please do 53 | // not modify this file directly. Change the script instead. 54 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 55 | 56 | #ifndef MYSQLPP_QUERYDEF_H 57 | #define MYSQLPP_QUERYDEF_H 58 | 59 | #define MYSQLPP_TQUERY_MAX_PARAMETERS $max_parameters 60 | 61 | --- 62 | 63 | ## Build mysql_query_define0 macro 64 | print OUT "#define mysql_query_define0(RETURN, FUNC) \\\n"; 65 | for (my $i = 1; $i < $max_parameters; ++$i) { 66 | print OUT "\tRETURN FUNC("; 67 | for (my $j = 0; $j < $i + 1; ++$j) { 68 | print OUT 'const SQLTypeAdapter& arg', $j; 69 | print OUT ', ' unless $j == $i; 70 | } 71 | print OUT ") \\\n"; 72 | 73 | print OUT "\t\t{ return FUNC(SQLQueryParms()"; 74 | for (my $j = 0; $j < $i + 1; ++$j) { 75 | print OUT ' << arg', $j; 76 | } 77 | print OUT "); } \\\n"; 78 | } 79 | print OUT "\n"; 80 | 81 | ## Add mysql_query_define1 macro 82 | print OUT "#define mysql_query_define1(FUNC) \\\n"; 83 | for (my $i = 1; $i < $max_parameters; ++$i) { 84 | print OUT "\ttemplate void FUNC(T& container"; 85 | for (my $j = 0; $j < $i + 1; ++$j) { 86 | print OUT ', const SQLTypeAdapter& arg', $j; 87 | } 88 | print OUT ") \\\n"; 89 | print OUT "\t\t{ FUNC(container, SQLQueryParms()"; 90 | for (my $j = 0; $j < $i + 1; ++$j) { 91 | print OUT ' << arg', $j; 92 | } 93 | print OUT "); } \\\n"; 94 | } 95 | print OUT "\n"; 96 | 97 | ## That's all, folks! 98 | print OUT "#endif // !defined(MYSQLPP_QUERYDEF_H)\n"; 99 | 100 | -------------------------------------------------------------------------------- /lib/scopedconnection.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | scopedconnection.cpp - Implements the ScopedConnection class. 3 | 4 | Copyright (c) 2010 by Switchplane, Ltd. Others may also hold 5 | copyrights on code in this file. See the CREDITS.txt file in the 6 | top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include "scopedconnection.h" 27 | 28 | #include "cpool.h" 29 | 30 | namespace mysqlpp { 31 | 32 | ScopedConnection::ScopedConnection(ConnectionPool& pool, bool safe) : 33 | pool_(pool), 34 | connection_(safe ? pool.safe_grab() : pool.grab()) 35 | { 36 | } 37 | 38 | ScopedConnection::~ScopedConnection() 39 | { 40 | pool_.release(connection_); 41 | } 42 | 43 | } // end namespace mysqlpp 44 | -------------------------------------------------------------------------------- /lib/scopedconnection.h: -------------------------------------------------------------------------------- 1 | /// \file scopedconnection.h 2 | /// \brief Declares the ScopedConnection class. 3 | /// 4 | /// This class lets you grab a connection from a ConnectionPool in a 5 | /// scoped and therefore RAII way. The Connection object will always be 6 | /// returned to the pool when the scope block ends, plugging a potential 7 | /// leak in the pool. 8 | 9 | /*********************************************************************** 10 | Copyright © 2010 by Joel Fielder. Others may also hold copyrights 11 | on code in this file. See the CREDITS.txt file in the top directory 12 | of the distribution for details. 13 | 14 | This file is part of MySQL++. 15 | 16 | MySQL++ is free software; you can redistribute it and/or modify it 17 | under the terms of the GNU Lesser General Public License as published 18 | by the Free Software Foundation; either version 2.1 of the License, or 19 | (at your option) any later version. 20 | 21 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | License for more details. 25 | 26 | You should have received a copy of the GNU Lesser General Public 27 | License along with MySQL++; if not, write to the Free Software 28 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 29 | USA 30 | ***********************************************************************/ 31 | 32 | #if !defined(MYSQLPP_SCOPEDCONNECTION_H) 33 | #define MYSQLPP_SCOPEDCONNECTION_H 34 | 35 | #include "common.h" 36 | 37 | namespace mysqlpp { 38 | 39 | #if !defined(DOXYGEN_IGNORE) 40 | // Make Doxygen ignore this 41 | class MYSQLPP_EXPORT Connection; 42 | class MYSQLPP_EXPORT ConnectionPool; 43 | #endif 44 | 45 | /// \brief Grabs a Connection from a ConnectionPool on construction 46 | /// and releases it back to the pool on destruction, and provides access 47 | /// to the relevant Connection pointer. 48 | class MYSQLPP_EXPORT ScopedConnection 49 | { 50 | public: 51 | /// \brief Standard constructor 52 | /// 53 | /// Grabs a Connection from the specified pool. 54 | /// 55 | /// \internal Note that there is no default ctor on purpose. RAII. 56 | /// 57 | /// \param pool The ConnectionPool to use. 58 | /// \param safe By default, we get the connection from the pool with 59 | /// ConnectionPool::grab(), but we can call safe_grab() instead. 60 | explicit ScopedConnection(ConnectionPool& pool, bool safe = false); 61 | 62 | #if __cplusplus >= 201103L 63 | // ScopedConnection objects cannot be copied. We want them to be 64 | // tightly scoped to their use point, not put in containers or 65 | // passed around promiscuously. 66 | ScopedConnection(ScopedConnection&&) = default; 67 | ScopedConnection(const ScopedConnection& no_copies) = delete; 68 | const ScopedConnection& operator=(const ScopedConnection& no_copies) = delete; 69 | #endif 70 | 71 | /// \brief Destructor 72 | /// 73 | /// Releases the Connection back to the ConnectionPool. 74 | ~ScopedConnection(); 75 | 76 | /// \brief Access the Connection pointer 77 | Connection* operator->() const { return connection_; } 78 | 79 | /// \brief Dereference 80 | Connection& operator*() const { return *connection_; } 81 | 82 | /// \brief Truthiness operator 83 | operator void*() const { return connection_; } 84 | 85 | private: 86 | #if __cplusplus < 201103L 87 | // Pre C++11 alternative to no-copies ctors above. 88 | ScopedConnection(const ScopedConnection& no_copies); 89 | const ScopedConnection& operator=(const ScopedConnection& no_copies); 90 | #endif 91 | 92 | ConnectionPool& pool_; 93 | Connection* const connection_; 94 | }; 95 | 96 | } // end namespace mysqlpp 97 | 98 | #endif // !defined(MYSQLPP_SCOPEDCONNECTION_H) 99 | 100 | -------------------------------------------------------------------------------- /lib/sql_buffer.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | sql_buffer.cpp - Implements the SQLBuffer class. 3 | 4 | Copyright (c) 2007-2008 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include "sql_buffer.h" 27 | 28 | #include "datetime.h" 29 | #include "sql_types.h" 30 | 31 | #include 32 | 33 | namespace mysqlpp { 34 | 35 | 36 | SQLBuffer& 37 | SQLBuffer::assign(const char* data, size_type length, mysql_type_info type, 38 | bool is_null) 39 | { 40 | replace_buffer(data, length); 41 | type_ = type; 42 | is_null_ = is_null; 43 | return *this; 44 | } 45 | 46 | SQLBuffer& 47 | SQLBuffer::assign(const std::string& s, mysql_type_info type, bool is_null) 48 | { 49 | replace_buffer(s.data(), s.length()); 50 | type_ = type; 51 | is_null_ = is_null; 52 | return *this; 53 | } 54 | 55 | bool 56 | SQLBuffer::quote_q() const 57 | { 58 | if ((type_.base_type().c_type() == typeid(mysqlpp::sql_datetime)) && 59 | data_ && (length_ >= 5) && (memcmp(data_, "NOW()", 5) == 0)) { 60 | // The default DATETIME value is special-cased as a call to the 61 | // SQL NOW() function, which must not be quoted. 62 | return false; 63 | } 64 | else { 65 | // Normal case: we can infer the need to quote from the type. 66 | return type_.quote_q(); 67 | } 68 | } 69 | 70 | void 71 | SQLBuffer::replace_buffer(const char* pd, size_type length) 72 | { 73 | delete[] data_; 74 | data_ = 0; 75 | length_ = 0; 76 | 77 | if (pd) { 78 | // The casts for the data member are because the C type system 79 | // can't distinguish initialization from modification when it 80 | // happens in 2 steps like this. 81 | // 82 | // We cast away const for pd in case we're on a system that uses 83 | // the old definition of memcpy() with non-const 2nd parameter. 84 | data_ = new char[length + 1]; 85 | length_ = length; 86 | memcpy(const_cast(data_), const_cast(pd), length_); 87 | const_cast(data_)[length_] = '\0'; 88 | } 89 | } 90 | 91 | } // end namespace mysqlpp 92 | 93 | -------------------------------------------------------------------------------- /lib/sqlstream.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | sqlstream.cpp - Implements the SQLStream class. 3 | 4 | Copyright (c) 2008 by AboveNet, Inc. Others may also hold copyrights 5 | on code in this file. See the CREDITS file in the top directory of 6 | the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include "sqlstream.h" 27 | 28 | #include "dbdriver.h" 29 | #include "connection.h" 30 | 31 | #include 32 | 33 | namespace mysqlpp { 34 | 35 | SQLStream::SQLStream(Connection* c, const char* pstr) : 36 | std::ostringstream(), 37 | conn_(c) 38 | { 39 | if (pstr != 0) { 40 | str(pstr); 41 | } 42 | } 43 | 44 | 45 | SQLStream::SQLStream(const SQLStream& s) : 46 | std::ostringstream(s.str()), 47 | conn_(s.conn_) 48 | { 49 | } 50 | 51 | 52 | size_t 53 | SQLStream::escape_string(std::string* ps, const char* original, 54 | size_t length) const 55 | { 56 | if (conn_ && *conn_) { 57 | // Normal case 58 | return conn_->driver()->escape_string(ps, original, length); 59 | } 60 | else { 61 | // Should only happen in test/test_manip.cpp, since it doesn't 62 | // want to open a DB connection just to test the manipulators. 63 | return DBDriver::escape_string_no_conn(ps, original, length); 64 | } 65 | } 66 | 67 | 68 | size_t 69 | SQLStream::escape_string(char* escaped, const char* original, 70 | size_t length) const 71 | { 72 | if (conn_ && *conn_) { 73 | // Normal case 74 | return conn_->driver()->escape_string(escaped, original, length); 75 | } 76 | else { 77 | // Should only happen in test/test_manip.cpp, since it doesn't 78 | // want to open a DB connection just to test the manipulators. 79 | return DBDriver::escape_string_no_conn(escaped, original, length); 80 | } 81 | } 82 | 83 | 84 | SQLStream& 85 | SQLStream::operator=(const SQLStream& rhs) 86 | { 87 | conn_ = rhs.conn_; 88 | str(rhs.str()); 89 | 90 | return *this; 91 | } 92 | 93 | 94 | } // end namespace mysqlpp 95 | 96 | -------------------------------------------------------------------------------- /lib/ssqls2.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssqls2.cpp - Implements the SsqlsBase class. 3 | 4 | Copyright (c) 2009 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #define MYSQLPP_NOT_HEADER 27 | #include "ssqls2.h" 28 | 29 | #include "connection.h" 30 | #include "exceptions.h" 31 | #include "query.h" 32 | 33 | using namespace std; 34 | 35 | // All of the Active Record calls below follow a common pattern, which 36 | // we can only express as a macro. They just wrap similar calls in 37 | // Query, varying only in minor per-call specific details. 38 | #define QUERY_ACTIVE_RECORD_WRAPPER(action, conn, fs) \ 39 | if (conn) conn_ = conn; \ 40 | if (conn_) { \ 41 | if (conn_->connected()) { \ 42 | if (populated(fs)) return conn_->query().action(*this).execute(); \ 43 | else if (conn_->throw_exceptions()) throw BadQuery( \ 44 | "Cannot " #action " insufficiently populated SSQLS"); \ 45 | else return false; \ 46 | } \ 47 | else if (conn_->throw_exceptions()) throw ConnectionFailed( \ 48 | "Cannot " #action " SSQLS without established connection"); \ 49 | else return false; \ 50 | } \ 51 | else throw ObjectNotInitialized(typeid(*this).name()); 52 | 53 | namespace mysqlpp { 54 | 55 | bool 56 | SsqlsBase::create(Connection* conn) const 57 | { 58 | (void)conn; 59 | //TODO define Query::insert(SsqlsBase&) 60 | //QUERY_ACTIVE_RECORD_WRAPPER(insert, conn, fs_not_autoinc); 61 | return false; 62 | } 63 | 64 | bool 65 | SsqlsBase::load(Connection* conn) const 66 | { 67 | (void)conn; 68 | //TODO define Query::select(SsqlsBase&) 69 | //QUERY_ACTIVE_RECORD_WRAPPER(select, conn, fs_key); 70 | return false; 71 | } 72 | 73 | bool 74 | SsqlsBase::remove(Connection* conn) const 75 | { 76 | (void)conn; 77 | //TODO define Query::remove(SsqlsBase&) 78 | //QUERY_ACTIVE_RECORD_WRAPPER(remove, conn, fs_key); 79 | return false; 80 | } 81 | 82 | bool 83 | SsqlsBase::save(Connection* conn) const 84 | { 85 | (void)conn; 86 | //TODO define Query::update(SsqlsBase&) 87 | //QUERY_ACTIVE_RECORD_WRAPPER(update, conn, fs_all); 88 | return false; 89 | } 90 | 91 | } // end namespace mysqlpp 92 | 93 | -------------------------------------------------------------------------------- /lib/stream2string.h: -------------------------------------------------------------------------------- 1 | /// \file stream2string.h 2 | /// \brief Declares an adapter that converts something that can be 3 | /// inserted into a C++ stream into a std::string type. 4 | 5 | /*********************************************************************** 6 | Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and 7 | (c) 2004-2007 by Educational Technology Resources, Inc. Others may 8 | also hold copyrights on code in this file. See the CREDITS.txt file 9 | in the top directory of the distribution for details. 10 | 11 | This file is part of MySQL++. 12 | 13 | MySQL++ is free software; you can redistribute it and/or modify it 14 | under the terms of the GNU Lesser General Public License as published 15 | by the Free Software Foundation; either version 2.1 of the License, or 16 | (at your option) any later version. 17 | 18 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 19 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 | License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with MySQL++; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | USA 27 | ***********************************************************************/ 28 | 29 | #if !defined(MYSQLPP_STREAM2STRING_H) 30 | #define MYSQLPP_STREAM2STRING_H 31 | 32 | #include 33 | #include 34 | 35 | namespace mysqlpp { 36 | 37 | /// \brief Converts anything you can insert into a C++ stream to a 38 | /// \c std::string via \c std::ostringstream. 39 | 40 | template 41 | std::string stream2string(const T& object) 42 | { 43 | std::ostringstream str; 44 | str << object; 45 | return str.str(); 46 | } 47 | 48 | } // end namespace mysqlpp 49 | 50 | #endif // !defined(MYSQLPP_STREAM2STRING_H) 51 | 52 | -------------------------------------------------------------------------------- /lib/uds_connection.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | uds_connection.cpp - Implements the UnixDomainSocketConnection class. 3 | 4 | Copyright (c) 2007-2008 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #define MYSQLPP_NOT_HEADER 27 | #include "common.h" 28 | #include "uds_connection.h" 29 | 30 | #include "exceptions.h" 31 | 32 | #if !defined(MYSQLPP_PLATFORM_WINDOWS) 33 | # include 34 | # include 35 | #endif 36 | 37 | using namespace std; 38 | 39 | namespace mysqlpp { 40 | 41 | static const char* common_complaint = 42 | "UnixDomainSocketConnection only works on POSIX systems"; 43 | 44 | bool 45 | UnixDomainSocketConnection::connect(const char* path, 46 | const char* db, const char* user, const char* pass) 47 | { 48 | #if !defined(MYSQLPP_PLATFORM_WINDOWS) 49 | if (is_socket(path, &error_message_)) { 50 | return Connection::connect(db, path, user, pass); 51 | } 52 | (void)common_complaint; 53 | #else 54 | error_message_ = common_complaint; 55 | #endif 56 | 57 | if (throw_exceptions()) { 58 | throw ConnectionFailed(error_message_.c_str()); 59 | } 60 | else { 61 | return false; 62 | } 63 | } 64 | 65 | 66 | bool 67 | UnixDomainSocketConnection::is_socket(const char* path, std::string* error) 68 | { 69 | #if !defined(MYSQLPP_PLATFORM_WINDOWS) 70 | if (path) { 71 | struct stat fi; 72 | 73 | if (access(path, F_OK) != 0) { 74 | if (error) { 75 | *error = path; 76 | *error += " does not exist"; 77 | } 78 | } 79 | else if (access(path, R_OK | W_OK) != 0) { 80 | if (error) { 81 | *error = "Don't have read-write permission for "; 82 | *error += path; 83 | } 84 | } 85 | else if (stat(path, &fi) != 0) { 86 | if (error) { 87 | *error = "Failed to get information for "; 88 | *error += path; 89 | } 90 | } 91 | else if (!S_ISSOCK(fi.st_mode)) { 92 | if (error) { 93 | *error = path; 94 | *error += " is not a Unix domain socket"; 95 | } 96 | } 97 | else { 98 | // It's a socket, and we have permission to use it 99 | if (error) { 100 | error->clear(); 101 | } 102 | return true; 103 | } 104 | } 105 | else 106 | #endif 107 | if (error) { 108 | #if !defined(MYSQLPP_PLATFORM_WINDOWS) 109 | *error = "NULL is not a valid Unix domain socket"; 110 | #else 111 | *error = common_complaint; 112 | #endif 113 | } 114 | 115 | return false; 116 | } 117 | 118 | 119 | } // end namespace mysqlpp 120 | 121 | -------------------------------------------------------------------------------- /lib/utility.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | utility.cpp - Implements utility functions used within the library. 3 | 4 | Copyright (c) 2009 by Warren Young. Others may also hold copyrights 5 | on code in this file. See the CREDITS file in the top directory of 6 | the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include "utility.h" 27 | 28 | namespace mysqlpp { 29 | namespace internal { 30 | void str_to_lwr(std::string& s) 31 | { 32 | std::string::iterator it; 33 | for (it = s.begin(); it != s.end(); ++it) { 34 | *it = tolower(*it); 35 | } 36 | } 37 | 38 | void str_to_lwr(std::string& ls, const char* mcs) 39 | { 40 | ls.reserve(strlen(mcs)); 41 | while (mcs && *mcs) { 42 | ls += tolower(*mcs++); 43 | } 44 | } 45 | } // end namespace internal 46 | } // end namespace mysqlpp 47 | 48 | -------------------------------------------------------------------------------- /lib/utility.h: -------------------------------------------------------------------------------- 1 | /// \file utility.h 2 | /// \brief Declares utility functions used within MySQL++ 3 | /// 4 | /// None of this is meant to be used outside the library itself. None 5 | /// of this is considered part of the library interface. It is subject 6 | /// to change at any time, with no notice. 7 | 8 | /*********************************************************************** 9 | Copyright (c) 2009 by Warren Young. Others may also hold copyrights 10 | on code in this file. See the CREDITS.txt file in the top directory 11 | of the distribution for details. 12 | 13 | This file is part of MySQL++. 14 | 15 | MySQL++ is free software; you can redistribute it and/or modify it 16 | under the terms of the GNU Lesser General Public License as published 17 | by the Free Software Foundation; either version 2.1 of the License, or 18 | (at your option) any later version. 19 | 20 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 21 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with MySQL++; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 28 | USA 29 | ***********************************************************************/ 30 | 31 | #if !defined(MYSQLPP_UTILITY_H) 32 | #define MYSQLPP_UTILITY_H 33 | 34 | #include "common.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace mysqlpp { 41 | /// \brief Namespace for holding things used only within MySQL++ 42 | namespace internal { 43 | /// \brief Lowercase a C++ string in place 44 | void MYSQLPP_EXPORT str_to_lwr(std::string& s); 45 | 46 | /// \brief Copy a C string into a C++ string, lowercasing 47 | /// it along the way 48 | void MYSQLPP_EXPORT str_to_lwr(std::string& ls, const char* mcs); 49 | } // end namespace mysqlpp::internal 50 | } // end namespace mysqlpp 51 | 52 | #endif // !defined(MYSQLPP_UTILITY_H) 53 | -------------------------------------------------------------------------------- /lib/wnp_connection.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | wnp_connection.cpp - Implements the WindowsNamedPipeConnection class. 3 | 4 | Copyright (c) 2007-2008 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #define MYSQLPP_NOT_HEADER 27 | #include "common.h" 28 | #include "wnp_connection.h" 29 | 30 | #include "exceptions.h" 31 | 32 | using namespace std; 33 | 34 | namespace mysqlpp { 35 | 36 | static const char* common_complaint = 37 | "WindowsNamedPipeConnection only works on Windows"; 38 | 39 | 40 | bool 41 | WindowsNamedPipeConnection::connect(const char* db, const char* user, 42 | const char* pass) 43 | { 44 | #if defined(MYSQLPP_PLATFORM_WINDOWS) 45 | return Connection::connect(db, ".", user, pass); 46 | #else 47 | (void)db; 48 | (void)user; 49 | (void)pass; 50 | error_message_ = common_complaint; 51 | if (throw_exceptions()) { 52 | throw ConnectionFailed(error_message_.c_str()); 53 | } 54 | else { 55 | return false; 56 | } 57 | #endif 58 | } 59 | 60 | 61 | bool 62 | WindowsNamedPipeConnection::is_wnp(const char* server) 63 | { 64 | #if defined(MYSQLPP_PLATFORM_WINDOWS) 65 | return server && (strcmp(server, ".") == 0); 66 | #else 67 | (void)server; 68 | return false; 69 | #endif 70 | } 71 | 72 | } // end namespace mysqlpp 73 | 74 | -------------------------------------------------------------------------------- /mysql++.ebuild: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2008 Gentoo Foundation 2 | # Distributed under the terms of the GNU General Public License v2 3 | # $Header: /var/cvsroot/gentoo-x86/dev-db/mysql++/mysql++-2.3.2.ebuild,v 1.3 2008/04/21 03:00:49 dirtyepic Exp $ 4 | 5 | inherit eutils 6 | 7 | DESCRIPTION="C++ API interface to the MySQL database" 8 | HOMEPAGE="http://tangentsoft.net/mysql++/" 9 | SRC_URI="http://www.tangentsoft.net/mysql++/releases/${P}.tar.gz" 10 | 11 | LICENSE="LGPL-2" 12 | SLOT="0" 13 | KEYWORDS="~alpha ~amd64 ~hppa ~mips ~ppc ~sparc ~x86" 14 | IUSE="" 15 | 16 | DEPEND=">=sys-devel/gcc-3" 17 | RDEPEND="${DEPEND} 18 | >=virtual/mysql-4.0" 19 | 20 | src_unpack() { 21 | unpack ${A} 22 | cd "${S}" 23 | 24 | epatch "${FILESDIR}"/${P}-gcc-4.3.patch 25 | 26 | for i in "${S}"/lib/*.h ; do 27 | sed -i \ 28 | -e '/#include /dev/null 2>&1 3 | then 4 | echo -n rh 5 | grep Red /etc/issue |cut -f5 -d' ' 6 | elif grep Fedora /etc/issue > /dev/null 2>&1 7 | then 8 | echo -n fc 9 | grep Fedora /etc/issue |cut -f4 -d' ' 10 | elif grep CentOS /etc/issue > /dev/null 2>&1 11 | then 12 | echo -n el 13 | grep CentOS /etc/issue |cut -f3 -d' ' |cut -f1 -d. 14 | else 15 | echo UNKNOWN 16 | fi 17 | -------------------------------------------------------------------------------- /rebake.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | bakefile_gen %* 3 | -------------------------------------------------------------------------------- /ssx/genv2.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssx/genv2.cpp - Walks the SSQLS v2 parse result, writing back out 3 | the equivalent SSQLS v2 DSL code. This is useful for testing that 4 | our parser has correctly understood a given piece of code. It is 5 | also something like the preprocessor mode of a C++ compiler, 6 | emitting a digested version of its input. 7 | 8 | Copyright (c) 2009 by Warren Young and (c) 2009-2010 by Educational 9 | Technology Resources, Inc. Others may also hold copyrights on code 10 | in this file. See the CREDITS.txt file in the top directory of the 11 | distribution for details. 12 | 13 | This file is part of MySQL++. 14 | 15 | MySQL++ is free software; you can redistribute it and/or modify it 16 | under the terms of the GNU Lesser General Public License as published 17 | by the Free Software Foundation; either version 2.1 of the License, or 18 | (at your option) any later version. 19 | 20 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 21 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 23 | License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with MySQL++; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 28 | USA 29 | ***********************************************************************/ 30 | 31 | #include "genv2.h" 32 | 33 | #include "parsev2.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | using namespace std; 41 | 42 | //// generate_ssqls2 /////////////////////////////////////////////////// 43 | // 2 versions: second checks its arguments and opens the named file, 44 | // calling the second to actually generate the SSQLS v2 output from 45 | // the parse result only if we were given sane parameters. 46 | 47 | static bool 48 | generate_ssqls2(ostream& os, const ParseV2* pparse) 49 | { 50 | ParseV2::LineListIt it; 51 | for (it = pparse->begin(); it != pparse->end(); ++it) { 52 | if (dynamic_cast(*it)) { 53 | // 'field' directives must be indented under the preceding 54 | // 'table'. We don't want to hard-code this in 55 | // ParseV2::Field::print() in case we later start calling 56 | // those routines for other reasons, such as to construct 57 | // error messages. It's really a special case of -o, not 58 | // really something that print() routine should know. 59 | os << '\t'; 60 | } 61 | os << **it << endl; 62 | } 63 | 64 | return true; 65 | } 66 | 67 | bool 68 | generate_ssqls2(const char* file_name, const ParseV2* pparse) 69 | { 70 | if (pparse) { 71 | if (strcmp(file_name, "-") == 0) { 72 | return generate_ssqls2(cout, pparse); 73 | } 74 | else { 75 | ofstream ofs(file_name); 76 | if (ofs) { 77 | cout << "TRACE: Generating SSQLS v2 file " << file_name << 78 | " from " << (pparse->end() - pparse->begin()) << 79 | " line parse result." << endl; 80 | return generate_ssqls2(ofs, pparse); 81 | } 82 | else { 83 | cerr << "Failed to open " << file_name << \ 84 | " for writing for -o!" << endl; 85 | return false; 86 | } 87 | } 88 | } 89 | else { 90 | cerr << "No parse result given to -o handler!" << endl; 91 | return false; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /ssx/genv2.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ssx/genv2.h - Mechanism for generating SSQLS v2 DSL code from 3 | an SSQLS v2 parse result. Implements ssqlsxlat -o flag. 4 | 5 | Copyright (c) 2009 by Warren Young. Others may also hold copyrights 6 | on code in this file. See the CREDITS.txt file in the top directory 7 | of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #if !defined(MYSQLPP_SSX_GENV2_H) 28 | #define MYSQLPP_SSX_GENV2_H 29 | 30 | class ParseV2; 31 | extern bool generate_ssqls2(const char* file_name, const ParseV2* pparse); 32 | 33 | #endif // !defined(MYSQLPP_SSX_GENV2_H) 34 | -------------------------------------------------------------------------------- /static/logo-large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangentsoft/mysqlpp/f40d94c4eddbad5ff319d8886bcf68dbf14528cf/static/logo-large.jpg -------------------------------------------------------------------------------- /static/logo-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangentsoft/mysqlpp/f40d94c4eddbad5ff319d8886bcf68dbf14528cf/static/logo-small.jpg -------------------------------------------------------------------------------- /test/cpool.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/cpool.cpp - Tests the ConnectionPool class. 3 | 4 | Copyright (c) 2007-2008 by Educational Technology Resources, Inc. and 5 | (c) 2007 by Jonathan Wakely. Others may also hold copyrights on 6 | code in this file. See the CREDITS.txt file in the top directory of 7 | the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #if defined(MYSQLPP_PLATFORM_WINDOWS) 33 | # define SLEEP(n) Sleep((n) * 1000) 34 | #else 35 | # include 36 | # define SLEEP(n) sleep(n) 37 | #endif 38 | 39 | using namespace std; 40 | 41 | class TestConnection : public mysqlpp::Connection 42 | { 43 | public: 44 | TestConnection() : itime_(time(0)) { } 45 | time_t instantiation_time() const { return itime_; } 46 | 47 | private: 48 | time_t itime_; 49 | }; 50 | 51 | 52 | class TestConnectionPool : public mysqlpp::ConnectionPool 53 | { 54 | public: 55 | ~TestConnectionPool() { clear(); } 56 | 57 | unsigned int max_idle_time() { return 1; } 58 | 59 | private: 60 | TestConnection* create() { return new TestConnection; } 61 | void destroy(mysqlpp::Connection* cp) { delete cp; } 62 | }; 63 | 64 | 65 | int 66 | main() 67 | { 68 | TestConnectionPool pool; 69 | 70 | mysqlpp::Connection* conn1 = pool.grab(); 71 | mysqlpp::Connection* conn2 = pool.grab(); 72 | if (conn1 == conn2) { 73 | cerr << "Pool returned the same connection twice!" << endl; 74 | return 1; 75 | } 76 | 77 | pool.release(conn2); 78 | mysqlpp::Connection* conn3 = pool.grab(); 79 | if (conn2 != conn3) { 80 | cerr << "conn2 should have been reused but wasn't!" << endl; 81 | return 1; 82 | } 83 | 84 | time_t itime_c1 = dynamic_cast(conn1)-> 85 | instantiation_time(); 86 | pool.release(conn1); 87 | SLEEP(pool.max_idle_time() + 1); 88 | mysqlpp::Connection* conn4 = pool.grab(); 89 | time_t itime_c4 = dynamic_cast(conn4)-> 90 | instantiation_time(); 91 | if (itime_c1 == itime_c4) { 92 | cerr << "conn1 should have been destroyed but wasn't!" << endl; 93 | return 1; 94 | } 95 | 96 | pool.release(conn3); 97 | pool.release(conn4); 98 | pool.shrink(); 99 | if (!pool.empty()) { 100 | cerr << "Shrunken pool is not empty!" << endl; 101 | return 1; 102 | } 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /test/insertpolicy.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/insertpolicy.cpp - Checks that the *InsertPolicy objects work 3 | as expected. 4 | 5 | Copyright (c) 2009 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the 7 | CREDITS.txt file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | static const unsigned char nonzero = 4; 33 | 34 | 35 | template 36 | static bool 37 | test_policy(InsertPolicy& ip, unsigned char max, bool expected_to_fail) 38 | { 39 | unsigned char i; 40 | mysqlpp::Row dummy; 41 | for (i = 0; i < UCHAR_MAX; ++i) { 42 | if (!ip.can_add(i, dummy)) { 43 | break; 44 | } 45 | } 46 | 47 | if (expected_to_fail ? i != max : i == max) { 48 | return true; 49 | } 50 | else { 51 | std::cerr << typeid(ip).name() << '(' << int(max) << 52 | ") allowed " << int(i) << " inserts!" << std::endl; 53 | return false; 54 | } 55 | } 56 | 57 | 58 | template 59 | static bool 60 | test_policy(InsertPolicy& ip, unsigned char expected_allow_count) 61 | { 62 | return test_policy(ip, expected_allow_count, false) && 63 | test_policy(ip, expected_allow_count + 1, true) && 64 | test_policy(ip, expected_allow_count - 1, true) && 65 | test_policy(ip, expected_allow_count ? 0 : nonzero, true); 66 | } 67 | 68 | 69 | static bool 70 | test_row_count_nonzero() 71 | { 72 | mysqlpp::Query::RowCountInsertPolicy<> ip_nonzero(nonzero); 73 | return test_policy(ip_nonzero, nonzero); 74 | } 75 | 76 | 77 | static bool 78 | test_row_count_zero() 79 | { 80 | mysqlpp::Query::RowCountInsertPolicy<> ip_zero(0); 81 | return test_policy(ip_zero, 0); 82 | } 83 | 84 | 85 | static bool 86 | test_row_count() 87 | { 88 | return test_row_count_nonzero() && 89 | test_row_count_zero(); 90 | } 91 | 92 | 93 | int 94 | main() 95 | { 96 | try { 97 | return test_row_count() ? 0 : 1; 98 | } 99 | catch (...) { 100 | std::cerr << "Unhandled exception caught by " 101 | "test/insertpolicy!" << std::endl; 102 | return 2; 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /test/inttypes.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/inttypes.cpp - Tests whether the integer typedef equivalents for 3 | SQL types in lib/sql_types.h are correct on this system. If not, 4 | you need to change either that file, lib/common.h, or both. 5 | 6 | Copyright (c) 2008 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the 8 | CREDITS.txt file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include 29 | 30 | #include 31 | 32 | template 33 | static bool 34 | test_size(const char* desc, IntType value, size_t expected_size) 35 | { 36 | size_t actual_size = sizeof(value); 37 | if (actual_size == expected_size) { 38 | return true; 39 | } 40 | else { 41 | std::cerr << desc << " is sized incorrectly on this " 42 | "platform:" << std::endl << "\t" << actual_size << 43 | " bytes, not " << expected_size << " as expected." << 44 | std::endl; 45 | return false; 46 | } 47 | } 48 | 49 | 50 | int 51 | main() 52 | { 53 | int failures = 0; 54 | 55 | failures += test_size("sql_tinyint", 56 | mysqlpp::sql_tinyint(0), 1) == false; 57 | failures += test_size("sql_tinyint_unsigned", 58 | mysqlpp::sql_tinyint_unsigned(0), 1) == false; 59 | failures += test_size("sql_smallint", 60 | mysqlpp::sql_smallint(0), 2) == false; 61 | failures += test_size("sql_smallint_unsigned", 62 | mysqlpp::sql_smallint_unsigned(0), 2) == false; 63 | failures += test_size("sql_mediumint", 64 | mysqlpp::sql_mediumint(0), 4) == false; 65 | failures += test_size("sql_mediumint_unsigned", 66 | mysqlpp::sql_mediumint_unsigned(0), 4) == false; 67 | failures += test_size("sql_int", 68 | mysqlpp::sql_int(0), 4) == false; 69 | failures += test_size("sql_int_unsigned", 70 | mysqlpp::sql_int_unsigned(0), 4) == false; 71 | failures += test_size("sql_bigint", 72 | mysqlpp::sql_bigint(0), 8) == false; 73 | failures += test_size("sql_bigint_unsigned", 74 | mysqlpp::sql_bigint_unsigned(0), 8) == false; 75 | 76 | return failures; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /test/null_comparison.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/null_comparison.cpp - Tests that Null and null_type comparison 3 | operators and SSQLS comparison functions work correctly. 4 | 5 | Copyright (c) 2008-2009 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the 7 | CREDITS.txt file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | #define MYSQLPP_ALLOW_SSQLS_V1 // suppress deprecation warning 29 | #include 30 | 31 | #include 32 | 33 | sql_create_1(ssqls, 1, 0, mysqlpp::Null, a_column) 34 | 35 | int 36 | main() 37 | { 38 | mysqlpp::Null null_int = mysqlpp::null; 39 | mysqlpp::Null non_null_int = 42; 40 | if ( !(null_int == non_null_int) && 41 | (null_int != non_null_int) && 42 | (null_int < non_null_int) && 43 | !(non_null_int == null_int) && 44 | (non_null_int != null_int) && 45 | !(non_null_int < null_int) && 46 | (null_int == mysqlpp::null) && 47 | !(null_int != mysqlpp::null) && 48 | (non_null_int != mysqlpp::null) && 49 | !(non_null_int == mysqlpp::null) && 50 | (mysqlpp::sql_cmp(null_int, null_int) == 0) && 51 | (mysqlpp::sql_cmp(null_int, non_null_int) < 0) && 52 | (mysqlpp::sql_cmp(non_null_int, null_int) > 0)) { 53 | ssqls foo(null_int), bar(non_null_int); 54 | if ((foo < bar) && (foo != bar) && !(bar < foo) && !(foo == bar)) { 55 | return 0; 56 | } 57 | else { 58 | std::cerr << "SSQLS comparison gave unexpected result" << 59 | std::endl; 60 | return 1; 61 | } 62 | } 63 | else { 64 | std::cerr << "Null comparison gave unexpected result" << std::endl; 65 | return 1; 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /test/null_uniqueness.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/null_uniqueness.cpp - Code for checking that null_type cannot be 3 | converted to anything else. Because it triggers a compile-time 4 | check, it can't be included in the test suite. You have to just 5 | try building it. Comment out the assignment to int to check that 6 | the return statement also triggers the compile-time check. 7 | 8 | Copyright (c) 2008 by Educational Technology Resources, Inc. 9 | Others may also hold copyrights on code in this file. See the 10 | CREDITS.txt file in the top directory of the distribution for details. 11 | 12 | This file is part of MySQL++. 13 | 14 | MySQL++ is free software; you can redistribute it and/or modify it 15 | under the terms of the GNU Lesser General Public License as published 16 | by the Free Software Foundation; either version 2.1 of the License, or 17 | (at your option) any later version. 18 | 19 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 22 | License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with MySQL++; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 27 | USA 28 | ***********************************************************************/ 29 | 30 | #include 31 | 32 | int 33 | main() 34 | { 35 | mysqlpp::Null ni = mysqlpp::null; 36 | int this_should_not_even_compile = mysqlpp::null; 37 | return ni; // neither should this 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/qssqls.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/qssqls.cpp - Tests SQL query creation from SSQLS in Query. 3 | 4 | Copyright (c) 2008-2009 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include 27 | #define MYSQLPP_ALLOW_SSQLS_V1 // suppress deprecation warning 28 | #include 29 | 30 | #include 31 | 32 | using namespace mysqlpp; 33 | using namespace std; 34 | 35 | 36 | sql_create_19(test, 37 | 19, 0, 38 | sql_tinyint, tinyint_v, 39 | sql_tinyint_unsigned, tinyint_unsigned_v, 40 | sql_smallint, smallint_v, 41 | sql_smallint_unsigned, smallint_unsigned_v, 42 | sql_int, int_v, 43 | sql_int_unsigned, int_unsigned_v, 44 | sql_mediumint, mediumint_v, 45 | sql_mediumint_unsigned, mediumint_unsigned_v, 46 | sql_bigint, bigint_v, 47 | sql_bigint_unsigned, bigint_unsigned_v, 48 | sql_float, float_v, 49 | sql_double, double_v, 50 | sql_decimal, decimal_v, 51 | sql_bool, bool_v, 52 | sql_date, date_v, 53 | sql_time, time_v, 54 | sql_datetime, datetime_v, 55 | sql_char, char_v, // only need one stringish type... 56 | sql_blob, blob_v) // ...and one blob type; they're all 57 | // the same under the hood in MySQL++ 58 | 59 | int 60 | main() 61 | { 62 | mysql_library_init(0, 0, 0); // no longer implicit in newer MariaDB 63 | 64 | Query q(0); // don't pass 0 for conn parameter in real code 65 | test empty(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 66 | Date(), Time(), DateTime(), "", sql_blob()); 67 | test filled(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.0, 12.0, 13.0, 68 | bool(14), Date("1515-15-15"), Time("16:16:16"), 69 | DateTime("1717-17-17 17:17:17"), "18", sql_blob("1\09", 3)); 70 | 71 | cout << q.insert(empty) << endl << endl; 72 | cout << q.insert(filled) << endl << endl; 73 | cout << q.replace(empty) << endl << endl; 74 | cout << q.replace(filled) << endl << endl; 75 | cout << q.update(filled, empty) << endl << endl; 76 | 77 | return 0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /test/qstream.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/qstream.cpp - Tests insertion of all officially-supported data 3 | types into a Query stream, plus some that aren't official. Failure 4 | is defined as an exception being thrown for any one of these. 5 | 6 | Copyright (c) 2008 by Educational Technology Resources, Inc. 7 | Others may also hold copyrights on code in this file. See the 8 | CREDITS.txt file in the top directory of the distribution for details. 9 | 10 | This file is part of MySQL++. 11 | 12 | MySQL++ is free software; you can redistribute it and/or modify it 13 | under the terms of the GNU Lesser General Public License as published 14 | by the Free Software Foundation; either version 2.1 of the License, or 15 | (at your option) any later version. 16 | 17 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with MySQL++; if not, write to the Free Software 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 25 | USA 26 | ***********************************************************************/ 27 | 28 | #include 29 | 30 | #include 31 | 32 | using namespace mysqlpp; 33 | 34 | int 35 | main() 36 | { 37 | try { 38 | // If you're reading this for implicit recommendations of good 39 | // code style, please ignore the hack-job on the following line. 40 | mysqlpp::Query q = mysqlpp::Connection().query(); 41 | 42 | // Throw everything we can think of at Query's stream interface. 43 | // Don't do this in real code, either. 44 | q << sql_tinyint(0) << sql_tinyint_unsigned(0) << 45 | sql_smallint(0) << sql_smallint_unsigned(0) << 46 | sql_mediumint(0) << sql_mediumint_unsigned(0) << 47 | sql_int(0) << sql_int_unsigned(0) << long(0) << 48 | sql_bigint(0) << sql_bigint_unsigned(0) << longlong(0) << 49 | sql_int1(0) << sql_int2(0) << sql_int3(0) << 50 | sql_int4(0) << sql_int8(0) << sql_middleint(0) << 51 | sql_float(0) << sql_double(0) << sql_decimal(0) << 52 | sql_numeric(0) << 53 | sql_fixed(0) << sql_float4(0) << sql_float8(0) << 54 | sql_bool(false) << sql_boolean(false) << bool(false) << 55 | sql_enum() << 56 | sql_char() << sql_varchar() << sql_long_varchar() << 57 | sql_character_varying() << sql_long() << 58 | sql_tinytext() << sql_text() << 59 | sql_mediumtext() << sql_longtext() << 60 | sql_blob() << sql_tinyblob() << sql_mediumblob() << 61 | sql_longblob() << sql_long_varbinary() << 62 | sql_date() << sql_time() << sql_datetime() << 63 | sql_timestamp() << 64 | sql_set(); 65 | std::cout << q << std::endl; 66 | return 0; 67 | } 68 | catch (const mysqlpp::TypeLookupFailed& e) { 69 | std::cerr << "Query stream insert failed: " << e.what() << 70 | std::endl; 71 | return 1; 72 | } 73 | catch (const std::exception& e) { 74 | std::cerr << "Unexpected exception: " << e.what() << 75 | std::endl; 76 | return 1; 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /test/query_copy.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/query_copy.cpp - Tests SQL query copies, to ensure that we copy 3 | it deeply enough. 4 | 5 | Copyright (c) 2009 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the 7 | CREDITS.txt file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | 29 | #include 30 | 31 | using namespace mysqlpp; 32 | using namespace std; 33 | 34 | 35 | static bool 36 | test_parm(const char* testname, Query& q1, Query q2, const char* parm) 37 | { 38 | string s1 = q1.str(parm); 39 | string s2 = q2.str(parm); 40 | if (s1.compare(s2) == 0) { 41 | return true; 42 | } 43 | else { 44 | std::cerr << "TEST " << testname << " failed: " << 45 | "s1('" << s1 << "') != " << 46 | "s2('" << s2 << "')!" << std::endl; 47 | return false; 48 | } 49 | } 50 | 51 | 52 | static bool 53 | test_plain(const char* testname, Query& q1, Query q2) 54 | { 55 | if (q1.str().compare(q2.str()) == 0) { 56 | return true; 57 | } 58 | else { 59 | std::cerr << "TEST " << testname << " failed: " << 60 | "q1('" << q1.str() << "') != " << 61 | "q2('" << q2.str() << "')!" << std::endl; 62 | return false; 63 | } 64 | } 65 | 66 | 67 | int 68 | main() 69 | { 70 | try { 71 | Query orig1(0); // don't pass 0 for conn parameter in real code 72 | orig1 << "raw string insert method test"; 73 | Query copy1(orig1); 74 | Query copy2(0); copy2 = orig1; 75 | 76 | Query orig2(0, false, "string ctor test"); // don't do this, either 77 | Query copy3(orig2); 78 | Query copy4(0); copy4 = orig2; 79 | 80 | Query orig3(0, false, "template %0 test"); 81 | orig3.parse(); 82 | Query copy5(orig3); 83 | Query copy6(0); copy6 = orig3; 84 | 85 | if ( test_plain("1a", orig1, copy1) && 86 | test_plain("1b", orig1, copy2) && 87 | test_plain("2a", orig2, copy3) && 88 | test_plain("2b", orig2, copy4) && 89 | test_parm("3a", orig3, copy5, "query") && 90 | test_parm("3b", orig3, copy6, "query")) { 91 | return 0; 92 | } 93 | } 94 | catch (const mysqlpp::Exception& e) { 95 | std::cerr << "Query copy test failed: " << e.what() << 96 | std::endl; 97 | } 98 | catch (const std::exception& e) { 99 | std::cerr << "Unexpected exception: " << e.what() << 100 | std::endl; 101 | } 102 | 103 | return 1; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /test/sqlstream.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/sqlstream.cpp - Tests SQLStream class, which is handled by the 3 | stream manipulators just like Query. 4 | 5 | Copyright (c) 2008 by AboveNet, Inc. Others may also hold copyrights 6 | on code in this file. See the CREDITS file in the top directory of 7 | the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | #define MYSQLPP_ALLOW_SSQLS_V1 // suppress deprecation warning 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | using namespace mysqlpp; 35 | using namespace std; 36 | 37 | 38 | sql_create_23(test, 39 | 23, 0, 40 | sql_tinyint, tinyint_v, 41 | sql_tinyint_unsigned, tinyint_unsigned_v, 42 | sql_smallint, smallint_v, 43 | sql_smallint_unsigned, smallint_unsigned_v, 44 | sql_int, int_v, 45 | sql_int_unsigned, int_unsigned_v, 46 | sql_mediumint, mediumint_v, 47 | sql_mediumint_unsigned, mediumint_unsigned_v, 48 | sql_bigint, bigint_v, 49 | sql_bigint_unsigned, bigint_unsigned_v, 50 | sql_float, float_v, 51 | sql_double, double_v, 52 | sql_decimal, decimal_v, 53 | sql_bool, bool_v, 54 | sql_date, date_v, 55 | sql_time, time_v, 56 | sql_datetime, datetime_v, 57 | sql_char, char_v, 58 | sql_varchar, varchar_v, 59 | sql_tinytext, tinytext_v, 60 | sql_text, text_v, 61 | sql_mediumtext, mediumtext_v, 62 | sql_longtext, longtext_v) 63 | 64 | 65 | int 66 | main() 67 | { 68 | mysql_library_init(0, 0, 0); // no longer implicit in newer MariaDB 69 | 70 | SQLStream sqls(0); // don't do this in real code 71 | test empty(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 72 | Date(), Time(), DateTime(),"","","","","",""); 73 | test filled(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.0, 12.0, 13.0, 74 | bool(14), Date("1515-15-15"), Time("16:16:16"), 75 | DateTime("1717-17-17 17:17:17"),"18","19","20","21","22","23"); 76 | 77 | sqls << "INSERT INTO " << filled.table() << " (" << 78 | filled.field_list() << ") VALUES (" << 79 | filled.value_list() << ")"; 80 | 81 | cout << sqls.str() << endl; 82 | 83 | sqls.str(""); 84 | 85 | sqls << "INSERT INTO " << empty.table() << " (" << 86 | empty.field_list() << ") VALUES (" << 87 | empty.value_list() << ")"; 88 | 89 | cout << sqls.str() << endl; 90 | 91 | return 0; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /test/tcp.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/tcp.cpp - Tests the address parser/verifier in TCPConnection. 3 | 4 | Copyright (c) 2007 by Educational Technology Resources, Inc. 5 | Others may also hold copyrights on code in this file. See the 6 | CREDITS.txt file in the top directory of the distribution for details. 7 | 8 | This file is part of MySQL++. 9 | 10 | MySQL++ is free software; you can redistribute it and/or modify it 11 | under the terms of the GNU Lesser General Public License as published 12 | by the Free Software Foundation; either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with MySQL++; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 23 | USA 24 | ***********************************************************************/ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | 33 | static void 34 | test(const char* addr_svc, unsigned int port, const char* exp_addr, 35 | unsigned int exp_port) 36 | { 37 | std::string addr(addr_svc), error; 38 | 39 | mysqlpp::TCPConnection::parse_address(addr, port, error); 40 | if (error.size()) { 41 | throw mysqlpp::SelfTestFailed("TCP address parse error: " + 42 | error); 43 | } 44 | else if (addr.compare(exp_addr) != 0) { 45 | std::ostringstream outs; 46 | outs << "TCP address parse mismatch: '" << addr << "' != '" << 47 | exp_addr << "'"; 48 | throw mysqlpp::SelfTestFailed(outs.str()); 49 | } 50 | else if (port != exp_port) { 51 | std::ostringstream outs; 52 | outs << "TCP port parse mismatch: '" << port << "' != '" << 53 | exp_port << "'"; 54 | throw mysqlpp::SelfTestFailed(outs.str()); 55 | } 56 | } 57 | 58 | 59 | static void 60 | fail(const char* addr_svc, unsigned int port, const char* exp_addr, 61 | unsigned int exp_port) 62 | { 63 | try { 64 | test(addr_svc, port, exp_addr, exp_port); 65 | } 66 | catch (...) { 67 | return; // eat expected error 68 | } 69 | 70 | std::ostringstream outs; 71 | outs << "'" << addr_svc << "' == ('" << exp_addr << 72 | "', " << exp_port << ") but should not."; 73 | throw mysqlpp::SelfTestFailed(outs.str()); 74 | } 75 | 76 | 77 | int 78 | main() 79 | { 80 | try { 81 | // Domain name and IPv4 literal tests 82 | test(":", 0, "", 0); 83 | test("1.2.3.4", 0, "1.2.3.4", 0); 84 | test("1.2.3.4:", 0, "1.2.3.4", 0); 85 | test("1.2.3.4:567", 0, "1.2.3.4", 567); 86 | test("1.2.3.4", 890, "1.2.3.4", 890); 87 | test("1.2.3.4:telnet", 0, "1.2.3.4", 23); 88 | test("a.b.com", 0, "a.b.com", 0); 89 | test("a.b.com", 987, "a.b.com", 987); 90 | fail("@", 0, "@", 0); 91 | fail("::", 0, "", 0); 92 | fail(":", 0, "1.2.3.4", 45); 93 | fail("a.b.com::", 0, "a.b.com", 0); 94 | fail("a.b:com:1", 0, "a.b.com", 1); 95 | 96 | // IPv6 literal tests 97 | test("[]:123", 0, "", 123); 98 | test("[::]:telnet", 0, "::", 23); 99 | 100 | std::cout << "TCP address parsing passed." << std::endl; 101 | return 0; 102 | } 103 | catch (mysqlpp::SelfTestFailed& e) { 104 | std::cerr << "TCP address parse error: " << e.what() << std::endl; 105 | return 1; 106 | } 107 | catch (std::exception& e) { 108 | std::cerr << "Unexpected test failure: " << e.what() << std::endl; 109 | return 2; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /test/test1.ssqls: -------------------------------------------------------------------------------- 1 | # This is a comment. 2 | # The following blank lines should also be ignored. 3 | 4 | include test2.ssqls 5 | 6 | table test_ssqls alias TestSsqls filebase test3 7 | field item type bigint alias id is autoinc is key 8 | field num type bigint 9 | field weight type double 10 | field price type decimal(2) 11 | field sdate type date 12 | field description type mediumtext is null 13 | 14 | -------------------------------------------------------------------------------- /test/test2.ssqls: -------------------------------------------------------------------------------- 1 | # Here we give non-default values for all known options, partly to 2 | # exercise them, and partly to test that the include directive works. 3 | option implementation_extension cc 4 | option header_extension hh 5 | option accessor_style getX 6 | option exception_on_schema_mismatch true 7 | -------------------------------------------------------------------------------- /test/wnp.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | test/wnp.cpp - Tests WindowsNamedPipeConnection::is_wnp(). This test 3 | can only fail on Windows! It succeeds when built for anything else. 4 | 5 | Copyright (c) 2007 by Educational Technology Resources, Inc. 6 | Others may also hold copyrights on code in this file. See the 7 | CREDITS.txt file in the top directory of the distribution for details. 8 | 9 | This file is part of MySQL++. 10 | 11 | MySQL++ is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published 13 | by the Free Software Foundation; either version 2.1 of the License, or 14 | (at your option) any later version. 15 | 16 | MySQL++ is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with MySQL++; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ***********************************************************************/ 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | 33 | int 34 | main() 35 | { 36 | #if defined(MYSQLPP_PLATFORM_WINDOWS) 37 | if (!mysqlpp::WindowsNamedPipeConnection::is_wnp(".")) { 38 | std::cerr << "Failed to identify Windows named pipe" << std::endl; 39 | 40 | } 41 | else if (mysqlpp::WindowsNamedPipeConnection::is_wnp("bogus")) { 42 | std::cerr << "Failed to fail for bogus named pipe" << std::endl; 43 | } 44 | else if (mysqlpp::WindowsNamedPipeConnection::is_wnp(0)) { 45 | std::cerr << "Failed to fail for null named pipe" << std::endl; 46 | } 47 | else { 48 | return 0; 49 | } 50 | 51 | return 1; 52 | #else 53 | return 0; 54 | #endif 55 | } 56 | -------------------------------------------------------------------------------- /tools/corecount: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################################## 3 | # corecount - Prints the number of CPU cores found on this system 4 | # 5 | # Copyright © 2017-2018 by Warren Young 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a 8 | # copy of this software and associated documentation files (the 9 | # "Software"), to deal in the Software without restriction, including 10 | # without limitation the rights to use, copy, modify, merge, publish, 11 | # distribute, sublicense, and/or sell copies of the Software, and to 12 | # permit persons to whom the Software is furnished to do so, subject to 13 | # the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be included 16 | # in all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | # IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE FOR ANY CLAIM, 22 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 | # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 24 | # THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | # 26 | # Except as contained in this notice, the names of the authors above shall 27 | # not be used in advertising or otherwise to promote the sale, use or 28 | # other dealings in this Software without prior written authorization from 29 | # those authors. 30 | ######################################################################## 31 | 32 | sys=`uname -s` 33 | if [ -r /proc/cpuinfo ] 34 | then 35 | # It's a Linux box, or something that *looks* like one, such as 36 | # NetBSD, Cygwin, or the Windows Subsystem for Linux. 37 | grep -Ec '^processor[[:space:]]+:' /proc/cpuinfo 38 | elif [ "$sys" = "Darwin" -o "$sys" = "OpenBSD" -o "$sys" = "NetBSD" ] 39 | then 40 | # It's a macOS or BSD box 41 | /usr/sbin/sysctl -n hw.ncpu 42 | elif [ "$sys" = "FreeBSD" ] 43 | then 44 | # FreeBSD puts sysctl elsewhere 45 | /sbin/sysctl -n hw.ncpu 46 | else 47 | # No known way to find out, so report only 1 core 48 | echo 1 49 | fi 50 | -------------------------------------------------------------------------------- /tools/mkrel: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ######################################################################## 3 | # mkrel - Automatically merge trunk changes into the release branch 4 | # for a new public release of the software. Also tags the trunk with 5 | # the date of release, so old releases can be easily checked out. 6 | # 7 | # Copyright © 2016-2021 Warren Young 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE FOR ANY CLAIM, 24 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 25 | # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 26 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | # Except as contained in this notice, the names of the authors above 29 | # shall not be used in advertising or otherwise to promote the sale, 30 | # use or other dealings in this Software without prior written 31 | # authorization from those authors. 32 | ######################################################################## 33 | 34 | set -e 35 | 36 | ggrep=$(which ggrep grep 2> /dev/null | head -1) 37 | ver=$(grep -F so_version mysql++.bkl | $ggrep -Po '\d+\.\d+.\d+') 38 | if [ $? != 0 ] || [ -z "$ver" ] 39 | then 40 | echo "Failed to extract version info from Bakefile!" 41 | echo 42 | exit 1 43 | fi 44 | 45 | make=$(which gmake make 2> /dev/null | head -1) 46 | alias f=fossil 47 | f update && 48 | ( test -z "$(f changes --no-classify)" || f ci -m "Released v$ver" ) && 49 | cd ../release && 50 | f update release && 51 | f merge trunk && 52 | test -z "$(f changes --conflict)" && 53 | f diff -w --tk && 54 | ./bootstrap && 55 | tools/mmake && 56 | $make dist && 57 | cp mysql++-${ver}.tar.gz ~/tangentsoft.com/mysqlpp/releases && 58 | cd ~/tangentsoft.com/mysqlpp && 59 | $make doc synch && 60 | cd - && 61 | f ci --tag v$ver -m "Merged trunk changes for v$ver into release branch" 62 | -------------------------------------------------------------------------------- /tools/mmake: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ######################################################################## 3 | # mmake - Runs make -jN where N is 1.5x the number of CPU cores 4 | # 5 | # Copyright © 2017-2019 Warren Young 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining 8 | # a copy of this software and associated documentation files (the 9 | # "Software"), to deal in the Software without restriction, including 10 | # without limitation the rights to use, copy, modify, merge, publish, 11 | # distribute, sublicense, and/or sell copies of the Software, and to 12 | # permit persons to whom the Software is furnished to do so, subject to 13 | # the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be 16 | # included in all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | # IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE FOR ANY CLAIM, 22 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 23 | # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 24 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | # 26 | # Except as contained in this notice, the names of the authors above 27 | # shall not be used in advertising or otherwise to promote the sale, 28 | # use or other dealings in this Software without prior written 29 | # authorization from those authors. 30 | ######################################################################## 31 | 32 | MAKE=make 33 | MAKE=$(which gmake make 2> /dev/null | head -1) 34 | 35 | BDIR="$(dirname "$0")" 36 | if [ -z $BDIR ] ; then BDIR="$(dirname "$(which "$0")")" ; fi 37 | 38 | $MAKE -j$(($("$BDIR"/corecount) * 15 / 10)) "$@" 39 | -------------------------------------------------------------------------------- /tools/print-version.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo @MYSQLPP_VERSION_MAJOR@.@MYSQLPP_VERSION_MINOR@.@MYSQLPP_VERSION_BUGFIX@ 3 | -------------------------------------------------------------------------------- /tools/tarballs-to-fossil: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ignores="$(tr '\n' ',' < ../tb-ignore-glob)" 3 | rdir=~/tangentsoft.com/mysql++/releases 4 | 5 | set -e 6 | ls $rdir/*.tar.gz | 7 | ggrep -Po '\d[\d.]+\d[.a-f]{0,2}' | 8 | sed -e 's/\.$//' | 9 | gsort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | 10 | while read ver 11 | do 12 | f=$(echo $rdir/*-${ver}.tar.gz) 13 | echo -e "\n----------------------------------------------------------" 14 | echo -e "Processing MySQL++ v$ver, $(basename $f)...\n" 15 | 16 | find . -type f -not -name .fslckout -delete 17 | find . -type d -delete 18 | 19 | if gtar -x --strip-components=1 -f "$f" 20 | then 21 | fossil addremove --ignore "$ignores" 22 | 23 | if [ -e ChangeLog ] 24 | then 25 | newest=ChangeLog 26 | else 27 | newest=$(find . -type f -print0 | xargs -0 ls -t | head -n 2 | tail -1) 28 | fi 29 | mtime=$(date -u -r "$newest" +%FT%TZ) 30 | 31 | echo "Checking in MySQL++ v$ver, mtime=$mtime..." 32 | fossil ci \ 33 | --comment "Version $ver" \ 34 | --date-override $mtime \ 35 | --no-warnings \ 36 | --tag "v$ver" 37 | fi 38 | done 39 | 40 | fossil ui 41 | -------------------------------------------------------------------------------- /tools/tb-ignore-glob: -------------------------------------------------------------------------------- 1 | *~ 2 | */#* 3 | *.dsp 4 | *.dsw 5 | *.log 6 | *.old 7 | *.svn/* 8 | *.vcproj 9 | abi.xml 10 | acconfig.h 11 | acinclude.m4 12 | aclocal.m4 13 | bk.deps 14 | config.guess 15 | config.h 16 | config.status 17 | config.sub 18 | Configure 19 | configure 20 | config/libtool.m4 21 | config/lt*.m4 22 | devel/* 23 | depcomp 24 | doc/*.pdf 25 | doc/*.tex 26 | doc/CVS/* 27 | doc/html/* 28 | doc/html.sty 29 | doc/Makefile.in 30 | doc/Makefile.org 31 | doc/man-html/* 32 | doc/man-text/* 33 | doc/manual.aux 34 | doc/manual.dvi 35 | doc/manual.ps 36 | doc/manual.ps.gz 37 | doc/manual.toc 38 | doc/refman/html/* 39 | doc/userman/*.txt 40 | doc/userman/html/* 41 | examples/*.bpg 42 | examples/*.bpf 43 | examples/*.bpr 44 | examples/*.dsp 45 | examples/*.dsw 46 | examples/*.vcproj 47 | examples/Makefile.in 48 | html.sty 49 | install.hta 50 | install-sh 51 | lib/Doxyfile 52 | lib/mysql++.h 53 | libtool 54 | ltconfig 55 | ltmain.sh 56 | macros/Makefile.in 57 | Makefile 58 | Makefile.in 59 | man-html/* 60 | man-text/* 61 | manual.aux 62 | manual.dvi 63 | manual.tex 64 | manual.toc 65 | missing 66 | mkinstalldirs 67 | mysql-config 68 | mysql++-config.hh 69 | mysql++-int/*.gif 70 | mysql++-int/gifs.db 71 | mysql++-int/less 72 | mysql++-int/libmysql++.so 73 | mysql++.xcodeproj/* 74 | mysql++.spec 75 | sqlplusint/*.bpg 76 | sqlplusint/*.bpf 77 | sqlplusint/*.bpr 78 | sqlplusint/*.flt 79 | sqlplusint/*.gif 80 | sqlplusint/*.plt 81 | sqlplusint/bad_query.hh 82 | sqlplusint/custom*.hh 83 | sqlplusint/doc-fix.pl 84 | sqlplusint/doc-trim.pl 85 | sqlplusint/doc.tex 86 | sqlplusint/doc.tex.tmpl 87 | sqlplusint/headers 88 | sqlplusint/includes.pl 89 | sqlplusint/gifs.db 90 | sqlplusint/less 91 | sqlplusint/stamp-h2 92 | sqlplusint/stamp-h2.in 93 | sqlplusint/undef_short 94 | ssx/Doxyfile 95 | stamp-h 96 | stamp-h.in 97 | stamp-h1 98 | stamp-h1.in 99 | vc2*/* 100 | version 101 | 102 | --------------------------------------------------------------------------------