Skip to content

fix: made to work with node 14+ #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@
"author": "SQL ANYWHERE",
"name": "sqlanywhere",
"description": "SQL Anywhere JavaScript Driver.",
"version": "1.0.25",
"version": "2.0.3",
"repository": {
"url": "https://github.com/sqlanywhere/node-sqlanywhere"
},
"main": "./lib/index",
"engines": {
"node": ">=0.10"
"node": ">=14.0.0"
},
"scripts": {
"install": "node build.js"
},
"dependencies": {
"help": "^3.0.2",
"nan": "2.14.2"
"nan": "^2.15.0"
}
}
84 changes: 38 additions & 46 deletions src/h/connection.h
Original file line number Diff line number Diff line change
@@ -136,38 +136,30 @@ using namespace node;
*/
class Connection : public ObjectWrap
{
public:
public:
/// @internal
#if v010
static void Init();
#else
static void Init( Isolate * );
#endif
static void Init(Isolate *);

/// @internal
static NODE_API_FUNC( NewInstance );
private:
static NODE_API_FUNC(NewInstance);

private:
/// @internal
#if v010
Connection( const Arguments &args );
#else
Connection( const FunctionCallbackInfo<Value> &args );
#endif
Connection(const FunctionCallbackInfo<Value> &args);
/// @internal
~Connection();

/// @internal
static Persistent<Function> constructor;

/// @internal
static void noParamAfter( uv_work_t *req );
static void noParamAfter(uv_work_t *req);
/// @internal
static void connectAfter( uv_work_t *req );
static void connectAfter(uv_work_t *req);
/// @internal
static void connectWork( uv_work_t *req );
static void connectWork(uv_work_t *req);
/// @internal
static NODE_API_FUNC( New );
static NODE_API_FUNC(New);

/// Connect using an existing connection.
//
@@ -202,7 +194,7 @@ class Connection : public ObjectWrap
//
// @internal
///

/** Creates a new connection.
*
* This method creates a new connection using either a connection string
@@ -242,7 +234,7 @@ class Connection : public ObjectWrap
*
* @see Connection::disconnect
*/
static NODE_API_FUNC( connect );
static NODE_API_FUNC(connect);

/** Closes the current connection.
*
@@ -275,11 +267,11 @@ class Connection : public ObjectWrap
*
* @see Connection::connect
*/
static NODE_API_FUNC( disconnect );
static NODE_API_FUNC(disconnect);

/// @internal
static void disconnectWork( uv_work_t *req );
static void disconnectWork(uv_work_t *req);

/** Executes the specified SQL statement.
*
* This method takes in a SQL statement and an optional array of bind
@@ -335,8 +327,8 @@ class Connection : public ObjectWrap
* @return If no callback is specified, the result is returned.
*
*/
static NODE_API_FUNC( exec );
static NODE_API_FUNC(exec);

/** Prepares the specified SQL statement.
*
* This method prepares a SQL statement and returns a Statement object
@@ -373,13 +365,13 @@ class Connection : public ObjectWrap
* @return If no callback is specified, a Statement object is returned.
*
*/
static NODE_API_FUNC( prepare );
static NODE_API_FUNC(prepare);

/// @internal
static void prepareAfter( uv_work_t *req );
static void prepareAfter(uv_work_t *req);
/// @internal
static void prepareWork( uv_work_t *req );
static void prepareWork(uv_work_t *req);

/** Performs a commit on the connection.
*
* This method performs a commit on the connection.
@@ -421,11 +413,11 @@ class Connection : public ObjectWrap
* @param callback The optional callback function. ( type: Function )
*
*/
static NODE_API_FUNC( commit );
static NODE_API_FUNC(commit);

/// @internal
static void commitWork( uv_work_t *req );
static void commitWork(uv_work_t *req);

/** Performs a rollback on the connection.
*
* This method performs a rollback on the connection.
@@ -465,10 +457,10 @@ class Connection : public ObjectWrap
* @param callback The optional callback function. ( type: Function )
*
*/
static NODE_API_FUNC( rollback );
static NODE_API_FUNC(rollback);

/// @internal
static void rollbackWork( uv_work_t *req );
static void rollbackWork(uv_work_t *req);

/** Indicates whether the connection is connected.
*
@@ -492,24 +484,24 @@ class Connection : public ObjectWrap
* @return true if the connection is connected, false if not.
*
*/
static NODE_API_FUNC( connected );
static NODE_API_FUNC(connected);

public:
public:
/// @internal
a_sqlany_connection *conn;
a_sqlany_connection *conn;
/// @internal
unsigned int max_api_ver;
unsigned int max_api_ver;
/// @internal
bool sqlca_connection;
bool sqlca_connection;
/// @internal
uv_mutex_t conn_mutex;
uv_mutex_t conn_mutex;
/// @internal
Persistent<String> _arg;
Persistent<String> _arg;
/// @internal
std::vector<void*> statements;
std::vector<void *> statements;

/// @internal
void removeStmt( class StmtObject *stmt );
void removeStmt(class StmtObject *stmt);
/// @internal
void cleanupStmts( void );
void cleanupStmts(void);
};
18 changes: 9 additions & 9 deletions src/h/errors.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ***************************************************************************
// Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved.
// ***************************************************************************
#define JS_ERR_INVALID_OBJECT -2001
#define JS_ERR_INVALID_ARGUMENTS -2002
#define JS_ERR_CONNECTION_ALREADY_EXISTS -2003
#define JS_ERR_INITIALIZING_DBCAPI -2004
#define JS_ERR_NOT_CONNECTED -2005
#define JS_ERR_BINDING_PARAMETERS -2006
#define JS_ERR_GENERAL_ERROR -2007
#define JS_ERR_RESULTSET -2008
#define JS_ERR_NO_WIDE_STATEMENTS -2009
#define JS_ERR_INVALID_OBJECT -2001
#define JS_ERR_INVALID_ARGUMENTS -2002
#define JS_ERR_CONNECTION_ALREADY_EXISTS -2003
#define JS_ERR_INITIALIZING_DBCAPI -2004
#define JS_ERR_NOT_CONNECTED -2005
#define JS_ERR_BINDING_PARAMETERS -2006
#define JS_ERR_GENERAL_ERROR -2007
#define JS_ERR_RESULTSET -2008
#define JS_ERR_NO_WIDE_STATEMENTS -2009
17 changes: 1 addition & 16 deletions src/h/nodever_cover.h
Original file line number Diff line number Diff line change
@@ -3,19 +3,4 @@
// ***************************************************************************
#include <node_version.h>

