Skip to content

Commit

Permalink
Merge pull request #44 from CUBRID/42.return-error-on-batch-execute
Browse files Browse the repository at this point in the history
Fix #42: Error on batch execute request is not propagated.
  • Loading branch information
kadishmal committed May 29, 2015
2 parents aad3745 + b15ec08 commit 147b5d0
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 153 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# node-cubrid change log

## Version 2.2.4 (May 29, 2015)

- Fix #42: Error on batch execute request is not propagated.

## Version 2.2.3 (Mar 17, 2015)

- Enh #40: No need to escape double quotes when wrapped in single quotes.
Expand Down
36 changes: 10 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
# This is a Dockerfile to build an image for running
# node-cubrid tests.

# To auto run node-cubrid test execute the following:
# docker run --name node-cubrid -v /Users/naver/repos/node-cubrid:/node-cubrid lighthopper/node-cubrid:dev
FROM node:0.10

# Note that the node-cubrid source code should reside under
# /Users/naver/repos/node-cubrid directory. Otherwise
# set your own path. Internally it must bind to
# /node-cubrid path.

# When the container is run, it will enter into bash.
# 1) the first thing to do is:
# npm install

# 2) Prepare a build script for Chef to install CUBRID.
# echo '{"cubrid":{"version":"'$CUBRID_VERSION'"},"run_list":["cubrid::demodb"]}' > cubrid_chef.json

# 3) Run Chef:
# chef-solo -c test/testSetup/solo.rb -j cubrid_chef.json -r http://sourceforge.net/projects/cubrid/files/CUBRID-Demo-Virtual-Machines/Vagrant/chef-cookbooks.tar.gz/download

# 4) Now CUBRID is running. Run the node-cubrid tests.
# npm test


# To build an image, run:
# docker build -t="lighthopper/node-cubrid:dev" .

FROM dockerfile/nodejs
MAINTAINER Esen Sagynov <kadishmal@gmail.com>

WORKDIR /node-cubrid
Expand All @@ -41,7 +17,7 @@ RUN apt-get install -y build-essential zlib1g-dev libssl-dev libreadline6-dev li

# Install Chef Solo prerequisites.
# Ruby >=2.0.0 is required by one of the Chef dependencies.
# Build Ruby from source. Will auto install gem.
# Build Ruby from source. Will auto install gem.
# Download Ruby source into the current directory.
RUN \
RUBY_MAJOR_VERSION=2.2 && \
Expand All @@ -63,6 +39,14 @@ RUN gem install chef --no-rdoc --no-ri
# Make sure the target directory for cookbooks exists.
RUN mkdir -p /tmp/chef-solo

# CUBRID requires `libgcrypt11` while the base Docker image does not
# have it.
RUN \
LIBGCRYPT11_FILE_NAME=libgcrypt11_1.5.0-5+deb7u3_amd64.deb \
curl -L http://security.debian.org/debian-security/pool/updates/main/libg/libgcrypt11/$LIBGCRYPT11_FILE_NAME > $LIBGCRYPT11_FILE_NAME \
dpkg -i $LIBGCRYPT11_FILE_NAME \
rm $LIBGCRYPT11_FILE_NAME

ENV NODE_ENV test
ENV CUBRID_VERSION=9.1.0

Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -884,33 +884,40 @@ repository

2. Then pull the Docker image:

docker pull lighthopper/node-cubrid:dev
docker pull lighthopper/node-cubrid:0.10-test

3. Start the container by mounting the node-cubrid directory to `/node-cubrid`
inside the container:

docker run -it --name node-cubrid -v $NODE_CUBRID_SRC:/node-cubrid lighthopper/node-cubrid:dev
docker run -it --name node-cubrid -v $NODE_CUBRID_SRC:/node-cubrid lighthopper/node-cubrid:0.10-test

4. This will enter into the bash inside the container. At this point all commands you type
will be executed inside this container. Now install all NPM dependencies.

npm install

5. Prepare a build instructions for Chef to install CUBRID Database. Defaults to version 9.1.x.
If you prefer to test against a different version of CUBRID like `8.4.1`, set
`CUBRID_VERSION=8.4.1` environment variable. Then run the following command to prepare
the Chef instructions.
5. The default CUBRID Database version is 9.1.0. You can override it as follows. Supported version are: `9.1.0`, `9.0.0`, `8.4.4`, `8.4.3`, and `8.4.1`.

CUBRID_VERSION=8.4.1

6. Run the following command to prepare the Chef instructions.

echo '{"cubrid":{"version":"'$CUBRID_VERSION'"},"run_list":["cubrid::demodb"]}' > cubrid_chef.json

6. Run Chef to actually install and start up CUBRID Server:

chef-solo -c test/testSetup/solo.rb -j cubrid_chef.json -r http://sourceforge.net/projects/cubrid/files/CUBRID-Demo-Virtual-Machines/Vagrant/chef-cookbooks.tar.gz/download

7. Now CUBRID is running. Run the node-cubrid tests.
7. Now CUBRID is running. Run the node-cubrid tests as follows.

