diff options
Diffstat (limited to 'odb')
31 files changed, 1448 insertions, 1243 deletions
diff --git a/odb/GPLv3 b/odb/GPLv3 index 94a9ed0..b90b0f4 100644..120000 --- a/odb/GPLv3 +++ b/odb/GPLv3 @@ -1,674 +1 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - <program> Copyright (C) <year> <name of author> - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. +../GPLv3
\ No newline at end of file diff --git a/odb/INSTALL b/odb/INSTALL deleted file mode 100644 index 6bd473c..0000000 --- a/odb/INSTALL +++ /dev/null @@ -1,36 +0,0 @@ -Prerequisites -============= - - - GNU g++ >= 4.5.0 http://gcc.gnu.org/ - - libcutl >= 1.9.0 http://www.codesynthesis.com/projects/libcutl/ - -ODB requires the GCC compiler (g++) to be built with plugin support. -If you are building GCC yourself, you can enable plugin support with -the --enable-plugin configure option. If you are using a pre-packaged -GCC (for example, as part of your distribution), then you can verify -that GCC was built with plugin support by running g++ with the -v -option and then making sure --enable-plugin is present in the output. - -Note also that for pre-packaged GCC, plugin headers are usually -distributed in a separate package, normally called gcc-plugin-dev -or similar. You will need to install this package in order to build -ODB. For Debian/Ubuntu, this package is called gcc-X.Y-plugin-dev, -for example: - -apt-get install gcc-4.7-plugin-dev - -For RedHat/Fedora, this package is called gcc-plugin-devel, for -example: - -yum install gcc-plugin-devel - - -Building -======== - -The easiest way to build this package is with the bpkg package manager: - -$ bpkg build odb - -But if you don't want to use the package manager, then you can also build it -manually using the standard build2 build system. diff --git a/odb/LICENSE b/odb/LICENSE index 8f76d96..f9be5a4 100644 --- a/odb/LICENSE +++ b/odb/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2024 Code Synthesis. +Copyright (c) 2009-2025 Code Synthesis. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as @@ -16,6 +16,5 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. You should have received a copy of the GNU General Public License -along with this program; if not, see: - -http://www.codesynthesis.com/licenses/gpl-3.txt +version 3 along with this program; if not, contact Code Synthesis +at info@codesynthesis.com. diff --git a/odb/PACKAGE-README.md b/odb/PACKAGE-README.md new file mode 120000 index 0000000..422e63f --- /dev/null +++ b/odb/PACKAGE-README.md @@ -0,0 +1 @@ +../PACKAGE-README.md
\ No newline at end of file diff --git a/odb/README b/odb/README deleted file mode 100644 index 90078e5..0000000 --- a/odb/README +++ /dev/null @@ -1,20 +0,0 @@ -ODB is an object-relational mapping (ORM) system for C++. It provides -tools, APIs, and library support that allow you to persist C++ objects -to a relational database (RDBMS) without having to deal with tables, -columns, or SQL and without manually writing any of the mapping code. -For more information see: - -http://www.codesynthesis.com/products/odb/ - -This package contains the ODB compiler and the ODB system documentation. - -See the NEWS file for the user-visible changes from the previous release. - -See the LICENSE file for distribution conditions. - -See the INSTALL file for prerequisites and installation instructions. - -See the doc/ directory for documentation. - -Send questions, bug reports, or any other feedback to the -odb-users@codesynthesis.com mailing list. diff --git a/odb/README.md b/odb/README.md new file mode 100644 index 0000000..2a2487c --- /dev/null +++ b/odb/README.md @@ -0,0 +1,12 @@ +# odb - ODB compiler + +ODB is an open-source, cross-platform, and cross-database object-relational +mapping (ORM) system for C++. It allows you to persist C++ classes to a +relational database without having to deal with tables, columns, or SQL and +without manually writing any mapping code. + +For further information, including licensing conditions, documentation, and +binary packages, refer to the [ODB project +page](https://codesynthesis.com/products/odb/). + +This package contains the ODB compiler. diff --git a/odb/build/bindist-archive-post.bx b/odb/build/bindist-archive-post.bx new file mode 100644 index 0000000..fa48d5f --- /dev/null +++ b/odb/build/bindist-archive-post.bx @@ -0,0 +1,118 @@ +# file : build/bindist-archive-post.bx +# license : GNU GPL v3; see accompanying LICENSE file + +# Overlay the ODB compiler Windows distribution archive with the contents of +# the MinGW GCC distribution archive (see odb/manifest for details). +# +# Usage: $0 <odb-archive> +# +# Note that we expect to be operating in a clean temporary directory. + +info = [cmdline] echo 1>&2 + +odb_path = [path] $1 + +ife $odb_path + exit "ODB archive path is not specified" + +# Extract the top directory name from the ODB archive path. +# +# Note that we expect the archive path to contain the directory prefix since +# it cannot be located in the current directory (see above). +# +odb_name = [dir_path] $regex.match( \ + $odb_path, \ + '.+[/\\](odb-[^/\\]+-x86_64-windows[^/\\]+)\.(?:zip|tar\.[^./\\]+)', \ + return_subs) + +ifn $odb_name + exit "unable to extract top directory name from ODB archive path '$odb_path'" + +# Discover the URL of the GCC distribution archive (assumed to be named as +# build2-mingw-X.Y.Z-x86_64-windows.tar.xz). While at it, retrieve the archive +# checksum. +# +base_url = ($shell.version.stage \ + ? 'https://stage.build2.org/0' \ + : 'https://download.build2.org') + +u = "$base_url/toolchain.sha256" + +$info "fetching $u" + +curl -sS $u | \ + sed -n -e 's/^([^ ]+) \*([^ ]+build2-mingw-[^ ]+)$/\1 \2/p' | \ + set -w mi [strings] + +ife $mi + exit "unable to obtain MinGW GCC distribution info from $u" + +mingw_checksum = ($mi[0]) +mingw_url = "$base_url/($mi[1])" + +# Download the GCC distribution archive. +# +mingw_file = [path] $regex.match($mingw_url, '.+/([^/]+)', return_subs) + +ifn $mingw_file + exit "unable to extract archive file name from '$mingw_url'" + +$info "fetching $mingw_url" + +curl -sSf -o $mingw_file $mingw_url + +# Verify the checksum of the downloaded GCC distribution archive. +# +sha256sum -b --sum-only $mingw_file | set checksum [string] + +if ($checksum != $mingw_checksum) + exit "$mingw_file checksum $checksum does not match expected $mingw_checksum" + +# Overlay the original ODB archive with the downloaded GCC distribution +# archive. +# +$info "overlaying $odb_path with $mingw_file" + +bsdtar -xf $odb_path + +mkdir $odb_name/mingw +bsdtar -xf $mingw_file -C $odb_name/mingw --strip-components=1 +rm $mingw_file + +# While at it, verify that the version of the system g++ (used to build ODB) +# matches the version of the being bundled g++. +# +# Note: compare only the (first) `g++...` lines of `g++ --version` outputs. +# +g++ --version | \ + sed -n -e 's/^(g\+\+.+)$/\1/p' | \ + set -n system_gcc_ver [string] + +ife $system_gcc_ver + exit "unable to extract version of system g++" + +# Note that the below $path_search() function calls expect absolute path as a +# pattern argument. +# +mingw_bin = [dir_path] $~/$odb_name/mingw/bin + +$mingw_bin/g++ --version | \ + sed -n -e 's/^(g\+\+.+)$/\1/p' | \ + set -n bundled_gcc_ver [string] + +ife $bundled_gcc_ver + exit "unable to extract version of bundled g++" + +if ($system_gcc_ver != $bundled_gcc_ver) + exit "version of system g++ '$system_gcc_ver' does not match version of bundled g++ '$bundled_gcc_ver'" + +cp $path_search($mingw_bin/libgcc_s_seh-*.dll) $odb_name/bin/ +cp $path_search($mingw_bin/libstdc++-*.dll) $odb_name/bin/ +cp $path_search($mingw_bin/libwinpthread-*.dll) $odb_name/bin/ + +# Note that on Windows bsdtar doesn't like trailing slashes, so let's use +# $odb_name's string representation. +# +rm $odb_path +bsdtar -a --options=compression-level=9 -cf $odb_path $string($odb_name) +rm -r $odb_name diff --git a/odb/buildfile b/odb/buildfile index 78b5d08..bc65d81 100644 --- a/odb/buildfile +++ b/odb/buildfile @@ -1,9 +1,16 @@ # file : buildfile # license : GNU GPL v3; see accompanying LICENSE file -./: {*/ -build/ -m4/} doc{INSTALL NEWS README} legal{GPLv3 LICENSE} manifest +./: {*/ -build/ -m4/} \ + doc{README.md PACKAGE-README.md NEWS} \ + legal{GPLv3 LICENSE} \ + manifest -# Don't install tests or the INSTALL file. +# bbot worker hook script (see bindist-windows build configuration for +# details). # -tests/: install = false -doc{INSTALL}@./: install = false +./: build/file{bindist-archive-post.bx} + +# Don't install tests. +# +tests/: install = false diff --git a/odb/doc/buildfile b/odb/doc/buildfile index 88f30fc..fadbe40 100644 --- a/odb/doc/buildfile +++ b/odb/doc/buildfile @@ -83,7 +83,6 @@ if $develop # if! diff $src_base/pregenerated/odb.1 $path($>) >- cp $path($>) $src_base/pregenerated/odb.1 - end }} xhtml{odb}: ../odb/cli{options} file{odb-prologue.xhtml odb-epilogue.xhtml} $cli @@ -97,7 +96,6 @@ if $develop if! diff $src_base/pregenerated/odb.xhtml $path($>) >- cp $path($>) $src_base/pregenerated/odb.xhtml - end }} # diff --git a/odb/doc/manual.html2ps b/odb/doc/manual.html2ps index 65f0c9d..fb3d7bb 100644 --- a/odb/doc/manual.html2ps +++ b/odb/doc/manual.html2ps @@ -21,7 +21,7 @@ <h1> </h1> <h1> </h1> </div> - <p>Copyright © 2009-2020 Code Synthesis.</p> + <p>Copyright © 2009-2025 Code Synthesis.</p> <p>Permission is granted to copy, distribute and/or modify this document under the terms of the diff --git a/odb/doc/manual.xhtml b/odb/doc/manual.xhtml index a004cd7..e0389ef 100644 --- a/odb/doc/manual.xhtml +++ b/odb/doc/manual.xhtml @@ -5,11 +5,11 @@ <head> <title>C++ Object Persistence with ODB</title> - <meta name="copyright" content="© 2009-2020 Code Synthesis"/> + <meta name="copyright" content="© 2009-2025 Code Synthesis"/> <meta name="keywords" content="odb,c++,object,persistence,ORM,relational,database,RDBMS,ODBMS,OODBMS"/> <meta name="description" content="C++ Object Persistence with ODB"/> - <meta name="revision" content="2.4"/> - <meta name="version" content="2.4.0"/> + <meta name="revision" content="2.6"/> + <meta name="version" content="2.6.0"/> <!-- @@ -35,9 +35,22 @@ for consistency. <link rel="stylesheet" type="text/css" href="default.css" /> <style type="text/css"> + code + { + background-color: rgba(0, 0, 0, 0.05); + border-radius: 0.2em; + padding: .2em .32em .18em .32em; + } + + table.toc * code + { + background-color: white; + border-radius: none; + } + pre { - padding : 0 0 0 0em; - margin : 0em 0em 0em 0; + padding : 0 0 0 0; + margin : 0 0 0 0; font-size : 102% } @@ -281,7 +294,7 @@ for consistency. <div id="titlepage"> <div class="title">C++ Object Persistence with ODB</div> - <p>Copyright © 2009-2020 Code Synthesis</p> + <p>Copyright © 2009-2025 Code Synthesis</p> <p>Permission is granted to copy, distribute and/or modify this document under the terms of the @@ -290,8 +303,8 @@ for consistency. no Front-Cover Texts and no Back-Cover Texts.</p> <!-- REMEMBER TO CHANGE VERSIONS IN THE META TAGS ABOVE! --> - <p id="revision">Revision 2.4, February 2015</p> - <p>This revision of the manual describes ODB 2.4.0 and is available + <p id="revision">Revision 2.6, March 2025</p> + <p>This revision of the manual describes ODB 2.6.0 and is available in the following formats: <a href="http://www.codesynthesis.com/products/odb/doc/manual.xhtml">XHTML</a>, <a href="http://www.codesynthesis.com/products/odb/doc/odb-manual.pdf">PDF</a>, and @@ -621,6 +634,7 @@ for consistency. <tr><th>14.4.34</th><td><a href="#14.4.34"><code>index_column</code></a></td></tr> <tr><th>14.4.35</th><td><a href="#14.4.35"><code>key_column</code></a></td></tr> <tr><th>14.4.36</th><td><a href="#14.4.36"><code>value_column</code></a></td></tr> + <tr><th>14.4.36</th><td><a href="#14.4.37"><code>points_to</code></a></td></tr> </table> </td> </tr> @@ -645,7 +659,12 @@ for consistency. <th>14.7</th><td><a href="#14.7">Index Definition Pragmas</a></td> </tr> <tr> - <th>14.8</th><td><a href="#14.8">Database Type Mapping Pragmas</a></td> + <th>14.8</th><td><a href="#14.8">Type Mapping Pragmas</a> + <table class="toc"> + <tr><th>14.8.1</th><td><a href="#14.8.1">C++ Type Mapping Pragmas</a></td></tr> + <tr><th>14.8.2</th><td><a href="#14.8.2">Database Type Mapping Pragmas</a></td></tr> + </table> + </td> </tr> <tr> <th>14.9</th><td><a href="#14.9">C++ Compiler Warnings</a> @@ -700,6 +719,7 @@ for consistency. <table class="toc"> <tr><th>17.1.1</th><td><a href="#17.1.1">String Type Mapping</a></td></tr> <tr><th>17.1.2</th><td><a href="#17.1.2">Binary Type Mapping</a></td></tr> + <tr><th>17.1.3</th><td><a href="#17.1.3">Mixed Automatic/0 Object Id Assignment</a></td></tr> </table> </td> </tr> @@ -728,26 +748,28 @@ for consistency. <tr><th>18.1.1</th><td><a href="#18.1.1">String Type Mapping</a></td></tr> <tr><th>18.1.2</th><td><a href="#18.1.2">Binary Type Mapping</a></td></tr> <tr><th>18.1.3</th><td><a href="#18.1.3">Incremental <code>BLOB</code>/<code>TEXT</code> I/O</a></td></tr> + <tr><th>18.1.4</th><td><a href="#18.1.4">Mixed Automatic/Manual Object Id Assignment</a></td></tr> </table> </td> </tr> <tr><th>18.2</th><td><a href="#18.2">SQLite Database Class</a></td></tr> <tr><th>18.3</th><td><a href="#18.3">SQLite Connection and Connection Factory</a></td></tr> - <tr><th>18.4</th><td><a href="#18.4">SQLite Exceptions</a></td></tr> + <tr><th>18.4</th><td><a href="#18.4">Attached SQLite Databases</a></td></tr> + <tr><th>18.5</th><td><a href="#18.5">SQLite Exceptions</a></td></tr> <tr> - <th>18.5</th><td><a href="#18.5">SQLite Limitations</a> + <th>18.6</th><td><a href="#18.6">SQLite Limitations</a> <table class="toc"> - <tr><th>18.5.1</th><td><a href="#18.5.1">Query Result Caching</a></td></tr> - <tr><th>18.5.2</th><td><a href="#18.5.2">Automatic Assignment of Object Ids</a></td></tr> - <tr><th>18.5.3</th><td><a href="#18.5.3">Foreign Key Constraints</a></td></tr> - <tr><th>18.5.4</th><td><a href="#18.5.4">Constraint Violations</a></td></tr> - <tr><th>18.5.5</th><td><a href="#18.5.5">Sharing of Queries</a></td></tr> - <tr><th>18.5.6</th><td><a href="#18.5.6">Forced Rollback</a></td></tr> - <tr><th>18.5.7</th><td><a href="#18.5.7">Database Schema Evolution</a></td></tr> + <tr><th>18.6.1</th><td><a href="#18.6.1">Query Result Caching</a></td></tr> + <tr><th>18.6.2</th><td><a href="#18.6.2">Automatic Assignment of Object Ids</a></td></tr> + <tr><th>18.6.3</th><td><a href="#18.6.3">Foreign Key Constraints</a></td></tr> + <tr><th>18.6.4</th><td><a href="#18.6.4">Constraint Violations</a></td></tr> + <tr><th>18.6.5</th><td><a href="#18.6.5">Sharing of Queries</a></td></tr> + <tr><th>18.6.6</th><td><a href="#18.6.6">Forced Rollback</a></td></tr> + <tr><th>18.6.7</th><td><a href="#18.6.7">Database Schema Evolution</a></td></tr> </table> </td> </tr> - <tr><th>18.6</th><td><a href="#18.6">SQLite Index Definition</a></td></tr> + <tr><th>18.7</th><td><a href="#18.7">SQLite Index Definition</a></td></tr> </table> </td> </tr> @@ -780,6 +802,7 @@ for consistency. </td> </tr> <tr><th>19.6</th><td><a href="#19.6">PostgreSQL Index Definition</a></td></tr> + <tr><th>19.7</th><td><a href="#19.7">PostgreSQL Stored Procedures and Functions</a></td></tr> </table> </td> </tr> @@ -1263,14 +1286,11 @@ for consistency. <h2><a name="1.3">1.3 Supported C++ Standards</a></h2> - <p>ODB provides support for ISO/IEC C++ 1998/2003 (C++98/03), - ISO/IEC TR 19768 C++ Library Extensions (C++ TR1), and - ISO/IEC C++ 2011 (C++11). While the majority of the examples in - this manual use C++98/03, support for the new functionality and - library components introduced in TR1 and C++11 are discussed - throughout the document. The <code>c++11</code> example in the - <code>odb-examples</code> package also shows ODB support for - various C++11 features.</p> + <p>ODB provides support for ISO/IEC C++ 1998/2003 (C++98/03), ISO/IEC C++ + 2011 (C++11), as well later standards with the majority of the examples + in this manual using C++11. The <code>c++11</code> example in the + <code>odb-examples</code> package shows ODB support for various + features new in C++11.</p> <!-- CHAPTER --> @@ -1351,7 +1371,7 @@ private: friend class odb::access; // (4) #pragma db id auto // (5) - unsigned long id_; // (5) + unsigned long long id_; // (5) std::string first_; std::string last_; @@ -1614,7 +1634,7 @@ mysql --user=odb_test --database=odb_test < person.sql // driver.cxx // -#include <memory> // std::auto_ptr +#include <memory> // std::unique_ptr #include <iostream> #include <odb/database.hxx> @@ -1633,9 +1653,9 @@ main (int argc, char* argv[]) { try { - auto_ptr<database> db (new odb::mysql::database (argc, argv)); + unique_ptr<database> db (new odb::mysql::database (argc, argv)); - unsigned long john_id, jane_id, joe_id; + unsigned long long john_id, jane_id, joe_id; // Create a few persistent person objects. // @@ -1854,8 +1874,8 @@ main (int argc, char* argv[]) ... } - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; // Say hello to those over 30. // @@ -1884,10 +1904,10 @@ main (int argc, char* argv[]) replaced with "..." in the above listing for brevity. Again, let's examine the rest of it piece by piece.</p> - <p>The two <code>typedef</code>s create convenient aliases for two - template instantiations that will be used a lot in our application. - The first is the query type for the <code>person</code> objects - and the second is the result type for that query.</p> + <p>The two <code>using</code> declarations create convenient aliases for two + template instantiations that will be used a lot in our application. The + first is the query type for the <code>person</code> objects and the + second is the result type for that query.</p> <p>Then we begin a new transaction and call the <code>query()</code> database function. We pass a query expression @@ -1976,7 +1996,7 @@ main (int argc, char* argv[]) { ... - unsigned long john_id, jane_id, joe_id; + unsigned long long john_id, jane_id, joe_id; // Create a few persistent person objects. // @@ -1995,7 +2015,7 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); - auto_ptr<person> joe (db->load<person> (joe_id)); + unique_ptr<person> joe (db->load<person> (joe_id)); joe->age (joe->age () + 1); db->update (*joe); @@ -2022,13 +2042,11 @@ main (int argc, char* argv[]) <code>person</code> object with Joe's persistent state. We pass Joe's object identifier that we stored earlier when we made this object persistent. While here we use - <code>std::auto_ptr</code> to manage the returned object, we + <code>std::unique_ptr</code> to manage the returned object, we could have also used another smart pointer, for example - <code>std::unique_ptr</code> from C++11 or <code>shared_ptr</code> - from TR1, C++11, or Boost. For more information - on the object lifetime management and the smart pointers that we - can use for that, see <a href="#3.3">Section 3.3, "Object - and View Pointers"</a>.</p> + <code>shared_ptr</code> from C++11 or Boost. For more information on the + object lifetime management and the smart pointers that we can use for + that, see <a href="#3.3">Section 3.3, "Object and View Pointers"</a>.</p> <p>With the instantiated object in hand we increment the age and call the <code>update()</code> function to update @@ -2064,7 +2082,7 @@ Hello, Joe! // database so we use the query_one() shortcut instead of // manually iterating over the result returned by query(). // - auto_ptr<person> joe ( + unique_ptr<person> joe ( db->query_one<person> (query::first == "Joe" && query::last == "Dirt")); @@ -2200,7 +2218,7 @@ max age: 33 // Here we know that there can be only one John Doe in our // database so we use the query_one() shortcut again. // - auto_ptr<person> john ( + unique_ptr<person> john ( db->query_one<person> (query::first == "John" && query::last == "Doe")); @@ -2394,7 +2412,7 @@ odb --multi-database dynamic -d common -d mysql -d pgsql \ is how we create the database instance. Specifically, this line:</p> <pre class="cxx"> -auto_ptr<database> db (new odb::mysql::database (argc, argv)); +unique_ptr<database> db (new odb::mysql::database (argc, argv)); </pre> <p>Now our example is capable of storing its data either in MySQL or @@ -2413,7 +2431,7 @@ auto_ptr<database> db (new odb::mysql::database (argc, argv)); // #include <string> -#include <memory> // std::auto_ptr +#include <memory> // std::unique_ptr #include <iostream> #include <odb/database.hxx> @@ -2428,10 +2446,10 @@ auto_ptr<database> db (new odb::mysql::database (argc, argv)); using namespace std; using namespace odb::core; -auto_ptr<database> +unique_ptr<database> create_database (int argc, char* argv[]) { - auto_ptr<database> r; + unique_ptr<database> r; if (argc < 2) { @@ -2456,7 +2474,7 @@ main (int argc, char* argv[]) { try { - auto_ptr<database> db (create_database (argc, argv)); + unique_ptr<database> db (create_database (argc, argv)); if (db.get () == 0) return 1; // Diagnostics has already been issued. @@ -2714,7 +2732,7 @@ class person ... #pragma db id - unsigned long id_; + unsigned long long id_; }; </pre> @@ -2778,7 +2796,7 @@ private: person () {} #pragma db id - unsigned long id_; + unsigned long long id_; std::string name_; }; @@ -2812,15 +2830,15 @@ public: ... - unsigned long id () const; - void id (unsigned long); + unsigned long long id () const; + void id (unsigned long long); const std::string& get_name () const; std::string& set_name (); private: #pragma db id - unsigned long id_; // Uses id() for access. + unsigned long long id_; // Uses id() for access. std::string name_; // Uses get_name()/set_name() for access. }; @@ -2895,15 +2913,15 @@ class name or object relationships. In particular, a dynamically allocated object or view that is returned as a raw pointer from a database operation can be assigned to a smart pointer of our choice, for example - <code>std::auto_ptr</code>, <code>std::unique_ptr</code> from C++11, or - <code>shared_ptr</code> from TR1, C++11, or Boost.</p> + <code>std::auto_ptr</code> (C++98/03 only), <code>std::unique_ptr</code> + from C++11, or <code>shared_ptr</code> from C++11 or Boost.</p> <p>However, to avoid any possibility of a mistake, such as forgetting to use a smart pointer for a returned object or view, as well as to simplify the use of more advanced ODB functionality, such as sessions and bidirectional object relationships, it is recommended that you use smart pointers with the sharing semantics as object pointers. - The <code>shared_ptr</code> smart pointer from TR1, C++11, or Boost + The <code>shared_ptr</code> smart pointer from C++11 or Boost is a good default choice. However, if sharing is not required and sessions are not used, then <code>std::unique_ptr</code> or <code>std::auto_ptr</code> can be used just as well.</p> @@ -2913,7 +2931,7 @@ class name we can use the <code>db pointer</code> pragma, for example:</p> <pre class="cxx"> -#pragma db object pointer(std::tr1::shared_ptr) +#pragma db object pointer(std::shared_ptr) class person { ... @@ -2924,7 +2942,7 @@ class person views at the namespace level:</p> <pre class="cxx"> -#pragma db namespace pointer(std::tr1::shared_ptr) +#pragma db namespace pointer(std::shared_ptr) namespace accounting { #pragma db object @@ -2948,14 +2966,14 @@ namespace accounting The typical usage is shown below:</p> <pre class="terminal"> ---default-pointer std::tr1::shared_ptr +--default-pointer std::shared_ptr </pre> <p>An alternative to this method with the same effect is to specify the default pointer for the global namespace:</p> <pre class="terminal"> -#pragma db namespace() pointer(std::tr1::shared_ptr) +#pragma db namespace() pointer(std::shared_ptr) </pre> <p>Note that we can always override the default pointer specified @@ -2987,13 +3005,13 @@ namespace accounting (namespace)"</a> for more information on these mechanisms.</p> <p>Built-in support that is provided by the ODB runtime library allows us - to use <code>shared_ptr</code> (TR1 or C++11), - <code>std::unique_ptr</code> (C++11), or <code>std::auto_ptr</code> as - pointer types. Plus, ODB profile libraries, that are available for - commonly used frameworks and libraries (such as Boost and Qt), - provide support for smart pointers found in these frameworks and - libraries (<a href="#III">Part III, "Profiles"</a>). It is also - easy to add support for our own smart pointers, as described in + to use <code>std::shared_ptr</code> (C++11), + <code>std::unique_ptr</code> (C++11), or <code>std::auto_ptr</code> + (C++98/03 only) as pointer types. Plus, ODB profile libraries, that are + available for commonly used frameworks and libraries (such as Boost and + Qt), provide support for smart pointers found in these frameworks and + libraries (<a href="#III">Part III, "Profiles"</a>). It is also easy to + add support for our own smart pointers, as described in <a href="#6.5"> Section 6.5, "Using Custom Smart Pointers"</a>.</p> <h2><a name="3.4">3.4 Database</a></h2> @@ -3014,7 +3032,7 @@ namespace accounting #include <odb/database.hxx> #include <odb/mysql/database.hxx> -auto_ptr<odb::database> db ( +unique_ptr<odb::database> db ( new odb::mysql::database ( "test_user" // database login name "test_password" // database password @@ -3206,8 +3224,8 @@ namespace odb class transaction { public: - typedef odb::database database_type; - typedef odb::connection connection_type; + using database_type = odb::database; + using connection_type = odb::connection; explicit transaction (transaction_impl*, bool make_current = true); @@ -3376,11 +3394,11 @@ update_age (database& db, person& p) <pre class="cxx"> void -update_age (database& db, unsigned long id) +update_age (database& db, unsigned long long id) { transaction t (db.begin ()); - auto_ptr<person> p (db.load<person> (id)); + unique_ptr<person> p (db.load<person> (id)); p.age (p.age () + 1); db.update (p); @@ -3452,7 +3470,7 @@ namespace odb class connection { public: - typedef odb::database database_type; + using database_type = odb::database; transaction begin () = 0; @@ -3470,7 +3488,7 @@ namespace odb database (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } </pre> @@ -3668,7 +3686,7 @@ shared_ptr<person> jane (new person ("Jane", "Doe", 32)); transaction t (db.begin ()); db.persist (john); -unsigned long jane_id (db.persist (jane)); +unsigned long long jane_id (db.persist (jane)); t.commit (); @@ -3726,7 +3744,7 @@ cerr << "Jane's id: " << jane_id << endl; <pre class="cxx"> transaction t (db.begin ()); -auto_ptr<person> jane (db.load<person> (jane_id)); +unique_ptr<person> jane (db.load<person> (jane_id)); db.load (jane_id, *jane); @@ -3834,8 +3852,8 @@ t.commit (); <pre class="cxx"> void transfer (database& db, - unsigned long from_acc, - unsigned long to_acc, + unsigned long long from_acc, + unsigned long long to_acc, unsigned int amount) { bank_account from, to; @@ -3963,7 +3981,7 @@ t.commit (); <pre class="cxx"> person& john = ... shared_ptr<jane> jane = ... -unsigned long joe_id = ... +unsigned long long joe_id = ... transaction t (db.begin ()); @@ -4019,7 +4037,7 @@ t.commit (); specify the object type we are erasing. For example:</p> <pre class="cxx"> -typedef odb::query<person> query; +using query = odb::query<person>; transaction t (db.begin ()); @@ -4045,7 +4063,7 @@ t.commit (); classes.</p> <pre class="cxx"> -typedef odb::query<employee> query; +using query = odb::query<employee>; transaction t (db.begin ()); @@ -4630,8 +4648,8 @@ namespace odb introductory chapters. Below is another, more interesting, example:</p> <pre class="cxx"> - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; unsigned short age; query q (query::first == "John" && query::age < query::_ref (age)); @@ -4693,7 +4711,7 @@ namespace odb <code>||</code> (OR), and <code>!</code> (NOT). For example:</p> <pre class="cxx"> - typedef odb::query<person> query; + using query = odb::query<person>; query q (query::first == "John" || query::age == 31); </pre> @@ -4916,8 +4934,8 @@ namespace odb explicitly specify the object type we are querying. For example:</p> <pre class="cxx"> - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; result all (db.query<person> ()); result johns (db.query<person> (query::first == "John")); @@ -4971,9 +4989,9 @@ result r (find_minors (db, query::first == "John")); <code>database::query_value()</code> shortcut functions, for example:</p> <pre class="cxx"> - typedef odb::query<person> query; + using query = odb::query<person>; - auto_ptr<person> p ( + unique_ptr<person> p ( db.query_one<person> ( query::email == "jon@example.com")); </pre> @@ -5060,8 +5078,8 @@ result r (find_minors (db, query::first == "John")); class template, for example:</p> <pre class="cxx"> - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; result johns (db.query<person> (query::first == "John")); </pre> @@ -5086,7 +5104,7 @@ namespace odb class result { public: - typedef odb::result_iterator<T> iterator; + using iterator = odb::result_iterator<T>; public: result (); @@ -5272,7 +5290,7 @@ namespace odb { if (i->last == "Doe") { - auto_ptr p (i.load ()); + unique_ptr p (i.load ()); ... } } @@ -5305,7 +5323,7 @@ namespace odb identifier. For example:</p> <pre class="cxx"> - std::set<unsigned long> set = ...; // Persons of interest. + std::set<unsigned long long> set = ...; // Persons of interest. result r (db.query<person> (query::first == "John")); @@ -5405,8 +5423,8 @@ namespace odb querying. For example:</p> <pre class="cxx"> -typedef odb::query<person> query; -typedef odb::prepared_query<person> prep_query; +using query = odb::query<person>; +using prep_query = odb::prepared_query<person>; prep_query pq ( db.prepare_query<person> ("person-age-query", query::age > 50)); @@ -5516,9 +5534,9 @@ namespace odb <code>odb-examples</code> package.</p> <pre class="cxx"> -typedef odb::query<person> query; -typedef odb::prepared_query<person> prep_query; -typedef odb::result<person> result; +using query = odb::query<person>; +using prep_query = odb::prepared_query<person>; +using result = odb::result<person>; transaction t (db.begin ()); @@ -5604,8 +5622,8 @@ for (age = 90; age > 40; age -= 10) query on the connection. The second overloaded version of <code>cache_query()</code> also takes a pointer to the by-reference query parameters. In C++98/03 it should be - <code>std::auto_ptr</code> while in C++11 <code>std::auto_ptr</code> - or <code>std::unique_ptr</code> can be used. The + <code>std::auto_ptr</code> while in C++11 + — <code>std::unique_ptr</code>. The <code>cache_query()</code> function assumes ownership of the passed <code>params</code> argument. If a prepared query with the same name is already cached on this connection, @@ -5666,7 +5684,7 @@ for (unsigned short age (90); age > 40; age -= 10) if (!pq) { - auto_ptr<unsigned short> p (new unsigned short); + unique_ptr<unsigned short> p (new unsigned short); age_param = p.get (); query q (query::age > query::_ref (*age_param)); pq = db.prepare_query<person> ("person-age-query", q); @@ -5735,7 +5753,7 @@ struct params static void query_factory (const char* name, connection& c) { - auto_ptr<params> p (new params); + unique_ptr<params> p (new params); query q (query::age > query::_ref (p->age) && query::first == query::_ref (p->first)); prep_query pq (c.prepare_query<person> (name, q)); @@ -5761,8 +5779,7 @@ for (unsigned short age (90); age > 40; age -= 10) } </pre> - <p>In C++11 we could have instead used a lambda function as well as - <code>unique_ptr</code> rather than <code>auto_ptr</code>:</p> + <p>Instead of a static function we could have used a lambda:</p> <pre> db.query_factory ( @@ -5916,7 +5933,7 @@ class person ... private: #pragma db id auto - unsigned long id_; + unsigned long long id_; std::vector<std::string> nicknames_; ... @@ -6011,7 +6028,7 @@ class person ... private: #pragma db id auto - unsigned long id_; + unsigned long long id_; std::set<std::string> emails_; ... @@ -6078,7 +6095,7 @@ class person ... private: #pragma db id auto - unsigned long id_; + unsigned long long id_; std::map<unsigned short, float> age_weight_map_; ... @@ -6187,7 +6204,7 @@ p.names.pop_back (); { transaction t (db.begin ()); - auto_ptr<person> p1 (db.load<person> (...)); // Start change tracking. + unique_ptr<person> p1 (db.load<person> (...)); // Start change tracking. p1->names.insert (p1->names.begin (), "Joe Do"); db.update (*p1); // One UPDATE, one INSERT; reset change state. t.commit (); @@ -6304,7 +6321,7 @@ for (;;) <pre class="cxx"> namespace odb { - template <class T, class A = std::allocator<T> > + template <class T, class A = std::allocator<T>> class vector { ... @@ -6329,7 +6346,7 @@ namespace odb // Iterators. // - typedef typename std::vector<T, A>::const_iterator const_iterator; + using const_iterator = typename std::vector<T, A>::const_iterator; class iterator { @@ -6469,19 +6486,19 @@ std::sort (v.mbegin (), v.mend ()); <p>Relationships between persistent objects are expressed with pointers or containers of pointers. The ODB runtime library provides built-in support - for <code>shared_ptr</code>/<code>weak_ptr</code> (TR1 or C++11), + for <code>std::shared_ptr</code>/<code>std::weak_ptr</code> (C++11), <code>std::unique_ptr</code> (C++11), - <code>std::auto_ptr</code>, and raw pointers. Plus, ODB profile - libraries, that are available for commonly used frameworks and libraries - (such as Boost and Qt), provide support for smart pointers found in these - frameworks and libraries (<a href="#III">Part III, "Profiles"</a>). It is - also easy to add support for a custom smart pointer as discussed later - in <a href="#6.5"> Section 6.5, "Using Custom Smart Pointers"</a>. Any - supported smart pointer can be used in a data member as long as it can be - explicitly constructed from the canonical object pointer - (<a href="#3.3">Section 3.3, "Object and View Pointers"</a>). For - example, we can use <code>weak_ptr</code> if the object pointer - is <code>shared_ptr</code>.</p> + <code>std::auto_ptr</code> (C++98/03 only), and raw pointers. Plus, ODB + profile libraries, that are available for commonly used frameworks and + libraries (such as Boost and Qt), provide support for smart pointers + found in these frameworks and libraries (<a href="#III">Part III, + "Profiles"</a>). It is also easy to add support for a custom smart + pointer as discussed later in <a href="#6.5"> Section 6.5, "Using Custom + Smart Pointers"</a>. Any supported smart pointer can be used in a data + member as long as it can be explicitly constructed from the canonical + object pointer (<a href="#3.3">Section 3.3, "Object and View + Pointers"</a>). For example, we can use <code>weak_ptr</code> if the + object pointer is <code>shared_ptr</code>.</p> <p>When an object containing a pointer to another object is loaded, the pointed-to object is loaded as well. In some situations this @@ -6498,8 +6515,8 @@ std::sort (v.mbegin (), v.mend ()); <p>As a simple example, consider the following employee-employer relationship. Code examples presented in this chapter - will use the <code>shared_ptr</code> and <code>weak_ptr</code> - smart pointers from the TR1 (<code>std::tr1</code>) namespace.</p> + will use the C++11 <code>shared_ptr</code> and <code>weak_ptr</code> + smart pointers from the <code>std</code> namespace.</p> <pre class="cxx"> #pragma db object @@ -6517,7 +6534,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; std::string first_name_; std::string last_name_; @@ -6545,7 +6562,7 @@ class employee shared_ptr<employer> current_employer_; #pragma db value_not_null - std::vector<shared_ptr<employer> > previous_employers_; + std::vector<shared_ptr<employer>> previous_employers_; }; </pre> @@ -6563,7 +6580,7 @@ class employee <pre class="cxx"> // Create an employer and a few employees. // -unsigned long john_id, jane_id; +unsigned long long john_id, jane_id; { shared_ptr<employer> er (new employer ("Example Inc")); shared_ptr<employee> john (new employee ("John", "Doe")); @@ -6630,8 +6647,8 @@ unsigned long john_id, jane_id; employees of Example Inc that have the Doe last name:</p> <pre class="cxx"> -typedef odb::query<employee> query; -typedef odb::result<employee> result; +using query = odb::query<employee>; +using result = odb::result<employee>; session s; transaction t (db.begin ()); @@ -6720,7 +6737,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<employer> employer_; @@ -6761,10 +6778,10 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db value_not_null unordered - std::vector<shared_ptr<project> > projects_; + std::vector<shared_ptr<project>> projects_; }; </pre> @@ -6794,7 +6811,7 @@ class employee #pragma db value_not_null unordered \ id_column("employee_id") value_column("project_name") - std::vector<shared_ptr<project> > projects_; + std::vector<shared_ptr<project>> projects_; }; </pre> @@ -6826,7 +6843,7 @@ class position ... #pragma db id - unsigned long id_; + unsigned long long id_; weak_ptr<employee> employee_; }; @@ -6837,7 +6854,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<position> position_; @@ -7024,7 +7041,7 @@ class position ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db inverse(position_) weak_ptr<employee> employee_; @@ -7036,7 +7053,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<position> position_; @@ -7085,7 +7102,7 @@ class employer std::string name_; #pragma db value_not_null inverse(employer_) - std::vector<weak_ptr<employee> > employees_ + std::vector<weak_ptr<employee>> employees_ }; #pragma db object @@ -7094,7 +7111,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<employer> employer_; @@ -7150,7 +7167,7 @@ class project std::string name_; #pragma db value_not_null inverse(projects_) - std::vector<weak_ptr<employee> > employees_; + std::vector<weak_ptr<employee>> employees_; }; #pragma db object @@ -7159,10 +7176,10 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db value_not_null unordered - std::vector<shared_ptr<project> > projects_; + std::vector<shared_ptr<project>> projects_; }; </pre> @@ -7230,7 +7247,7 @@ class position ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db inverse(position_) weak_ptr<employee> employee_; @@ -7248,7 +7265,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<position> position_; @@ -7366,7 +7383,7 @@ class employer std::string name_; #pragma db value_not_null inverse(employer_) - std::vector<weak_ptr<employee> > employees_; + std::vector<weak_ptr<employee>> employees_; }; #pragma db object @@ -7375,7 +7392,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; #pragma db not_null shared_ptr<employer> employer_; @@ -7386,7 +7403,7 @@ class employee name given the employee id:</p> <pre class="cxx"> -unsigned long id = ... +unsigned long long id = ... string name; session s; @@ -7419,16 +7436,12 @@ t.commit (); supported pointers, namely: <code>odb::lazy_shared_ptr</code>/<code>lazy_weak_ptr</code> for C++11 <code>std::shared_ptr</code>/<code>weak_ptr</code>, - <code>odb::tr1::lazy_shared_ptr</code>/<code>lazy_weak_ptr</code> - for TR1 <code>std::tr1::shared_ptr</code>/<code>weak_ptr</code>, <code>odb::lazy_unique_ptr</code> for C++11 <code>std::unique_ptr</code>, - <code>odb::lazy_auto_ptr</code> for <code>std::auto_ptr</code>, - and <code>odb::lazy_ptr</code> for raw pointers. The TR1 lazy - pointers are defined in the <code><odb/tr1/lazy-ptr.hxx></code> - header while all the others — in - <code><odb/lazy-ptr.hxx></code>. The ODB profile - libraries also provide lazy pointer implementations for smart pointers - from popular frameworks and libraries (<a href="#III">Part III, + <code>odb::lazy_auto_ptr</code> for C++98/03 <code>std::auto_ptr</code>, + and <code>odb::lazy_ptr</code> for raw pointers. All these lazy pointers + are defined in the <code><odb/lazy-ptr.hxx></code> header. The ODB + profile libraries also provide lazy pointer implementations for smart + pointers from popular frameworks and libraries (<a href="#III">Part III, "Profiles"</a>).</p> <p>While we will discuss the interface of lazy pointers in more detail @@ -7454,7 +7467,7 @@ class employer ... #pragma db value_not_null inverse(employer_) - std::vector<lazy_weak_ptr<employee> > employees_; + std::vector<lazy_weak_ptr<employee>> employees_; }; #pragma db object @@ -7470,7 +7483,7 @@ class employee <p>And the transaction is changed like this:</p> <pre class="cxx"> -unsigned long id = ... +unsigned long long id = ... string name; session s; @@ -7571,7 +7584,7 @@ public: presented earlier.</p> <pre class="cxx"> -typedef std::vector<lazy_weak_ptr<employee> > employees; +using employees = std::vector<lazy_weak_ptr<employee>>; session s; transaction t (db.begin ()); @@ -7821,7 +7834,7 @@ class basic_name std::string last_; }; -typedef std::vector<basic_name> basic_names; +using basic_names = std::vector<basic_name>; #pragma db value class name_extras @@ -7886,7 +7899,7 @@ struct point T z; }; -typedef point<int> int_point; +using int_point = point<int>; #pragma db value(int_point) #pragma db object @@ -7901,7 +7914,7 @@ class object <p>Note that the database support code for such a composite value type is generated when compiling the header containing the <code>db value</code> pragma and not the header containing - the template definition or the <code>typedef</code> name. This + the template definition or the <code>using</code> alias. This allows us to use templates defined in other files, such as <code>std::pair</code> defined in the <code>utility</code> standard header file:</p> @@ -7909,7 +7922,7 @@ class object <pre class="cxx"> #include <utility> // std::pair -typedef std::pair<std::string, std::string> phone_numbers; +using phone_numbers = std::pair<std::string, std::string>; #pragma db value(phone_numbers) #pragma db object @@ -7938,8 +7951,8 @@ class person objects. For example:</p> <pre class="cxx"> -typedef odb::query<person> query; -typedef odb::result<person> result; +using query = odb::query<person>; +using result = odb::result<person>; transaction t (db.begin ()); @@ -8009,7 +8022,7 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; name name_; }; @@ -8224,7 +8237,7 @@ namespace odb class nullable { public: - typedef T value_type; + using value_type = T; nullable (); nullable (const T&); @@ -8323,19 +8336,19 @@ class person std::string first_; #pragma db null - std::auto_ptr<std::string> middle_; + std::unique_ptr<std::string> middle_; std::string last_; }; </pre> <p>The ODB compiler includes built-in support for using - <code>std::auto_ptr</code>, <code>std::unique_ptr</code> (C++11), - and <code>shared_ptr</code> (TR1 or C++11) as pointers to values. - Plus, ODB profile libraries, that are - available for commonly used frameworks and libraries (such as Boost and - Qt), provide support for smart pointers found in these frameworks - and libraries (<a href="#III">Part III, "Profiles"</a>).</p> + <code>std::auto_ptr</code> (C++98/03 only), <code>std::unique_ptr</code> + (C++11), and <code>std::shared_ptr</code> (C++11) as pointers to values. + Plus, ODB profile libraries, that are available for commonly used + frameworks and libraries (such as Boost and Qt), provide support for + smart pointers found in these frameworks and libraries + (<a href="#III">Part III, "Profiles"</a>).</p> <p>ODB also supports the <code>NULL</code> semantics for composite values. In the relational database the <code>NULL</code> composite @@ -8372,7 +8385,7 @@ class person { ... - std::auto_ptr<std::vector<std::string> > aliases_; + std::unique_ptr<std::vector<std::string>> aliases_; }; </pre> @@ -8546,7 +8559,7 @@ class employee: public person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; }; // Concrete permanent_employee class. Note that it doesn't define @@ -8655,7 +8668,7 @@ employee e; person& r1 (p); person& r2 (e); -auto_ptr<person> p1 (new employee); +unique_ptr<person> p1 (new employee); </pre> <p>In the above example, the <code>r1</code> reference's both static @@ -8692,7 +8705,7 @@ class person ~person () = 0; // Automatically abstract. #pragma db id auto - unsigned long id_; + unsigned long long id_; std::string first_; std::string last_; @@ -8765,7 +8778,7 @@ class contractor: public person example:</p> <pre class="cxx"> -unsigned long id1, id2; +unsigned long long id1, id2; // Persist. // @@ -8793,8 +8806,8 @@ unsigned long id1, id2; // Query. // { - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; transaction t (db.begin ()); @@ -8853,8 +8866,8 @@ unsigned long id1, id2; instantiating the object. For example:</p> <pre class="cxx"> -typedef odb::query<person> query; -typedef odb::result<person> result; +using query = odb::query<person>; +using result = odb::result<person>; transaction t (db.begin ()); @@ -8944,7 +8957,7 @@ CREATE TABLE contractor ( difference:</p> <pre class="cxx"> -unsigned long id; +unsigned long long id; { employee e (...); @@ -9066,7 +9079,7 @@ struct contractor_manager be used in the query condition. For example:</p> <pre class="cxx"> -typedef odb::query<employee> query; +using query = odb::query<employee>; transaction t (db.begin ()); db.erase_query<employee> (query::permanent); // Ok. @@ -9142,7 +9155,7 @@ class person transaction t (db.begin ()); -auto_ptr<person> p (db.load<person> (...)); // Keys are not loaded. +unique_ptr<person> p (db.load<person> (...)); // Keys are not loaded. if (need_keys) { @@ -9371,7 +9384,7 @@ private: ... }; -auto_ptr<person> p (db.load<person> (...)); +unique_ptr<person> p (db.load<person> (...)); section s (p->keys ()); db.load (*p, s); // Throw section_not_in_object, copy. @@ -9408,7 +9421,7 @@ private: ... }; -auto_ptr<person> p (db.load<person> (...)); +unique_ptr<person> p (db.load<person> (...)); section& s (p->keys ()); db.load (*p, s); // Ok, reference. @@ -9462,7 +9475,7 @@ person p ("John", "Doe"); // Section state is undefined (transient). db.persist (p); // Section state: loaded, unchanged. -auto_ptr<person> l ( +unique_ptr<person> l ( db.load<person> (...)); // Section state: unloaded, unchanged. db.update (*l); // Section not updated since not loaded. @@ -9496,7 +9509,7 @@ class person { ... - typedef std::array<char, 1024> key_type; + using key_type = std::array<char, 1024>; const key_type& public_key () const {return public_key_;} @@ -9543,7 +9556,7 @@ private: the previous example):</p> <pre class="cxx"> -auto_ptr<person> p; +unique_ptr<person> p; try { @@ -9601,7 +9614,7 @@ class employee: public person transaction t (db.begin ()); -auto_ptr<person> p (db.load<person> (...)); // Person or employee. +unique_ptr<person> p (db.load<person> (...)); // Person or employee. db.load (*p, p->print_); // Load data members needed for print. p->print (); @@ -9645,7 +9658,7 @@ class manager: public employee ... }; -auto_ptr<manager> m (db.load<manager> (...)); +unique_ptr<manager> m (db.load<manager> (...)); person& p (*m); employee& e (*m); @@ -9681,7 +9694,7 @@ class person std::string bio_; }; -auto_ptr<person> p; +unique_ptr<person> p; { transaction t (db.begin ()); @@ -9773,7 +9786,7 @@ class employee transaction t (db.begin ()); -auto_ptr<employee> e (db.load<employee> (...)); // employer_ is NULL. +unique_ptr<employee> e (db.load<employee> (...)); // employer_ is NULL. db.load (*e, e->extras_); // employer_ contains valid employer id. @@ -9805,7 +9818,7 @@ class person transaction t (db.begin ()); -auto_ptr<person> p (db.load<person> (...)); +unique_ptr<person> p (db.load<person> (...)); db.load (*p, p->extras_); p->nicknames_.push_back ("JD"); @@ -9866,7 +9879,7 @@ class employer ... #pragma db id - unsigned long id_; + unsigned long long id_; std::string name_; }; @@ -9877,7 +9890,7 @@ class employee ... #pragma db id - unsigned long id_; + unsigned long long id_; std::string first_; std::string last_; @@ -9939,8 +9952,8 @@ struct employee_name employees that are younger than 31:</p> <pre class="cxx"> -typedef odb::query<employee_name> query; -typedef odb::result<employee_name> result; +using query = odb::query<employee_name>; +using result = odb::result<employee_name>; transaction t (db.begin ()); @@ -10219,7 +10232,7 @@ struct employee_count querying the database for an object. For example:</p> <pre class="cxx"> -typedef odb::query<employee_count> query; +using query = odb::query<employee_count>; transaction t (db.begin ()); @@ -10269,8 +10282,8 @@ struct employee_employer For example:</p> <pre class="cxx"> -typedef odb::result<employee_employer> result; -typedef odb::query<employee_employer> query; +using result = odb::result<employee_employer>; +using query = odb::query<employee_employer>; transaction t (db.begin ()); @@ -10302,8 +10315,8 @@ struct employee_country country of residence and nationality:</p> <pre class="cxx"> -typedef odb::query<employee_country> query; -typedef odb::result<employee_country> result; +using query = odb::query<employee_country>; +using result = odb::result<employee_country>; transaction t (db.begin ()); @@ -10321,8 +10334,8 @@ t.commit (); the following query is invalid:</p> <pre class="cxx"> -typedef odb::query<employee_name> query; -typedef odb::result<employee_name> result; +using query = odb::query<employee_name>; +using result = odb::result<employee_name>; transaction t (db.begin ()); @@ -10387,7 +10400,7 @@ struct employee_employer point to the loaded objects. For example:</p> <pre class="cxx"> -typedef odb::query<employee_employer> query; +using query = odb::query<employee_employer>; transaction t (db.begin ()); @@ -10419,7 +10432,7 @@ struct employer_view employ seniors:</p> <pre class="cxx"> -typedef odb::query<employer_view> query; +using query = odb::query<employer_view>; db.query<employer_view> (query::employee::age > 65) </pre> @@ -10526,7 +10539,7 @@ struct employee_employer of our transaction that uses the <code>employee_employer</code> view:</p> <pre class="cxx"> -typedef odb::query<employee_employer> query; +using query = odb::query<employee_employer>; transaction t (db.begin ()); odb::session s; @@ -10586,7 +10599,7 @@ t.commit (); object(country = res: employee::residence_) transient struct employee_res_country { - typedef country* country_ptr; + using country_ptr = country*; #pragma db member(res_) virtual(country_ptr) get(&this.res) \ set(this.res_null = ((?) == nullptr)) @@ -10617,7 +10630,7 @@ struct employee_res_country object(country = res: employee::residence_) transient struct employee_res_country { - typedef country* country_ptr; + using country_ptr = country*; #pragma db member(res_) virtual(country_ptr) get(&this.res) set() @@ -10648,7 +10661,7 @@ struct employee_country <p>And here is how we can use this view:</p> <pre class="cxx"> -typedef odb::result<employee_country> result; +using result = odb::result<employee_country>; transaction t (db.begin ()); @@ -10762,7 +10775,7 @@ struct view struct employee_vacation { #pragma db column("employee_id") type("INTEGER") - unsigned long employee_id; + unsigned long long employee_id; #pragma db column("vacation_days") type("INTEGER") unsigned short vacation_days; @@ -10873,7 +10886,7 @@ CREATE TABLE employee_health( struct employee_leave { #pragma db column("extra.employee_id") type("INTEGER") - unsigned long employee_id; + unsigned long long employee_id; #pragma db column("vacation_days") type("INTEGER") unsigned short vacation_days; @@ -10888,8 +10901,8 @@ struct employee_leave For example:</p> <pre class="cxx"> -typedef odb::query<employee_leave> query; -typedef odb::result<employee_leave> result; +using query = odb::query<employee_leave>; +using result = odb::result<employee_leave>; transaction t (db.begin ()); @@ -10932,8 +10945,8 @@ struct employee_vacation involve table columns. For example:</p> <pre class="cxx"> -typedef odb::query<employee_vacation> query; -typedef odb::result<employee_vacation> result; +using query = odb::query<employee_vacation>; +using result = odb::result<employee_vacation>; transaction t (db.begin ()); @@ -11126,7 +11139,7 @@ struct employer_info struct employee_vacation { #pragma db type("INTEGER") - unsigned long employee_id; + unsigned long long employee_id; #pragma db type("INTEGER") unsigned short vacation_days; @@ -11223,8 +11236,8 @@ struct sequence_value <p>Given this view, we can perform the following queries:</p> <pre class="cxx"> -typedef odb::query<sequence_value> query; -typedef odb::result<sequence_value> result; +using query = odb::query<sequence_value>; +using result = odb::result<sequence_value>; string seq_name = ... @@ -11529,7 +11542,7 @@ shared_ptr<person> p (new person ("John", "Doe")); session s; transaction t (db.begin ()); -unsigned long id (db.persist (p)); // p is cached in s. +unsigned long long id (db.persist (p)); // p is cached in s. shared_ptr<person> p1 (db.load<person> (id)); // p1 same as p. t.commit (); @@ -11568,7 +11581,7 @@ void save (database& db, shared_ptr<const person> p) session s; shared_ptr<const person> p1 (new const person ("John", "Doe")); -unsigned long id1 (save (db, p1)); // p1 is cached in s as non-const. +unsigned long long id1 (save (db, p1)); // p1 is cached in s as non-const. { transaction t (db.begin ()); @@ -11578,7 +11591,7 @@ unsigned long id1 (save (db, p1)); // p1 is cached in s as non-const. } shared_ptr<const person> p2 (new person ("Jane", "Doe")); -unsigned long id2 (save (db, p2)); // p2 is cached in s as non-const. +unsigned long long id2 (save (db, p2)); // p2 is cached in s as non-const. { transaction t (db.begin ()); @@ -11751,7 +11764,7 @@ public: updating the object in another database transaction. For example:</p> <pre class="cxx"> -unsigned long id = ...; +unsigned long long id = ...; person p; { @@ -11811,7 +11824,7 @@ class person ... #pragma db version - unsigned long version_; + unsigned long long version_; }; </pre> @@ -11834,7 +11847,7 @@ class person ... #pragma db version - const unsigned long version_; + const unsigned long long version_; }; </pre> @@ -11857,7 +11870,7 @@ class person transaction using the second recovery option:</p> <pre class="cxx"> -unsigned long id = ...; +unsigned long long id = ...; person p; { @@ -11909,7 +11922,7 @@ p.age (age); application transaction:</p> <pre class="cxx"> -unsigned long id = ...; +unsigned long long id = ...; person p; { @@ -11938,7 +11951,7 @@ if (answer == "yes") using optimistic concurrency:</p> <pre class="cxx"> -unsigned long id = ...; +unsigned long long id = ...; person p; { @@ -12274,7 +12287,7 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; std::string first_; std::string last_; @@ -12321,7 +12334,7 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; std::string first_; std::string middle_; @@ -12746,7 +12759,7 @@ CREATE TABLE "schema_version" ( <pre class="cxx"> namespace odb { - typedef unsigned long long schema_version; + using schema_version = unsigned long long; struct LIBODB_EXPORT schema_version_migration { @@ -13231,7 +13244,7 @@ namespace odb schema_version = 0, const std::string& name = ""); - typedef void data_migration_function_type (database&); + using data_migration_function_type = void (database&); // Common (for all the databases) data migration, C++98/03 version: // @@ -13615,7 +13628,7 @@ class person static void migrate_gender (odb::database& db) { - typedef odb::query<person> query; + using query = odb::query<person>; for (person& p: db.query<person> (query::gender.is_null ())) { @@ -13699,7 +13712,7 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; #pragma db deleted(4) std::string first_; @@ -13762,7 +13775,7 @@ private: friend class odb::access; #pragma db id auto - unsigned long id_; + unsigned long long id_; #pragma db deleted(4) std::string first_; @@ -13837,7 +13850,7 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; #pragma db added(4) std::string name_; @@ -13907,7 +13920,7 @@ class employee ... #pragma db id auto - unsigned long id_; + unsigned long long id_; std::string name_; gender gender_; @@ -14135,7 +14148,7 @@ class person ... private: #pragma db member id - unsigned long id_; + unsigned long long id_; ... }; </pre> @@ -14149,7 +14162,7 @@ private: <pre class="cxx"> #pragma db id - unsigned long id_; + unsigned long long id_; </pre> <p>Note also that if the C++ declaration immediately following a @@ -14158,7 +14171,7 @@ private: <pre class="cxx"> #pragma db object // Error: expected class instead of data member. - unsigned long id_; + unsigned long long id_; </pre> <p>While keeping the C++ declarations and database declarations close @@ -14174,7 +14187,7 @@ class person { ... private: - unsigned long id_; + unsigned long long id_; ... }; @@ -14194,7 +14207,7 @@ namespace db { ... private: - unsigned long id_; + unsigned long long id_; ... }; } @@ -14412,7 +14425,7 @@ class person class. For example:</p> <pre class="cxx"> -#pragma db object pointer(std::tr1::shared_ptr<person>) +#pragma db object pointer(std::shared_ptr<person>) class person { ... @@ -14428,7 +14441,7 @@ class person equivalent to the one above:</p> <pre class="cxx"> -#pragma db object pointer(std::tr1::shared_ptr) +#pragma db object pointer(std::shared_ptr) class person { ... @@ -14532,7 +14545,7 @@ class person ... #pragma db version - unsigned long version_; + unsigned long long version_; }; </pre> @@ -15434,9 +15447,7 @@ class person columns that allow <code>NULL</code> values. For example:</p> <pre class="cxx"> -using std::tr1::shared_ptr; - -typedef shared_ptr<std::string> string_ptr; +using string_ptr = std::shared_ptr<std::string>; #pragma db value(string_ptr) type("TEXT") null #pragma db object @@ -15447,7 +15458,7 @@ class person string_ptr name_; // Mapped to TEXT NULL. }; -typedef shared_ptr<person> person_ptr; +using person_ptr = std::shared_ptr<person>; #pragma db value(person_ptr) not_null </pre> @@ -15644,7 +15655,7 @@ class object not be the same as the order in which they were stored. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> names; +using names = std::vector<std::string>; #pragma db value(names) unordered </pre> @@ -15662,7 +15673,7 @@ typedef std::vector<std::string> names; database type is expected to be an integer type. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> names; +using names = std::vector<std::string>; #pragma db value(names) index_type("SMALLINT UNSIGNED") </pre> @@ -15676,7 +15687,7 @@ typedef std::vector<std::string> names; example:</p> <pre class="cxx"> -typedef std::map<unsigned short, float> age_weight_map; +using age_weight_map = std::map<unsigned short, float>; #pragma db value(age_weight_map) key_type("INT UNSIGNED") </pre> @@ -15690,7 +15701,7 @@ typedef std::map<unsigned short, float> age_weight_map; example:</p> <pre class="cxx"> -typedef std::vector<std::string> names; +using names = std::vector<std::string>; #pragma db value(names) value_type("VARCHAR(255)") </pre> @@ -15711,15 +15722,13 @@ typedef std::vector<std::string> names; For example:</p> <pre class="cxx"> -using std::tr1::shared_ptr; - #pragma db object class account { ... }; -typedef std::vector<shared_ptr<account> > accounts; +using accounts = std::vector<std::shared_ptr<account>>; #pragma db value(accounts) value_not_null </pre> @@ -15735,7 +15744,7 @@ typedef std::vector<shared_ptr<account> > accounts; id column. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> nicknames; +using nicknames = std::vector<std::string>; #pragma db value(nicknames) id_options("COLLATE binary") </pre> @@ -15752,7 +15761,7 @@ typedef std::vector<std::string> nicknames; index column. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> nicknames; +using nicknames = std::vector<std::string>; #pragma db value(nicknames) index_options("ZEROFILL") </pre> @@ -15769,7 +15778,7 @@ typedef std::vector<std::string> nicknames; key column. For example:</p> <pre class="cxx"> -typedef std::map<std::string, std::string> properties; +using properties = std::map<std::string, std::string>; #pragma db value(properties) key_options("COLLATE binary") </pre> @@ -15786,7 +15795,7 @@ typedef std::map<std::string, std::string> properties; value column. For example:</p> <pre class="cxx"> -typedef std::set<std::string> nicknames; +using nicknames = std::set<std::string>; #pragma db value(nicknames) value_options("COLLATE binary") </pre> @@ -15803,7 +15812,7 @@ typedef std::set<std::string> nicknames; container's table. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> names; +using names = std::vector<std::string>; #pragma db value(names) id_column("id") </pre> @@ -15817,7 +15826,7 @@ typedef std::vector<std::string> names; ordered container's table. For example:</p> <pre class="cxx"> -typedef std::vector<std::string> names; +using names = std::vector<std::string>; #pragma db value(names) index_column("name_number") </pre> @@ -15831,7 +15840,7 @@ typedef std::vector<std::string> names; container's table. For example:</p> <pre class="cxx"> -typedef std::map<unsigned short, float> age_weight_map; +using age_weight_map = std::map<unsigned short, float>; #pragma db value(age_weight_map) key_column("age") </pre> @@ -15845,7 +15854,7 @@ typedef std::map<unsigned short, float> age_weight_map; container's table. For example:</p> <pre class="cxx"> -typedef std::map<unsigned short, float> age_weight_map; +using age_weight_map = std::map<unsigned short, float>; #pragma db value(age_weight_map) value_column("weight") </pre> @@ -16086,6 +16095,12 @@ typedef std::map<unsigned short, float> age_weight_map; <td><a href="#14.4.36">14.4.36</a></td> </tr> + <tr> + <td><code>points_to</code></td> + <td>establish relationship without object pointer</td> + <td><a href="#14.4.37">14.4.37</a></td> + </tr> + </table> <p>Many of the member specifiers have corresponding value type @@ -16137,16 +16152,15 @@ class person ... #pragma db id auto - unsigned long id_; + unsigned long long id_; }; </pre> - <p>Note that automatically-assigned object ids are not reused. - If you have a high object turnover (that is, objects are routinely - made persistent and then erased), then care must be taken not to - run out of object ids. In such situations, using - <code>unsigned long long</code> as the identifier type - is a safe choice.</p> + <p>Note that automatically-assigned object ids are not reused. If you have + a high object turnover (that is, objects are routinely made persistent + and then erased), then care must be taken not to run out of object + ids. In such situations, using a 64-bit integer as the identifier type is + a safe choice.</p> <p>For additional information on the automatic identifier assignment, refer to <a href="#3.8">Section 3.8, "Making Objects Persistent"</a>.</p> @@ -16308,21 +16322,29 @@ private: single or multiple (separated by semicolon) C++ statements with the effect of setting the new member value.</p> - <p>There are two special placeholders that are recognized by the + <p>There are three special placeholders that are recognized by the ODB compiler in accessor and modifier expressions. The first is the <code>this</code> keyword which denotes a reference (note: not a pointer) to the persistent object. In accessor expressions this reference is <code>const</code> while in modifier expressions it is non-<code>const</code>. If an expression does not contain the <code>this</code> placeholder, - then the ODB compiler automatically prefixes it with <code>this.</code> - sequence.</p> + then the ODB compiler automatically prefixes it with the + <code>this.</code> sequence.</p> <p>The second placeholder, the <code>(?)</code> sequence, is used to denote the new value in by-value modifier expressions. The ODB compiler replaces the question mark with the variable name, - keeping the surrounding parenthesis. The following example shows - a few more interesting accessor and modifier expressions:</p> + keeping the surrounding parenthesis.</p> + + <p>The third placeholder, the <code>(!)</code> sequence, is used to denote + the database instance in the modifier expressions. The ODB compiler + replaces the exclamation mark with the reference to the database, + keeping the surrounding parenthesis. The database instance can, for + example, be used to load an object pointer.</p> + + <p>The following example shows a few more interesting accessor and + modifier expressions:</p> <pre class="cxx"> #pragma db value @@ -16461,8 +16483,6 @@ private: to columns that allow <code>NULL</code> values. For example:</p> <pre class="cxx"> -using std::tr1::shared_ptr; - #pragma db object class person { @@ -16478,7 +16498,7 @@ class account ... #pragma db not_null - shared_ptr<person> holder_; + std::shared_ptr<person> holder_; }; </pre> @@ -16682,7 +16702,7 @@ class person ... #pragma db id column("person_id") - unsigned long id_; + unsigned long long id_; }; </pre> @@ -16800,7 +16820,7 @@ class person { ... - const std::auto_ptr<const date> born_; + const std::unique_ptr<const date> born_; }; </pre> @@ -16896,6 +16916,34 @@ class person #pragma db member(person::name) virtual(std::string) access(name_) </pre> + <p>The order of data members determines the order of columns in the + resulting table. The order of virtual data members in relation to other + data members (virtual or not) is the order of declaration, with virtual + data members declared outside of the class coming last. This order, + however, can be adjusted with the <code>before</code> + and <code>after</code> specifiers. One of these specifiers without a + parameter places the virtual member at the beginning or at the end of the + members list, respectively. Alternatively, we can specify the member + (virtual or not) before/after which this virtual member should be + placed. For example:</p> + + <pre class="cxx"> +#pragma db object +class person +{ + ... + + #pragma db id auto + unsigned long long id_; + + #pragma db member(first) virtual(std::string) before + #pragma db member(last) virtual(std::string) after(first) +}; + </pre> + + <p>The order of columns in the resulting table will be: <code>first</code>, + <code>last</code>, <code>id</code>.</p> + <p>While in the above examples using virtual data members doesn't seem to yield any benefits, this mechanism can be useful in a number of situations. As one example, consider the need to @@ -17060,26 +17108,23 @@ private: member name in the referenced object. For example:</p> <pre class="cxx"> -using std::tr1::shared_ptr; -using std::tr1::weak_ptr; - class person; -#pragma db object pointer(shared_ptr) +#pragma db object pointer(std::shared_ptr) class employer { ... - std::vector<shared_ptr<person> > employees_; + std::vector<std::shared_ptr<person>> employees_; }; -#pragma db object pointer(shared_ptr) +#pragma db object pointer(std::shared_ptr) class person { ... #pragma db inverse(employee_) - weak_ptr<employer> employer_; + std::weak_ptr<employer> employer_; }; </pre> @@ -17117,7 +17162,7 @@ class employer ... #pragma db id auto - unsigned long id_; + unsigned long long id_; }; #pragma db object @@ -17129,7 +17174,7 @@ class person employer* employer_; }; -unsigned long id; +unsigned long long id; { employer e; @@ -17234,16 +17279,15 @@ class person ... #pragma db version - unsigned long version_; + unsigned long long version_; }; </pre> - <p>A version member must be of an integral C++ type and must map to - an integer or similar database type. Note also that object versions - are not reused. If you have a high update frequency, then care must - be taken not to run out of versions. In such situations, using - <code>unsigned long long</code> as the version type is a safe - choice.</p> + <p>A version member must be of an integral C++ type and must map to an + integer or similar database type. Note also that object versions are not + reused. If you have a high update frequency, then care must be taken not + to run out of versions. In such situations, using a 64-bit integer as the + version type is a safe choice.</p> <p>For a more detailed discussion of optimistic concurrency, refer to <a href="#12">Chapter 12, "Optimistic Concurrency"</a>.</p> @@ -17469,8 +17513,6 @@ class person For example:</p> <pre class="cxx"> -using std::tr1::shared_ptr; - #pragma db object class person { @@ -17483,7 +17525,7 @@ class account ... #pragma db value_not_null - std::vector<shared_ptr<person> > holders_; + std::vector<std::shared_ptr<person>> holders_; }; </pre> @@ -17674,6 +17716,32 @@ class person <p>If the column name is not specified, then <code>value</code> is used by default.</p> + <h3><a name="14.4.37">14.4.37 <code>points_to</code></a></h3> + + <p>The <code>points_to</code> specifier allows the establishment of + object relationships without using object pointers. For example:</p> + +<pre class="cxx"> + +#pragma db object +class employer +{ + ... + + #pragma db id + std::string id_; +}; + +#pragma db object +class person +{ + ... + + #pragma db points_to(employer) + std::string employer_; +}; + </pre> + <h2><a name="14.5">14.5 Namespace Pragmas</a></h2> <p>A pragma with the <code>namespace</code> qualifier describes a @@ -17741,7 +17809,7 @@ namespace test example:</p> <pre class="cxx"> -#pragma db namespace pointer(std::tr1::shared_ptr) +#pragma db namespace pointer(std::shared_ptr) namespace accounting { #pragma db object @@ -18133,7 +18201,104 @@ class object <h2><a name="14.8">14.8 Database Type Mapping Pragmas</a></h2> - <p>A pragma with the <code>map</code> qualifier describes a + <p>A pragma with the <code>map</code> qualifier describes a mapping between + either two C++ types (<a href="#14.8.1">Section 14.8.1, "C++ Type Mapping + Pragmas"</a>) or two database types (<a href="#14.8.2">Section 14.8.2, + "Database Type Mapping Pragmas"</a>).</p> + + <h3><a name="14.8.1">14.8.1 C++ Type Mapping Pragmas</a></h3> + + <p>A pragma with the <code>map</code> qualifier can describe a mapping + between two C++ types. For each database system ODB provides built-in + support for mapping a standard set of C++ types, such as integers, + strings, binary, etc. However, many codebases may use custom versions of + corresponding (or similar) C++ types. While it is possible to add support + for such custom types by providing a suitable specialization of the + <code>value_traits</code> class template, it is often simpler to define + their mapping in terms of one of the already supported types by + specifying the conversion between the two types. This mechanism can also + be used to redefine the mapping for one of the standard types. For + example, we could map <code>bool</code> to <code>std::string</code> in + order to save boolean values as string literals. This mechanism can also + be used with composite value types.</p> + + <p>The <code>map</code> pragma for C++ types has the following format:</p> + +<pre class="cxx"> +#pragma db map type(<name>) \ + as(<name>) \ + [to(<expr>)] \ + [from(<expr>)] +</pre> + + <p>The <code>type</code> clause specifies the name of the C++ type + that we are mapping. We will refer to it as the <em>mapped type</em> + from now on.</p> + + <p>The <code>as</code> clause specifies the name of the C++ type that we are + mapping the mapped type to. We will refer to it as the <em>interface + type</em> from now on.</p> + + <p>The optional <code>to</code> and <code>from</code> clauses specify the + C++ conversion expressions between the mapped type and the + interface type. The <code>to</code> expression converts from the + interface type to the mapped type and <code>from</code> converts + in the other direction. If no explicit conversion is required for + either direction, then the corresponding clause can be omitted. + + If the conversion expressions are specified, then they must contain the + special <code>(?)</code> placeholder which will be replaced with the + actual value to be converted.</p> + + <p>As an example, suppose we have the <code>path</code> type which + represents a filesystem path and which we wish to store in the + database. Suppose also that it has a constructor that allows implicit + conversion of <code>std::string</code> to <code>path</code> as well as + the <code>string()</code> member function which returns the + <code>std::string</code> representation of <code>path</code>. This is + how we can map <code>path</code> to <code>std::string</code> to be able + to store it in the database:</p> + +<pre class="cxx"> +#pragma db map type(path) \ + as(std::string) \ + from((?).string ()) +</pre> + + <p>Notice that we could omit the <code>to</code> expression because + <code>std::string</code> can be implicitly converted to + <code>path</code>. In this case the implied expression is equivalent + to <code>to((?))</code>.</p> + + <p>As a more elaborate example, the following <code>map</code> pragma maps + the standard <code>chrono</code> <code>time_point</code> type (that is, a + timestamp) as <code>uint64</code> with the stored values representing the + number of nanoseconds since the UNIX epoch:</p> + +<pre class="cxx"> +#pragma db map \ + type(std::chrono::system_clock::time_point) \ + as(std::uint64_t) \ + to(std::chrono::duration_cast<std::chrono::nanoseconds> ( \ + (?).time_since_epoch ()).count ()) \ + from(std::chrono::system_clock::time_point ( \ + std::chrono::duration_cast<std::chrono::system_clock::duration> ( \ + std::chrono::nanoseconds (?)))) +</pre> + + <p>And the following example shows how to redefine the mapping for one of + the standard types:</p> + +<pre class="cxx"> +#pragma db map type(bool) \ + as(std::string) \ + to((?) ? "true" : "false") \ + from((?) == "true") +</pre> + + <h3><a name="14.8.2">14.8.2 Database Type Mapping Pragmas</a></h3> + + <p>A pragma with the <code>map</code> qualifier can describe a mapping between two database types. For each database system ODB provides built-in support for a core set of database types, such as integers, strings, binary, etc. However, many database @@ -18146,10 +18311,14 @@ class object and thus establish a mapping between an extended database type and its C++ equivalent.</p> - <p>The <code>map</code> pragma has the following format:</p> + <p>The <code>map</code> pragma for database types has the following + format:</p> <pre class="cxx"> -#pragma db map type("regex") as("subst") [to("subst")] [from("subst")] +#pragma db map type("<regex>") \ + as("<subst>") \ + [to("<subst>")] \ + [from("<subst>")] </pre> <p>The <code>type</code> clause specifies the name of the database type @@ -18230,9 +18399,9 @@ namespace odb class value_traits<std::vector<int>, id_string> { public: - typedef std::vector<int> value_type; - typedef value_type query_type; - typedef details::buffer image_type; + using value_type = std::vector<int>; + using query_type = value_type; + using image_type = details::buffer; static void set_value (value_type& v, @@ -18313,7 +18482,7 @@ class object write:</p> <pre class="cxx"> -typedef std::vector<int> int_vector; +using int_vector = std::vector<int>; #pragma db value(int_vector) type("INTEGER[]") #pragma db object @@ -18359,7 +18528,7 @@ class person ... PRAGMA_DB(id) - unsigned long id_; + unsigned long long id_; }; </pre> @@ -18373,7 +18542,7 @@ class person { ... - unsigned long id_; + unsigned long long id_; }; #ifdef ODB_COMPILER @@ -18425,7 +18594,7 @@ class person ... #pragma db id - unsigned long id_; + unsigned long long id_; }; #pragma warning (pop) @@ -18491,7 +18660,7 @@ class person ... #pragma db id - unsigned long id_; + unsigned long long id_; }; #pragma clang diagnostic pop @@ -18531,7 +18700,7 @@ namespace odb static const unsigned short event_rollback = 0x02; static const unsigned short event_all = event_commit | event_rollback; - typedef void (*callback_type) ( + using callback_type = void (*) ( unsigned short event, void* key, unsigned long long data); void @@ -18683,7 +18852,7 @@ class person T last_; }; -typedef person<std::string> std_person; +using std_person = person<std::string>; #pragma db object(std_person) #pragma db member(std_person::last_) id @@ -18692,13 +18861,13 @@ typedef person<std::string> std_person; <p>Note that the database support code for such a persistent object is generated when compiling the header containing the <code>db object</code> pragma and not the header containing - the template definition or the <code>typedef</code> name. This + the template definition or the <code>using</code> alias. This allows us to use templates defined in other files, for example:</p> <pre class="cxx"> #include <utility> // std::pair -typedef std::pair<unsigned int, std::string> person; +using person = std::pair<unsigned int, std::string>; #pragma db object(person) #pragma db member(person::first) id auto column("id") #pragma db member(person::second) column("name") @@ -18733,7 +18902,7 @@ class base_common ... #pragma db id auto - unsigned long id; + unsigned long long id; }; template <typename T> @@ -18744,7 +18913,7 @@ class base: public base_common T value; }; -typedef base<std::string> string_base; +using string_base = base<std::string>; #pragma db object(string_base) abstract #pragma db object @@ -18802,7 +18971,7 @@ class person ... #pragma db id auto - unsigned long id; + unsigned long long id; }; </pre> @@ -18931,7 +19100,7 @@ struct person_entry ... }; -typedef std::vector<person_entry> people; +using people = std::vector<person_entry>; void persist (odb::database& db, people& p) @@ -18956,7 +19125,7 @@ persist (odb::database& db, people& p) have to specify the object type explicitly, for example:</p> <pre class="cxx"> -std::vector<unsigned long> ids {1, 2}; +std::vector<unsigned long long> ids {1, 2}; db.erase<person> (ids.begin (), ids.end ()); </pre> @@ -19004,10 +19173,10 @@ struct multiple_exceptions: odb::exception // Iteration. // - typedef std::set<value_type> set_type; + using set_type = std::set<value_type>; - typedef set_type::const_iterator iterator; - typedef set_type::const_iterator const_iterator; + using iterator = set_type::const_iterator; + using const_iterator = set_type::const_iterator; iterator begin () const; @@ -19399,8 +19568,8 @@ odb --odb-file-suffix common:-odb-common ... odb::database& db = ... -typedef odb::query<person> query; -typedef odb::result<person> result; +using query = odb::query<person>; +using result = odb::result<person>; odb::transaction t (db.begin ()); result r (db.query<person> (query::age < 30)); @@ -19416,8 +19585,8 @@ t.commit (); odb::sqlite::database& db = ... -typedef odb::sqlite::query<person> query; -typedef odb::result<person> result; // odb:: not odb::sqlite:: +using query = odb::sqlite::query<person>; +using result = odb::result<person>; // odb:: not odb::sqlite:: odb::sqlite::transaction t (db.begin ()); result r (db.query<person> (query::age < 30)); @@ -19458,8 +19627,8 @@ odb::database& db = ... { using namespace odb::core; - typedef query<person> person_query; - typedef result<person> person_result; + using person_query = query<person>; + using person_result = result<person>; transaction t (db.begin ()); person_result r (db.query<person> (person_query::age < 30)); @@ -19483,8 +19652,8 @@ odb::sqlite::database& db = ... { using namespace odb::sqlite::core; - typedef query<person> person_query; - typedef result<person> person_result; + using person_query = query<person>; + using person_result = result<person>; transaction t (db.begin ()); person_result r (db.query<person> (person_query::age < 30)); @@ -19508,9 +19677,9 @@ namespace sl = odb::sqlite; pg::database& pg_db = ... sl::database& sl_db = ... -typedef pg::query<person> pg_query; -typedef sl::query<person> sl_query; -typedef odb::result<person> result; +using pg_query = pg::query<person>; +using sl_query = sl::query<person>; +using result = odb::result<person>; // First check the local cache. // @@ -19651,8 +19820,8 @@ if (p == 0) void print (odb::database& db, unsigned short age, unsigned long limit) { - typedef odb::query<person> query; - typedef odb::result<person> result; + using query = odb::query<person>; + using result = odb::result<person>; odb::transaction t (db.begin ()); @@ -19665,7 +19834,7 @@ print (odb::database& db, unsigned short age, unsigned long limit) // add the LIMIT clause to the query. // namespace pg = odb::pgsql; - typedef pg::query<person> pg_query; + using pg_query = pg::query<person>; pg::database& pg_db (static_cast<pg::database&> (db)); pg_query pg_q (pg_query (q) + "LIMIT" + pg_query::_val (limit)); @@ -20168,7 +20337,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::vector<char> buffer; +using buffer = std::vector<char>; #pragma db value(buffer) type("BLOB") #pragma db object @@ -20195,6 +20364,23 @@ db.query<object> ("uuid = " + query::_val<odb::mysql::id_blob> (u)); db.query<object> (query::uuid == query::_ref (u)); </pre> + + <h3><a name="17.1.3">17.1.3 Mixed Automatic/0 Object Id Assignment</a></h3> + + <p>In MySQL an automatic object id can also be set manually to + <code>0</code>. For example:</p> + + <pre class="cxx"> + #pragma db id auto + odb::nullable<int64_t> id; + </pre> + + <p>Then, when used with the <code>NO_AUTO_VALUE_ON_ZERO</code> mode, set the + id member to <code>NULL</code> to get auto-assignment or to <code>0</code> + to use <code>0</code> as the id. This functionality is normally used to + assign the special <code>0</code> id to a special object.</p> + + <h2><a name="17.2">17.2 MySQL Database Class</a></h2> <p>The MySQL <code>database</code> class has the following @@ -20396,7 +20582,7 @@ namespace odb handle (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } } </pre> @@ -20487,7 +20673,7 @@ namespace odb pooled_connection (database_type&, MYSQL*); }; - typedef details::shared_ptr<pooled_connection> pooled_connection_ptr; + using pooled_connection_ptr = details::shared_ptr<pooled_connection>; virtual pooled_connection_ptr create (); @@ -20561,10 +20747,10 @@ namespace odb int main (int argc, char* argv[]) { - auto_ptr<odb::mysql::connection_factory> f ( + unique_ptr<odb::mysql::connection_factory> f ( new odb::mysql::connection_pool_factory (20)); - auto_ptr<odb::database> db ( + unique_ptr<odb::database> db ( new mysql::database (argc, argv, false, 0, f)); } </pre> @@ -20704,8 +20890,8 @@ struct person_range print the list of people in a specific age range:</p> <pre class="cxx"> -typedef odb::query<person_range> query; -typedef odb::result<person_range> result; +using query = odb::query<person_range>; +using result = odb::result<person_range>; transaction t (db.begin ()); @@ -20732,16 +20918,15 @@ t.commit (); <p>In MySQL, a stored procedure can produce multiple results. For example, if a stored procedure executes several - <code>SELECT</code> statements, then the result of calling such - a procedure consists of two row sets, one for each <code>SELECT</code> - statement. Additionally, if the procedure has any <code>OUT</code> - or <code>INOUT</code> parameters, then their values are returned as - an additional special row set containing only a single row. - Because such multiple row sets can contain varying number - and type of columns, they cannot be all extracted into a - single view. As a result, an ODB view will only extract the - data from the first row set and ignore all the subsequent - ones.</p> + <code>SELECT</code> statements, then the result of calling such a + procedure consists of multiple row sets, one for + each <code>SELECT</code> statement. Additionally, if the procedure has + any <code>OUT</code> or <code>INOUT</code> parameters, then their values + are returned as an additional special row set containing only a single + row. Because such multiple row sets can contain varying number and type + of columns, they cannot be all extracted into a single view. As a + result, an ODB view will only extract the data from the first row set + and ignore all the subsequent ones.</p> <p>In particular, this means that we can use an ODB view to extract the values of the <code>OUT</code> and <code>INOUT</code> @@ -20767,7 +20952,7 @@ struct person_min_max_age </pre> <pre class="cxx"> -typedef odb::query<person_min_max_age> query; +using query = odb::query<person_min_max_age>; transaction t (db.begin ()); @@ -21010,7 +21195,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::array<char, 128> name_type; +using name_type = std::array<char, 128>; #pragma db value(name_type) type("TEXT") #pragma db object @@ -21061,7 +21246,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::vector<char> buffer; +using buffer = std::vector<char>; #pragma db value(buffer) type("BLOB") #pragma db object @@ -21113,7 +21298,7 @@ class object { public #pragma db id auto - unsigned long id; + unsigned long long id; odb::sqlite::blob b; // Mapped to BLOB. odb::sqlite::text t; // Mapped to TEXT. @@ -21295,7 +21480,7 @@ object o; // { transaction tx (db.begin ()); - auto_ptr<object> p (db.load<object> (o.id)); + unique_ptr<object> p (db.load<object> (o.id)); text_stream ts (p->t, false); // Open for reading. vector<char> t (ts.size () + 1, '\0'); @@ -21358,7 +21543,7 @@ struct load_b odb::sqlite::blob b; }; -typedef odb::query<load_b> query; +using query = odb::query<load_b>; transaction tx (db.begin ()); @@ -21412,7 +21597,7 @@ text_stream ts (o.t, true); <pre class="cxx"> transaction tx (db.begin ()); -auto_ptr<object> p (db.load<object> (o.id)); +unique_ptr<object> p (db.load<object> (o.id)); p->name = "foo"; // Update some other member. db.update (*p); // Bad behavior: incremental BLOB/TEXT invalidated. @@ -21433,6 +21618,22 @@ tx.commit (); default; see SQLite <code>PRAGMA encoding</code> documentation for details).</p> + <h3><a name="18.1.4">18.1.4 Mixed Automatic/Manual Object Id Assignment</a></h3> + + <p>In SQLite an automatic object id can also be assigned manually. For + example:</p> + + <pre class="cxx"> + #pragma db id auto + odb::nullable<int64_t> id; + </pre> + + <p>Then set the id member to <code>NULL</code> to get auto-assignment or to + the actual value to use a manual id. This functionality is normally + used to reserve a special id, typically <code>0</code>, for a special + object.</p> + + <h2><a name="18.2">18.2 SQLite Database Class</a></h2> <p>The SQLite <code>database</code> class has the following @@ -21506,7 +21707,7 @@ namespace odb values, refer to the <code>sqlite3_open_v2()</code> function description in the SQLite C API documentation. The <code>foreign_keys</code> argument specifies whether foreign key constraints checking - should be enabled. See <a href="#18.5.3">Section 18.5.3, + should be enabled. See <a href="#18.6.3">Section 18.6.3, "Foreign Key Constraints"</a> for more information on foreign keys. The <code>vfs</code> argument specifies the SQLite virtual file system module that should be used to access the @@ -21518,7 +21719,7 @@ namespace odb database in the read-write mode and create it if it does not exist:</p> <pre class="cxx"> -auto_ptr<odb::database> db ( +unique_ptr<odb::database> db ( new odb::sqlite::database ( "test.db", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); @@ -21562,7 +21763,7 @@ auto_ptr<odb::database> db ( <p>The third constructor throws the <code>odb::sqlite::cli_exception</code> exception if the SQLite option values are missing or invalid. - See <a href="#18.4">Section 18.4, "SQLite Exceptions"</a> + See <a href="#18.5">Section 18.5, "SQLite Exceptions"</a> for more information on this exception.</p> <p>The static <code>print_usage()</code> function prints the list of options @@ -21619,7 +21820,7 @@ namespace odb handle (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } } </pre> @@ -21670,8 +21871,9 @@ namespace odb <code>connect()</code> function is called whenever a database connection is requested.</p> - <p>The three implementations of the <code>connection_factory</code> + <p>The four implementations of the <code>connection_factory</code> interface provided by the SQLite ODB runtime library are + <code>serial_connection_factory</code>, <code>single_connection_factory</code>, <code>new_connection_factory</code>, and <code>connection_pool_factory</code>. You will need to include @@ -21679,6 +21881,37 @@ namespace odb header file to make the <code>connection_factory</code> interface and these implementation classes available in your application.</p> + <p>The <code>serial_connection_factory</code> class creates a single + connection that is expected to be used by an application in a serialized + manner. For example, a single-threaded application that executes all the + database operations via the database instance and without dealing with + multiple connections/transactions would qualify. The + <code>serial_connection_factory</code> class has the following + interface:</p> + + <pre class="cxx"> +namespace odb +{ + namespace sqlite + { + class serial_connection_factory: public connection_factory + { + public: + serial_connection_factory (); + + protected: + virtual connection_ptr + create (); + }; +}; + </pre> + + <p>The <code>create()</code> virtual function is called when the + factory needs to create the connection. By deriving from the + <code>serial_connection_factory</code> class and overriding this + function we can implement custom connection establishment + and configuration.</p> + <p>The <code>single_connection_factory</code> class creates a single connection that is shared between all the threads in an application. If the connection is currently not in use, @@ -21705,7 +21938,7 @@ namespace odb single_connection (database&, sqlite3*); }; - typedef details::shared_ptr<single_connection> single_connection_ptr; + using single_connection_ptr = details::shared_ptr<single_connection>; virtual single_connection_ptr create (); @@ -21760,7 +21993,7 @@ namespace odb pooled_connection (database_type&, sqlite3*); }; - typedef details::shared_ptr<pooled_connection> pooled_connection_ptr; + using pooled_connection_ptr = details::shared_ptr<pooled_connection>; virtual pooled_connection_ptr create (); @@ -21831,15 +22064,119 @@ namespace odb int main (int argc, char* argv[]) { - auto_ptr<odb::sqlite::connection_factory> f ( + unique_ptr<odb::sqlite::connection_factory> f ( new odb::sqlite::connection_pool_factory (20)); - auto_ptr<odb::database> db ( + unique_ptr<odb::database> db ( new sqlite::database (argc, argv, false, SQLITE_OPEN_READWRITE, f)); } </pre> - <h2><a name="18.4">18.4 SQLite Exceptions</a></h2> + + <h2><a name="18.4">18.4 Attached SQLite Databases</a></h2> + + <p>The SQLite database class provides support for attaching additional + databases to the main database connections using the SQLite <code>ATTACH + DATABASE</code> statement. Good understanding of the SQLite attached + database semantics and ODB connection management is strongly recommended + when using this functionality.</p> + + <p>The relevant part of the SQLite database class interface is shown + below:</p> + + <pre class="cxx"> +namespace odb +{ + namespace sqlite + { + class database: public odb::database + { + public: + + ... + + database (const connection_ptr&, + const std::string& name, + const std::string& schema, + std::[auto|unique]_ptr<attached_connection_factory> = 0); + + void + detach (); + + database& + main_database (); + + const std::string& + schema () const; + }; + } +} + </pre> + + <p>The shown constructor attaches to the specified connection a database + with the specified name as the specified schema.</p> + + <p>The resulting database instance is referred to as an <em>attached + database</em> and the connection it returns as an <em>attached + connection</em> (which is just a proxy for the main connection). Database + operations executed on the attached database or attached connection are + automatically translated to refer to the specified schema rather than + <code>"main"</code>. For uniformity attached databases can also be + created for the pre-attached <code>"main"</code> and <code>"temp"</code> + schemas (in this case the <code>name</code> argument can be + anything).</p> + + <p>The automatic translation of the statements relies on their text having + references to top-level database entities (tables, indexes, etc) + qualified with the <code>"main"</code> schema. To achieve this, compile + your headers with the <code>--schema main</code> option and, if using + schema migration, with the <code>--schema-version-table + main.schema_version</code> option. You must also not + use <code>"main"</code> as an object/table alias in views of native + statements. For optimal translation performance use 4-character schema + names.</p> + + <p>The main connection and attached to it databases and connections are all + meant to be used within the same thread. In particular, the attached + database holds a counted reference to the main connection which means the + connection will not be released until all the attached to this connection + databases are destroyed.</p> + + <p>Note that in this model the attached databases are attached to the main + connection, not to the (main) database, which mimics the underlying + semantics of SQLite. An alternative model would have been to notionally + attach the databases to the main database and under the hood + automatically attach them to each returned connection. While this may + seem like a more convenient model in some cases, it is also less + flexible: the current model allows attaching a different set of databases + to different connections, attaching them on demand as the transaction + progresses, etc. Also, the more convenient model can be implemented on + top of this model by deriving an application-specific database class + and/or providing custom connection factories.</p> + + <p>Note also that unless the name is a URI with appropriate mode, the + attached database is opened with the + <code>SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE</code> flags. In + particular, if you want just <code>SQLITE_OPEN_READWRITE</code>, then you + will need to verify the database file existence manually prior to calling + this constructor.</p> + + <p>Note that attaching/detaching databases within a transaction is only + supported since SQLite 3.21.0.</p> + + <p>The <code>detach()</code> function detaches the attached database. The + database is automatically detached on destruction but a failure to detach + is ignored. To detect such a failure perform explicit detach. For + uniformity detaching a main database is a no-op.</p> + + <p>The <code>main_database()</code> function returns the main database of an + attached database. If this database is main, return itself.</p> + + <p>The <code>schema()</code> function returns the schema name under which + this database was attached or empty if this is the main database.</p> + + + <h2><a name="18.5">18.5 SQLite Exceptions</a></h2> <p>The SQLite ODB runtime library defines the following SQLite-specific exceptions:</p> @@ -21887,7 +22224,7 @@ namespace odb <p>The <code>odb::sqlite::forced_rollback</code> exception is thrown if SQLite is forcing the current transaction to roll back. For more - information on this behavior refer to <a href="#18.5.6">Section 18.5.6, + information on this behavior refer to <a href="#18.6.6">Section 18.6.6, "Forced Rollback"</a>.</p> <p>The <code>odb::sqlite::database_exception</code> is thrown if @@ -21904,12 +22241,12 @@ namespace odb of an error.</p> - <h2><a name="18.5">18.5 SQLite Limitations</a></h2> + <h2><a name="18.6">18.6 SQLite Limitations</a></h2> <p>The following sections describe SQLite-specific limitations imposed by the current SQLite and ODB runtime versions.</p> - <h3><a name="18.5.1">18.5.1 Query Result Caching</a></h3> + <h3><a name="18.6.1">18.6.1 Query Result Caching</a></h3> <p>SQLite ODB runtime implementation does not perform query result caching (<a href="#4.4">Section 4.4, "Query Result"</a>) even when explicitly @@ -21924,7 +22261,7 @@ namespace odb thrown. Future versions of the SQLite ODB runtime library may add support for result caching.</p> - <h3><a name="18.5.2">18.5.2 Automatic Assignment of Object Ids</a></h3> + <h3><a name="18.6.2">18.6.2 Automatic Assignment of Object Ids</a></h3> <p>Due to SQLite API limitations, every automatically assigned object id (<a href="#14.4.2">Section 14.4.2, "<code>auto</code>"</a>) should have @@ -21950,7 +22287,7 @@ class person }; </pre> - <h3><a name="18.5.3">18.5.3 Foreign Key Constraints</a></h3> + <h3><a name="18.6.3">18.6.3 Foreign Key Constraints</a></h3> <p>By default the SQLite ODB runtime enables foreign key constraints checking (<code>PRAGMA foreign_keys=ON</code>). You can disable foreign @@ -22020,7 +22357,7 @@ CREATE TABLE Employee ( which you persist, update, and erase objects within a transaction becomes important.</p> - <h3><a name="18.5.4">18.5.4 Constraint Violations</a></h3> + <h3><a name="18.6.4">18.6.4 Constraint Violations</a></h3> <p>Due to the granularity of the SQLite error codes, it is impossible to distinguish between the duplicate primary key and other constraint @@ -22029,7 +22366,7 @@ CREATE TABLE Employee ( <code>object_already_persistent</code> exception (<a href="#3.14">Section 3.14, "ODB Exceptions"</a>).</p> - <h3><a name="18.5.5">18.5.5 Sharing of Queries</a></h3> + <h3><a name="18.6.5">18.6.5 Sharing of Queries</a></h3> <p>As discussed in <a href="#4.3">Section 4.3, "Executing a Query"</a>, a query instance that does not have any by-reference parameters is @@ -22038,7 +22375,7 @@ CREATE TABLE Employee ( functionality. Future versions of the library will remove this limitation.</p> - <h3><a name="18.5.6">18.5.6 Forced Rollback</a></h3> + <h3><a name="18.6.6">18.6.6 Forced Rollback</a></h3> <p>In SQLite 3.7.11 or later, if one of the connections participating in the shared cache rolls back a transaction, then ongoing transactions @@ -22049,12 +22386,12 @@ CREATE TABLE Employee ( <p>If a transaction is being forced to roll back by SQLite, then ODB throws <code>odb::sqlite::forced_rollback</code> - (<a href="#18.4">Section 18.4, "SQLite Exceptions"</a>) which is + (<a href="#18.5">Section 18.5, "SQLite Exceptions"</a>) which is a recoverable exception (<a href="#3.7">3.7 Error Handling and Recovery</a>). As a result, the recommended way to handle this exception is to re-execute the affected transaction.</p> - <h3><a name="18.5.7">18.5.7 Database Schema Evolution</a></h3> + <h3><a name="18.6.7">18.6.7 Database Schema Evolution</a></h3> <p>From the list of schema migration changes supported by ODB (<a href="#13.2">Section 13.2, "Schema Migration"</a>), the @@ -22126,7 +22463,7 @@ CREATE TABLE Employee ( avoid composite object ids if we are planning to use object relationships.</p> - <h2><a name="18.6">18.6 SQLite Index Definitions</a></h2> + <h2><a name="18.7">18.7 SQLite Index Definitions</a></h2> <p>When the <code>index</code> pragma (<a href="#14.7">Section 14.7, "Index Definition Pragmas"</a>) is used to define an SQLite index, @@ -22412,7 +22749,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::vector<char> buffer; +using buffer = std::vector<char>; #pragma db value(buffer) type("BYTEA") #pragma db object @@ -22608,7 +22945,7 @@ namespace odb handle (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } } </pre> @@ -22698,7 +23035,7 @@ namespace odb pooled_connection (database_type&, PGconn*); }; - typedef details::shared_ptr<pooled_connection> pooled_connection_ptr; + using pooled_connection_ptr = details::shared_ptr<pooled_connection>; virtual pooled_connection_ptr create (); @@ -22762,10 +23099,10 @@ namespace odb int main (int argc, char* argv[]) { - auto_ptr<odb::pgsql::connection_factory> f ( + unique_ptr<odb::pgsql::connection_factory> f ( new odb::pgsql::connection_pool_factory (20)); - auto_ptr<odb::database> db ( + unique_ptr<odb::database> db ( new pgsql::database (argc, argv, false, "", f)); } </pre> @@ -22942,6 +23279,236 @@ class object ODB automatically prefixes each index name with the table name on which it is defined.</p> + + <h2><a name="19.7">19.7 PostgreSQL Stored Procedures and Functions</a></h2> + + <p>ODB native views (<a href="#10.6">Section 10.6, "Native Views"</a>) can + be used to call PostgreSQL stored procedures and functions. For example, + assuming we are using the <code>person</code> class + from <a href="#2">Chapter 2, "Hello World Example"</a> (and the + corresponding <code>person</code> table), we can create a stored + function that given the min and max ages returns some information about + all the people in that range:</p> + + <pre class="sql"> +CREATE FUNCTION +person_range (IN min_age INTEGER, + IN max_age INTEGER, + OUT age SMALLINT, + OUT first TEXT, + OUT last TEXT) +RETURNS SETOF RECORD AS $$ + SELECT age, first, last + FROM person + WHERE age >= min_age AND age <= max_age; +$$ LANGUAGE SQL STABLE; + </pre> + + <p>Given the above stored function we can then define an ODB view that can + be used to call it and retrieve its result:</p> + + <pre class="cxx"> +#pragma db view query("/*CALL*/ SELECT * FROM person_range((?))") +struct person_range +{ + unsigned short age; + std::string first; + std::string last; +}; + </pre> + + <p>Notice the special <code>/*CALL*/</code> prefix: because PostgreSQL uses + ordinary <code>SELECT</code> queries to call functions, we need to + communicate to ODB that the query is actually a function call.</p> + + <p>The following example shows how we can use the above view to + print the list of people in a specific age range:</p> + + <pre class="cxx"> +using query = odb::query<person_range>; +using result = odb::result<person_range>; + +transaction t (db.begin ()); + +result r ( + db.query<person_range> ( + query::_val (1) + "," + query::_val (18))); + +for (result::iterator i (r.begin ()); i != r.end (); ++i) + cerr << i->first << " " << i->last << " " << i->age << endl; + +t.commit (); + </pre> + + <p>Note that as with all native views, the order and types of data members + must match those returned by the stored function or procedure.</p> + + <p>In the above example, the stored function returned a set of rows. Other + common cases are functions that return a single row, a single value, or + nothing (<code>VOID</code>). An example of a function returning a single + row via the <code>OUT</code> parameters:</p> + + <pre class="sql"> +CREATE FUNCTION +person_age_range (IN last_name TEXT, + OUT min_age SMALLINT, + OUT max_age SMALLINT) +AS $$ + SELECT min(age), max(age) + FROM person + WHERE last = last_name; +$$ LANGUAGE SQL STABLE; + </pre> + + <pre class="cxx"> +#pragma db view query("/*CALL*/ SELECT * FROM person_age_range((?))") +struct person_age_range +{ + unsigned short min_age; + unsigned short max_age; +}; + </pre> + + <pre class="cxx"> +using query = odb::query<person_age_range>; + +person_age_range r ( + db.query_value<person_age_range> ( + query::_val ("Doe"))); + </pre> + + <p>An example of a function returning a single value:</p> + + <pre class="sql"> +CREATE FUNCTION +person_count () +RETURNS BIGINT AS $$ + SELECT count(id) + FROM person; +$$ LANGUAGE SQL STABLE; + </pre> + + <pre class="cxx"> +#pragma db view query("/*CALL*/ SELECT * FROM person_count()") +struct person_count +{ + unsigned long long count; +}; + </pre> + + <pre class="cxx"> +unsigned long long count (db.query_value<person_count> ().count); + </pre> + + <p>Finally, a function that returns <code>VOID</code>:</p> + + <pre class="sql"> +CREATE FUNCTION +person_increment_age (IN min_age INTEGER, + IN max_age INTEGER) +RETURNS VOID AS $$ + UPDATE person + SET age = age + 1 + WHERE age >= min_age AND age <= max_age; +$$ LANGUAGE SQL; + </pre> + + <pre class="cxx"> +#pragma db view query("/*CALL*/ SELECT * FROM person_increment_age((?))") +struct person_increment_age {}; + </pre> + + <pre class="cxx"> +using query = odb::query<person_increment_age>; + +db.query_value<person_increment_age> ( + query::_val (1) + "," + + query::_val (18)); + </pre> + + <p>We can reuse a single view to call several functions (or procedure; see + below) that return <code>VOID</code> or, more generally, return the same + result, by specifying the function (or procedure) at the call site rather + than in the view definition. For example:</p> + + <pre class="cxx"> +#pragma db view +struct no_result {}; + +using query = odb::query<no_result>; + +db.query_one<no_result> ( + "/*CALL*/ SELECT * FROM person_increment_age(" + + query::_val (1) + "," + + query::_val (18) + ")"); + </pre> + + <p>In contrast to functions, stored procedures in PostgreSQL are called with + the <code>CALL</code> statement. They can only return a single set of + values via the <code>OUT</code> parameters. If there are no output + parameters, then a stored procedure doesn't return anything. For + example:</p> + + <pre class="sql"> +CREATE PROCEDURE +person_increment_age (IN id BIGINT, + OUT first TEXT, + OUT last TEXT, + OUT age SMALLINT) +AS $$ + UPDATE person + SET age = age + 1 + WHERE person.id = id + RETURNING first, last, age; +$$ LANGUAGE SQL; + </pre> + + <pre class="cxx"> +#pragma db view query("CALL person_increment_age((?))") +struct person_increment_age +{ + std::string first; + std::string last; + unsigned short age; +}; + </pre> + + <pre class="cxx"> +using query = odb::query<person_increment_age>; + +person_increment_age r ( + db.query_value<person_increment_age> ( + query::_val (123) + ",NULL,NULL,NULL")); + </pre> + + <p>Note that in the <code>CALL</code> statement, output parameters must + be included in the argument list, normally as <code>NULL</code>.</p> + + <p>A stored procedure that doesn't return anything and has no parameters can + be called with <code>execute()</code> (<a href="#3.12">3.12 Executing + Native SQL Statements</a>) rather than <code>query()</code>. Such a + procedure can also control transactions. For example:</p> + + <pre class="sql"> +CREATE PROCEDURE +person_increment_all_ages () +AS $$ +BEGIN + UPDATE person + SET age = age + 1; + COMMIT; +END; +$$ LANGUAGE PLPGSQL; + </pre> + + <pre class="cxx"> +db.connection ()->execute ("CALL person_increment_all_ages()"); + </pre> + + <p>For more information on how to call stored procedures and functions with + the various return approaches refer to the <code>pgsql/stored-proc</code> + test in the <code>odb-tests</code> package.</p> + <!-- CHAPTER --> @@ -23202,7 +23769,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::vector<char> buffer; +using buffer = std::vector<char>; #pragma db value(buffer) type("BLOB") #pragma db object @@ -23432,7 +23999,7 @@ namespace odb lob_buffer (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } } </pre> @@ -23537,7 +24104,7 @@ namespace odb pooled_connection (database_type&, OCISvcCtx*); }; - typedef details::shared_ptr<pooled_connection> pooled_connection_ptr; + using pooled_connection_ptr = details::shared_ptr<pooled_connection>; virtual pooled_connection_ptr create (); @@ -23601,10 +24168,10 @@ namespace odb int main (int argc, char* argv[]) { - auto_ptr<odb::oracle::connection_factory> f ( + unique_ptr<odb::oracle::connection_factory> f ( new odb::oracle::connection_pool_factory (20)); - auto_ptr<odb::database> db ( + unique_ptr<odb::database> db ( new oracle::database (argc, argv, false, 0, 0, 0, f)); } </pre> @@ -23632,10 +24199,10 @@ namespace odb message () const; }; - typedef std::vector<record> records; + using records = std::vector<record>; - typedef records::size_type size_type; - typedef records::const_iterator iterator; + using size_type = records::size_type; + using iterator = records::const_iterator; iterator begin () const; @@ -24181,7 +24748,7 @@ class object <p>Alternatively, this can be done on the per-type basis, for example:</p> <pre class="cxx"> -typedef std::vector<char> buffer; +using buffer = std::vector<char>; #pragma db value(buffer) type("VARBINARY(max)") #pragma db object @@ -24280,8 +24847,8 @@ class object std::string str_; }; -typedef odb::query<object> query; -typedef odb::result<object> result; +using query = odb::query<object>; +using result = odb::result<object>; transaction t (db.begin ()); @@ -24336,8 +24903,8 @@ namespace odb class database: public odb::database { public: - typedef protocol protocol_type; - typedef transaction_isolation transaction_isolation_type; + using protocol_type = protocol; + using transaction_isolation_type = transaction_isolation; database (const std::string& user, const std::string& password, @@ -24657,7 +25224,7 @@ namespace odb long_data_buffer (); }; - typedef details::shared_ptr<connection> connection_ptr; + using connection_ptr = details::shared_ptr<connection>; } } </pre> @@ -24758,7 +25325,7 @@ namespace odb pooled_connection (database_type&, SQLHDBC handle); }; - typedef details::shared_ptr<pooled_connection> pooled_connection_ptr; + using pooled_connection_ptr = details::shared_ptr<pooled_connection>; virtual pooled_connection_ptr create (); @@ -24822,10 +25389,10 @@ namespace odb int main (int argc, char* argv[]) { - auto_ptr<odb::mssql::connection_factory> f ( + unique_ptr<odb::mssql::connection_factory> f ( new odb::mssql::connection_pool_factory (20)); - auto_ptr<odb::database> db ( + unique_ptr<odb::database> db ( new mssql::database (argc, argv, false, "", 0, f)); } </pre> @@ -24856,10 +25423,10 @@ namespace odb message () const; }; - typedef std::vector<record> records; + using records = std::vector<record>; - typedef records::size_type size_type; - typedef records::const_iterator iterator; + using size_type = records::size_type; + using iterator = records::const_iterator; iterator begin () const; @@ -25080,8 +25647,8 @@ struct person_range print the list of people in a specific age range:</p> <pre class="cxx"> -typedef odb::query<person_range> query; -typedef odb::result<person_range> result; +using query = odb::query<person_range>; +using result = odb::result<person_range>; transaction t (db.begin ()); @@ -25150,12 +25717,12 @@ t.commit (); <p>In SQL Server, a stored procedure can produce multiple results. For example, if a stored procedure executes several - <code>SELECT</code> statements, then the result of calling such - a procedure consists of two row sets, one for each <code>SELECT</code> - statement. Because such multiple row sets can contain varying number - and type of columns, they cannot be all extracted into a - single view. Consequently, these kind of stored procedures are - currently not supported.</p> + <code>SELECT</code> statements, then the result of calling such a + procedure consists of multiple row sets, one for each <code>SELECT</code> + statement. Because such multiple row sets can contain varying number and + type of columns, they cannot be all extracted into a single + view. Consequently, these kind of stored procedures are currently not + supported.</p> <p>A stored procedure may also produce no row sets at all. For example, a stored procedure that only executes DML statements @@ -25408,14 +25975,14 @@ class person { ... - typedef - mi::multi_index_container< - std::string, - mi::indexed_by< - mi::sequenced<>, - mi::ordered_unique<mi::identity<std::string> > - > - > emails; + using emails = + mi::multi_index_container< + std::string, + mi::indexed_by< + mi::sequenced<>, + mi::ordered_unique<mi::identity<std::string>> + > + >; emails emails_; }; @@ -25458,19 +26025,19 @@ class person { ... - typedef - mi::multi_index_container< - name, - mi::indexed_by< - mi::ordered_unique<mi::identity<name> > - mi::ordered_non_unique< - mi::member<name, std::string, &name::first> - >, - mi::ordered_non_unique< - mi::member<name, std::string, &name::last> + using aliases = + mi::multi_index_container< + name, + mi::indexed_by< + mi::ordered_unique<mi::identity<name>> + mi::ordered_non_unique< + mi::member<name, std::string, &name::first> + >, + mi::ordered_non_unique< + mi::member<name, std::string, &name::last> + > > - > - > aliases; + > ; aliases aliases_; }; @@ -26603,7 +27170,7 @@ class QOdbList // Iterators. // - typedef typename QList<T>::const_iterator const_iterator; + using const_iterator = typename QList<T>::const_iterator; class iterator { diff --git a/odb/doc/odb-prologue.1 b/odb/doc/odb-prologue.1 index 24e83f4..9092f95 100644 --- a/odb/doc/odb-prologue.1 +++ b/odb/doc/odb-prologue.1 @@ -1,7 +1,7 @@ .\" Process this file with .\" groff -man -Tascii odb.1 .\" -.TH ODB 1 "February 2015" "ODB 2.4.0" +.TH ODB 1 "January 2025" "ODB 2.6.0" .SH NAME odb \- object-relational mapping (ORM) compiler for C++ .\" diff --git a/odb/doc/odb-prologue.xhtml b/odb/doc/odb-prologue.xhtml index b8cc694..0ad11a4 100644 --- a/odb/doc/odb-prologue.xhtml +++ b/odb/doc/odb-prologue.xhtml @@ -2,7 +2,7 @@ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> - <title>ODB 2.4.0 Compiler Command Line Manual</title> + <title>ODB 2.6.0 Compiler Command Line Manual</title> <meta name="copyright" content="© $copyright$"/> <meta name="keywords" content="odb,object,relational,mapping,compiler,c++"/> diff --git a/odb/doc/pregenerated/odb.1 b/odb/doc/pregenerated/odb.1 index c440ca1..69bf59b 100644 --- a/odb/doc/pregenerated/odb.1 +++ b/odb/doc/pregenerated/odb.1 @@ -1,7 +1,7 @@ .\" Process this file with .\" groff -man -Tascii odb.1 .\" -.TH ODB 1 "February 2015" "ODB 2.4.0" +.TH ODB 1 "January 2025" "ODB 2.6.0" .SH NAME odb \- object-relational mapping (ORM) compiler for C++ .\" @@ -260,8 +260,8 @@ must be declared \fBextern\fR\. This option is normally used together with enabled\. .IP "\fB--std\fR \fIversion\fR" Specify the C++ standard that should be used during compilation\. Valid values -are \fBc++98\fR (default), \fBc++11\fR, \fBc++14\fR, \fBc++17\fR, and -\fBc++20\fR\. +are \fBc++98\fR (default), \fBc++11\fR, \fBc++14\fR, \fBc++17\fR, \fBc++20\fR, +\fBc++23\fR, and \fBc++26\fR\. .IP "\fB--warn-hard-add\fR" Warn about hard-added data members\. .IP "\fB--warn-hard-delete\fR" @@ -790,7 +790,7 @@ Send bug reports to the odb-users@codesynthesis.com mailing list. .\" COPYRIGHT .\" .SH COPYRIGHT -Copyright (c) 2009-2024 Code Synthesis. +Copyright (c) 2009-2025 Code Synthesis. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, diff --git a/odb/doc/pregenerated/odb.xhtml b/odb/doc/pregenerated/odb.xhtml index 8abce64..0988717 100644 --- a/odb/doc/pregenerated/odb.xhtml +++ b/odb/doc/pregenerated/odb.xhtml @@ -2,9 +2,9 @@ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> - <title>ODB 2.4.0 Compiler Command Line Manual</title> + <title>ODB 2.6.0 Compiler Command Line Manual</title> - <meta name="copyright" content="© 2009-2024 Code Synthesis"/> + <meta name="copyright" content="© 2009-2025 Code Synthesis"/> <meta name="keywords" content="odb,object,relational,mapping,compiler,c++"/> <meta name="description" content="ODB Compiler Command Line Manual"/> @@ -317,8 +317,9 @@ <dt><code><b>--std</b></code> <code><i>version</i></code></dt> <dd>Specify the C++ standard that should be used during compilation. Valid values are <code><b>c++98</b></code> (default), <code><b>c++11</b></code>, - <code><b>c++14</b></code>, <code><b>c++17</b></code>, and - <code><b>c++20</b></code>.</dd> + <code><b>c++14</b></code>, <code><b>c++17</b></code>, + <code><b>c++20</b></code>, <code><b>c++23</b></code>, and + <code><b>c++26</b></code>.</dd> <dt><code><b>--warn-hard-add</b></code></dt> <dd>Warn about hard-added data members.</dd> @@ -963,7 +964,7 @@ </div> <div id="footer"> - Copyright © 2009-2024 Code Synthesis. + Copyright © 2009-2025 Code Synthesis. <div id="terms"> Permission is granted to copy, distribute and/or modify this diff --git a/odb/manifest b/odb/manifest index 2ef8b08..7751cec 100644 --- a/odb/manifest +++ b/odb/manifest @@ -1,34 +1,174 @@ : 1 name: odb -version: 2.5.0-b.26.z +version: 2.6.0-b.1.z summary: ODB compiler license: GPL-3.0-only topics: C++, ORM, source code generation, object persistence, \ relational database -description-file: README +description-file: README.md +package-description-file: PACKAGE-README.md changes-file: NEWS url: https://www.codesynthesis.com/products/odb/ doc-url: https://www.codesynthesis.com/products/odb/doc/manual.xhtml src-url: https://git.codesynthesis.com/cgit/odb/odb/ email: odb-users@codesynthesis.com build-warning-email: odb-builds@codesynthesis.com -builds: all +builds: all relocatable builds: -( +windows -gcc ) ; Requires MinGW GCC. builds: &gcc ; Requires GCC with plugin support enabled. builds: &gcc-5+ ; Requires GCC 5 or later. builds: -static ; Implementation uses plugins and requires -fPIC. requires: host requires: c++11 +depends: * build2 >= 0.18.0- +depends: * bpkg >= 0.18.0- -# @@ TMP Bump the toolchain version to 0.17.0 after it is released. +depends: libstudxml ^1.1.0 +depends: libcutl ^1.11.0 + +#depends: libstudxml == 1.1.0-b.10 +#depends: libcutl == 1.11.0-b.1 + +depends: * cli ^1.2.0 ? ($config.odb.develop) + +# Binary distribution packages. Overall notes: +# +# - Link dependencies that don't come from system packages statically. Note +# that duplicate symbols are not an issue since the plugin shared library is +# loaded by the GCC compiler, not ODB. +# +# - We suppress generating binary packages for dependencies (libstudxml, +# libcutl) with --recursive=auto since they are linked statically. # -depends: * build2 >= 0.16.0- -depends: * bpkg >= 0.16.0- -depends: libstudxml ^1.1.0- -depends: libcutl ^1.11.0- +# Linux binary distributions packages. +# +# - Compile (static) dependencies with -fPIC since they are linked to the ODB +# plugin shared library. +# +# - Note that Fedora's rpmbuild and Ubuntu's dpkg-buildpackage compile the +# ODB's sources with the -flto=auto option, which breaks the plugin. Thus, +# we always disable the link-time optimization by adding -fno-lto. +# +bindist-debian-builds: bindist +bindist-debian-build-include: linux_debian*-** +bindist-debian-build-include: linux_ubuntu*-** +bindist-debian-build-exclude: ** +bindist-debian-build-config: +\ ++bpkg.bindist.debian: ++bbot.bindist.upload: +bpkg.bindist.debian:--recursive=auto +bpkg.bindist.debian:--debian-main-extradep=g++ -#depends: libstudxml == 1.1.0-b.10 -#depends: libcutl == 1.11.0-b.9 +# Prepend system package manager options instead of overriding. +# +bpkg.bindist.debian:--debian-buildflags=prepend + +bpkg.create:config.bin.lib=static + +# Reset common options for dependencies (because we are prepending). +# +bpkg.create:config.cc.poptions=[null] +bpkg.create:config.cc.coptions=[null] +bpkg.create:config.cc.loptions=[null] + +# Append custom options for dependencies. +# +bpkg.create:config.c.coptions="-fPIC -fno-lto" +bpkg.create:config.cxx.coptions="-fPIC -fno-lto" + +# Reset common options for odb (because we are prepending). +# +bpkg.configure.build:.../config.cc.poptions=[null] +bpkg.configure.build:.../config.cc.coptions=[null] +bpkg.configure.build:.../config.cc.loptions=[null] + +# Append custom options for odb. +# +bpkg.configure.build:.../config.cxx.coptions=-fno-lto +\ + +bindist-fedora-builds: bindist +bindist-fedora-build-include: linux_fedora*-** +bindist-fedora-build-include: linux_rhel*-** +bindist-fedora-build-exclude: ** +bindist-fedora-build-config: +\ ++bpkg.bindist.fedora: ++bbot.bindist.upload: +bpkg.bindist.fedora:--recursive=auto +bpkg.bindist.fedora:--fedora-main-extrareq=gcc-c++ + +# Prepend system package manager options instead of overriding. +# +bpkg.bindist.fedora:--fedora-buildflags=prepend + +bpkg.create:config.bin.lib=static + +# Reset common options for dependencies (because we are prepending). +# +bpkg.create:config.cc.poptions=[null] +bpkg.create:config.cc.coptions=[null] +bpkg.create:config.cc.loptions=[null] + +# Append custom options for dependencies. +# +bpkg.create:config.c.coptions="-fPIC -fno-lto" +bpkg.create:config.cxx.coptions="-fPIC -fno-lto" + +# Reset common options for odb (because we are prepending). +# +bpkg.configure.build:.../config.cc.poptions=[null] +bpkg.configure.build:.../config.cc.coptions=[null] +bpkg.configure.build:.../config.cc.loptions=[null] + +# Append custom options for odb. +# +bpkg.configure.build:.../config.cxx.coptions=-fno-lto +\ + +# Windows binary distribution archive. +# +# - Strip the default compiler name from metadata in the archive name since it +# is built with GCC and the run-time libraries are supposed to be bundled +# (see below for details). +# +# - Note that the contents of this archive can be overlaid with the contents +# of the ODB runtime library archives extracted into the root directory. +# +bindist-windows-builds: bindist +bindist-windows-build-include: windows*-gcc** +bindist-windows-build-exclude: ** +bindist-windows-build-config: +\ ++bpkg.bindist.archive: ++bbot.bindist.upload: +bpkg.bindist.archive:--recursive=auto +bpkg.bindist.archive:--archive-lang-impl=cc= + +# Relocatable by default (see target configuration for details). +# +#bpkg.bindist.archive:config.install.relocatable=true + +# Supplement the generated archive with the GCC compiler and run-time +# libraries by overlaying it with the contents of the +# build2-mingw-X.Y.Z-x86_64-windows.tar.xz archive (located at +# https://download.build2.org/) extracted into the mingw/ subdirectory and +# mingw/bin/{libgcc_s_seh-*,libstdc++-*,libwinpthread-*}.dll files copied into +# the bin/ subdirectory. +# +# Note that since the resulting archive is quite big (about 120MB for zip), we +# use the tar.xz archive type to reduce its size (to about 45MB). +# ++bpkg.bindist.archive.post:build/bindist-archive-post.bx +bpkg.bindist.archive:--archive-type=tar.xz + +# At the bpkg.bindist.archive step, configure odb to refer to g++ using the +# relative ../mingw/bin/g++ path (see above for details). +# +bpkg.bindist.archive:config.odb.gxx_name=../mingw/bin/g++ -depends: * cli ^1.2.0- ? ($config.odb.develop) +bpkg.create:config.bin.lib=static +b.create:config.cc.coptions="-Wall -O3" +\ diff --git a/odb/odb/buildfile b/odb/odb/buildfile index 96eb95f..fafc10a 100644 --- a/odb/odb/buildfile +++ b/odb/odb/buildfile @@ -30,6 +30,8 @@ if ($cxx.target.class != 'windows') # # NOTE: see ODB_GCC_PLUGIN_DIR when adding this support. # +# NOTE: also think about relocatable installation. +# plugin{*}: install = bin/ import libs = libcutl%lib{cutl} @@ -43,11 +45,19 @@ import libs += libstudxml%lib{studxml} # We, however, don't want to install via the driver since the same driver # build could be used with multiple plugin builds (e.g., for different GCC # versions, which is something distribution packagers sometimes want to do). -# @@ For this we will have to wait for operation-specific values support. # exe{odb}: cxx{odb} exe{odb}: libus{odb}: bin.whole = false -exe{odb}: plugin{odb}: include = adhoc +exe{odb}: plugin{odb}: +{ + include = adhoc + + # @@ This work but triggers "incompatible libs{cutl} build". Feels like to + # solve this we will also need to say update_for_install=false which + # we currently cant. + # + #install = false +} # Target metadata, see also --build2-metadata in odb.cxx. # @@ -153,7 +163,6 @@ if $develop diff $src_base/pregenerated/odb/options.ixx $path($>[1]) >- && \ diff $src_base/pregenerated/odb/options.cxx $path($>[2]) >- exit - end cp $path($>[0]) $src_base/pregenerated/odb/options.hxx cp $path($>[1]) $src_base/pregenerated/odb/options.ixx diff --git a/odb/odb/gcc-fwd.hxx b/odb/odb/gcc-fwd.hxx index 83d3746..4587814 100644 --- a/odb/odb/gcc-fwd.hxx +++ b/odb/odb/gcc-fwd.hxx @@ -25,8 +25,12 @@ # undef SAFE_CTYPE_H # include <coretypes.h> +#if BUILDING_GCC_MAJOR >= 15 +# include <line-map.h> // location_t (included anyway by above headers) +#else typedef unsigned int source_location; // <line-map.h> typedef source_location location_t; // <input.h> +#endif #else // GCC < 6 diff --git a/odb/odb/gcc.hxx b/odb/odb/gcc.hxx index e5fecef..c546ee1 100644 --- a/odb/odb/gcc.hxx +++ b/odb/odb/gcc.hxx @@ -176,7 +176,7 @@ INCLUDED_FROM (line_maps* set, const line_map_ordinary* map) return linemap_included_from_linemap (set, map); } -inline source_location +inline location_t LAST_SOURCE_LINE_LOCATION (const line_map_ordinary* map) { return (((map[1].start_location - 1 diff --git a/odb/odb/odb.cxx b/odb/odb/odb.cxx index 9899262..12d8fc6 100644 --- a/odb/odb/odb.cxx +++ b/odb/odb/odb.cxx @@ -185,6 +185,9 @@ main (int argc, char* argv[]) // Also modify LD_LIBRARY_PATH to include the lib path. // + // @@ Hm, I wonder why we are doing this? (One some platforms, like + // Fedora, the directory could be called something else, like lib64). + // #ifndef _WIN32 { #ifdef __APPLE__ @@ -546,12 +549,12 @@ main (int argc, char* argv[]) // // To allow executing the ODB compiler in-place we add the odb.exe.dlls/ // directory to PATH. It is a bit of hack but then DLL assemblies for - // DLLs is whole new level of insanity that we are unlikely to ever + // DLLs is a whole new level of insanity that we are unlikely to ever // touch. // // And it turns out we have the same problem in the installed case: if // the installation directory is not in PATH, then GCC won't find the - // DLLs the plugin needs. So we handle both here. + // DLLs the plugin needs. So we handle both cases here. // { path d (plugin.directory ()); @@ -706,6 +709,16 @@ main (int argc, char* argv[]) args[3] = "-std=c++2a"; break; } + case cxx_version::cxx23: + { + args[3] = "-std=c++2b"; + break; + } + case cxx_version::cxx26: + { + args[3] = "-std=c++2c"; + break; + } } } @@ -1616,8 +1629,8 @@ plugin_path (path const& drv, char const plugin_ext[] = ".dll"; // While GCC 8 switched to using .dylib as the plugin extension, there is a -// bug in the extension stripping code. So for now we use the .so extension -// everywhere (see also buildfile if changing this). +// bug (86358) in the extension stripping code. So for now we use the .so +// extension everywhere (see also buildfile if changing this). // //#elif defined(__APPLE__) // char const plugin_ext[] = ".dylib"; @@ -1638,7 +1651,7 @@ plugin_path (path const& drv, if (dp.empty ()) { - cerr << drv << ": error: unable to resolve ODB driver path" << endl; + cerr << drv << ": error: unable to resolve ODB compiler driver path" << endl; return path (); } diff --git a/odb/odb/option-types.cxx b/odb/odb/option-types.cxx index c4a030b..6055c12 100644 --- a/odb/odb/option-types.cxx +++ b/odb/odb/option-types.cxx @@ -19,7 +19,9 @@ static const char* cxx_version_[] = "c++11", "c++14", "c++17", - "c++20" + "c++20", + "c++23", + "c++26" }; string cxx_version:: @@ -46,6 +48,10 @@ operator>> (istream& is, cxx_version& v) v = cxx_version::cxx17; else if (s == "c++20") v = cxx_version::cxx20; + else if (s == "c++23") + v = cxx_version::cxx23; + else if (s == "c++26") + v = cxx_version::cxx26; else is.setstate (istream::failbit); } diff --git a/odb/odb/option-types.hxx b/odb/odb/option-types.hxx index 869fc83..91371f5 100644 --- a/odb/odb/option-types.hxx +++ b/odb/odb/option-types.hxx @@ -23,7 +23,9 @@ struct cxx_version cxx11, cxx14, cxx17, - cxx20 + cxx20, + cxx23, + cxx26 }; cxx_version (value v = value (0)) : v_ (v) {} diff --git a/odb/odb/options.cli b/odb/odb/options.cli index 17ee438..db2ae5b 100644 --- a/odb/odb/options.cli +++ b/odb/odb/options.cli @@ -127,8 +127,8 @@ class options bool --generate-schema-only { "Generate only the database schema. Note that this option is only valid - when generating schema as a standalone SQL file (see \cb{--schema-format} - for details)." + when generating schema into a separate file (SQL or C++; see + \cb{--schema-format} for details)." }; bool --suppress-migration @@ -317,7 +317,7 @@ class options "<version>", "Specify the C++ standard that should be used during compilation. Valid values are \cb{c++98} (default), \cb{c++11}, \cb{c++14}, - \cb{c++17}, and \cb{c++20}." + \cb{c++17}, \cb{c++20}, \cb{c++23}, and \cb{c++26}." }; // Diagnostics. diff --git a/odb/odb/pragma.cxx b/odb/odb/pragma.cxx index 6668733..378286d 100644 --- a/odb/odb/pragma.cxx +++ b/odb/odb/pragma.cxx @@ -159,12 +159,17 @@ parse_expression (cxx_lexer& l, string& tl, tree& tn, cxx_tokens& ts, - string const& prag) + string const& prag, + bool balance_angles = false) { // Keep reading tokens until we see a mis-matching ')' or ',' while - // keeping track of the '()' and '{}' balance. + // keeping track of the '()', '{}', and '<>' balance. // - size_t p_balance (0), b_balance (0); + // @@ The below implementation of the '<>' balance tracking doesn't + // distinguish angle brackets from the comparison/stream operators and + // should be fixed one day. + // + size_t p_balance (0), b_balance (0), a_balance (0); for (; tt != CPP_EOF; tt = l.next (tl, &tn)) { @@ -173,6 +178,34 @@ parse_expression (cxx_lexer& l, switch (tt) { + case CPP_LESS: + { + if (balance_angles) + a_balance++; + + break; + } + case CPP_GREATER: + { + if (balance_angles) + a_balance--; + + break; + } + case CPP_LSHIFT: + { + if (balance_angles) + a_balance += 2; + + break; + } + case CPP_RSHIFT: + { + if (balance_angles) + a_balance -= 2; + + break; + } case CPP_OPEN_BRACE: { b_balance++; @@ -190,7 +223,7 @@ parse_expression (cxx_lexer& l, } case CPP_CLOSE_PAREN: { - if (p_balance == 0 && b_balance == 0) + if (p_balance == 0 && b_balance == 0 && a_balance == 0) done = true; else p_balance--; @@ -198,7 +231,7 @@ parse_expression (cxx_lexer& l, } case CPP_COMMA: { - if (p_balance == 0 && b_balance == 0) + if (p_balance == 0 && b_balance == 0 && a_balance == 0) done = true; else break; @@ -1202,7 +1235,7 @@ handle_pragma (cxx_lexer& l, tt = l.next (tl, &tn); if (tt != CPP_CLOSE_PAREN) // Empty expression are ok. { - if (!parse_expression (l, tt, tl, tn, ma.expr, p)) + if (!parse_expression (l, tt, tl, tn, ma.expr, p, true /* balance_angles */)) return; // Diagnostics has already been issued. if (tt != CPP_CLOSE_PAREN) diff --git a/odb/odb/pragma.hxx b/odb/odb/pragma.hxx index 0d4d3f1..3efe559 100644 --- a/odb/odb/pragma.hxx +++ b/odb/odb/pragma.hxx @@ -210,13 +210,13 @@ struct pragma_set: std::multimap<std::string, pragma> if (r.first != r.second) { i = r.first; - assert (++r.first == r.second); + assert (++r.first == r.second); // NDEBUG-ok (unused). i->second = p; } } else if (r.first != r.second) - assert ((--r.second)->second.loc <= p.loc); + assert ((--r.second)->second.loc <= p.loc); // NDEBUG-ok (unused). if (i == end ()) i = base::insert (base::value_type (n, p)); diff --git a/odb/odb/processor.cxx b/odb/odb/processor.cxx index fb129fa..3de95e1 100644 --- a/odb/odb/processor.cxx +++ b/odb/odb/processor.cxx @@ -1883,7 +1883,14 @@ namespace // specialization for this type. // tree inst ( - lookup_template_class (t, args, 0, 0, 0, tf_warning_or_error)); + lookup_template_class (t, + args, + 0, + 0, +#if BUILDING_GCC_MAJOR < 15 + 0 /* entering_scope */, +#endif + tf_warning_or_error)); if (inst == error_mark_node) { diff --git a/odb/odb/relational/header.cxx b/odb/odb/relational/header.cxx index 364d48e..fe715e6 100644 --- a/odb/odb/relational/header.cxx +++ b/odb/odb/relational/header.cxx @@ -862,7 +862,7 @@ traverse_view (type& c) os << "," << endl << "const schema_version_migration&"; - os << ")" << (columns != 0 ? ";\n" : "{}"); + os << ")" << (columns != 0 ? ";\n" : "{return false;}"); } // bind (image_type) diff --git a/odb/odb/relational/processor.cxx b/odb/odb/relational/processor.cxx index 0f60359..7abd6d9 100644 --- a/odb/odb/relational/processor.cxx +++ b/odb/odb/relational/processor.cxx @@ -1181,11 +1181,11 @@ namespace relational string q (upcase (vq.literal)); //@@ We need to recognize database-specific list of prefixes. For - // example, PG has WITH. Alternatively (or in addition) we could - // do the same comment trick (e.g., /*SELECT*/ to treat it as a - // SELECT-like queiry). + // now any unrecognized prefix can be worked around with the + // /*SELECT*/ comment prefix. // - if (q.compare (0, 7, "SELECT ") == 0) + if (q.compare (0, 7, "SELECT ") == 0 || + q.compare (0, 5, "WITH ") == 0) vq.kind = view_query::complete_select; else if (q.compare (0, 5, "EXEC ") == 0 || q.compare (0, 5, "CALL ") == 0 || @@ -1200,21 +1200,30 @@ namespace relational vq.literal = string (vq.literal, q[8] == ' ' ? 9 : 8); vq.kind = view_query::complete_execute; } + // + // Hint that what follows is a SELECT-like query. + // + else if (q.compare (0, 10, "/*SELECT*/") == 0) + { + vq.literal = string (vq.literal, q[10] == ' ' ? 11 : 10); + vq.kind = view_query::complete_select; + } else vq.kind = view_query::condition; } else if (!vq.expr.empty ()) { - // If the first token in the expression is a string and - // it starts with "SELECT " or is equal to "SELECT" or - // one of the stored procedure call keywords, then we - // have a complete query. + // If the first token in the expression is a string and it starts + // with "SELECT " or is equal to "SELECT" (or equivalent) or one + // of the stored procedure call keywords, then we have a complete + // query. // if (vq.expr.front ().type == CPP_STRING) { string q (upcase (vq.expr.front ().literal)); - if (q.compare (0, 7, "SELECT ") == 0 || q == "SELECT") + if (q.compare (0, 7, "SELECT ") == 0 || q == "SELECT" || + q.compare (0, 5, "WITH ") == 0 || q == "WITH") vq.kind = view_query::complete_select; else if (q.compare (0, 5, "EXEC ") == 0 || q == "EXEC" || q.compare (0, 5, "CALL ") == 0 || q == "CALL" || @@ -1226,6 +1235,12 @@ namespace relational string (vq.expr.front ().literal, q[8] == ' ' ? 9 : 8); vq.kind = view_query::complete_execute; } + else if (q.compare (0, 10, "/*SELECT*/") == 0) + { + vq.expr.front ().literal = + string (vq.expr.front ().literal, q[10] == ' ' ? 11 : 10); + vq.kind = view_query::complete_select; + } else vq.kind = view_query::condition; } diff --git a/odb/odb/semantics/elements.cxx b/odb/odb/semantics/elements.cxx index b5793d0..9bc96e4 100644 --- a/odb/odb/semantics/elements.cxx +++ b/odb/odb/semantics/elements.cxx @@ -254,7 +254,8 @@ namespace semantics // namespace) but we only use this function to print names // of anonymous types. // - assert (l.next (t) == CPP_SCOPE); + cpp_ttype tt (l.next (t)); + assert (tt == CPP_SCOPE); continue; } } diff --git a/odb/odb/version.hxx.in b/odb/odb/version.hxx.in index 2bf2ae7..52a5343 100644 --- a/odb/odb/version.hxx.in +++ b/odb/odb/version.hxx.in @@ -45,10 +45,10 @@ // 2.2.0.a1 02019901 // 3.0.0.b2 02999952 // -#define ODB_COMPILER_VERSION_OLD 2049976 +#define ODB_COMPILER_VERSION_OLD 2059951 // ODB interface version: minor, major, and alpha/beta versions. // -#define ODB_VERSION 20476 +#define ODB_VERSION 20551 #endif // ODB_COMPILER_VERSION diff --git a/odb/tests/build/bootstrap.build b/odb/tests/build/bootstrap.build index 5e48571..c6cf800 100644 --- a/odb/tests/build/bootstrap.build +++ b/odb/tests/build/bootstrap.build @@ -3,6 +3,7 @@ project = # Unnamed subproject. +using version using config using dist using test |