Skip to content

Instantly share code, notes, and snippets.

@twilkinson twilkinson/README.md
Last active Feb 10, 2016

Embed
What would you like to do?
SA-17 Error using ''sa_dbcapi_handle" in JavaScript External Environment with WIndows
function test1() {
var logfile = 'C:/temp/tests.log';
var fs = require('fs');
fs.appendFileSync( logfile, "starting test1\r\n" );
var sqla = require( 'sqlanywhere-xs' );
var conn = sqla.createConnection();
var cstr = "DSN=SQL Anywhere 17 Demo;UID=DBA;PWD=sql";
conn.connect(cstr);
fs.appendFileSync( logfile, "Connected\r\n" );
stmt = conn.prepareStatement( "SELECT * FROM Customers" );
stmt.execute();
var result = stmt.getResultSet();
var c = 0;
while ( result.next() && c < 10 ) {
var str =result.getString(1) + " " + result.getString(3) + " " + result.getString(2);
fs.appendFileSync( logfile, str + "\r\n" );
c += 1;
}
conn.disconnect();
fs.appendFileSync( logfile, "stopping test1\r\n" );
}
function test2() {
var logfile = 'C:/temp/tests.log';
var fs = require('fs');
fs.appendFileSync( logfile, "starting test2\r\n" );
var sqla = require( 'sqlanywhere-xs' );
var conn = sqla.createConnection();
conn.connect(sa_dbcapi_handle);
fs.appendFileSync( logfile, "Connected\r\n" );
stmt = conn.prepareStatement( "SELECT * FROM Customers" );
stmt.execute();
var result = stmt.getResultSet();
var c = 0;
while ( result.next() && c < 10 ) {
var str =result.getString(1) + " " + result.getString(3) + " " + result.getString(2);
fs.appendFileSync( logfile, str + "\r\n" );
c += 1;
}
conn.disconnect();
fs.appendFileSync( logfile, "stopping test2\r\n" );
}
INSTALL EXTERNAL OBJECT 'testscripts'
UPDATE
FROM FILE 'C:/temp/tests.js'
ENVIRONMENT JS;
CREATE OR REPLACE PROCEDURE test1()
EXTERNAL NAME '<file=testscripts> test1()'
LANGUAGE JS;
CREATE OR REPLACE PROCEDURE test2()
EXTERNAL NAME '<file=testscripts> test2()'
LANGUAGE JS;
CALL test1();
CALL test2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.