npm test

### Build a Docker container

Run the following in order to build an image for node-cubrid testing.

docker build -t="lighthopper/node-cubrid:0.10-test" .

## What's next

We intend to continuosly improve this driver, by adding more features and improving the existing code base.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-cubrid",
"version": "2.2.3",
"version": "2.2.4",
"description": "This is a Node.js driver for CUBRID RDBMS. It is developed in 100% JavaScript and does not require specific platform compilation.",
"author": "CUBRID <contact@cubrid.org> (http://www.cubrid.org/)",
"repository": {
Expand Down
74 changes: 38 additions & 36 deletions src/CUBRIDConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ CUBRIDConnection.prototype._doGetBrokerPort = function (callback) {
packetWriter = new PacketWriter(clientInfoExchangePacket.getBufferLength()),
self = this,
socket = this._socket = Net.createConnection(this.initialBrokerPort, this.brokerServer);

socket.setNoDelay(true);
socket.setTimeout(this._CONNECTION_TIMEOUT);

Expand Down Expand Up @@ -304,7 +304,7 @@ CUBRIDConnection.prototype._setSocketTimeoutErrorListeners = function (callback)
*/
CUBRIDConnection.prototype._doDatabaseLogin = function (callback) {
var socket;

if (this.connectionBrokerPort) {
socket = this._socket = Net.createConnection(this.connectionBrokerPort, this.brokerServer);

Expand Down Expand Up @@ -353,7 +353,7 @@ CUBRIDConnection.prototype._getEngineVersion = function (callback) {
parserFunction: this._parseEngineVersionBuffer,
dataPacket: getEngineVersionPacket
}, callback));

socket.write(packetWriter._buffer);
};

Expand Down Expand Up @@ -420,7 +420,7 @@ CUBRIDConnection.prototype._implyConnect = function(cb) {
*/
CUBRIDConnection.prototype.getEngineVersion = function (callback) {
var self = this;

Helpers._emitEvent(this, this._NO_ERROR, this.EVENT_ERROR, this.EVENT_ENGINE_VERSION_AVAILABLE, this._DB_ENGINE_VER);

if (typeof(callback) === 'function') {
Expand Down Expand Up @@ -565,7 +565,7 @@ CUBRIDConnection.prototype._executeWithTypedParams = function (sql, arrParamsVal
}),
packetWriter = new PacketWriter(prepareExecuteOldProtocolPacket.getPrepareBufferLength()),
socket = self._socket;

prepareExecuteOldProtocolPacket.writePrepare(packetWriter);

self._socketCurrentEventCallback = cb;
Expand All @@ -580,7 +580,7 @@ CUBRIDConnection.prototype._executeWithTypedParams = function (sql, arrParamsVal
}
], function (err) {
Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_BATCH_COMMANDS_COMPLETED);

if (typeof(callback) === 'function') {
callback(err);
}
Expand All @@ -600,7 +600,7 @@ CUBRIDConnection.prototype._receiveBytes = function (options, cb) {

CUBRIDConnection.prototype._receiveFirstBytes = function (data) {
var socket = this._socket;

// Clear timeout if any.
socket.setTimeout(0);
socket.removeAllListeners('timeout');
Expand Down Expand Up @@ -746,7 +746,13 @@ CUBRIDConnection.prototype._parseBatchExecuteBuffer = function (packetReader) {
var errorCode = dataPacket.errorCode,
err;

if (!this._DB_ENGINE_VER.startsWith('8.4.1')) {
// If there is a gloal error, get the error message
// from dataPacket.errorMsg.
if (errorCode !== 0 && dataPacket.errorMsg) {
err = new Error(errorCode + ':' + dataPacket.errorMsg);
} else {
// Otherwise, check the individual responses of each query in the batch
// and see if there is an error.
err = [];

for (var i = 0; i < dataPacket.arrResultsCode.length; ++i) {
Expand All @@ -758,10 +764,6 @@ CUBRIDConnection.prototype._parseBatchExecuteBuffer = function (packetReader) {
if (!err.length) {
err = null;
}
} else {
if (errorCode !== 0) {
err = new Error(errorCode + ':' + dataPacket.errorMsg);
}
}

this._callback(err);
Expand Down Expand Up @@ -1155,7 +1157,7 @@ CUBRIDConnection.prototype._closeQuery = function (queryHandle, callback) {
break;
}
}

if (foundQueryHandle === false) {
err = new Error(ErrorMessages.ERROR_NO_ACTIVE_QUERY + ": " + queryHandle);

Expand Down Expand Up @@ -1191,22 +1193,22 @@ CUBRIDConnection.prototype._closeQuery = function (queryHandle, callback) {
}

function onConnectionReset() {
// CUBRID Broker may occasionally reset the connection between the client and the
// CAS that the Broker has assigned to this client. Refer to
// https://github.com/CUBRID/node-cubrid/issues/15 for details. According to
// CUBRID Broker may occasionally reset the connection between the client and the
// CAS that the Broker has assigned to this client. Refer to
// https://github.com/CUBRID/node-cubrid/issues/15 for details. According to
// CUBRID CCI native driver implementation function qe_send_close_handle_msg(),
// we can consider the connection closed operation as a successful request.
// This is true because internally CUBRID Broker manages a pool of CAS
// (CUBRID Application Server) processes. When a client connects, the Broker
// This is true because internally CUBRID Broker manages a pool of CAS
// (CUBRID Application Server) processes. When a client connects, the Broker
// assigns/connect it to one of the CAS. Then the client sends some query requests
// to this CAS. After the client receives a response, it may decide to do some
// other application logic before it closes the query handle. Once the client is
// done with the response, it may try to close the query handle.
// In between these receive response and close query, CUBRID Broker may reassign
// the CAS to another client. Notice the client-Broker connection is not broken.
// When the actual close query request arrives to the Broker, it finds out that
// When the actual close query request arrives to the Broker, it finds out that
// the CAS referred by the client is reassigned, it sends CONNECTION RESET to the
// client. node-cubrid should listen it and consider such event as if the close
// client. node-cubrid should listen it and consider such event as if the close
// query request was successful.
socket.removeAllListeners('data');
// Execute `onResponse` without an error.
Expand Down Expand Up @@ -1312,7 +1314,7 @@ function close(callback) {
self.connectionOpened = false;

Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_CONNECTION_CLOSED);

if (typeof(callback) === 'function') {
callback(err);
}
Expand Down Expand Up @@ -1341,7 +1343,7 @@ CUBRIDConnection.prototype.beginTransaction = function (callback) {
*/
CUBRIDConnection.prototype.setAutoCommitMode = function (autoCommitMode, callback) {
var self = this;

_toggleAutoCommitMode(this, autoCommitMode, function (err) {
Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_SET_AUTOCOMMIT_MODE_COMPLETED);
if (typeof(callback) === 'function') {
Expand Down Expand Up @@ -1458,9 +1460,9 @@ CUBRIDConnection.prototype._commit = function (callback) {
socket.write(packetWriter._buffer);
} else {
err = new Error(ErrorMessages.ERROR_NO_COMMIT);

Helpers._emitEvent(this, err, this.EVENT_ERROR, null);

if (typeof(callback) === 'function') {
callback(err);
}
Expand All @@ -1479,7 +1481,7 @@ function _toggleAutoCommitMode(self, autoCommitMode, callback) {

if (!Helpers._validateInputBoolean(autoCommitMode)) {
err = new Error(ErrorMessages.ERROR_INPUT_VALIDATION);

Helpers._emitEvent(self, err, self.EVENT_ERROR, null);
} else {
self.autoCommitMode = autoCommitMode;
Expand Down Expand Up @@ -1588,7 +1590,7 @@ CUBRIDConnection.prototype._lobNew = function (lobType, callback) {
],
function (err, lobObject) {
Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_LOB_NEW_COMPLETED, lobObject);

if (typeof(callback) === 'function') {
callback(err, lobObject);
}
Expand Down Expand Up @@ -1720,7 +1722,7 @@ CUBRIDConnection.prototype._lobWrite = function (lobObject, position, dataBuffer
if (totalWriteLen > lobObject.lobLength) {
lobObject.lobLength = totalWriteLen;
}

Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_LOB_WRITE_COMPLETED, lobObject, totalWriteLen);

if (typeof(callback) === 'function') {
Expand Down Expand Up @@ -1855,7 +1857,7 @@ CUBRIDConnection.prototype._lobRead = function (lobObject, position, length, cal
},
function (err) {
Helpers._emitEvent(self, err, self.EVENT_ERROR, self.EVENT_LOB_READ_COMPLETED, buffer, totalReadLen);

if (typeof(callback) === 'function') {
callback(err, buffer, totalReadLen);
}
Expand Down Expand Up @@ -1906,15 +1908,15 @@ CUBRIDConnection.prototype._setDatabaseParameter = function (parameter, value, c
if (parameter === CASConstants.CCIDbParam.CCI_PARAM_MAX_STRING_LENGTH) {
var errorCode = -1011,
errorMsg = Helpers._resolveErrorCode(errorCode);

err = new Error(errorCode + ':' + errorMsg);

Helpers._emitEvent(this, err, this.EVENT_ERROR, null);

if (typeof(callback) === 'function') {
callback(err);
}

return;
}

Expand Down Expand Up @@ -1968,15 +1970,15 @@ CUBRIDConnection.prototype._getDatabaseParameter = function (parameter, callback
if (parameter === CASConstants.CCIDbParam.CCI_PARAM_MAX_STRING_LENGTH) {
var errorCode = -1011,
errorMsg = Helpers._resolveErrorCode(errorCode);

err = new Error(errorCode + ':' + errorMsg);

Helpers._emitEvent(this, err, this.EVENT_ERROR, null);

if (typeof(callback) === 'function') {
callback(err);
}

return;
}

Expand Down
Loading

0 comments on commit 147b5d0

Please sign in to comment.