#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION == 10
#define v010 1
#define v012 0
#elif NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION == 12
#define v010 0
#define v012 1
#else
#define v010 0
#define v012 0
#endif

#if v010
#define NODE_API_FUNC( name ) Handle<Value> name ( const Arguments &args )
#else
#define NODE_API_FUNC( name ) void name ( const FunctionCallbackInfo<Value> &args )
#endif
#define NODE_API_FUNC(name) void name(const FunctionCallbackInfo<Value> &args)
732 changes: 367 additions & 365 deletions src/h/sacapi.h

Large diffs are not rendered by default.

251 changes: 126 additions & 125 deletions src/h/sacapidll.h

Large diffs are not rendered by default.

296 changes: 134 additions & 162 deletions src/h/sqlany_utils.h
Original file line number Diff line number Diff line change
@@ -4,22 +4,22 @@
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
#include <sstream>
#include <vector>
#include "sacapidll.h"
#include "sacapi.h"

#pragma warning (disable : 4100)
#pragma warning (disable : 4506)
#pragma warning (disable : 4068)
#pragma warning (disable : 4800)
#pragma warning(disable : 4100)
#pragma warning(disable : 4506)
#pragma warning(disable : 4068)
#pragma warning(disable : 4800)
#pragma GCC diagnostic ignored "-Wunused-parameter"

#if defined( _MSC_VER )
#if defined(_MSC_VER)
// According to the github page for node.js, some warnings generated by
// Visual Studio are "overzealous". They should be fixed in VS 2017 15.6.
// https://github.com/nodejs/node/issues/17114
#pragma warning( disable : 4251 )
#pragma warning(disable : 4251)
#endif
#include "node.h"
#include "v8.h"
@@ -28,10 +28,10 @@
#include "uv.h"

#pragma GCC diagnostic pop
#pragma warning (default : 4100)
#pragma warning (default : 4506)
#pragma warning (default : 4068)
#pragma warning (default : 4800)
#pragma warning(default : 4100)
#pragma warning(default : 4506)
#pragma warning(default : 4068)
#pragma warning(default : 4800)

