Skip to content

Commit

Permalink
Feature CORE-6482 - System table with keywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Feb 7, 2021
1 parent 4cfcfde commit dd2fcfe
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 6 deletions.
4 changes: 3 additions & 1 deletion builds/win32/msvc12/engine.vcxproj
Expand Up @@ -91,6 +91,7 @@
<ClCompile Include="..\..\..\src\jrd\intl_builtin.cpp" />
<ClCompile Include="..\..\..\src\jrd\jrd.cpp" />
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp" />
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp" />
<ClCompile Include="..\..\..\src\jrd\lck.cpp" />
<ClCompile Include="..\..\..\src\jrd\Mapping.cpp" />
<ClCompile Include="..\..\..\src\jrd\Monitoring.cpp" />
Expand Down Expand Up @@ -276,6 +277,7 @@
<ClInclude Include="..\..\..\src\jrd\jrd.h" />
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h" />
<ClInclude Include="..\..\..\src\jrd\jrd_proto.h" />
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h" />
<ClInclude Include="..\..\..\src\jrd\lck.h" />
<ClInclude Include="..\..\..\src\jrd\lck_proto.h" />
<ClInclude Include="..\..\..\src\jrd\license.h" />
Expand Down Expand Up @@ -558,4 +560,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion builds/win32/msvc12/engine.vcxproj.filters
Expand Up @@ -288,6 +288,9 @@
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\lck.cpp">
<Filter>JRD files</Filter>
</ClCompile>
Expand Down Expand Up @@ -824,6 +827,9 @@
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\lck.h">
<Filter>Header files</Filter>
</ClInclude>
Expand Down Expand Up @@ -1088,4 +1094,4 @@
<Filter>Resource files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion builds/win32/msvc14/engine.vcxproj
Expand Up @@ -91,6 +91,7 @@
<ClCompile Include="..\..\..\src\jrd\intl_builtin.cpp" />
<ClCompile Include="..\..\..\src\jrd\jrd.cpp" />
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp" />
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp" />
<ClCompile Include="..\..\..\src\jrd\lck.cpp" />
<ClCompile Include="..\..\..\src\jrd\Mapping.cpp" />
<ClCompile Include="..\..\..\src\jrd\MetaName.cpp" />
Expand Down Expand Up @@ -277,6 +278,7 @@
<ClInclude Include="..\..\..\src\jrd\jrd.h" />
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h" />
<ClInclude Include="..\..\..\src\jrd\jrd_proto.h" />
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h" />
<ClInclude Include="..\..\..\src\jrd\lck.h" />
<ClInclude Include="..\..\..\src\jrd\lck_proto.h" />
<ClInclude Include="..\..\..\src\jrd\license.h" />
Expand Down Expand Up @@ -560,4 +562,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion builds/win32/msvc14/engine.vcxproj.filters
Expand Up @@ -288,6 +288,9 @@
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\lck.cpp">
<Filter>JRD files</Filter>
</ClCompile>
Expand Down Expand Up @@ -827,6 +830,9 @@
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\lck.h">
<Filter>Header files</Filter>
</ClInclude>
Expand Down Expand Up @@ -1094,4 +1100,4 @@
<Filter>Resource files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion builds/win32/msvc15/engine.vcxproj
Expand Up @@ -91,6 +91,7 @@
<ClCompile Include="..\..\..\src\jrd\intl_builtin.cpp" />
<ClCompile Include="..\..\..\src\jrd\jrd.cpp" />
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp" />
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp" />
<ClCompile Include="..\..\..\src\jrd\lck.cpp" />
<ClCompile Include="..\..\..\src\jrd\Mapping.cpp" />
<ClCompile Include="..\..\..\src\jrd\MetaName.cpp" />
Expand Down Expand Up @@ -277,6 +278,7 @@
<ClInclude Include="..\..\..\src\jrd\jrd.h" />
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h" />
<ClInclude Include="..\..\..\src\jrd\jrd_proto.h" />
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h" />
<ClInclude Include="..\..\..\src\jrd\lck.h" />
<ClInclude Include="..\..\..\src\jrd\lck_proto.h" />
<ClInclude Include="..\..\..\src\jrd\license.h" />
Expand Down Expand Up @@ -561,4 +563,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion builds/win32/msvc15/engine.vcxproj.filters
Expand Up @@ -288,6 +288,9 @@
<ClCompile Include="..\..\..\src\jrd\JrdStatement.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\KeywordsTable.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\lck.cpp">
<Filter>JRD files</Filter>
</ClCompile>
Expand Down Expand Up @@ -827,6 +830,9 @@
<ClInclude Include="..\..\..\src\jrd\JrdStatement.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\KeywordsTable.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\lck.h">
<Filter>Header files</Filter>
</ClInclude>
Expand Down Expand Up @@ -1094,4 +1100,4 @@
<Filter>Resource files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
101 changes: 101 additions & 0 deletions src/jrd/KeywordsTable.cpp
@@ -0,0 +1,101 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Adriano dos Santos Fernandes
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2021 Adriano dos Santos Fernandes <adrianosf@gmail.com>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/

