Skip to content

Commit 14a308b

Browse files
[QTS: 826141] Node.js silently ignored fetch errors
Node.js could ignore fetch errors such as SQLE_OVERFLOW_ERROR. This has been fixed.
1 parent b82fdbd commit 14a308b

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ npm install sqlanywhere
99
```
1010
#### Prerequisites
1111
This driver communicates with the native SQL Anywhere libraries, and thus requires
12-
native compilation. Native compilation is managed by [`node-gyp`](https://github.com/TooTallNate/node-gyp/). Please see that project for additional prerequisites including Python 2.7, and C/C++ tool chain.
12+
native compilation. Native compilation is managed by [`node-gyp`](https://github.com/TooTallNate/node-gyp/). Please see that project for additional prerequisites including Python and a C/C++ tool chain.
1313

1414
The official version hosted on NPM includes precompiled libraries for Windows (64-bit).
1515

@@ -24,6 +24,7 @@ Versions supported:
2424
<tr><td>1.0.23</td><td>10.x</td></tr>
2525
<tr><td>1.0.24<td><b>Only</b> 5.x through 10.x (support for 0.10, 0.12, and 4.x is dropped)</td></tr>
2626
<tr><td>1.0.25<td>5.x through 12.x</td></tr>
27+
<tr><td>1.0.26<td>5.x through 12.x</td></tr>
2728
</table>
2829

2930
## Getting Started

build.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ exec( "rm ./build/Release/sqlanywhere.node", function( error, out, err ) {
2121
if( error ) {
2222
console.log( error, out );
2323
console.log( "Error when executing node-gyp configure" );
24+
console.log( "Make sure node-gyp is installed and in the PATH");
2425
process.exit( -1 );
2526
}
2627
var build = require('child_process').exec;
2728
build( "node-gyp build", function( error, out ) {
2829
if( error ) {
29-
console.log( "Error when executing node-gyp configure" );
30+
console.log( "Error when executing node-gyp build" );
31+
console.log( "Make sure a C++ tool chain is installed and in the PATH");
3032
process.exit( -1 );
3133
}
3234
db = require( "./lib/index" );
@@ -37,7 +39,7 @@ exec( "rm ./build/Release/sqlanywhere.node", function( error, out, err ) {
3739
});
3840
});
3941
} catch( err ) {
40-
console.log( "Error Building Binaries. Make sure node-gyp is installed and in the PATH")
42+
console.log( "Error Building Binaries. Make sure node-gyp is installed and in the PATH");
4143
throw new Error( "Could not build binaries" );
4244
process.exit( -1 );
4345
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "SQL ANYWHERE",
33
"name": "sqlanywhere",
44
"description": "SQL Anywhere JavaScript Driver.",
5-
"version": "1.0.25",
5+
"version": "1.0.26",
66
"repository": {
77
"url": "https://github.com/sqlanywhere/node-sqlanywhere"
88
},

src/h/sqlany_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class ExecuteData {
133133
};
134134

135135
bool cleanAPI (); // Finalizes the API and frees up resources
136+
int getError( a_sqlany_connection *conn, char *str, size_t len );
136137
void getErrorMsg( a_sqlany_connection *conn, std::string &str );
137138
void getErrorMsg( int code, std::string &str );
138139
void throwError( a_sqlany_connection *conn );

src/sqlanywhere.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ static bool fillResult( executeBaton *baton, Persistent<Value> &ResultSet )
8585
void executeWork( uv_work_t *req )
8686
/********************************/
8787
{
88+
int rc = 0;
89+
int sqlcode = 0;
90+
8891
executeBaton *baton = static_cast<executeBaton*>(req->data);
8992
scoped_lock lock( baton->obj->conn_mutex );
9093

@@ -112,7 +115,7 @@ void executeWork( uv_work_t *req )
112115
return;
113116
}
114117
baton->stmt_obj->sqlany_stmt = sqlany_stmt;
115-
118+
116119
} else if( sqlany_stmt == NULL ) {
117120
baton->err = true;
118121
getErrorMsg( JS_ERR_INVALID_OBJECT, baton->error_msg );
@@ -155,12 +158,17 @@ void executeWork( uv_work_t *req )
155158
getErrorMsg( baton->obj->conn, baton->error_msg );
156159
return;
157160
}
158-
159-
if( !fetchResultSet( sqlany_stmt, baton->rows_affected, baton->colNames,
160-
baton->execData[0], baton->col_types ) ) {
161-
baton->err = true;
162-
getErrorMsg( baton->obj->conn, baton->error_msg );
163-
return;
161+
162+
rc = fetchResultSet( sqlany_stmt, baton->rows_affected, baton->colNames,
163+
baton->execData[0], baton->col_types );
164+
165+
if( !rc ) {
166+
sqlcode = getError( baton->obj->conn, NULL, 0 );
167+
if( (sqlcode != 0) && (sqlcode != 100) ) {
168+
baton->err = true;
169+
getErrorMsg( baton->obj->conn, baton->error_msg );
170+
return;
171+
}
164172
}
165173
}
166174

@@ -283,6 +291,9 @@ NODE_API_FUNC( StmtObject::exec )
283291
void getMoreResultsWork( uv_work_t *req )
284292
/***************************************/
285293
{
294+
int rc = 0;
295+
int sqlcode = 0;
296+
286297
executeBaton *baton = static_cast<executeBaton*>(req->data);
287298
scoped_lock lock( baton->obj->conn_mutex );
288299

@@ -314,11 +325,16 @@ void getMoreResultsWork( uv_work_t *req )
314325
}
315326

316327
baton->execData[0]->clear();
317-
if( !fetchResultSet( stmt, baton->rows_affected, baton->colNames,
318-
baton->execData[0], baton->col_types ) ) {
319-
baton->err = true;
320-
getErrorMsg( baton->obj->conn, baton->error_msg );
321-
return;
328+
rc = fetchResultSet( stmt, baton->rows_affected, baton->colNames,
329+
baton->execData[0], baton->col_types );
330+
331+
if( !rc ) {
332+
sqlcode = getError( baton->obj->conn, NULL, 0 );
333+
if( (sqlcode != 0 ) && (sqlcode != 100) ) {
334+
baton->err = true;
335+
getErrorMsg( baton->obj->conn, baton->error_msg );
336+
return;
337+
}
322338
}
323339
}
324340

@@ -563,7 +579,6 @@ void Connection::prepareWork( uv_work_t *req )
563579

564580
baton->obj->sqlany_stmt = api.sqlany_prepare( baton->obj->connection->conn,
565581
baton->stmt.c_str() );
566-
567582
if( baton->obj->sqlany_stmt == NULL ) {
568583
baton->err = true;
569584
getErrorMsg( baton->obj->connection->conn, baton->error_msg );

src/utils.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
using namespace v8;
1111
using namespace node;
1212

13+
int getError( a_sqlany_connection *conn, char *str, size_t len )
14+
/**************************************************************/
15+
{
16+
int sqlcode;
17+
sqlcode = api.sqlany_error( conn, str, len );
18+
return sqlcode;
19+
}
20+
1321
void getErrorMsg( int code, std::string &str )
1422
/********************************************/
1523
{
@@ -57,11 +65,11 @@ void getErrorMsg( a_sqlany_connection *conn, std::string &str )
5765
/*************************************************************/
5866
{
5967
char buffer[SACAPI_ERROR_SIZE];
60-
int rc;
61-
rc = api.sqlany_error( conn, buffer, sizeof(buffer) );
68+
int sqlcode;
69+
sqlcode = getError( conn, buffer, sizeof(buffer) );
6270
std::ostringstream message;
6371
message << "Code: ";
64-
message << rc;
72+
message << sqlcode;
6573
message << " Msg: ";
6674
message << buffer;
6775
str = message.str();
@@ -568,13 +576,16 @@ bool fetchResultSet( a_sqlany_stmt * sqlany_stmt,
568576
}
569577

570578
int count_string = 0, count_num = 0, count_int = 0;
571-
while( api.sqlany_fetch_next( sqlany_stmt ) ) {
579+
while( true ) {
580+
581+
if( !api.sqlany_fetch_next( sqlany_stmt ) ) {
582+
return false;
583+
}
572584

573585
for( int i = 0; i < num_cols; i++ ) {
574586

575587
if( !api.sqlany_get_column( sqlany_stmt, i, &value ) ) {
576588
return false;
577-
break;
578589
}
579590

580591
if( *(value.is_null) ) {

0 commit comments

Comments
 (0)