#include "nodever_cover.h"
#include "errors.h"
@@ -44,175 +44,147 @@ extern SQLAnywhereInterface api;
extern unsigned openConnections;
extern uv_mutex_t api_mutex;

#define CLEAN_STRINGS( vector ) \
{ \
for( size_t i = 0; i < vector.size(); i++ ) { \
delete[] vector[i]; \
} \
vector.clear(); \
}

#define CLEAN_PTRS( vector ) \
{ \
for( size_t i = 0; i < vector.size(); i++ ) { \
delete vector[i]; \
} \
vector.clear(); \
}
#define CLEAN_STRINGS(vector) \
{ \
for (size_t i = 0; i < vector.size(); i++) \
{ \
delete[] vector[i]; \
} \
vector.clear(); \
}

#define CLEAN_PTRS(vector) \
{ \
for (size_t i = 0; i < vector.size(); i++) \
{ \
delete vector[i]; \
} \
vector.clear(); \
}

class scoped_lock
{
public:
scoped_lock( uv_mutex_t &mtx ) : _mtx( mtx )
{
uv_mutex_lock( &_mtx );
}
~scoped_lock()
{

uv_mutex_unlock( &_mtx );
}

private:
uv_mutex_t &_mtx;
public:
scoped_lock(uv_mutex_t &mtx) : _mtx(mtx)
{
uv_mutex_lock(&_mtx);
}
~scoped_lock()
{

uv_mutex_unlock(&_mtx);
}

private:
uv_mutex_t &_mtx;
};