#include "../jrd/KeywordsTable.h"
#include "../jrd/ini.h"
#include "../jrd/ids.h"
#include "../common/keywords.h"

using namespace Jrd;
using namespace Firebird;


RecordBuffer* KeywordsTable::getRecords(thread_db* tdbb, jrd_rel* relation)
{
fb_assert(relation);
fb_assert(relation->rel_id == rel_keywords);

auto recordBuffer = getData(relation);
if (recordBuffer)
return recordBuffer;

recordBuffer = allocBuffer(tdbb, *tdbb->getDefaultPool(), relation->rel_id);

const auto record = recordBuffer->getTempRecord();

for (const auto* token = keywordGetTokens(); token->tok_string; ++token)
{
if (isalpha(token->tok_string[0]))
{
record->nullify();

putField(tdbb, record,
DumpField(f_keyword_name, VALUE_STRING, strlen(token->tok_string), token->tok_string));

const bool reserved = !token->nonReserved;
putField(tdbb, record, DumpField(f_keyword_reserved, VALUE_BOOLEAN, 1, &reserved));

recordBuffer->store(record);
}
}

return recordBuffer;
}


//--------------------------------------


void KeywordsTableScan::close(thread_db* tdbb) const
{
const auto request = tdbb->getRequest();
const auto impure = request->getImpure<Impure>(impureOffset);

delete impure->table;
impure->table = nullptr;

VirtualTableScan::close(tdbb);
}

const Format* KeywordsTableScan::getFormat(thread_db* tdbb, jrd_rel* relation) const
{
const auto records = getRecords(tdbb, relation);
return records->getFormat();
}

bool KeywordsTableScan::retrieveRecord(thread_db* tdbb, jrd_rel* relation,
FB_UINT64 position, Record* record) const
{
const auto records = getRecords(tdbb, relation);
return records->fetch(position, record);
}

RecordBuffer* KeywordsTableScan::getRecords(thread_db* tdbb, jrd_rel* relation) const
{
const auto request = tdbb->getRequest();
const auto impure = request->getImpure<Impure>(impureOffset);

if (!impure->table)
impure->table = FB_NEW_POOL(*tdbb->getDefaultPool()) KeywordsTable(*tdbb->getDefaultPool());

return impure->table->getRecords(tdbb, relation);
}
79 changes: 79 additions & 0 deletions src/jrd/KeywordsTable.h
@@ -0,0 +1,79 @@
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Adriano dos Santos Fernandes
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2021 Adriano dos Santos Fernandes <adrianosf@gmail.com>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/

#ifndef JRD_KEYWORDS_TABLE_H
#define JRD_KEYWORDS_TABLE_H

#include "firebird.h"
#include "../common/classes/fb_string.h"
#include "../jrd/Monitoring.h"
#include "../jrd/recsrc/RecordSource.h"


