mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-27 18:03:04 +01:00
ed0e0daeb3
- Plugins API. - Feature CORE-2700 - UDR (User Defined Routines) Engine - C++ API supporting functions, triggers and stored procedures. - Feature CORE-2470 - Support for alternate format of strings literals. - Feature CORE-2310 - DDL triggers. - Feature CORE-2312 - PSQL Packages. - Feature CORE-1209 - CONTINUE statement. - Feature CORE-1180 - DDL syntax to change (not) nullable state of columns. - Feature CORE-2090 - Support OVER () clause with current aggregate functions. - Fixed CORE-2699 - Common table expression context could be used with parameters. - Introduce ODS 12.0. - Work in progress in type-safe parser. - Refactor some DDL commands (procedures and triggers) from DYN to DdlNodes. - Refactor virtual tables to use a class hierarchy instead of namespaces. This is basic thing, not based on the changes done in Vulcan. Window functions is based on this work. - Refactor COMMENT ON and DROP FUNCTION from DYN to DdlNodes. COMMENT ON do not use GDML anymore, it uses DSQL with PreparedStatement class. - Refactor EXECUTE BLOCK to StmtNodes. - Refactor the IUDF to SysFunctions. That eliminates RDB$GET_CONTEXT and RDB$SET_CONTEXT from RDB$FUNCTIONS.
202 lines
4.9 KiB
C++
202 lines
4.9 KiB
C++
/*
|
|
* 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 Dmitry Yemanov
|
|
* for the Firebird Open Source RDBMS project.
|
|
*
|
|
* Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net>
|
|
* and all contributors signed below.
|
|
*
|
|
* All Rights Reserved.
|
|
* Contributor(s): ______________________________________.
|
|
* Adriano dos Santos Fernandes
|
|
*/
|
|
|
|
#include "firebird.h"
|
|
#include "ids.h"
|
|
#include "../jrd/constants.h"
|
|
#include "../jrd/gdsassert.h"
|
|
#include "../jrd/jrd.h"
|
|
#include "../jrd/dsc.h"
|
|
#include "../jrd/exe.h"
|
|
#include "../jrd/ini.h"
|
|
#include "../jrd/req.h"
|
|
#include "../jrd/rse.h"
|
|
#include "../jrd/val.h"
|
|
#include "../jrd/cmp_proto.h"
|
|
#include "../jrd/err_proto.h"
|
|
#include "../jrd/evl_proto.h"
|
|
#include "../jrd/lck_proto.h"
|
|
#include "../jrd/met_proto.h"
|
|
#include "../jrd/mov_proto.h"
|
|
#include "../jrd/vio_proto.h"
|
|
|
|
#include "../jrd/DatabaseSnapshot.h"
|
|
#include "../jrd/RecordBuffer.h"
|
|
#include "../jrd/VirtualTable.h"
|
|
|
|
using namespace Jrd;
|
|
using namespace Firebird;
|
|
|
|
|
|
RecordSource* VirtualTable::create(thread_db* tdbb, OptimizerBlk* opt, SSHORT stream)
|
|
{
|
|
SET_TDBB(tdbb);
|
|
|
|
CompilerScratch* csb = opt->opt_csb;
|
|
CompilerScratch::csb_repeat* csb_tail = &csb->csb_rpt[stream];
|
|
|
|
RecordSource* rsb = FB_NEW_RPT(*tdbb->getDefaultPool(), 0) RecordSource;
|
|
rsb->rsb_type = rsb_record_stream;
|
|
rsb->rsb_stream = stream;
|
|
rsb->rsb_relation = csb_tail->csb_relation;
|
|
rsb->rsb_impure = CMP_impure(csb, sizeof(irsb_virtual));
|
|
rsb->rsb_record_stream = FB_NEW(*tdbb->getDefaultPool()) VirtualTable(rsb);
|
|
|
|
return rsb;
|
|
}
|
|
|
|
|
|
void VirtualTable::erase(thread_db* tdbb, record_param* rpb)
|
|
{
|
|
SET_TDBB(tdbb);
|
|
|
|
Database* dbb = tdbb->getDatabase();
|
|
fb_assert(dbb);
|
|
|
|
jrd_rel* relation = rpb->rpb_relation;
|
|
fb_assert(relation);
|
|
|
|
dsc desc;
|
|
lck_t lock_type;
|
|
|
|
if (relation->rel_id == rel_mon_attachments)
|
|
{
|
|
// Get attachment id
|
|
if (!EVL_field(relation, rpb->rpb_record, f_mon_att_id, &desc))
|
|
return;
|
|
lock_type = LCK_attachment;
|
|
}
|
|
else if (relation->rel_id == rel_mon_statements)
|
|
{
|
|
// Get transaction id
|
|
if (!EVL_field(relation, rpb->rpb_record, f_mon_stmt_tra_id, &desc))
|
|
return;
|
|
lock_type = LCK_cancel;
|
|
}
|
|
else
|
|
{
|
|
ERR_post(Arg::Gds(isc_read_only));
|
|
}
|
|
|
|
const SLONG id = MOV_get_long(&desc, 0);
|
|
|
|
// Post a blocking request
|
|
Lock temp_lock;
|
|
temp_lock.lck_dbb = dbb;
|
|
temp_lock.lck_type = lock_type;
|
|
temp_lock.lck_parent = dbb->dbb_lock;
|
|
temp_lock.lck_owner_handle = LCK_get_owner_handle(tdbb, temp_lock.lck_type);
|
|
temp_lock.lck_length = sizeof(SLONG);
|
|
temp_lock.lck_key.lck_long = id;
|
|
|
|
ThreadStatusGuard temp_status(tdbb);
|
|
|
|
if (LCK_lock(tdbb, &temp_lock, LCK_EX, -1))
|
|
LCK_release(tdbb, &temp_lock);
|
|
}
|
|
|
|
|
|
void VirtualTable::modify(thread_db* tdbb, record_param* /*org_rpb*/, record_param* /*new_rpb*/)
|
|
{
|
|
ERR_post(Arg::Gds(isc_read_only));
|
|
}
|
|
|
|
|
|
void VirtualTable::store(thread_db* tdbb, record_param* rpb)
|
|
{
|
|
ERR_post(Arg::Gds(isc_read_only));
|
|
}
|
|
|
|
|
|
unsigned VirtualTable::dump(UCHAR* buffer, unsigned bufferLen)
|
|
{
|
|
UCHAR* bufferStart = buffer;
|
|
|
|
if (bufferLen > 0)
|
|
*buffer++ = isc_info_rsb_virt_sequential;
|
|
|
|
return buffer - bufferStart;
|
|
}
|
|
|
|
|
|
void VirtualTable::open(thread_db* tdbb)
|
|
{
|
|
SET_TDBB(tdbb);
|
|
|
|
jrd_req* request = tdbb->getRequest();
|
|
|
|
jrd_rel* const relation = rsb->rsb_relation;
|
|
record_param* const rpb = &request->req_rpb[rsb->rsb_stream];
|
|
irsb_virtual* const impure = (irsb_virtual*) ((UCHAR*) request + rsb->rsb_impure);
|
|
|
|
const Record* const record = rpb->rpb_record;
|
|
const Format* format = NULL;
|
|
if (!record || !record->rec_format)
|
|
{
|
|
format = MET_current(tdbb, relation);
|
|
VIO_record(tdbb, rpb, format, request->req_pool);
|
|
}
|
|
else {
|
|
format = record->rec_format;
|
|
}
|
|
|
|
rpb->rpb_number.setValue(BOF_NUMBER);
|
|
|
|
DatabaseSnapshot* snapshot = DatabaseSnapshot::create(tdbb);
|
|
impure->irsb_record_buffer = snapshot->getData(relation);
|
|
}
|
|
|
|
|
|
void VirtualTable::close(thread_db* tdbb)
|
|
{
|
|
SET_TDBB(tdbb);
|
|
|
|
irsb_virtual* impure = (irsb_virtual*) ((UCHAR*) tdbb->getRequest() + rsb->rsb_impure);
|
|
|
|
impure->irsb_record_buffer = NULL;
|
|
}
|
|
|
|
|
|
bool VirtualTable::get(thread_db* tdbb)
|
|
{
|
|
SET_TDBB(tdbb);
|
|
|
|
jrd_req* request = tdbb->getRequest();
|
|
|
|
record_param* const rpb = &request->req_rpb[rsb->rsb_stream];
|
|
irsb_virtual* const impure = (irsb_virtual*) ((UCHAR*) request + rsb->rsb_impure);
|
|
|
|
if (!impure->irsb_record_buffer)
|
|
return false;
|
|
|
|
rpb->rpb_number.increment();
|
|
|
|
return impure->irsb_record_buffer->fetch(rpb->rpb_number.getValue(), rpb->rpb_record);
|
|
}
|
|
|
|
|
|
void VirtualTable::markRecursive()
|
|
{
|
|
// Do nothing.
|
|
}
|