|
| 1 | +/* |
| 2 | + * The contents of this file are subject to the Initial |
| 3 | + * Developer's Public License Version 1.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the |
| 5 | + * License. You may obtain a copy of the License at |
| 6 | + * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
| 7 | + * |
| 8 | + * Software distributed under the License is distributed AS IS, |
| 9 | + * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing rights |
| 11 | + * and limitations under the License. |
| 12 | + * |
| 13 | + * The Original Code was created by Adriano dos Santos Fernandes |
| 14 | + * for the Firebird Open Source RDBMS project. |
| 15 | + * |
| 16 | + * Copyright (c) 2021 Adriano dos Santos Fernandes <[email protected]> |
| 17 | + * and all contributors signed below. |
| 18 | + * |
| 19 | + * All Rights Reserved. |
| 20 | + * Contributor(s): ______________________________________. |
| 21 | + */ |
| 22 | + |
| 23 | +#include "../jrd/KeywordsTable.h" |
| 24 | +#include "../jrd/ini.h" |
| 25 | +#include "../jrd/ids.h" |
| 26 | +#include "../common/keywords.h" |
| 27 | + |
| 28 | +using namespace Jrd; |
| 29 | +using namespace Firebird; |
| 30 | + |
| 31 | + |
| 32 | +RecordBuffer* KeywordsTable::getRecords(thread_db* tdbb, jrd_rel* relation) |
| 33 | +{ |
| 34 | + fb_assert(relation); |
| 35 | + fb_assert(relation->rel_id == rel_keywords); |
| 36 | + |
| 37 | + auto recordBuffer = getData(relation); |
| 38 | + if (recordBuffer) |
| 39 | + return recordBuffer; |
| 40 | + |
| 41 | + recordBuffer = allocBuffer(tdbb, *tdbb->getDefaultPool(), relation->rel_id); |
| 42 | + |
| 43 | + const auto record = recordBuffer->getTempRecord(); |
| 44 | + |
| 45 | + for (const auto* token = keywordGetTokens(); token->tok_string; ++token) |
| 46 | + { |
| 47 | + if (isalpha(token->tok_string[0])) |
| 48 | + { |
| 49 | + record->nullify(); |
| 50 | + |
| 51 | + putField(tdbb, record, |
| 52 | + DumpField(f_keyword_name, VALUE_STRING, strlen(token->tok_string), token->tok_string)); |
| 53 | + |
| 54 | + const bool reserved = !token->nonReserved; |
| 55 | + putField(tdbb, record, DumpField(f_keyword_reserved, VALUE_BOOLEAN, 1, &reserved)); |
| 56 | + |
| 57 | + recordBuffer->store(record); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return recordBuffer; |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +//-------------------------------------- |
| 66 | + |
| 67 | + |
| 68 | +void KeywordsTableScan::close(thread_db* tdbb) const |
| 69 | +{ |
| 70 | + const auto request = tdbb->getRequest(); |
| 71 | + const auto impure = request->getImpure<Impure>(impureOffset); |
| 72 | + |
| 73 | + delete impure->table; |
| 74 | + impure->table = nullptr; |
| 75 | + |
| 76 | + VirtualTableScan::close(tdbb); |
| 77 | +} |
| 78 | + |
| 79 | +const Format* KeywordsTableScan::getFormat(thread_db* tdbb, jrd_rel* relation) const |
| 80 | +{ |
| 81 | + const auto records = getRecords(tdbb, relation); |
| 82 | + return records->getFormat(); |
| 83 | +} |
| 84 | + |
| 85 | +bool KeywordsTableScan::retrieveRecord(thread_db* tdbb, jrd_rel* relation, |
| 86 | + FB_UINT64 position, Record* record) const |
| 87 | +{ |
| 88 | + const auto records = getRecords(tdbb, relation); |
| 89 | + return records->fetch(position, record); |
| 90 | +} |
| 91 | + |
| 92 | +RecordBuffer* KeywordsTableScan::getRecords(thread_db* tdbb, jrd_rel* relation) const |
| 93 | +{ |
| 94 | + const auto request = tdbb->getRequest(); |
| 95 | + const auto impure = request->getImpure<Impure>(impureOffset); |
| 96 | + |
| 97 | + if (!impure->table) |
| 98 | + impure->table = FB_NEW_POOL(*tdbb->getDefaultPool()) KeywordsTable(*tdbb->getDefaultPool()); |
| 99 | + |
| 100 | + return impure->table->getRecords(tdbb, relation); |
| 101 | +} |
0 commit comments