Skip to content

Commit 0199b8a

Browse files
committed
Merge branch 'master' into nodev16-2
2 parents a155c8a + 4465ee0 commit 0199b8a

File tree

5 files changed

+75
-45
lines changed

5 files changed

+75
-45
lines changed

README.md

Lines changed: 3 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,8 @@ 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>6.x through 12.x</td></tr>
28+
<tr><td>1.0.27<td>6.x through 12.x</td></tr>
2729
</table>
2830

2931
## 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
}

src/h/sqlany_utils.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ class ExecuteData
138138
std::vector<sacapi_bool *> null_vals;
139139
};
140140

141-
bool cleanAPI(); // Finalizes the API and frees up resources
142-
void getErrorMsg(a_sqlany_connection *conn, std::string &str);
143-
void getErrorMsg(int code, std::string &str);
144-
void throwError(a_sqlany_connection *conn);
145-
void throwError(int code);
141+
bool cleanAPI (); // Finalizes the API and frees up resources
142+
int getError( a_sqlany_connection *conn, char *str, size_t len );
143+
void getErrorMsg( a_sqlany_connection *conn, std::string &str );
144+
void getErrorMsg( int code, std::string &str );
145+
void throwError( a_sqlany_connection *conn );
146+
void throwError( int code );
146147

147148
void callBack(std::string *str,
148149
Persistent<Function> &callback,

src/sqlanywhere.cpp

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ static bool fillResult(executeBaton *baton, Persistent<Value> &ResultSet)
9090
void executeWork(uv_work_t *req)
9191
/********************************/
9292
{
93-
executeBaton *baton = static_cast<executeBaton *>(req->data);
94-
scoped_lock lock(baton->obj->conn_mutex);
93+
int rc = 0;
94+
int sqlcode = 0;
95+
96+
executeBaton *baton = static_cast<executeBaton*>(req->data);
97+
scoped_lock lock( baton->obj->conn_mutex );
9598

9699
if (baton->obj->conn == NULL)
97100
{
@@ -112,17 +115,20 @@ void executeWork(uv_work_t *req)
112115
sqlany_stmt = baton->stmt_obj->sqlany_stmt;
113116
}
114117

115-
if (sqlany_stmt == NULL && baton->stmt.length() > 0)
116-
{
117-
sqlany_stmt = api.sqlany_prepare(baton->obj->conn,
118-
baton->stmt.c_str());
119-
if (sqlany_stmt == NULL)
120-
{
121-
baton->err = true;
122-
getErrorMsg(baton->obj->conn, baton->error_msg);
123-
return;
124-
}
125-
baton->stmt_obj->sqlany_stmt = sqlany_stmt;
118+
if( sqlany_stmt == NULL && baton->stmt.length() > 0 ) {
119+
sqlany_stmt = api.sqlany_prepare( baton->obj->conn,
120+
baton->stmt.c_str() );
121+
if( sqlany_stmt == NULL ) {
122+
baton->err = true;
123+
getErrorMsg( baton->obj->conn, baton->error_msg );
124+
return;
125+
}
126+
baton->stmt_obj->sqlany_stmt = sqlany_stmt;
127+
128+
} else if( sqlany_stmt == NULL ) {
129+
baton->err = true;
130+
getErrorMsg( JS_ERR_INVALID_OBJECT, baton->error_msg );
131+
return;
126132
}
127133
else if (sqlany_stmt == NULL)
128134
{
@@ -174,12 +180,16 @@ void executeWork(uv_work_t *req)
174180
return;
175181
}
176182

177-
if (!fetchResultSet(sqlany_stmt, baton->rows_affected, baton->colNames,
178-
baton->execData[0], baton->col_types))
179-
{
180-
baton->err = true;
181-
getErrorMsg(baton->obj->conn, baton->error_msg);
182-
return;
183+
rc = fetchResultSet( sqlany_stmt, baton->rows_affected, baton->colNames,
184+
baton->execData[0], baton->col_types );
185+
186+
if( !rc ) {
187+
sqlcode = getError( baton->obj->conn, NULL, 0 );
188+
if( (sqlcode != 0) && (sqlcode != 100) ) {
189+
baton->err = true;
190+
getErrorMsg( baton->obj->conn, baton->error_msg );
191+
return;
192+
}
183193
}
184194
}
185195

@@ -315,8 +325,11 @@ NODE_API_FUNC(StmtObject::exec)
315325
void getMoreResultsWork(uv_work_t *req)
316326
/***************************************/
317327
{
318-
executeBaton *baton = static_cast<executeBaton *>(req->data);
319-
scoped_lock lock(baton->obj->conn_mutex);
328+
int rc = 0;
329+
int sqlcode = 0;
330+
331+
executeBaton *baton = static_cast<executeBaton*>(req->data);
332+
scoped_lock lock( baton->obj->conn_mutex );
320333

321334
if (baton->obj->conn == NULL)
322335
{
@@ -350,12 +363,16 @@ void getMoreResultsWork(uv_work_t *req)
350363
}
351364

352365
baton->execData[0]->clear();
353-
if (!fetchResultSet(stmt, baton->rows_affected, baton->colNames,
354-
baton->execData[0], baton->col_types))
355-
{
356-
baton->err = true;
357-
getErrorMsg(baton->obj->conn, baton->error_msg);
358-
return;
366+
rc = fetchResultSet( stmt, baton->rows_affected, baton->colNames,
367+
baton->execData[0], baton->col_types );
368+
369+
if( !rc ) {
370+
sqlcode = getError( baton->obj->conn, NULL, 0 );
371+
if( (sqlcode != 0 ) && (sqlcode != 100) ) {
372+
baton->err = true;
373+
getErrorMsg( baton->obj->conn, baton->error_msg );
374+
return;
375+
}
359376
}
360377
}
361378

src/utils.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
using namespace v8;
99
using namespace node;
1010

11-
void getErrorMsg(int code, std::string &str)
11+
int getError( a_sqlany_connection *conn, char *str, size_t len )
12+
/**************************************************************/
13+
{
14+
int sqlcode;
15+
sqlcode = api.sqlany_error( conn, str, len );
16+
return sqlcode;
17+
}
18+
19+
void getErrorMsg( int code, std::string &str )
1220
/********************************************/
1321
{
1422
std::ostringstream message;
@@ -54,15 +62,15 @@ void getErrorMsg(int code, std::string &str)
5462
void getErrorMsg(a_sqlany_connection *conn, std::string &str)
5563
/*************************************************************/
5664
{
57-
char buffer[SACAPI_ERROR_SIZE];
58-
int rc;
59-
rc = api.sqlany_error(conn, buffer, sizeof(buffer));
60-
std::ostringstream message;
61-
message << "Code: ";
62-
message << rc;
63-
message << " Msg: ";
64-
message << buffer;
65-
str = message.str();
65+
char buffer[SACAPI_ERROR_SIZE];
66+
int sqlcode;
67+
sqlcode = getError( conn, buffer, sizeof(buffer) );
68+
std::ostringstream message;
69+
message << "Code: ";
70+
message << sqlcode;
71+
message << " Msg: ";
72+
message << buffer;
73+
str = message.str();
6674
}
6775

6876
void throwError(a_sqlany_connection *conn)

0 commit comments

Comments
 (0)