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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
//
// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/sqlite/meta_data.hpp>
BOOST_SQLITE_BEGIN_NAMESPACE
auto table_column_meta_data(connection& conn,
cstring_ref db_name, cstring_ref table_name, cstring_ref column_name,
system::error_code & ec, error_info &ei) -> column_meta_data
{
const char * data_type= "", *collation = "";
int nn, pk, ai;
int res = sqlite3_table_column_metadata(conn.handle(), db_name.c_str(), table_name.c_str(),
column_name.c_str(),
&data_type, &collation, &nn, &pk, &ai);
if (res != SQLITE_OK)
{
BOOST_SQLITE_ASSIGN_EC(ec, res);
ei.set_message(sqlite3_errmsg(conn.handle()));
}
return {data_type, collation, nn != 0, pk != 0, ai != 0};
}
auto table_column_meta_data(connection& conn,
cstring_ref table_name, cstring_ref column_name,
system::error_code & ec, error_info &ei) -> column_meta_data
{
const char * data_type= "", *collation = "";
int nn, pk, ai;
int res = sqlite3_table_column_metadata(conn.handle(), nullptr, table_name.c_str(), column_name.c_str(),
&data_type, &collation, &nn, &pk, &ai);
if (res != SQLITE_OK)
{
BOOST_SQLITE_ASSIGN_EC(ec, res);
ei.set_message(sqlite3_errmsg(conn.handle()));
}
return {data_type, collation, nn != 0, pk != 0, ai != 0};
}
auto table_column_meta_data(connection& conn,
cstring_ref db_name, cstring_ref table_name, cstring_ref column_name) -> column_meta_data
{
system::error_code ec;
error_info ei;
auto res = table_column_meta_data(conn, db_name, table_name, column_name, ec, ei);
if (ec)
throw_exception(system::system_error(ec, ei.message()));
return res;
}
auto table_column_meta_data(connection& conn,
cstring_ref table_name, cstring_ref column_name) -> column_meta_data
{
system::error_code ec;
error_info ei;
auto res = table_column_meta_data(conn, table_name, column_name, ec, ei);
if (ec)
throw_exception(system::system_error(ec, ei.message()));
return res;
}
BOOST_SQLITE_END_NAMESPACE
|