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

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/objects/pgsGenerator.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: 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
 
7
//
 
8
//////////////////////////////////////////////////////////////////////////
 
9
 
 
10
 
 
11
#include "pgAdmin3.h"
 
12
#include "pgscript/objects/pgsGenerator.h"
 
13
 
 
14
#include "pgscript/objects/pgsNumber.h"
 
15
#include "pgscript/objects/pgsRecord.h"
 
16
#include "pgscript/objects/pgsString.h"
 
17
#include "pgscript/exceptions/pgsCastException.h"
 
18
 
 
19
pgsGenerator::pgsGenerator(const pgsTypes & generator_type,
 
20
                pgsObjectGen * randomizer) :
 
21
        pgsVariable(generator_type), m_randomizer(randomizer)
 
22
{
 
23
 
 
24
}
 
25
 
 
26
pgsGenerator::~pgsGenerator()
 
27
{
 
28
 
 
29
}
 
30
 
 
31
pgsVariable * pgsGenerator::clone() const
 
32
{
 
33
        return pnew pgsGenerator(*this);
 
34
}
 
35
 
 
36
wxString pgsGenerator::value() const
 
37
{
 
38
        return m_randomizer->random();
 
39
}
 
40
 
 
41
pgsOperand pgsGenerator::operand() const
 
42
{
 
43
        switch (type())
 
44
        {
 
45
        case pgsTInt:
 
46
                return pnew pgsNumber(value(), pgsInt);
 
47
        case pgsTReal:
 
48
                return pnew pgsNumber(value(), pgsReal);
 
49
        default:
 
50
                return pnew pgsString(value());
 
51
        }
 
52
}
 
53
 
 
54
pgsOperand pgsGenerator::eval(pgsVarMap & vars) const
 
55
{
 
56
        return this->clone();
 
57
}
 
58
 
 
59
pgsOperand pgsGenerator::pgs_plus(const pgsVariable & rhs) const
 
60
{
 
61
        return *operand() + rhs;
 
62
}
 
63
 
 
64
pgsOperand pgsGenerator::pgs_minus(const pgsVariable & rhs) const
 
65
{
 
66
        return *operand() - rhs;
 
67
}
 
68
 
 
69
pgsOperand pgsGenerator::pgs_times(const pgsVariable & rhs) const
 
70
{
 
71
        return *operand() * rhs;
 
72
}
 
73
 
 
74
pgsOperand pgsGenerator::pgs_over(const pgsVariable & rhs) const
 
75
{
 
76
        return *operand() / rhs;
 
77
}
 
78
 
 
79
pgsOperand pgsGenerator::pgs_modulo(const pgsVariable & rhs) const
 
80
{
 
81
        return *operand() % rhs;
 
82
}
 
83
 
 
84
pgsOperand pgsGenerator::pgs_equal(const pgsVariable & rhs) const
 
85
{
 
86
        return *operand() == rhs;
 
87
}
 
88
 
 
89
pgsOperand pgsGenerator::pgs_different(const pgsVariable & rhs) const
 
90
{
 
91
        return *operand() != rhs;
 
92
}
 
93
 
 
94
pgsOperand pgsGenerator::pgs_greater(const pgsVariable & rhs) const
 
95
{
 
96
        return *operand() > rhs;
 
97
}
 
98
 
 
99
pgsOperand pgsGenerator::pgs_lower(const pgsVariable & rhs) const
 
100
{
 
101
        return *operand() < rhs;
 
102
}
 
103
 
 
104
pgsOperand pgsGenerator::pgs_lower_equal(const pgsVariable & rhs) const
 
105
{
 
106
        return *operand() <= rhs;
 
107
}
 
108
 
 
109
pgsOperand pgsGenerator::pgs_greater_equal(const pgsVariable & rhs) const
 
110
{
 
111
        return *operand() >= rhs;
 
112
}
 
113
 
 
114
pgsOperand pgsGenerator::pgs_not() const
 
115
{
 
116
        return !(*operand());
 
117
}
 
118
 
 
119
bool pgsGenerator::pgs_is_true() const
 
120
{
 
121
        return operand()->pgs_is_true();
 
122
}
 
123
 
 
124
pgsOperand pgsGenerator::pgs_almost_equal(const pgsVariable & rhs) const
 
125
{
 
126
        return *operand() &= rhs;
 
127
}
 
128
 
 
129
pgsNumber pgsGenerator::number() const
 
130
{
 
131
        wxString data = value().Strip(wxString::both);
 
132
        pgsTypes type = pgsNumber::num_type(data);
 
133
        switch (type)
 
134
        {
 
135
        case pgsTInt:
 
136
                return pgsNumber(data, pgsInt);
 
137
        case pgsTReal:
 
138
                return pgsNumber(data, pgsReal);
 
139
        default:
 
140
                throw pgsCastException(data, wxT("number"));
 
141
        }
 
142
}
 
143
 
 
144
pgsRecord pgsGenerator::record() const
 
145
{
 
146
        pgsRecord rec(1);
 
147
        rec.insert(0, 0, operand());
 
148
        return rec;
 
149
}
 
150
 
 
151
pgsString pgsGenerator::string() const
 
152
{
 
153
        return pgsString(value());
 
154
}