File: pgsContext.cpp

package info (click to toggle)
pgadmin3 1.14.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 69,368 kB
  • sloc: cpp: 163,662; sh: 4,339; ansic: 1,636; pascal: 1,120; yacc: 927; makefile: 733; lex: 421; perl: 40
file content (134 lines) | stat: -rw-r--r-- 2,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//////////////////////////////////////////////////////////////////////////
//
// pgScript - PostgreSQL Tools
//
// Copyright (C) 2002 - 2012, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////


#include "pgAdmin3.h"
#include "pgscript/utilities/pgsContext.h"

#include <wx/datetime.h>
#include <wx/regex.h>
#include <typeinfo>
#include "pgscript/objects/pgsNumber.h"
#include "pgscript/objects/pgsString.h"
#include "pgscript/statements/pgsExpressionStmt.h"

#include <wx/listimpl.cpp>
WX_DEFINE_LIST(pgsListExpression);

pgsContext::pgsContext(pgsOutputStream &cout) :
	m_cout(cout)
{

}

pgsContext::~pgsContext()
{

}

pgsVariable *pgsContext::zero()
{
	pgsVariable *zero = pnew pgsNumber(wxT("0"));
	push_var(zero);
	return zero;
}

pgsVariable *pgsContext::one()
{
	pgsVariable *one = pnew pgsNumber(wxT("1"));
	push_var(one);
	return one;
}

pgsVariable *pgsContext::seed()
{
	pgsVariable *seed = pnew pgsNumber(wxString() << wxDateTime::GetTimeNow());
	push_var(seed);
	return seed;
}

pgsVariable *pgsContext::encoding()
{
	pgsVariable *encoding = pnew pgsString(wxLocale::GetSystemEncodingName());
	push_var(encoding);
	return encoding;
}

pgsStmtList *pgsContext::stmt_list(pgsThread *app)
{
	pgsStmtList *stmt_list = pnew pgsStmtList(m_cout, app);
	push_stmt(stmt_list);
	return stmt_list;
}

void pgsContext::add_column(const wxString &column)
{
	m_columns.Add(column);
}

const wxArrayString &pgsContext::columns()
{
	return m_columns;
}

void pgsContext::clear_columns()
{
	m_columns.Clear();
}

void pgsContext::push_var(pgsExpression *var)
{
	wxLogScriptVerbose(wxT("PUSH EXPR %s"), var->value().c_str());
	m_vars.push_back(var);
}

void pgsContext::pop_var()
{
	wxLogScriptVerbose(wxT("POP EXPR %s"), m_vars.back()->value().c_str());
	m_vars.pop_back();
}

size_t pgsContext::size_vars() const
{
	return m_vars.GetCount();
}

void pgsContext::push_stmt(pgsStmt *stmt)
{
	wxLogScriptVerbose(wxT("PUSH STMT %s"), wxString(typeid(*stmt).name(),
	                   wxConvUTF8).c_str());
	m_stmts.push_back(stmt);
}

void pgsContext::pop_stmt()
{
	wxLogScriptVerbose(wxT("POP STMT %s"), wxString(typeid(*(m_stmts.back()))
	                   .name(), wxConvUTF8).c_str());
	m_stmts.pop_back();
}

size_t pgsContext::size_stmts() const
{
	return m_stmts.GetCount();
}

void pgsContext::clear_stacks()
{
	while (!m_vars.empty())
	{
		pdelete(m_vars.back());
		m_vars.pop_back();
	}

	while (!m_stmts.empty())
	{
		pdelete(m_stmts.back());
		m_stmts.pop_back();
	}
}