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

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/expressions/pgsGenInt.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: pgsGenInt.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/pgsGenInt.h"
 
13
 
 
14
#include "pgscript/exceptions/pgsParameterException.h"
 
15
#include "pgscript/generators/pgsDictionaryGen.h"
 
16
#include "pgscript/objects/pgsGenerator.h"
 
17
 
 
18
pgsGenInt::pgsGenInt(const pgsExpression * min, const pgsExpression * max,
 
19
                const pgsExpression * sequence, const pgsExpression * seed) :
 
20
        pgsExpression(), m_min(min), m_max(max), m_sequence(sequence), m_seed(seed)
 
21
{
 
22
 
 
23
}
 
24
 
 
25
pgsGenInt::~pgsGenInt()
 
26
{
 
27
        pdelete(m_min);
 
28
        pdelete(m_max);
 
29
        pdelete(m_sequence);
 
30
        pdelete(m_seed);
 
31
}
 
32
 
 
33
pgsExpression * pgsGenInt::clone() const
 
34
{
 
35
        return pnew pgsGenInt(*this);
 
36
}
 
37
 
 
38
pgsGenInt::pgsGenInt(const pgsGenInt & that) :
 
39
        pgsExpression(that)
 
40
{
 
41
        m_min = that.m_min->clone();
 
42
        m_max = that.m_max->clone();
 
43
        m_sequence = that.m_sequence->clone();
 
44
        m_seed = that.m_seed->clone();
 
45
}
 
46
 
 
47
pgsGenInt & pgsGenInt::operator =(const pgsGenInt & that)
 
48
{
 
49
        if (this != &that)
 
50
        {
 
51
                pgsExpression::operator=(that);
 
52
                pdelete(m_min);
 
53
                pdelete(m_max);
 
54
                pdelete(m_sequence);
 
55
                pdelete(m_seed);
 
56
                m_min = that.m_min->clone();
 
57
                m_max = that.m_max->clone();
 
58
                m_sequence = that.m_sequence->clone();
 
59
                m_seed = that.m_seed->clone();
 
60
        }
 
61
        return (*this);
 
62
}
 
63
 
 
64
wxString pgsGenInt::value() const
 
65
{
 
66
        return wxString() << wxT("integer[ min = ") << m_min->value() << wxT(" max = ")
 
67
                        << m_max->value() << wxT(" sequence = ") << m_sequence->value()
 
68
                        << wxT(" seed = ") << m_seed->value() << wxT(" ]");
 
69
}
 
70
 
 
71
pgsOperand pgsGenInt::eval(pgsVarMap & vars) const
 
72
{
 
73
        // Evaluate parameters
 
74
        pgsOperand min(m_min->eval(vars));
 
75
        pgsOperand max(m_max->eval(vars));
 
76
        pgsOperand sequence(m_sequence->eval(vars));
 
77
        pgsOperand seed(m_seed->eval(vars));
 
78
 
 
79
        // Check parameters and create the generator
 
80
        if (min->is_integer() && max->is_integer() && sequence->is_integer()
 
81
                        && seed->is_integer())
 
82
        {
 
83
                long aux_sequence, aux_seed;
 
84
                sequence->value().ToLong(&aux_sequence);
 
85
                seed->value().ToLong(&aux_seed);
 
86
                return pnew pgsGenerator(pgsVariable::pgsTInt,
 
87
                                pnew pgsIntegerGen(pgsVariable::num(min), pgsVariable::num(max),
 
88
                                                aux_sequence != 0, aux_seed));
 
89
        }
 
90
        else
 
91
        {
 
92
                // Deal with errors
 
93
                if (!min->is_integer())
 
94
                {
 
95
                        throw pgsParameterException(wxString() << value()
 
96
                                        << wxT(":\nmin should be an integer"));
 
97
                }
 
98
                else if (!max->is_integer())
 
99
                {
 
100
                        throw pgsParameterException(wxString() << value()
 
101
                                        << wxT(":\nmax should be an integer"));
 
102
                }
 
103
                else if (!sequence->is_integer())
 
104
                {
 
105
                        throw pgsParameterException(wxString() << value()
 
106
                                        << wxT(":\nsequence should be an integer"));
 
107
                }
 
108
                else
 
109
                {
 
110
                        throw pgsParameterException(wxString() << value()
 
111
                                        << wxT(":\nseed should be an integer"));
 
112
                }
 
113
        }
 
114
}