Improve error message accuracy of native SendQuery

* add private method const char *GetLastError() to src/binding.cc
* add var const char *lastErrorMessage to SendQuery in src/binding.cc
* throw result of PQErrorMessage inside SendQuery

This commit replaces the static/vague error message "PQsendQuery
returned error code" with the actual message text of the error.
The method GetLastError() returns the text of PQErrorMessage.
GetLastError is called from within SendQuery to retrieve the message.
This commit is contained in:
Ben Montgomery 2012-07-24 12:53:00 -04:00
parent 0fcf7093d3
commit 1551f1d183

View File

@ -129,6 +129,7 @@ public:
{
HandleScope scope;
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
const char *lastErrorMessage;
if(!args[0]->IsString()) {
THROW("First parameter must be a string query");
}
@ -137,7 +138,8 @@ public:
int result = self->Send(queryText);
free(queryText);
if(result == 0) {
THROW("PQsendQuery returned error code");
lastErrorMessage = self->GetLastError();
THROW(lastErrorMessage);
}
//TODO should we flush before throw?
self->Flush();
@ -615,6 +617,11 @@ private:
{
EmitError(PQerrorMessage(connection_));
}
const char *GetLastError()
{
return PQerrorMessage(connection_);
}
void StopWrite()
{