1
//////////////////////////////////////////////////////////////////////////
3
// pgScript - PostgreSQL Tools
4
// RCS-ID: $Id: pgsGenerator.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/objects/pgsGenerator.h"
14
#include "pgscript/objects/pgsNumber.h"
15
#include "pgscript/objects/pgsRecord.h"
16
#include "pgscript/objects/pgsString.h"
17
#include "pgscript/exceptions/pgsCastException.h"
19
pgsGenerator::pgsGenerator(const pgsTypes & generator_type,
20
pgsObjectGen * randomizer) :
21
pgsVariable(generator_type), m_randomizer(randomizer)
26
pgsGenerator::~pgsGenerator()
31
pgsVariable * pgsGenerator::clone() const
33
return pnew pgsGenerator(*this);
36
wxString pgsGenerator::value() const
38
return m_randomizer->random();
41
pgsOperand pgsGenerator::operand() const
46
return pnew pgsNumber(value(), pgsInt);
48
return pnew pgsNumber(value(), pgsReal);
50
return pnew pgsString(value());
54
pgsOperand pgsGenerator::eval(pgsVarMap & vars) const
59
pgsOperand pgsGenerator::pgs_plus(const pgsVariable & rhs) const
61
return *operand() + rhs;
64
pgsOperand pgsGenerator::pgs_minus(const pgsVariable & rhs) const
66
return *operand() - rhs;
69
pgsOperand pgsGenerator::pgs_times(const pgsVariable & rhs) const
71
return *operand() * rhs;
74
pgsOperand pgsGenerator::pgs_over(const pgsVariable & rhs) const
76
return *operand() / rhs;
79
pgsOperand pgsGenerator::pgs_modulo(const pgsVariable & rhs) const
81
return *operand() % rhs;
84
pgsOperand pgsGenerator::pgs_equal(const pgsVariable & rhs) const
86
return *operand() == rhs;
89
pgsOperand pgsGenerator::pgs_different(const pgsVariable & rhs) const
91
return *operand() != rhs;
94
pgsOperand pgsGenerator::pgs_greater(const pgsVariable & rhs) const
96
return *operand() > rhs;
99
pgsOperand pgsGenerator::pgs_lower(const pgsVariable & rhs) const
101
return *operand() < rhs;
104
pgsOperand pgsGenerator::pgs_lower_equal(const pgsVariable & rhs) const
106
return *operand() <= rhs;
109
pgsOperand pgsGenerator::pgs_greater_equal(const pgsVariable & rhs) const
111
return *operand() >= rhs;
114
pgsOperand pgsGenerator::pgs_not() const
116
return !(*operand());
119
bool pgsGenerator::pgs_is_true() const
121
return operand()->pgs_is_true();
124
pgsOperand pgsGenerator::pgs_almost_equal(const pgsVariable & rhs) const
126
return *operand() &= rhs;
129
pgsNumber pgsGenerator::number() const
131
wxString data = value().Strip(wxString::both);
132
pgsTypes type = pgsNumber::num_type(data);
136
return pgsNumber(data, pgsInt);
138
return pgsNumber(data, pgsReal);
140
throw pgsCastException(data, wxT("number"));
144
pgsRecord pgsGenerator::record() const
147
rec.insert(0, 0, operand());
151
pgsString pgsGenerator::string() const
153
return pgsString(value());