|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, Volker Aßmann |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without modification, |
| 6 | + * are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * * Redistributions of source code must retain the above copyright notice, |
| 9 | + * this list of conditions and the following disclaimer. |
| 10 | + * * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer in the documentation |
| 12 | + * and/or other materials provided with the distribution. |
| 13 | + * |
| 14 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 15 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 17 | + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 18 | + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 19 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 20 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 21 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 22 | + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 23 | + * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + */ |
| 25 | + |
| 26 | +#include <iostream> |
| 27 | +#include <memory> |
| 28 | +#include <stdexcept> |
| 29 | + |
| 30 | +#include <sqlpp11/postgresql/connection.h> |
| 31 | +#include <sqlpp11/postgresql/exception.h> |
| 32 | +#include <sqlpp11/sqlpp11.h> |
| 33 | + |
| 34 | +namespace sql = sqlpp::postgresql; |
| 35 | +int BasicConstConfig(int, char*[]) |
| 36 | +{ |
| 37 | + const std::shared_ptr<const sql::connection_config> const_config = []() |
| 38 | + { |
| 39 | + auto config = std::make_shared<sql::connection_config>(); |
| 40 | + config->host = "localhost"; |
| 41 | + config->user = "unknown_user_must_fail"; |
| 42 | + return config; |
| 43 | + }(); |
| 44 | + |
| 45 | + try |
| 46 | + { |
| 47 | + sql::connection db(const_config); |
| 48 | + |
| 49 | + throw std::logic_error("should never reach this point"); |
| 50 | + } |
| 51 | + catch (const sqlpp::postgresql::broken_connection& ex) |
| 52 | + { |
| 53 | + std::cout << "Got exception: '" << ex.what() << "'"; |
| 54 | + return 0; |
| 55 | + } |
| 56 | + |
| 57 | + return 1; |
| 58 | +} |
0 commit comments