Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
SA-17 Problem using 'callback' form of 'connect', JavaScript External Environment
function test1A() {
var logfile = '/home/twilkinson/node_demo17/testa.log';
var fs = require('fs');
fs.appendFileSync( logfile, "start of test1A " + process.version +"\r\n" );
var sqla = require( '/opt/sqlanywhere17/node/sqlanywhere-xs' );
var conn = sqla.createConnection();
var cstr = "DSN=SQL Anywhere 17 Demo;UID=DBA;PWD=sql";
conn.connect(cstr, function(err){
if( err ) {
fs.appendFileSync( logfile, "ERR:" + err + "\r\n" );
} else {
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, "Disconnected\r\n" );
}
});
fs.appendFileSync( logfile, "end of test1A\r\n" );
}
test1A();
function test1A() {
var logfile = 'C:/temp/tests.log';
var fs = require('fs');
fs.appendFileSync( logfile, "start of test1A\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, function(err){
if( err ) {
fs.appendFileSync( logfile, "ERR:" + err + "\r\n" );
} else {
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, "Disconnected\r\n" );
}
});
fs.appendFileSync( logfile, "end of test1A\r\n" );
}
INSTALL EXTERNAL OBJECT 'testAscript'
UPDATE
FROM FILE 'C:/temp/testA.js'
ENVIRONMENT JS;
CREATE OR REPLACE PROCEDURE test1A()
EXTERNAL NAME '<file=testAscript> test1A()'
LANGUAGE JS;
CALL test1A();
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.