aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libpqxx/src/field.cxx
blob: 10f0f69e2bcf2186fe3388f211826ed06b641b35 (plain) (blame)
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
/** Implementation of the pqxx::field class.
 *
 * pqxx::field refers to a field in a query result.
 *
 * Copyright (c) 2000-2019, Jeroen T. Vermeulen.
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 */
#include "pqxx/compiler-internal.hxx"

#include <cstring>

#include "pqxx/internal/libpq-forward.hxx"

#include "pqxx/result"


pqxx::field::field(const pqxx::row &R, pqxx::row::size_type C) noexcept :
  m_col{static_cast<decltype(m_col)>(C)},
  m_home{R.m_result},
  m_row{pqxx::result_size_type(R.m_index)}
{
}


bool pqxx::field::operator==(const field &rhs) const
{
  if (is_null() != rhs.is_null()) return false;
  // TODO: Verify null handling decision
  const size_type s = size();
  if (s != rhs.size()) return false;
  return std::memcmp(c_str(), rhs.c_str(), s) == 0;
}


const char *pqxx::field::name() const
{
  return home().column_name(col());
}


pqxx::oid pqxx::field::type() const
{
  return home().column_type(col());
}


pqxx::oid pqxx::field::table() const
{
  return home().column_table(col());
}


pqxx::row::size_type pqxx::field::table_column() const
{
  return home().table_column(col());
}


const char *pqxx::field::c_str() const
{
  return home().GetValue(idx(), col());
}


bool pqxx::field::is_null() const noexcept
{
  return home().get_is_null(idx(), col());
}


pqxx::field::size_type pqxx::field::size() const noexcept
{
  return home().get_length(idx(), col());
}