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

« back to all changes in this revision

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