Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Move pgScript output prefixes to constants, instead of being embedded
Browse files Browse the repository at this point in the history
in all strings. Also make the error messages (but not the prefixes)
translatable.

Mickael Deloison with some surgery from me


git-svn-id: svn://svn.pgadmin.org/trunk@7664 a7884b65-44f6-0310-8a51-81a127f17b15
  • Loading branch information
mhagander committed Mar 10, 2009
1 parent e6ab859 commit 6ab4d6b
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
6 changes: 6 additions & 0 deletions pgadmin/include/pgscript/pgScript.h
Expand Up @@ -28,6 +28,12 @@ typedef unsigned short int USHORT;
#include <wx/txtstrm.h>
#define pgsOutputStream wxTextOutputStream

const wxString PGSOUTPGSCRIPT (wxT("[PGSCRIPT ] "));
const wxString PGSOUTEXCEPTION(wxT("[EXCEPTION] "));
const wxString PGSOUTQUERY (wxT("[QUERY ] "));
const wxString PGSOUTWARNING (wxT("[WARNING ] "));
const wxString PGSOUTERROR (wxT("[ERROR ] "));

/*** LOGGING ***/

#include "utils/sysLogger.h"
Expand Down
2 changes: 2 additions & 0 deletions pgadmin/include/utils/misc.h
Expand Up @@ -100,6 +100,8 @@ wxLongLong StrToLongLong(const wxString& value);
wxDateTime StrToDateTime(const wxString &value);
OID StrToOid(const wxString& value);

wxString generate_spaces(int length);

// nls aware
wxString BoolToYesNo(bool value);
wxString NumToStr(long value);
Expand Down
5 changes: 3 additions & 2 deletions pgadmin/pgscript/exceptions/pgsArithmeticException.cpp
Expand Up @@ -24,6 +24,7 @@ pgsArithmeticException::~pgsArithmeticException()

const wxString pgsArithmeticException::message() const
{
return wxString() << wxT("[EXCEPT] Arithmetic Exception - Operation impossible between ")
<< m_left << wxT(" and ") << m_right;
return wxString() << PGSOUTEXCEPTION <<
wxString::Format(_("Arithmetic Exception - Operation impossible between '%s' and '%s'"),
m_left.c_str(), m_right.c_str());
}
2 changes: 1 addition & 1 deletion pgadmin/pgscript/exceptions/pgsAssertException.cpp
Expand Up @@ -24,5 +24,5 @@ pgsAssertException::~pgsAssertException()

const wxString pgsAssertException::message() const
{
return wxString() << wxT("[EXCEPT] Assert Exception - ") << m_message;
return wxString() << PGSOUTEXCEPTION << _("Assert Exception - ") << m_message;
}
5 changes: 3 additions & 2 deletions pgadmin/pgscript/exceptions/pgsCastException.cpp
Expand Up @@ -24,6 +24,7 @@ pgsCastException::~pgsCastException()

const wxString pgsCastException::message() const
{
return wxString() << wxT("[EXCEPT] Cast Exception - Cannot convert ")
<< m_value << wxT(" to ") << m_type;
return wxString() << PGSOUTEXCEPTION <<
wxString::Format(_("Cast Exception - Cannot convert '%s' to '%s'"),
m_value.c_str(), m_type.c_str());
}
2 changes: 1 addition & 1 deletion pgadmin/pgscript/exceptions/pgsInterruptException.cpp
Expand Up @@ -24,5 +24,5 @@ pgsInterruptException::~pgsInterruptException()

const wxString pgsInterruptException::message() const
{
return wxT("[EXCEPT] pgScript interrupted");
return wxString() << PGSOUTEXCEPTION << _("pgScript interrupted");
}
10 changes: 7 additions & 3 deletions pgadmin/pgscript/exceptions/pgsParameterException.cpp
Expand Up @@ -9,6 +9,7 @@


#include "pgAdmin3.h"
#include "utils/misc.h"
#include "pgscript/exceptions/pgsParameterException.h"

