File: pgsThread.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 (94 lines) | stat: -rw-r--r-- 2,238 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
//////////////////////////////////////////////////////////////////////////
//
// 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/pgsThread.h"

#include "pgscript/pgsApplication.h"
#include "pgscript/statements/pgsProgram.h"
#include "pgscript/utilities/pgsContext.h"
#include "pgscript/utilities/pgsDriver.h"

pgsThread::pgsThread(pgsVarMap &vars, wxSemaphore &mutex,
                     pgConn *connection, const wxString &file, pgsOutputStream &out,
                     pgsApplication &app, wxMBConv *conv) :
	wxThread(wxTHREAD_DETACHED), m_vars(vars), m_mutex(mutex),
	m_connection(connection), m_data(file), m_out(out),
	m_app(app), m_conv(conv), m_last_error_line(-1)
{
	wxLogScript(wxT("Starting thread"));
	m_mutex.Wait();
}

pgsThread::pgsThread(pgsVarMap &vars, wxSemaphore &mutex,
                     pgConn *connection, const wxString &string, pgsOutputStream &out,
                     pgsApplication &app) :
	wxThread(wxTHREAD_DETACHED), m_vars(vars), m_mutex(mutex),
	m_connection(connection), m_data(string), m_out(out),
	m_app(app), m_conv(0), m_last_error_line(-1)
{
	wxLogScript(wxT("Starting thread"));
	m_mutex.Wait();
}

pgsThread::~pgsThread()
{
	wxLogScript(wxT("Finishing thread"));
	m_app.Complete();
	m_mutex.Post();
	wxLogScript(wxT("Thread  finished"));
}

void *pgsThread::Entry()
{
	pgsProgram program(m_vars);
	pgsContext context(m_out);
	pgscript::pgsDriver driver(context, program, *this);

	if (m_conv)
	{
		wxLogScript(wxT("Parsing file"));
		driver.parse_file(m_data, *m_conv);
		wxLogScript(wxT("File  parsed"));
	}
	else
	{
		wxLogScript(wxT("Parsing string"));
		driver.parse_string(m_data);
		wxLogScript(wxT("String  parsed"));
	}

	return 0;
}

pgConn *pgsThread::connection()
{
	return m_connection;
}

void pgsThread::LockOutput()
{
	m_app.LockOutput();
}

void pgsThread::UnlockOutput()
{
	m_app.UnlockOutput();
}

void pgsThread::last_error_line(int line)
{
	m_last_error_line = line;
}

int pgsThread::last_error_line() const
{
	return m_last_error_line;
}