2006-07-17 19:44:18 +02:00
|
|
|
/*
|
|
|
|
* 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): ______________________________________.
|
2009-10-21 02:42:38 +02:00
|
|
|
* Adriano dos Santos Fernandes
|
2006-07-17 19:44:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
2006-12-04 22:36:29 +01:00
|
|
|
#include "ids.h"
|
|
|
|
#include "../jrd/constants.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/gdsassert.h"
|
|
|
|
#include "../jrd/jrd.h"
|
|
|
|
#include "../jrd/dsc.h"
|
|
|
|
#include "../jrd/exe.h"
|
2006-12-04 22:36:29 +01:00
|
|
|
#include "../jrd/ini.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/req.h"
|
|
|
|
#include "../jrd/rse.h"
|
|
|
|
#include "../jrd/val.h"
|
2006-07-18 08:08:15 +02:00
|
|
|
#include "../jrd/cmp_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/err_proto.h"
|
2006-12-04 22:36:29 +01:00
|
|
|
#include "../jrd/evl_proto.h"
|
|
|
|
#include "../jrd/lck_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/met_proto.h"
|
2006-12-04 22:36:29 +01:00
|
|
|
#include "../jrd/mov_proto.h"
|
2006-07-17 19:44:18 +02:00
|
|
|
#include "../jrd/vio_proto.h"
|
|
|
|
|
|
|
|
#include "../jrd/DatabaseSnapshot.h"
|
|
|
|
#include "../jrd/RecordBuffer.h"
|
|
|
|
#include "../jrd/VirtualTable.h"
|
|
|
|
|
|
|
|
using namespace Jrd;
|
2008-08-27 14:20:47 +02:00
|
|
|
using namespace Firebird;
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
RecordSource* VirtualTable::create(thread_db* tdbb, OptimizerBlk* opt, SSHORT stream)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
CompilerScratch* csb = opt->opt_csb;
|
|
|
|
CompilerScratch::csb_repeat* csb_tail = &csb->csb_rpt[stream];
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
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;
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2006-12-04 22:36:29 +01:00
|
|
|
void VirtualTable::erase(thread_db* tdbb, record_param* rpb)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2006-12-04 22:36:29 +01:00
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2006-12-04 22:36:29 +01:00
|
|
|
fb_assert(dbb);
|
|
|
|
|
|
|
|
jrd_rel* relation = rpb->rpb_relation;
|
|
|
|
fb_assert(relation);
|
|
|
|
|
|
|
|
dsc desc;
|
2008-04-23 10:00:27 +02:00
|
|
|
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
|
|
|
|
{
|
2008-08-27 14:20:47 +02:00
|
|
|
ERR_post(Arg::Gds(isc_read_only));
|
2008-04-23 10:00:27 +02:00
|
|
|
}
|
2007-01-07 16:15:06 +01:00
|
|
|
|
2006-12-04 22:36:29 +01:00
|
|
|
const SLONG id = MOV_get_long(&desc, 0);
|
|
|
|
|
|
|
|
// Post a blocking request
|
|
|
|
Lock temp_lock;
|
|
|
|
temp_lock.lck_dbb = dbb;
|
2008-04-23 10:00:27 +02:00
|
|
|
temp_lock.lck_type = lock_type;
|
2006-12-04 22:36:29 +01:00
|
|
|
temp_lock.lck_parent = dbb->dbb_lock;
|
2008-04-23 10:00:27 +02:00
|
|
|
temp_lock.lck_owner_handle = LCK_get_owner_handle(tdbb, temp_lock.lck_type);
|
2006-12-04 22:36:29 +01:00
|
|
|
temp_lock.lck_length = sizeof(SLONG);
|
|
|
|
temp_lock.lck_key.lck_long = id;
|
|
|
|
|
2008-04-26 12:29:52 +02:00
|
|
|
ThreadStatusGuard temp_status(tdbb);
|
2008-04-23 10:00:27 +02:00
|
|
|
|
2008-01-26 14:17:19 +01:00
|
|
|
if (LCK_lock(tdbb, &temp_lock, LCK_EX, -1))
|
2006-12-04 22:36:29 +01:00
|
|
|
LCK_release(tdbb, &temp_lock);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
void VirtualTable::modify(thread_db* tdbb, record_param* /*org_rpb*/, record_param* /*new_rpb*/)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2009-10-21 02:42:38 +02:00
|
|
|
ERR_post(Arg::Gds(isc_read_only));
|
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2006-07-21 11:31:19 +02:00
|
|
|
|
2009-10-30 11:59:52 +01:00
|
|
|
void VirtualTable::store(thread_db* tdbb, record_param* /*rpb*/)
|
2009-10-21 02:42:38 +02:00
|
|
|
{
|
|
|
|
ERR_post(Arg::Gds(isc_read_only));
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
unsigned VirtualTable::dump(UCHAR* buffer, unsigned bufferLen)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2009-10-21 02:42:38 +02:00
|
|
|
UCHAR* bufferStart = buffer;
|
|
|
|
|
|
|
|
if (bufferLen > 0)
|
|
|
|
*buffer++ = isc_info_rsb_virt_sequential;
|
|
|
|
|
|
|
|
return buffer - bufferStart;
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-31 20:03:30 +01:00
|
|
|
void VirtualTable::open(thread_db* tdbb, jrd_req* request)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
|
|
|
jrd_rel* const relation = rsb->rsb_relation;
|
|
|
|
record_param* const rpb = &request->req_rpb[rsb->rsb_stream];
|
2009-10-21 02:42:38 +02:00
|
|
|
irsb_virtual* const impure = (irsb_virtual*) ((UCHAR*) request + rsb->rsb_impure);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
|
|
|
const Record* const record = rpb->rpb_record;
|
|
|
|
const Format* format = NULL;
|
2009-06-27 08:23:36 +02:00
|
|
|
if (!record || !record->rec_format)
|
|
|
|
{
|
2006-07-17 19:44:18 +02:00
|
|
|
format = MET_current(tdbb, relation);
|
|
|
|
VIO_record(tdbb, rpb, format, request->req_pool);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
format = record->rec_format;
|
|
|
|
}
|
|
|
|
|
2006-07-21 11:31:19 +02:00
|
|
|
rpb->rpb_number.setValue(BOF_NUMBER);
|
|
|
|
|
2006-07-17 19:44:18 +02:00
|
|
|
DatabaseSnapshot* snapshot = DatabaseSnapshot::create(tdbb);
|
|
|
|
impure->irsb_record_buffer = snapshot->getData(relation);
|
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
void VirtualTable::close(thread_db* tdbb)
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
irsb_virtual* impure = (irsb_virtual*) ((UCHAR*) tdbb->getRequest() + rsb->rsb_impure);
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
impure->irsb_record_buffer = NULL;
|
|
|
|
}
|
2006-07-17 19:44:18 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
|
2009-10-31 20:03:30 +01:00
|
|
|
bool VirtualTable::get(thread_db* tdbb, jrd_req* request)
|
2009-10-21 02:42:38 +02:00
|
|
|
{
|
|
|
|
SET_TDBB(tdbb);
|
|
|
|
|
|
|
|
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);
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 22:18:40 +02:00
|
|
|
|
2009-10-21 02:42:38 +02:00
|
|
|
void VirtualTable::markRecursive()
|
2006-07-17 19:44:18 +02:00
|
|
|
{
|
2009-10-21 02:42:38 +02:00
|
|
|
// Do nothing.
|
2006-07-17 19:44:18 +02:00
|
|
|
}
|