forked from SqliteModernCpp/sqlite_modern_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_view.cc
More file actions
26 lines (23 loc) · 748 Bytes
/
string_view.cc
File metadata and controls
26 lines (23 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cstdlib>
#include <sqlite_modern_cpp.h>
#include <catch.hpp>
#ifdef MODERN_SQLITE_STRINGVIEW_SUPPORT
#include <string_view>
using namespace sqlite;
using namespace std;
TEST_CASE("std::string_view works", "[string_view]") {
database db(":memory:");;
db << "CREATE TABLE foo (a integer, b string);\n";
const std::string_view test1 = "null terminated string view";
db << "INSERT INTO foo VALUES (?, ?)" << 1 << test1;
std::string str;
db << "SELECT b from FOO where a=?;" << 1 >> str;
REQUIRE(test1 == str);
const char s[] = "hello world";
std::string_view test2(&s[0], 2);
db << "INSERT INTO foo VALUES (?,?)" << 2 << test2;
db << "SELECT b from FOO where a=?" << 2 >> str;
REQUIRE(str == "he");
}
#endif