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:
parent
f5b49f1f42
commit
a9635a3d8d
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user