1
//////////////////////////////////////////////////////////////////////////
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
8
//////////////////////////////////////////////////////////////////////////
12
#include "pgscript/expressions/pgsGenInt.h"
14
#include "pgscript/exceptions/pgsParameterException.h"
15
#include "pgscript/generators/pgsDictionaryGen.h"
16
#include "pgscript/objects/pgsGenerator.h"
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)
25
pgsGenInt::~pgsGenInt()
33
pgsExpression * pgsGenInt::clone() const
35
return pnew pgsGenInt(*this);
38
pgsGenInt::pgsGenInt(const pgsGenInt & that) :
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();
47
pgsGenInt & pgsGenInt::operator =(const pgsGenInt & that)
51
pgsExpression::operator=(that);
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();
64
wxString pgsGenInt::value() const
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(" ]");
71
pgsOperand pgsGenInt::eval(pgsVarMap & vars) const
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));
79
// Check parameters and create the generator
80
if (min->is_integer() && max->is_integer() && sequence->is_integer()
81
&& seed->is_integer())
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));
93
if (!min->is_integer())
95
throw pgsParameterException(wxString() << value()
96
<< wxT(":\nmin should be an integer"));
98
else if (!max->is_integer())
100
throw pgsParameterException(wxString() << value()
101
<< wxT(":\nmax should be an integer"));
103
else if (!sequence->is_integer())
105
throw pgsParameterException(wxString() << value()
106
<< wxT(":\nsequence should be an integer"));
110
throw pgsParameterException(wxString() << value()
111
<< wxT(":\nseed should be an integer"));