1 | /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
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 as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ |
15 | |
16 | /** |
17 | @file storage/perfschema/cursor_by_account.cc |
18 | Cursor CURSOR_BY_ACCOUNT (implementation). |
19 | */ |
20 | |
21 | #include "my_global.h" |
22 | #include "cursor_by_account.h" |
23 | #include "pfs_user.h" |
24 | |
25 | cursor_by_account::cursor_by_account(const PFS_engine_table_share *share) |
26 | : PFS_engine_table(share, &m_pos), |
27 | m_pos(0), m_next_pos(0) |
28 | {} |
29 | |
30 | void cursor_by_account::reset_position(void) |
31 | { |
32 | m_pos.m_index= 0; |
33 | m_next_pos.m_index= 0; |
34 | } |
35 | |
36 | int cursor_by_account::rnd_next(void) |
37 | { |
38 | PFS_account *pfs; |
39 | |
40 | for (m_pos.set_at(&m_next_pos); |
41 | m_pos.m_index < account_max; |
42 | m_pos.next()) |
43 | { |
44 | pfs= &account_array[m_pos.m_index]; |
45 | if (pfs->m_lock.is_populated()) |
46 | { |
47 | make_row(pfs); |
48 | m_next_pos.set_after(&m_pos); |
49 | return 0; |
50 | } |
51 | } |
52 | |
53 | return HA_ERR_END_OF_FILE; |
54 | } |
55 | |
56 | int |
57 | cursor_by_account::rnd_pos(const void *pos) |
58 | { |
59 | PFS_account *pfs; |
60 | |
61 | set_position(pos); |
62 | DBUG_ASSERT(m_pos.m_index < account_max); |
63 | pfs= &account_array[m_pos.m_index]; |
64 | if (pfs->m_lock.is_populated()) |
65 | { |
66 | make_row(pfs); |
67 | return 0; |
68 | } |
69 | |
70 | return HA_ERR_RECORD_DELETED; |
71 | } |
72 | |
73 | |