class ExecuteData {
public:
~ExecuteData() {
clear();
class ExecuteData
{
public:
~ExecuteData()
{
clear();
}

void clear( void ) {
CLEAN_STRINGS( string_vals );
CLEAN_STRINGS( string_arr_vals );
CLEAN_PTRS( int_vals );
CLEAN_PTRS( num_vals );
CLEAN_PTRS( len_vals );
CLEAN_PTRS( null_vals );
void clear(void)
{
CLEAN_STRINGS(string_vals);
CLEAN_STRINGS(string_arr_vals);
CLEAN_PTRS(int_vals);
CLEAN_PTRS(num_vals);
CLEAN_PTRS(len_vals);
CLEAN_PTRS(null_vals);
}
void addString( char *str, size_t *len ) {
string_vals.push_back( str );
len_vals.push_back( len );
void addString(char *str, size_t *len)
{
string_vals.push_back(str);
len_vals.push_back(len);
}
void addStrings( char **str, size_t *len ) {
string_arr_vals.push_back( str );
len_vals.push_back( len );
void addStrings(char **str, size_t *len)
{
string_arr_vals.push_back(str);
len_vals.push_back(len);
}
void addInt( int *val ) { int_vals.push_back( val ); }
void addNum( double *val ) { num_vals.push_back( val ); }
void addNull( sacapi_bool *val ) { null_vals.push_back( val ); }

char * getString( size_t ind ) { return string_vals[ind]; }
char ** getStrings( size_t ind ) { return string_arr_vals[ind]; }
int getInt( size_t ind ) { return *(int_vals[ind]); }
double getNum( size_t ind ) { return *(num_vals[ind]); }
size_t getLen( size_t ind ) { return *(len_vals[ind]); }
sacapi_bool getNull( size_t ind ) { return *(null_vals[ind]); }

size_t stringSize( void ) const { return string_vals.size(); }
size_t intSize( void ) const { return int_vals.size(); }
size_t numSize( void ) const { return num_vals.size(); }
size_t lenSize( void ) const { return len_vals.size(); }
size_t nullSize( void ) const { return null_vals.size(); }

bool stringIsNull( size_t ind ) const { return string_vals[ind] == NULL; }
bool intIsNull( size_t ind ) const { return int_vals[ind] == NULL; }
bool numIsNull( size_t ind ) const { return num_vals[ind] == NULL; }
bool lenIsNull( size_t ind ) const { return string_vals[ind] == NULL; }
bool nullIsNull( size_t ind ) const { return string_vals[ind] == NULL; }

private:
std::vector<char *> string_vals;
std::vector<char **> string_arr_vals;
std::vector<int *> int_vals;
std::vector<double *> num_vals;
std::vector<size_t *> len_vals;
std::vector<sacapi_bool *> null_vals;
void addInt(int *val) { int_vals.push_back(val); }
void addNum(double *val) { num_vals.push_back(val); }
void addNull(sacapi_bool *val) { null_vals.push_back(val); }

char *getString(size_t ind) { return string_vals[ind]; }
char **getStrings(size_t ind) { return string_arr_vals[ind]; }
int getInt(size_t ind) { return *(int_vals[ind]); }
double getNum(size_t ind) { return *(num_vals[ind]); }
size_t getLen(size_t ind) { return *(len_vals[ind]); }
sacapi_bool getNull(size_t ind) { return *(null_vals[ind]); }

size_t stringSize(void) const { return string_vals.size(); }
size_t intSize(void) const { return int_vals.size(); }
size_t numSize(void) const { return num_vals.size(); }
size_t lenSize(void) const { return len_vals.size(); }
size_t nullSize(void) const { return null_vals.size(); }

bool stringIsNull(size_t ind) const { return string_vals[ind] == NULL; }
bool intIsNull(size_t ind) const { return int_vals[ind] == NULL; }
bool numIsNull(size_t ind) const { return num_vals[ind] == NULL; }
bool lenIsNull(size_t ind) const { return string_vals[ind] == NULL; }
bool nullIsNull(size_t ind) const { return string_vals[ind] == NULL; }

private:
std::vector<char *> string_vals;
std::vector<char **> string_arr_vals;
std::vector<int *> int_vals;
std::vector<double *> num_vals;
std::vector<size_t *> len_vals;
std::vector<sacapi_bool *> null_vals;
};

bool cleanAPI (); // Finalizes the API and frees up resources
void getErrorMsg( a_sqlany_connection *conn, std::string &str );
void getErrorMsg( int code, std::string &str );
void throwError( a_sqlany_connection *conn );
void throwError( int code );

#if v010
void callBack( std::string * str,
Persistent<Function> callback,
Local<Value> Result,
bool callback_required = true );
void callBack( std::string * str,
Local<Value> callback,
Local<Value> Result,
bool callback_required = true );
#else
void callBack( std::string * str,
Persistent<Function> & callback,
Local<Value> & Result,
bool callback_required = true );
void callBack( std::string * str,
const Local<Value> & callback,
Local<Value> & Result,
bool callback_required = true );
void callBack( std::string * str,
Persistent<Function> & callback,
Persistent<Value> & Result,
bool callback_required = true );
#endif
bool cleanAPI(); // Finalizes the API and frees up resources
void getErrorMsg(a_sqlany_connection *conn, std::string &str);
void getErrorMsg(int code, std::string &str);
void throwError(a_sqlany_connection *conn);
void throwError(int code);

bool getBindParameters( std::vector<ExecuteData *> &execData
, Isolate * isolate
, Local<Value> arg
, std::vector<a_sqlany_bind_param> &params
, unsigned &num_rows
);

#if v010
bool getResultSet( Local<Value> &Result
, int &rows_affected
, std::vector<char *> &colNames
, ExecuteData *execData
, std::vector<a_sqlany_data_type> &col_types );
#else
bool getResultSet( Persistent<Value> &Result
, int &rows_affected
, std::vector<char *> &colNames
, ExecuteData *execData
, std::vector<a_sqlany_data_type> &col_types );
#endif
void callBack(std::string *str,
Persistent<Function> &callback,
Local<Value> &Result,
bool callback_required = true);
void callBack(std::string *str,
const Local<Value> &callback,
Local<Value> &Result,
bool callback_required = true);
void callBack(std::string *str,
Persistent<Function> &callback,
Persistent<Value> &Result,
bool callback_required = true);

bool getBindParameters(std::vector<ExecuteData *> &execData, Isolate *isolate, Local<Value> arg, std::vector<a_sqlany_bind_param> &params, unsigned &num_rows);

bool getResultSet(Persistent<Value> &Result, int &rows_affected, std::vector<char *> &colNames, ExecuteData *execData, std::vector<a_sqlany_data_type> &col_types);

bool fetchResultSet(a_sqlany_stmt *sqlany_stmt, int &rows_affected, std::vector<char *> &colNames, ExecuteData *execData, std::vector<a_sqlany_data_type> &col_types);

struct noParamBaton
{
Persistent<Function> callback;
bool err;
std::string error_msg;
bool callback_required;

bool fetchResultSet( a_sqlany_stmt *sqlany_stmt
, int &rows_affected
, std::vector<char *> &colNames
, ExecuteData *execData
, std::vector<a_sqlany_data_type> &col_types );

struct noParamBaton {
Persistent<Function> callback;
bool err;
std::string error_msg;
bool callback_required;

Connection *obj;

noParamBaton() {
obj = NULL;
err = false;

noParamBaton()
{
obj = NULL;
err = false;
}

~noParamBaton() {
obj = NULL;

~noParamBaton()
{
obj = NULL;
}
};

void executeAfter( uv_work_t *req );
void executeWork( uv_work_t *req );
void executeAfter(uv_work_t *req);
void executeWork(uv_work_t *req);

#if NODE_MAJOR_VERSION > 0 || NODE_MINOR_VERSION > 10
void HashToString( Isolate *isolate, Local<Object> obj, Persistent<String> &ret );
#else
Persistent<String> HashToString( Local<Object> obj );
Handle<Value> CreateConnection( const Arguments &args );
#endif
void HashToString(Isolate *isolate, Local<Object> obj, Persistent<String> &ret);
82 changes: 38 additions & 44 deletions src/h/stmt.h
Original file line number Diff line number Diff line change
@@ -14,38 +14,32 @@ using namespace v8;
*/
class StmtObject : public node::ObjectWrap
{
public:
/// @internal
#if v010
static void Init();
#else
static void Init( Isolate * );
#endif

/// @internal
static NODE_API_FUNC( NewInstance );
public:
/// @internal
static void Init(Isolate *);

/// @internal
#if !v010
static void CreateNewInstance( const FunctionCallbackInfo<Value> &args,
Persistent<Object> &obj );
#endif
/// @internal
static NODE_API_FUNC(NewInstance);

/// @internal
StmtObject();
/// @internal
~StmtObject();
/// @internal
void cleanup( void );
void removeConnection( void );
/// @internal
static void CreateNewInstance(const FunctionCallbackInfo<Value> &args,
Persistent<Object> &obj);

private:
/// @internal
static Persistent<Function> constructor;
/// @internal
static NODE_API_FUNC( New );

/** Executes the prepared SQL statement.
/// @internal
StmtObject();
/// @internal
~StmtObject();
/// @internal
void cleanup(void);
void removeConnection(void);

private:
/// @internal
static Persistent<Function> constructor;
/// @internal
static NODE_API_FUNC(New);

/** Executes the prepared SQL statement.
*
* This method optionally takes in an array of bind
* parameters to execute.
@@ -89,9 +83,9 @@ class StmtObject : public node::ObjectWrap
* @return If no callback is specified, the result is returned.
*
*/
static NODE_API_FUNC( exec );
/** Drops the statement.
static NODE_API_FUNC(exec);

/** Drops the statement.
*
* This method drops the prepared statement and frees up resources.
*
@@ -125,14 +119,14 @@ class StmtObject : public node::ObjectWrap
* @param callback The optional callback function.
*
*/
static NODE_API_FUNC( drop );
static NODE_API_FUNC(drop);

/// @internal
static void dropAfter( uv_work_t *req );
/// @internal
static void dropWork( uv_work_t *req );
/// @internal
static void dropAfter(uv_work_t *req);
/// @internal
static void dropWork(uv_work_t *req);

/** Gets the next result set of a multi-result-set query.
/** Gets the next result set of a multi-result-set query.
*
* This method can be either synchronous or asynchronous depending on
* whether or not a callback function is specified.
@@ -166,11 +160,11 @@ class StmtObject : public node::ObjectWrap
* @param callback The optional callback function.
*
*/
static NODE_API_FUNC( getMoreResults );
static NODE_API_FUNC(getMoreResults);

public:
/// @internal
Connection *connection;
/// @internal
a_sqlany_stmt *sqlany_stmt;
public:
/// @internal
Connection *connection;
/// @internal
a_sqlany_stmt *sqlany_stmt;
};
247 changes: 124 additions & 123 deletions src/sacapidll.cpp
Original file line number Diff line number Diff line change
@@ -25,181 +25,182 @@
#include <stdlib.h>
#include <stdio.h>

#if defined( _WIN32 )
#include <windows.h>
#define DEFAULT_LIBRARY_NAME "dbcapi.dll"
#if defined(_WIN32)
#include <windows.h>
#define DEFAULT_LIBRARY_NAME "dbcapi.dll"
#else
#include <dlfcn.h>
/* assume we are running on a UNIX platform */
#if defined( __APPLE__ )
#define LIB_EXT "dylib"
#else
#define LIB_EXT "so"
#endif
#if defined( _REENTRANT ) || defined( _THREAD_SAFE ) \
|| defined( __USE_REENTRANT )
/* if building a thread-safe library, we need to load
#include <dlfcn.h>
/* assume we are running on a UNIX platform */
#if defined(__APPLE__)
#define LIB_EXT "dylib"
#else
#define LIB_EXT "so"
#endif
#if defined(_REENTRANT) || defined(_THREAD_SAFE) || defined(__USE_REENTRANT)
/* if building a thread-safe library, we need to load
the thread-safe dbcapi library */
#define DEFAULT_LIBRARY_NAME "libdbcapi_r." LIB_EXT
#else
#define DEFAULT_LIBRARY_NAME "libdbcapi." LIB_EXT
#endif
#define DEFAULT_LIBRARY_NAME "libdbcapi_r." LIB_EXT
#else
#define DEFAULT_LIBRARY_NAME "libdbcapi." LIB_EXT
#endif
#endif

#include "sacapidll.h"

static
void * loadLibrary( const char * name )
static void *loadLibrary(const char *name)
/*************************************/
{
void * handle;
#if defined( _WIN32 )
handle = LoadLibrary( name );
void *handle;
#if defined(_WIN32)
handle = LoadLibrary(name);
#else
handle = dlopen( name, RTLD_LAZY );
handle = dlopen(name, RTLD_LAZY);
#endif
return handle;
}

static
void unloadLibrary( void * handle )
static void unloadLibrary(void *handle)
/**********************************/
{
#if defined( _WIN32 )
FreeLibrary( (HMODULE)handle );
#if defined(_WIN32)
FreeLibrary((HMODULE)handle);
#else
dlclose( handle );
dlclose(handle);
#endif
}

static
void * findSymbol( void * dll_handle, const char * name )
static void *findSymbol(void *dll_handle, const char *name)
/*******************************************************/
{
#if defined( _WIN32 )
return GetProcAddress( (HMODULE)dll_handle, name );
#if defined(_WIN32)
return GetProcAddress((HMODULE)dll_handle, name);
#else
return dlsym( dll_handle, name );
return dlsym(dll_handle, name);
#endif
}

#define LookupSymbol( api, sym ) \
api->sym = (sym ## _func)findSymbol( api->dll_handle, #sym );
#define LookupSymbol(api, sym) \
api->sym = (sym##_func)findSymbol(api->dll_handle, #sym);

#define LookupSymbolAndCheck( api, sym ) \
api->sym = (sym ## _func)findSymbol( api->dll_handle, #sym ); \
if( api->sym == NULL ) { \
unloadLibrary( api->dll_handle ); \
return 0; \
}

int sqlany_initialize_interface( SQLAnywhereInterface * api, const char * path )
#define LookupSymbolAndCheck(api, sym) \
api->sym = (sym##_func)findSymbol(api->dll_handle, #sym); \
if (api->sym == NULL) \
{ \
unloadLibrary(api->dll_handle); \
return 0; \
}

int sqlany_initialize_interface(SQLAnywhereInterface *api, const char *path)
/*******************************************************************************/
{
char * env;
memset( api, 0, sizeof(*api));
char *env;
memset(api, 0, sizeof(*api));

if( path != NULL ) {
api->dll_handle = loadLibrary( path );
if( api->dll_handle != NULL ) {
goto loaded;
}
if (path != NULL)
{
api->dll_handle = loadLibrary(path);
if (api->dll_handle != NULL)
{
goto loaded;
}
}
env = getenv( "SQLANY_API_DLL" );
if( env != NULL ) {
api->dll_handle = loadLibrary( env );
if( api->dll_handle != NULL ) {
goto loaded;
}
env = getenv("SQLANY_API_DLL");
if (env != NULL)
{
api->dll_handle = loadLibrary(env);
if (api->dll_handle != NULL)
{
goto loaded;
}
}
api->dll_handle = loadLibrary( DEFAULT_LIBRARY_NAME );
if( api->dll_handle != NULL ) {
goto loaded;
api->dll_handle = loadLibrary(DEFAULT_LIBRARY_NAME);
if (api->dll_handle != NULL)
{
goto loaded;
}
return 0;

loaded:
LookupSymbolAndCheck( api, sqlany_init );
LookupSymbolAndCheck( api, sqlany_fini );
LookupSymbolAndCheck( api, sqlany_new_connection );
LookupSymbolAndCheck( api, sqlany_free_connection );
LookupSymbolAndCheck( api, sqlany_make_connection );
LookupSymbolAndCheck( api, sqlany_connect );
LookupSymbolAndCheck( api, sqlany_disconnect );
LookupSymbolAndCheck( api, sqlany_execute_immediate );
LookupSymbolAndCheck( api, sqlany_prepare );
LookupSymbolAndCheck( api, sqlany_free_stmt );
LookupSymbolAndCheck( api, sqlany_num_params );
LookupSymbolAndCheck( api, sqlany_describe_bind_param );
LookupSymbolAndCheck( api, sqlany_bind_param );
LookupSymbolAndCheck( api, sqlany_send_param_data );
LookupSymbolAndCheck( api, sqlany_reset );
LookupSymbolAndCheck( api, sqlany_get_bind_param_info );
LookupSymbolAndCheck( api, sqlany_execute );
LookupSymbolAndCheck( api, sqlany_execute_direct );
LookupSymbolAndCheck( api, sqlany_fetch_absolute );
LookupSymbolAndCheck( api, sqlany_fetch_next );
LookupSymbolAndCheck( api, sqlany_get_next_result );
LookupSymbolAndCheck( api, sqlany_affected_rows );
LookupSymbolAndCheck( api, sqlany_num_cols );
LookupSymbolAndCheck( api, sqlany_num_rows );
LookupSymbolAndCheck( api, sqlany_get_column );
LookupSymbolAndCheck( api, sqlany_get_data );
LookupSymbolAndCheck( api, sqlany_get_data_info );
LookupSymbolAndCheck( api, sqlany_get_column_info );
LookupSymbolAndCheck( api, sqlany_commit );
LookupSymbolAndCheck( api, sqlany_rollback );
LookupSymbolAndCheck( api, sqlany_client_version );
LookupSymbolAndCheck( api, sqlany_error );
LookupSymbolAndCheck( api, sqlany_sqlstate );
LookupSymbolAndCheck( api, sqlany_clear_error );
LookupSymbolAndCheck(api, sqlany_init);
LookupSymbolAndCheck(api, sqlany_fini);
LookupSymbolAndCheck(api, sqlany_new_connection);
LookupSymbolAndCheck(api, sqlany_free_connection);
LookupSymbolAndCheck(api, sqlany_make_connection);
LookupSymbolAndCheck(api, sqlany_connect);
LookupSymbolAndCheck(api, sqlany_disconnect);
LookupSymbolAndCheck(api, sqlany_execute_immediate);
LookupSymbolAndCheck(api, sqlany_prepare);
LookupSymbolAndCheck(api, sqlany_free_stmt);
LookupSymbolAndCheck(api, sqlany_num_params);
LookupSymbolAndCheck(api, sqlany_describe_bind_param);
LookupSymbolAndCheck(api, sqlany_bind_param);
LookupSymbolAndCheck(api, sqlany_send_param_data);
LookupSymbolAndCheck(api, sqlany_reset);
LookupSymbolAndCheck(api, sqlany_get_bind_param_info);
LookupSymbolAndCheck(api, sqlany_execute);
LookupSymbolAndCheck(api, sqlany_execute_direct);
LookupSymbolAndCheck(api, sqlany_fetch_absolute);
LookupSymbolAndCheck(api, sqlany_fetch_next);
LookupSymbolAndCheck(api, sqlany_get_next_result);
LookupSymbolAndCheck(api, sqlany_affected_rows);
LookupSymbolAndCheck(api, sqlany_num_cols);
LookupSymbolAndCheck(api, sqlany_num_rows);
LookupSymbolAndCheck(api, sqlany_get_column);
LookupSymbolAndCheck(api, sqlany_get_data);
LookupSymbolAndCheck(api, sqlany_get_data_info);
LookupSymbolAndCheck(api, sqlany_get_column_info);
LookupSymbolAndCheck(api, sqlany_commit);
LookupSymbolAndCheck(api, sqlany_rollback);
LookupSymbolAndCheck(api, sqlany_client_version);
LookupSymbolAndCheck(api, sqlany_error);
LookupSymbolAndCheck(api, sqlany_sqlstate);
LookupSymbolAndCheck(api, sqlany_clear_error);

#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_2
#if _SACAPI_VERSION + 0 >= SQLANY_API_VERSION_2
/* We don't report an error if we don't find the v2 entry points.
That allows the calling app to revert to v1 */
LookupSymbol( api, sqlany_init_ex );
LookupSymbol( api, sqlany_fini_ex );
LookupSymbol( api, sqlany_new_connection_ex );
LookupSymbol( api, sqlany_make_connection_ex );
LookupSymbol( api, sqlany_client_version_ex );
LookupSymbolAndCheck( api, sqlany_cancel );
LookupSymbol(api, sqlany_init_ex);
LookupSymbol(api, sqlany_fini_ex);
LookupSymbol(api, sqlany_new_connection_ex);
LookupSymbol(api, sqlany_make_connection_ex);
LookupSymbol(api, sqlany_client_version_ex);
LookupSymbolAndCheck(api, sqlany_cancel);
#endif
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_3
#if _SACAPI_VERSION + 0 >= SQLANY_API_VERSION_3
/* We don't report an error if we don't find the v3 entry points.
That allows the calling app to revert to v1 */
LookupSymbol( api, sqlany_register_callback );
LookupSymbol(api, sqlany_register_callback);
#endif
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_4
#if _SACAPI_VERSION + 0 >= SQLANY_API_VERSION_4
/* We don't report an error if we don't find the v4 entry points.
That allows the calling app to revert to v1 */
LookupSymbol( api, sqlany_set_batch_size );
LookupSymbol( api, sqlany_set_param_bind_type );
LookupSymbol( api, sqlany_get_batch_size );
LookupSymbol( api, sqlany_set_rowset_size );
LookupSymbol( api, sqlany_get_rowset_size );
LookupSymbol( api, sqlany_set_column_bind_type );
LookupSymbol( api, sqlany_bind_column );
LookupSymbol( api, sqlany_clear_column_bindings );
LookupSymbol( api, sqlany_fetched_rows );
LookupSymbol( api, sqlany_set_rowset_pos );
LookupSymbol(api, sqlany_set_batch_size);
LookupSymbol(api, sqlany_set_param_bind_type);
LookupSymbol(api, sqlany_get_batch_size);
LookupSymbol(api, sqlany_set_rowset_size);
LookupSymbol(api, sqlany_get_rowset_size);
LookupSymbol(api, sqlany_set_column_bind_type);
LookupSymbol(api, sqlany_bind_column);
LookupSymbol(api, sqlany_clear_column_bindings);
LookupSymbol(api, sqlany_fetched_rows);
LookupSymbol(api, sqlany_set_rowset_pos);
#endif
#if _SACAPI_VERSION+0 >= SQLANY_API_VERSION_5
LookupSymbol( api, sqlany_reset_param_data );
LookupSymbol( api, sqlany_error_length );
#if _SACAPI_VERSION + 0 >= SQLANY_API_VERSION_5
LookupSymbol(api, sqlany_reset_param_data);
LookupSymbol(api, sqlany_error_length);
#endif
api->initialized = 1;
return 1;
}
#undef LookupSymbolAndCheck

void sqlany_finalize_interface( SQLAnywhereInterface * api )
void sqlany_finalize_interface(SQLAnywhereInterface *api)
/***********************************************************/
{
if( !api->initialized ) {
return;
if (!api->initialized)
{
return;
}
unloadLibrary( api->dll_handle );
memset( api, 0, sizeof(*api));
unloadLibrary(api->dll_handle);
memset(api, 0, sizeof(*api));
}


1,971 changes: 1,039 additions & 932 deletions src/sqlanywhere.cpp

Large diffs are not rendered by default.

1,708 changes: 871 additions & 837 deletions src/utils.cpp

Large diffs are not rendered by default.