pgsParameterException::pgsParameterException(const wxString & message) :
Expand All @@ -25,7 +26,10 @@ pgsParameterException::~pgsParameterException()
const wxString pgsParameterException::message() const
{
wxString message(m_message);
message.Replace(wxT("\n"), wxT("\n "));
return wxString() << wxT("[EXCEPT] Parameter Exception - Some parameters ")
<< wxT("are invalid:\n>> ") << message;
message.Replace(wxT("\n"), wxT("\n") + generate_spaces(PGSOUTEXCEPTION.Length()));
message.Prepend(wxT(">> "));
message.Prepend(generate_spaces(PGSOUTEXCEPTION.Length()));
return wxString() << PGSOUTEXCEPTION <<
wxString::Format(_("Parameter Exception - Some parameters are invalid:\n>> %s"),
message.c_str());
}
10 changes: 6 additions & 4 deletions pgadmin/pgscript/expressions/pgsExecute.cpp
Expand Up @@ -116,12 +116,13 @@ pgsOperand pgsExecute::eval(pgsVarMap & vars) const
{
m_app->LockOutput();

(*m_cout) << wxT("[WRNING] ");
(*m_cout) << PGSOUTWARNING;
wxString message(stmt + wxT("\n") + thread
.GetMessagesAndClear().Strip(wxString::both));
wxRegEx multilf(wxT("(\n)+"));
multilf.ReplaceAll(&message, wxT("\n"));
message.Replace(wxT("\n"), wxT("\n "));
message.Replace(wxT("\n"), wxT("\n")
+ generate_spaces(PGSOUTWARNING.Length() + 1));
(*m_cout) << message << wxT("\n");

m_app->UnlockOutput();
Expand All @@ -133,7 +134,7 @@ pgsOperand pgsExecute::eval(pgsVarMap & vars) const
{
m_app->LockOutput();

(*m_cout) << wxT("[NOTICE] ");
(*m_cout) << PGSOUTQUERY;
wxString message(thread.GetMessagesAndClear()
.Strip(wxString::both));
if (!message.IsEmpty())
Expand All @@ -142,7 +143,8 @@ pgsOperand pgsExecute::eval(pgsVarMap & vars) const
message = stmt;
wxRegEx multilf(wxT("(\n)+"));
multilf.ReplaceAll(&message, wxT("\n"));
message.Replace(wxT("\n"), wxT("\n "));
message.Replace(wxT("\n"), wxT("\n")
+ generate_spaces(PGSOUTQUERY.Length() + 1));
(*m_cout) << message << wxT("\n");

m_app->UnlockOutput();
Expand Down
17 changes: 15 additions & 2 deletions pgadmin/pgscript/statements/pgsPrintStmt.cpp
Expand Up @@ -11,6 +11,7 @@
#include "pgAdmin3.h"
#include "pgscript/statements/pgsPrintStmt.h"

#include "pgscript/exceptions/pgsException.h"
#include "pgscript/utilities/pgsThread.h"
#include "pgscript/utilities/pgsUtilities.h"

Expand All @@ -33,8 +34,20 @@ void pgsPrintStmt::eval(pgsVarMap & vars) const
m_app->LockOutput();
}

m_cout << wxT("[OUTPUT] ") << wx_static_cast(const wxString,
m_var->eval(vars)->value()) << wxT("\n");
try
{
m_cout << PGSOUTPGSCRIPT << wx_static_cast(const wxString,
m_var->eval(vars)->value()) << wxT("\n");
}
catch (const pgsException &)
{
if (m_app != 0)
{
m_app->UnlockOutput();
}

throw;
}

if (m_app != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion pgadmin/pgscript/statements/pgsStmtList.cpp
Expand Up @@ -82,7 +82,7 @@ void pgsStmtList::eval(pgsVarMap & vars) const
m_app->LockOutput();
}

m_cout << wxT("[ERROR] Unknown exception:\n")
m_cout << PGSOUTERROR << _("Unknown exception:\n")
<< wx_static_cast(const wxString,
wxString(e.what(), wxConvUTF8));
m_exception_thrown = true;
Expand Down
4 changes: 4 additions & 0 deletions pgadmin/utils/misc.cpp
Expand Up @@ -132,6 +132,10 @@ OID StrToOid(const wxString& value)
return (OID)strtoul(value.ToAscii(), 0, 10);
}

wxString generate_spaces(int length)
{
return wxString().Pad(length);
}

wxString NumToStr(double value)
{
Expand Down

0 comments on commit 6ab4d6b

Please sign in to comment.