├── .gitattributes ├── CONTRIBUTING.md ├── LICENSE ├── Readme.md └── poster └── CDBC CppCon 2016 Poster.pdf /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.cpp text 7 | *.hpp text 8 | #*.md text 9 | 10 | # Declare files that will always have CRLF line endings on checkout. 11 | *.sln text eol=crlf 12 | 13 | # Denote all files that are truly binary and should not be modified. 14 | *.png binary 15 | *.jpg binary 16 | *.pdf binary -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | How to contribute 2 | ================= 3 | 4 | Thank you so much for wanting to contribute to CDBC! Here are a few important things you should know about contributing: 5 | 1. API changes require discussion, use cases, etc. Code comes later. 6 | 2. Pull requests are great for small fixes for bugs, documentation, etc. 7 | 3. Work with repo maintainers to get your change reviewed. 8 | 4. Code contributions require signing a Contributor License Agreement. 9 | 5. Delete your feature branch once the development is complete. 10 | 11 | 12 | API changes 13 | ----------- 14 | 15 | We make changes to CDBC's public APIs, including adding new APIs, very carefully. 16 | Because of this, if you're interested in seeing a new feature in CDBC, the best approach is to create an issue (or comment on an existing issue if there is one) requesting the feature and describing specific use cases for it. 17 | 18 | If the feature has merit, it will go through a thorough process of API design and review. Any code should come after this. 19 | 20 | Pull requests 21 | ------------- 22 | 23 | Unless the change is a trivial fix such as for a typo, it's generally best to start by opening a new issue describing the bug or feature you're intending to fix. 24 | Even if you think it's relatively minor, it's helpful to know what people are working on. And as mentioned above, API changes should be discussed thoroughly before moving to code. 25 | 26 | Some examples of types of pull requests that are immediately helpful: 27 | - Fixing a bug without changing a public API. 28 | - Fixing or improving documentation. 29 | 30 | Guidelines for any code contributions: 31 | -------------------------------------- 32 | 33 | 1. Any significant changes should be accompanied by tests that are easy to read and execute. The project already has good test coverage, so look at some of the existing tests if you're unsure how to go about it. 34 | 2. All contributions must be licensed Eclipse Public License 1.0 and all files must have a copy of the boilerplate licence comment (can be copied from an existing file). 35 | 3. Files should be formatted using clang-format with the style configuration found in the project. 36 | 4. Please squash all commits for a change into a single commit (this can be done using `git rebase -i`). Do your best to have a [well-formed commit message][] for the change. 37 | 5. Remember not to add sensitive/confidential data such as hard-coded passwords, client information, email addresses etc. 38 | 6. Remove legacy code (and tests) where possible to keep the codebase clean. 39 | 7. Any contribution must not contain, nor must be accompanied by: 40 | - materials not created by you, or source code or other materials which result in the inclusion of third party materials; 41 | - materials that would be considered confidential and/or proprietary information, or trade secrets owned by you or third parties; 42 | - your, our, or a third party’s, internal data, whether or not considered confidential and/or proprietary, e.g., intranet URLs, internal emails, client information or references to the foregoing; 43 | - materials which practice, or require the practice of, a patent owned or controlled by a third party, or a proprietary standard, specification, protocol, algorithm, or the like; 44 | - software or other materials which are known to be the subject of an actual or threatened patent infringement or other legal claim; 45 | - software which may be subject to export control laws or regulations; 46 | - trademarks, or software which generates trademarks; 47 | - nonpublic personal information, or personally identifying information generally (e.g. employee names), or information regulated or controlled by data privacy laws and regulations; 48 | - product code names, roadmaps, future product descriptions; 49 | - disparaging comments; 50 | - viruses or other malicious components (including “back doors”, “time bombs”, “logic bombs”, “Trojan horses”, “worms”, “drop dead devices”, “viruses”, “trap doors”, “timers”, “clocks”, “counters” or similar), or any other computer software routine intended or designed to disable, damage, erase, disrupt or impair the normal operation of, or provide unauthorized access to, computer systems or any software or information stored on those computer systems; 51 | - SSH private keys or passwords, or authentication means generally; 52 | 53 | Merging pull requests 54 | --------------------- 55 | 56 | Once a pull request is ready for merging, we'll merge the appropriate changes in the internal codebase. 57 | 58 | Contributor License Agreement 59 | ----------------------------- 60 | 61 | If you are not currently employed by Murex, or if your contribution was created outside of the scope of your work at Murex, you must have entered into a contribution agreement with Murex which governs your contribution. 62 | 63 | Please email one of the project owners for access to such agreements. 64 | 65 | You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Eclipse Public License - v 1.0 3 | 4 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 5 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF 6 | THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 7 | 8 | *1. DEFINITIONS* 9 | 10 | "Contribution" means: 11 | 12 | a) in the case of the initial Contributor, the initial code and 13 | documentation distributed under this Agreement, and 14 | 15 | b) in the case of each subsequent Contributor: 16 | 17 | i) changes to the Program, and 18 | 19 | ii) additions to the Program; 20 | 21 | where such changes and/or additions to the Program originate from and 22 | are distributed by that particular Contributor. A Contribution 23 | 'originates' from a Contributor if it was added to the Program by such 24 | Contributor itself or anyone acting on such Contributor's behalf. 25 | Contributions do not include additions to the Program which: (i) are 26 | separate modules of software distributed in conjunction with the Program 27 | under their own license agreement, and (ii) are not derivative works of 28 | the Program. 29 | 30 | "Contributor" means any person or entity that distributes the Program. 31 | 32 | "Licensed Patents" mean patent claims licensable by a Contributor which 33 | are necessarily infringed by the use or sale of its Contribution alone 34 | or when combined with the Program. 35 | 36 | "Program" means the Contributions distributed in accordance with this 37 | Agreement. 38 | 39 | "Recipient" means anyone who receives the Program under this Agreement, 40 | including all Contributors. 41 | 42 | *2. GRANT OF RIGHTS* 43 | 44 | a) Subject to the terms of this Agreement, each Contributor hereby 45 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 46 | license to reproduce, prepare derivative works of, publicly display, 47 | publicly perform, distribute and sublicense the Contribution of such 48 | Contributor, if any, and such derivative works, in source code and 49 | object code form. 50 | 51 | b) Subject to the terms of this Agreement, each Contributor hereby 52 | grants Recipient a non-exclusive, worldwide, royalty-free patent license 53 | under Licensed Patents to make, use, sell, offer to sell, import and 54 | otherwise transfer the Contribution of such Contributor, if any, in 55 | source code and object code form. This patent license shall apply to the 56 | combination of the Contribution and the Program if, at the time the 57 | Contribution is added by the Contributor, such addition of the 58 | Contribution causes such combination to be covered by the Licensed 59 | Patents. The patent license shall not apply to any other combinations 60 | which include the Contribution. No hardware per se is licensed hereunder. 61 | 62 | c) Recipient understands that although each Contributor grants the 63 | licenses to its Contributions set forth herein, no assurances are 64 | provided by any Contributor that the Program does not infringe the 65 | patent or other intellectual property rights of any other entity. Each 66 | Contributor disclaims any liability to Recipient for claims brought by 67 | any other entity based on infringement of intellectual property rights 68 | or otherwise. As a condition to exercising the rights and licenses 69 | granted hereunder, each Recipient hereby assumes sole responsibility to 70 | secure any other intellectual property rights needed, if any. For 71 | example, if a third party patent license is required to allow Recipient 72 | to distribute the Program, it is Recipient's responsibility to acquire 73 | that license before distributing the Program. 74 | 75 | d) Each Contributor represents that to its knowledge it has sufficient 76 | copyright rights in its Contribution, if any, to grant the copyright 77 | license set forth in this Agreement. 78 | 79 | *3. REQUIREMENTS* 80 | 81 | A Contributor may choose to distribute the Program in object code form 82 | under its own license agreement, provided that: 83 | 84 | a) it complies with the terms and conditions of this Agreement; and 85 | 86 | b) its license agreement: 87 | 88 | i) effectively disclaims on behalf of all Contributors all warranties 89 | and conditions, express and implied, including warranties or conditions 90 | of title and non-infringement, and implied warranties or conditions of 91 | merchantability and fitness for a particular purpose; 92 | 93 | ii) effectively excludes on behalf of all Contributors all liability for 94 | damages, including direct, indirect, special, incidental and 95 | consequential damages, such as lost profits; 96 | 97 | iii) states that any provisions which differ from this Agreement are 98 | offered by that Contributor alone and not by any other party; and 99 | 100 | iv) states that source code for the Program is available from such 101 | Contributor, and informs licensees how to obtain it in a reasonable 102 | manner on or through a medium customarily used for software exchange. 103 | 104 | When the Program is made available in source code form: 105 | 106 | a) it must be made available under this Agreement; and 107 | 108 | b) a copy of this Agreement must be included with each copy of the Program. 109 | 110 | Contributors may not remove or alter any copyright notices contained 111 | within the Program. 112 | 113 | Each Contributor must identify itself as the originator of its 114 | Contribution, if any, in a manner that reasonably allows subsequent 115 | Recipients to identify the originator of the Contribution. 116 | 117 | *4. COMMERCIAL DISTRIBUTION* 118 | 119 | Commercial distributors of software may accept certain responsibilities 120 | with respect to end users, business partners and the like. While this 121 | license is intended to facilitate the commercial use of the Program, the 122 | Contributor who includes the Program in a commercial product offering 123 | should do so in a manner which does not create potential liability for 124 | other Contributors. Therefore, if a Contributor includes the Program in 125 | a commercial product offering, such Contributor ("Commercial 126 | Contributor") hereby agrees to defend and indemnify every other 127 | Contributor ("Indemnified Contributor") against any losses, damages and 128 | costs (collectively "Losses") arising from claims, lawsuits and other 129 | legal actions brought by a third party against the Indemnified 130 | Contributor to the extent caused by the acts or omissions of such 131 | Commercial Contributor in connection with its distribution of the 132 | Program in a commercial product offering. The obligations in this 133 | section do not apply to any claims or Losses relating to any actual or 134 | alleged intellectual property infringement. In order to qualify, an 135 | Indemnified Contributor must: a) promptly notify the Commercial 136 | Contributor in writing of such claim, and b) allow the Commercial 137 | Contributor to control, and cooperate with the Commercial Contributor 138 | in, the defense and any related settlement negotiations. The Indemnified 139 | Contributor may participate in any such claim at its own expense. 140 | 141 | For example, a Contributor might include the Program in a commercial 142 | product offering, Product X. That Contributor is then a Commercial 143 | Contributor. If that Commercial Contributor then makes performance 144 | claims, or offers warranties related to Product X, those performance 145 | claims and warranties are such Commercial Contributor's responsibility 146 | alone. Under this section, the Commercial Contributor would have to 147 | defend claims against the other Contributors related to those 148 | performance claims and warranties, and if a court requires any other 149 | Contributor to pay any damages as a result, the Commercial Contributor 150 | must pay those damages. 151 | 152 | *5. NO WARRANTY* 153 | 154 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 155 | ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 156 | EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES 157 | OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR 158 | A PARTICULAR PURPOSE. Each Recipient is solely responsible for 159 | determining the appropriateness of using and distributing the Program 160 | and assumes all risks associated with its exercise of rights under this 161 | Agreement , including but not limited to the risks and costs of program 162 | errors, compliance with applicable laws, damage to or loss of data, 163 | programs or equipment, and unavailability or interruption of operations. 164 | 165 | *6. DISCLAIMER OF LIABILITY* 166 | 167 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR 168 | ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 169 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 170 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 171 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 172 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 173 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 174 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 175 | 176 | *7. GENERAL* 177 | 178 | If any provision of this Agreement is invalid or unenforceable under 179 | applicable law, it shall not affect the validity or enforceability of 180 | the remainder of the terms of this Agreement, and without further action 181 | by the parties hereto, such provision shall be reformed to the minimum 182 | extent necessary to make such provision valid and enforceable. 183 | 184 | If Recipient institutes patent litigation against any entity (including 185 | a cross-claim or counterclaim in a lawsuit) alleging that the Program 186 | itself (excluding combinations of the Program with other software or 187 | hardware) infringes such Recipient's patent(s), then such Recipient's 188 | rights granted under Section 2(b) shall terminate as of the date such 189 | litigation is filed. 190 | 191 | All Recipient's rights under this Agreement shall terminate if it fails 192 | to comply with any of the material terms or conditions of this Agreement 193 | and does not cure such failure in a reasonable period of time after 194 | becoming aware of such noncompliance. If all Recipient's rights under 195 | this Agreement terminate, Recipient agrees to cease use and distribution 196 | of the Program as soon as reasonably practicable. However, Recipient's 197 | obligations under this Agreement and any licenses granted by Recipient 198 | relating to the Program shall continue and survive. 199 | 200 | Everyone is permitted to copy and distribute copies of this Agreement, 201 | but in order to avoid inconsistency the Agreement is copyrighted and may 202 | only be modified in the following manner. The Agreement Steward reserves 203 | the right to publish new versions (including revisions) of this 204 | Agreement from time to time. No one other than the Agreement Steward has 205 | the right to modify this Agreement. The Eclipse Foundation is the 206 | initial Agreement Steward. The Eclipse Foundation may assign the 207 | responsibility to serve as the Agreement Steward to a suitable separate 208 | entity. Each new version of the Agreement will be given a distinguishing 209 | version number. The Program (including Contributions) may always be 210 | distributed subject to the version of the Agreement under which it was 211 | received. In addition, after a new version of the Agreement is 212 | published, Contributor may elect to distribute the Program (including 213 | its Contributions) under the new version. Except as expressly stated in 214 | Sections 2(a) and 2(b) above, Recipient receives no rights or licenses 215 | to the intellectual property of any Contributor under this Agreement, 216 | whether expressly, by implication, estoppel or otherwise. All rights in 217 | the Program not expressly granted under this Agreement are reserved. 218 | 219 | This Agreement is governed by the laws of the State of New York and the 220 | intellectual property laws of the United States of America. No party to 221 | this Agreement will bring a legal action under this Agreement more than 222 | one year after the cause of action arose. Each party waives its rights 223 | to a jury trial in any resulting litigation. 224 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # CDBC 2 | 3 | Database access library for C++. 4 | 5 | ## About 6 | 7 | Why does C++ need another database access library? First, nothing has been standardized yet. Secondly, we did not found a library which satisfied our needs of abstraction: 8 | 1. Driver abstraction: the API should be the same regardless of the database vendor. 9 | 2. SQL syntax abstraction: the API user should be able to write portable SQL queries regardless of the underlying vendor. 10 | 3. Runtime driver selection: user code should be able to switch accross database vendors at runtime without any need to recompile. 11 | 4. No data model definition: user code should be able to access the database without providing the data model to the API. ORM should be built on top of `CDBC` and not the other way around. 12 | 13 | `CDBC` tries to answer those requirements by providing a common abstraction of sql execution accross databases and at the same time an abstraction of the SQL dialect used by database. It offers a low-level building block for applications and higher level frameworks alike. 14 | 15 | We have built upon the previous work of Johan Anhofer published as [N3886: A proposal to add a Database Access Layer to the Standard Library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3886.pdf "N3886 draft"), amended it on some parts and completed it mainly on SQL dialect abstraction. 16 | We plan to write and submit a draft proposal to the C++ normalization committee. 17 | 18 | 19 | *We are currently open sourcing the library. We plan to finish this before mid October.* 20 | 21 | 22 | ## Documentation 23 | 24 | Here a very simple bootstrap example to perform a simple select on a `SQLite` in-memory database. 25 | ```cpp 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | using namespace murex::db; 32 | 33 | int main(int argc, char** argv) { 34 | connection cnx("sqlite"); 35 | cnx.open(":memory:"); 36 | statement stm("select * from EMPLOYEES", cnx); 37 | 38 | for (result res(stm.execute()); !res.is_eof(); res.move_next() { 39 | std::cout 40 | << "- " << res.get("NAME") 41 | << ", age:" << res.get("AGE") 42 | << ", salary: $" << res.get("SALARY") 43 | << '\n'; 44 | } 45 | return 0; 46 | } 47 | ``` 48 | 49 | And the same example using the DSL to abstract the SQL dialect: 50 | ```cpp 51 | #include 52 | #include 53 | 54 | #include 55 | 56 | using namespace murex::db; 57 | 58 | int main(int argc, char** argv) { 59 | connection cnx("sqlite"); 60 | cnx.open(":memory:"); 61 | statement stm(statement_builder(cnx) 62 | .from("EMPLOYEES") 63 | .select("NAME", "AGE", "SALARY") 64 | .to_statement()); 65 | 66 | for (result res(stm.execute()); !res.is_eof(); res.move_next() { 67 | std::cout 68 | << "- " << res.get("NAME") 69 | << ", age:" << res.get("AGE") 70 | << ", salary: $" << res.get("SALARY") 71 | << '\n'; 72 | } 73 | return 0; 74 | } 75 | ``` 76 | 77 | The DSL use natural expressions composition to build a filter: 78 | ```cpp 79 | statement stm(statement_builder(cnx) 80 | .from("EMPLOYEES") 81 | .where(column("AGE") > var("max_age") && 82 | column("SALARY") < var("min_salary")) 83 | .select("NAME") 84 | .to_statement()); 85 | 86 | stm.bind(var("max_age"), 50) 87 | .bind(var("min_salary", 42000.0)) 88 | 89 | result res(stm.execute()); 90 | ``` 91 | 92 | 93 | ## Supported Compilers 94 | 95 | The code is known to work on the following compilers: 96 | - Visual Studio 2008 97 | - GCC 3.4 98 | - clang 3.8 99 | 100 | **Development Status:** This code is still under heavy development on our side. However, it is well-tested and will be put in production soon. 101 | 102 | 103 | ## Contributing 104 | 105 | The `master` branch of this repository contains the latest stable changes of CDBC. Pull requests should be submitted against the latest head of master. See CONTRIBUTING.md for more details about how to contribute. 106 | -------------------------------------------------------------------------------- /poster/CDBC CppCon 2016 Poster.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/murex/cdbc/ecd4dd8776647659b07a7eead2a4dc4f5884cb91/poster/CDBC CppCon 2016 Poster.pdf --------------------------------------------------------------------------------