namespace Jrd
{

class KeywordsTable : public SnapshotData
{
public:
KeywordsTable(MemoryPool& pool)
: SnapshotData(pool)
{
}

public:
RecordBuffer* getRecords(thread_db* tdbb, jrd_rel* relation);
};


class KeywordsTableScan : public VirtualTableScan
{
public:
KeywordsTableScan(CompilerScratch* csb, const Firebird::string& alias,
StreamType stream, jrd_rel* relation)
: VirtualTableScan(csb, alias, stream, relation)
{
impureOffset = csb->allocImpure<Impure>();
}

void close(thread_db* tdbb) const override;

protected:
const Format* getFormat(thread_db* tdbb, jrd_rel* relation) const override;

bool retrieveRecord(thread_db* tdbb, jrd_rel* relation, FB_UINT64 position,
Record* record) const override;

private:
struct Impure
{
KeywordsTable* table;
};

RecordBuffer* getRecords(thread_db* tdbb, jrd_rel* relation) const;

ULONG impureOffset;
};

} // namespace Jrd

#endif // JRD_KEYWORDS_TABLE_H
3 changes: 3 additions & 0 deletions src/jrd/fields.h
Expand Up @@ -220,3 +220,6 @@
FIELD(fld_cfg_is_set , nam_cfg_is_set , dtype_boolean , 1 , 0 , NULL , false)

FIELD(fld_repl_mode , nam_repl_mode , dtype_short , sizeof(SSHORT) , 0 , NULL , true)

FIELD(fld_keyword_name , nam_keyword_name , dtype_varying , METADATA_IDENTIFIER_CHAR_LEN, dsc_text_type_ascii , NULL , false)
FIELD(fld_keyword_reserved, nam_keyword_reserved, dtype_boolean, 1 , 0 , NULL , false)
4 changes: 4 additions & 0 deletions src/jrd/names.h
Expand Up @@ -451,3 +451,7 @@ NAME("RDB$CONFIG_VALUE", nam_cfg_value)
NAME("RDB$CONFIG_DEFAULT", nam_cfg_default)
NAME("RDB$CONFIG_IS_SET", nam_cfg_is_set)
NAME("RDB$CONFIG_SOURCE", nam_cfg_source)

NAME("RDB$KEYWORDS", nam_keywords)
NAME("RDB$KEYWORD_NAME", nam_keyword_name)
NAME("RDB$KEYWORD_RESERVED", nam_keyword_reserved)
5 changes: 5 additions & 0 deletions src/jrd/opt.cpp
Expand Up @@ -75,6 +75,7 @@
#include "../jrd/par_proto.h"
#include "../yvalve/gds_proto.h"
#include "../jrd/DataTypeUtil.h"
#include "../jrd/KeywordsTable.h"
#include "../jrd/RecordSourceNodes.h"
#include "../jrd/VirtualTable.h"
#include "../jrd/Monitoring.h"
Expand Down Expand Up @@ -2316,6 +2317,10 @@ static RecordSource* gen_retrieval(thread_db* tdbb,
rsb = FB_NEW_POOL(*tdbb->getDefaultPool()) ConfigTableScan(csb, alias, stream, relation);
break;

case rel_keywords:
rsb = FB_NEW_POOL(*tdbb->getDefaultPool()) KeywordsTableScan(csb, alias, stream, relation);
break;

default:
rsb = FB_NEW_POOL(*tdbb->getDefaultPool()) MonitoringTableScan(csb, alias, stream, relation);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/jrd/relations.h
Expand Up @@ -734,3 +734,10 @@ RELATION(nam_config, rel_config, ODS_13_0, rel_virtual)
FIELD(f_cfg_is_set, nam_cfg_is_set, fld_cfg_is_set, 0, ODS_13_0)
FIELD(f_cfg_source, nam_cfg_source, fld_file_name2, 0, ODS_13_0)
END_RELATION

//// FIXME: ODS version
// Relation 54 (RDB$KEYWORDS)
RELATION(nam_keywords, rel_keywords, ODS_13_0, rel_virtual)
FIELD(f_keyword_name, nam_keyword_name, fld_keyword_name, 0, ODS_13_0)
FIELD(f_keyword_reserved, nam_keyword_reserved, fld_keyword_reserved, 0, ODS_13_0)
END_RELATION

0 comments on commit dd2fcfe

Please sign in to comment.