1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
//////////////////////////////////////////////////////////////////////////
//
// pgScript - PostgreSQL Tools
//
// Copyright (C) 2002 - 2012, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin3.h"
#include "pgscript/expressions/pgsIdentRecord.h"
#include "pgscript/objects/pgsRecord.h"
#include "pgscript/objects/pgsString.h"
pgsIdentRecord::pgsIdentRecord(const wxString &name, const pgsExpression *line,
const pgsExpression *column) :
pgsIdent(name), m_line(line), m_column(column)
{
}
pgsIdentRecord::~pgsIdentRecord()
{
pdelete(m_line);
pdelete(m_column);
}
pgsExpression *pgsIdentRecord::clone() const
{
return pnew pgsIdentRecord(*this);
}
pgsIdentRecord::pgsIdentRecord(const pgsIdentRecord &that) :
pgsIdent(that)
{
m_line = that.m_line->clone();
m_column = that.m_column != 0 ? that.m_column->clone() : 0;
}
pgsIdentRecord &pgsIdentRecord::operator=(const pgsIdentRecord &that)
{
if (this != &that)
{
pgsIdent::operator=(that);
pdelete(m_line);
pdelete(m_column);
m_line = that.m_line->clone();
m_column = that.m_column != 0 ? that.m_column->clone() : 0;
}
return (*this);
}
wxString pgsIdentRecord::value() const
{
wxString result;
result << m_name << wxT("[") << m_line->value() << wxT("]");
if (m_column != 0)
{
result << wxT("[") << m_column->value() << wxT("]");
}
return result;
}
pgsOperand pgsIdentRecord::eval(pgsVarMap &vars) const
{
// Check whether the variable is a record
if (vars.find(m_name) != vars.end() && vars[m_name]->is_record())
{
// Get the operand as a record
const pgsRecord &rec = dynamic_cast<const pgsRecord &>(*vars[m_name]);
// Evaluate parameters
pgsOperand line(m_line->eval(vars));
if (line->is_integer())
{
long aux_line;
line->value().ToLong(&aux_line);
if (m_column != 0)
{
pgsOperand column(m_column->eval(vars));
if (column->is_integer())
{
long aux_column;
column->value().ToLong(&aux_column);
return rec.get(aux_line, aux_column);
}
else if (column->is_string())
{
return rec.get(aux_line, rec.get_column(column->value()));
}
}
else
{
return rec.get_line(aux_line);
}
}
}
return pnew pgsString(wxT(""));
}
|