2021-08-02 03:49:16 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 - 2016, Roland Bock
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2023-07-17 12:14:23 +08:00
|
|
|
#include "make_test_connection.h"
|
2024-06-17 00:45:26 +08:00
|
|
|
#include "Tables.h"
|
2021-08-02 03:49:16 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <sqlpp11/alias_provider.h>
|
|
|
|
#include <sqlpp11/functions.h>
|
2024-07-29 01:37:39 +08:00
|
|
|
#include <sqlpp11/clause/insert.h>
|
2021-08-02 03:49:16 +08:00
|
|
|
#include <sqlpp11/mysql/connection.h>
|
2024-07-29 01:37:39 +08:00
|
|
|
#include <sqlpp11/clause/remove.h>
|
|
|
|
#include <sqlpp11/clause/select.h>
|
2021-08-02 03:49:16 +08:00
|
|
|
#include <sqlpp11/transaction.h>
|
2024-07-29 01:37:39 +08:00
|
|
|
#include <sqlpp11/clause/update.h>
|
2024-04-13 18:04:41 +08:00
|
|
|
#include "../../include/test_helpers.h"
|
2021-08-02 03:49:16 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
const auto library_raii = sqlpp::mysql::scoped_library_initializer_t{0, nullptr, nullptr};
|
|
|
|
|
|
|
|
namespace sql = sqlpp::mysql;
|
2024-06-17 00:45:26 +08:00
|
|
|
const auto tab = test::TabSample{};
|
2021-08-02 03:49:16 +08:00
|
|
|
|
2021-10-11 15:04:57 +08:00
|
|
|
int Truncated(int, char*[])
|
2021-08-02 03:49:16 +08:00
|
|
|
{
|
2023-07-17 12:14:23 +08:00
|
|
|
sql::global_library_init();
|
2021-08-02 03:49:16 +08:00
|
|
|
try
|
|
|
|
{
|
2023-07-17 12:14:23 +08:00
|
|
|
auto db = sql::make_test_connection();
|
2024-06-17 00:45:26 +08:00
|
|
|
test::createTabSample(db);
|
2021-08-02 03:49:16 +08:00
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
db(insert_into(tab).set(tab.boolN = true, tab.textN = "cheese"));
|
|
|
|
db(insert_into(tab).set(tab.boolN = true, tab.textN = "cheesecake"));
|
2021-08-02 03:49:16 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
for (const auto& row : db(db.prepare(sqlpp::select(all_of(tab)).from(tab).unconditionally())))
|
|
|
|
{
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cerr << ">>> row.intN: " << row.intN << ", row.textN: " << row.textN << ", row.boolN: " << row.boolN << std::endl;
|
2021-08-02 03:49:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2024-06-17 00:45:26 +08:00
|
|
|
auto result = db(db.prepare(sqlpp::select(all_of(tab)).from(tab).where(tab.id == 1).limit(1u)));
|
2021-08-02 03:49:16 +08:00
|
|
|
auto& row = result.front();
|
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cerr << ">>> row.intN: " << row.intN << ", row.textN: " << row.textN << ", row.boolN: " << row.boolN << std::endl;
|
|
|
|
assert(row.textN == "cheese");
|
2021-08-02 03:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2024-06-17 00:45:26 +08:00
|
|
|
auto result = db(db.prepare(sqlpp::select(all_of(tab)).from(tab).where(tab.id == 2).limit(1u)));
|
2021-08-02 03:49:16 +08:00
|
|
|
auto& row = result.front();
|
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cerr << ">>> row.intN: " << row.intN << ", row.textN: " << row.textN << ", row.boolN: " << row.boolN << std::endl;
|
|
|
|
assert(row.textN == "cheesecake");
|
2021-08-02 03:49:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Exception: " << e.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2021-10-11 15:04:57 +08:00
|
|
|
return 0;
|
2021-08-02 03:49:16 +08:00
|
|
|
}
|