1 /* Copyright (c) 2011, 2021, Oracle and/or its affiliates.
2 
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
22 
23 /**
24   @file storage/perfschema/cursor_by_host.cc
25   Cursor CURSOR_BY_HOST (implementation).
26 */
27 
28 #include "my_global.h"
29 #include "cursor_by_host.h"
30 #include "pfs_buffer_container.h"
31 
32 ha_rows
get_row_count(void)33 cursor_by_host::get_row_count(void)
34 {
35   return global_host_container.get_row_count();
36 }
37 
cursor_by_host(const PFS_engine_table_share * share)38 cursor_by_host::cursor_by_host(const PFS_engine_table_share *share)
39   : PFS_engine_table(share, &m_pos),
40     m_pos(0), m_next_pos(0)
41 {}
42 
reset_position(void)43 void cursor_by_host::reset_position(void)
44 {
45   m_pos.m_index= 0;
46   m_next_pos.m_index= 0;
47 }
48 
rnd_next(void)49 int cursor_by_host::rnd_next(void)
50 {
51   PFS_host *pfs;
52 
53   m_pos.set_at(&m_next_pos);
54   PFS_host_iterator it= global_host_container.iterate(m_pos.m_index);
55   pfs= it.scan_next(& m_pos.m_index);
56   if (pfs != NULL)
57   {
58     make_row(pfs);
59     m_next_pos.set_after(&m_pos);
60     return 0;
61   }
62 
63   return HA_ERR_END_OF_FILE;
64 }
65 
66 int
rnd_pos(const void * pos)67 cursor_by_host::rnd_pos(const void *pos)
68 {
69   PFS_host *pfs;
70 
71   set_position(pos);
72 
73   pfs= global_host_container.get(m_pos.m_index);
74   if (pfs != NULL)
75   {
76     make_row(pfs);
77     return 0;
78   }
79 
80   return HA_ERR_RECORD_DELETED;
81 }
82 
83