SQL Anywhere Node JS API Reference en
SQL Anywhere Node JS API Reference en
The Node.js API can be used to connect to SQL Anywhere databases, issue SQL queries, and obtain result sets.
The Node.js driver allows users to connect and perform queries on the database using JavaScript on Joyent's
Node.js software platform. Drivers are available for various versions of Node.js.
The API interface is very similar to the SAP HANA Node.js Client, and allows users to connect, disconnect,
execute, and prepare statements.
The driver is available for install through the NPM (Node Packaged Modules) web site: https://npmjs.org/ .
The SQL Anywhere Node.js API reference is available in the SQL Anywhere- Node.js API Reference at https://
help.sap.com/viewer/09fbca22f0344633b8951c3e9d624d28/LATEST/en-US.
In this section:
Syntax
class Connection
Members
Result exec(String, Array, Function) [page Executes the specified SQL statement.
9]
Statement prepare(String, Function) [page 10] Prepares the specified SQL statement.
Remarks
The following example uses synchronous calls to create a new connection to the database server, issue a SQL
query against the server, display the result set, and then disconnect from the server.
The following example does essentially the same thing using callbacks to perform asynchronous calls. Error
checking is included.
The following example also uses callbacks but the functions are not inlined and the code is easier to
understand.
You can also pass connection parameters into the createConnection function, and those parameters are
combined with those in the connect() function call to get the connection string used for the connection. You
can use a hash of connection parameters or a connection string fragment in either call.
In this section:
Syntax
connection.commit (callback)
Parameters
Remarks
This method performs a commit on the connection. By default, inserts, updates, and deletes are not
committed upon disconnection from the database server.
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
function( err ) {
};
The following synchronous example shows how to use the commit method.
Syntax
Parameters
Remarks
This method creates a new connection using either a connection string or a hash of connection parameters
passed in as a parameter. Before the end of the program, the connection should be disconnected using the
disconnect method to free up resources.
The CharSet (CS) connection parameter CS=UTF-8 is always appended to the end of the connection string by
the driver since it is required that all strings are sent in that encoding.
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
function( err )
{
The following synchronous example shows how to use the connect method. It is not necessary to specify the
CHARSET=UTF-8 connection parameter since it is always added automatically.
Related Information
Syntax
connection.disconnect (callback)
Parameters
Remarks
This method closes the current connection and should be called before the program ends to free up resources.
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
function( err )
{
};
The following synchronous example shows how to use the disconnect method.
Related Information
Syntax
Parameters
Returns
Remarks
This method takes in a SQL statement and an optional array of bind parameters to execute.
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
For queries producing result sets, the result set object is returned as the second parameter of the callback. For
insert, update and delete statements, the number of rows affected is returned as the second parameter of the
callback. For other statements, result is undefined.
The following synchronous example shows how to use the exec method.
Syntax
Parameters
Returns
This method prepares a SQL statement and returns a Statement object if successful.
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
The following synchronous example shows how to use the prepare method.
Syntax
connection.rollback (callback)
Parameters
Remarks
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
function( err ) {
};
Syntax
class Statement
Members
Methods
result exec(Array, Function) [page 14] Executes the prepared SQL statement.
In this section:
Syntax
statement.drop (callback)
Parameters
Remarks
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
function( err )
{
};
The following synchronous example shows how to use the drop method on a prepared statement.
Syntax
Parameters
Returns
Remarks
This method can be either synchronous or asynchronous depending on whether or not a callback function is
specified. The callback function is of the form:
For queries producing result sets, the result set object is returned as the second parameter of the callback. For
insert, update and delete statements, the number of rows affected is returned as the second parameter of the
callback. For other statements, result is undefined.
The following synchronous example shows how to use the exec method on a prepared statement.
Hyperlinks
Some links are classified by an icon and/or a mouseover text. These links provide additional information.
About the icons:
● Links with the icon : You are entering a Web site that is not hosted by SAP. By using such links, you agree (unless expressly stated otherwise in your
agreements with SAP) to this:
● The content of the linked-to site is not SAP documentation. You may not infer any product claims against SAP based on this information.
● SAP does not agree or disagree with the content on the linked-to site, nor does SAP warrant the availability and correctness. SAP shall not be liable for any
damages caused by the use of such content unless damages have been caused by SAP's gross negligence or willful misconduct.
● Links with the icon : You are leaving the documentation for that particular SAP product or service and are entering a SAP-hosted Web site. By using such
links, you agree that (unless expressly stated otherwise in your agreements with SAP) you may not infer any product claims against SAP based on this
information.
Example Code
Any software coding and/or code snippets are examples. They are not for productive use. The example code is only intended to better explain and visualize the syntax
and phrasing rules. SAP does not warrant the correctness and completeness of the example code. SAP shall not be liable for errors or damages caused by the use of
example code unless damages have been caused by SAP's gross negligence or willful misconduct.
Gender-Related Language
We try not to use gender-specific word forms and formulations. As appropriate for context and readability, SAP may use masculine word forms to refer to all genders.
SAP and other SAP products and services mentioned herein as well as
their respective logos are trademarks or registered trademarks of SAP
SE (or an SAP affiliate company) in Germany and other countries. All
other product and service names mentioned are the trademarks of their
respective companies.