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
|
//////////////////////////////////////////////////////////////////////////
//
// 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/pgsRemoveLine.h"
#include "pgscript/exceptions/pgsParameterException.h"
#include "pgscript/objects/pgsRecord.h"
#include "pgscript/objects/pgsString.h"
pgsRemoveLine::pgsRemoveLine(const wxString &rec, const pgsExpression *line) :
pgsExpression(), m_rec(rec), m_line(line)
{
}
pgsRemoveLine::~pgsRemoveLine()
{
pdelete(m_line);
}
pgsExpression *pgsRemoveLine::clone() const
{
return pnew pgsRemoveLine(*this);
}
pgsRemoveLine::pgsRemoveLine(const pgsRemoveLine &that) :
pgsExpression(that), m_rec(that.m_rec)
{
m_line = that.m_line->clone();
}
pgsRemoveLine &pgsRemoveLine::operator =(const pgsRemoveLine &that)
{
if (this != &that)
{
pgsExpression::operator=(that);
m_rec = that.m_rec;
pdelete(m_line);
m_line = that.m_line->clone();
}
return (*this);
}
wxString pgsRemoveLine::value() const
{
return wxString() << wxT("RMLINE(") << m_rec << wxT("[")
<< m_line->value() << wxT("])");
}
pgsOperand pgsRemoveLine::eval(pgsVarMap &vars) const
{
if (vars.find(m_rec) != vars.end() && vars[m_rec]->is_record())
{
pgsRecord &rec = dynamic_cast<pgsRecord &>(*vars[m_rec]);
// Evaluate parameter
pgsOperand line(m_line->eval(vars));
if (line->is_integer())
{
long aux_line;
line->value().ToLong(&aux_line);
if (!rec.remove_line(aux_line))
{
throw pgsParameterException(wxString() << wxT("an error ")
<< wxT("occurred while executing ") << value());
}
}
else
{
throw pgsParameterException(wxString() << line->value()
<< wxT(" is not a valid line number"));
}
return vars[m_rec];
}
else
{
throw pgsParameterException(wxString() << m_rec << wxT(" is not a record"));
}
}
|