~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/expressions/pgsRemoveLine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgScript - PostgreSQL Tools
 
4
// RCS-ID:      $Id: pgsRemoveLine.cpp 7758 2009-03-26 20:49:59Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
//////////////////////////////////////////////////////////////////////////
 
9
 
 
10
 
 
11
#include "pgAdmin3.h"
 
12
#include "pgscript/expressions/pgsRemoveLine.h"
 
13
 
 
14
#include "pgscript/exceptions/pgsParameterException.h"
 
15
#include "pgscript/objects/pgsRecord.h"
 
16
#include "pgscript/objects/pgsString.h"
 
17
 
 
18
pgsRemoveLine::pgsRemoveLine(const wxString & rec, const pgsExpression * line) :
 
19
        pgsExpression(), m_rec(rec), m_line(line)
 
20
{
 
21
 
 
22
}
 
23
 
 
24
pgsRemoveLine::~pgsRemoveLine()
 
25
{
 
26
        pdelete(m_line);
 
27
}
 
28
 
 
29
pgsExpression * pgsRemoveLine::clone() const
 
30
{
 
31
        return pnew pgsRemoveLine(*this);
 
32
}
 
33
 
 
34
pgsRemoveLine::pgsRemoveLine(const pgsRemoveLine & that) :
 
35
        pgsExpression(that), m_rec(that.m_rec)
 
36
{
 
37
        m_line = that.m_line->clone();
 
38
}
 
39
 
 
40
pgsRemoveLine & pgsRemoveLine::operator =(const pgsRemoveLine & that)
 
41
{
 
42
        if (this != &that)
 
43
        {
 
44
                pgsExpression::operator=(that);
 
45
                m_rec = that.m_rec;
 
46
                pdelete(m_line);
 
47
                m_line = that.m_line->clone();
 
48
        }
 
49
        return (*this);
 
50
}
 
51
 
 
52
wxString pgsRemoveLine::value() const
 
53
{
 
54
        return wxString() << wxT("RMLINE(") << m_rec << wxT("[")
 
55
                        << m_line->value() << wxT("])");
 
56
}
 
57
 
 
58
pgsOperand pgsRemoveLine::eval(pgsVarMap & vars) const
 
59
{
 
60
        if (vars.find(m_rec) != vars.end() && vars[m_rec]->is_record())
 
61
        {
 
62
                pgsRecord & rec = dynamic_cast<pgsRecord &>(*vars[m_rec]);
 
63
                
 
64
                // Evaluate parameter
 
65
                pgsOperand line(m_line->eval(vars));
 
66
                if (line->is_integer())
 
67
                {
 
68
                        long aux_line;
 
69
                        line->value().ToLong(&aux_line);
 
70
                        
 
71
                        if (!rec.remove_line(aux_line))
 
72
                        {
 
73
                                throw pgsParameterException(wxString() << wxT("an error ")
 
74
                                                << wxT("occurred while executing ") << value());
 
75
                        }
 
76
                }
 
77
                else
 
78
                {
 
79
                        throw pgsParameterException(wxString() << line->value()
 
80
                                        << wxT(" is not a valid line number"));
 
81
                }
 
82
                
 
83
                return vars[m_rec];
 
84
        }
 
85
        else
 
86
        {
 
87
                throw pgsParameterException(wxString() << m_rec << wxT(" is not a record"));
 
88
        }
 
89
}