Skip to content

Commit

Permalink
make sure demo works with latest build
Browse files Browse the repository at this point in the history
  • Loading branch information
TimelordUK committed Jul 24, 2016
1 parent 890fde5 commit a5c86df
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 27 deletions.
31 changes: 22 additions & 9 deletions demo-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,32 @@ var GlobalConn = (function() {
});
}

function init(sql, done) {
function init(sql, done, candidate_conn_str) {
var ds = new DemoSupport();
getLocalConnStr(function (cs) {

if (candidate_conn_str == null) {
getLocalConnStr(function (cs) {
var ret = {
driver: driver,
database: database,
conn_str: cs,
support: new DemoSupport(sql, cs),
async: new ds.Async(),
helper: new ds.EmployeeHelper(sql, cs),
};
done(ret);
})
}else {
var ret = {
driver : driver,
database : database,
conn_str : cs,
support : new DemoSupport(sql, cs),
async : new ds.Async(),
helper : new ds.EmployeeHelper(sql, cs),
driver: driver,
database: database,
conn_str: candidate_conn_str,
support: new DemoSupport(sql, candidate_conn_str),
async: new ds.Async(),
helper: new ds.EmployeeHelper(sql, candidate_conn_str),
};
done(ret);
})
}
}

function getConnStr() {
Expand Down
139 changes: 121 additions & 18 deletions mssql-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ var fs = require('fs');
sqllocaldb info node
*/

var conn_str = "Driver={SQL Server Native Client 11.0};Server= np:\\\\.\\pipe\\LOCALDB#E9B74E99\\tsql\\query;Database={scratch};Trusted_Connection=Yes;";
var test_conn_str = "Driver={SQL Server Native Client 11.0};Server= np:\\\\.\\pipe\\LOCALDB#8765A478\\tsql\\query;Database={scratch};Trusted_Connection=Yes;";

var support = new supp.DemoSupport(sql, conn_str);
var async = new support.Async();
// if you have a sqllocaldb running with instance called "node" and db "scratch" then
// this will be used automatically. To use another connection string for test
// uncomment below.

var conn_str;

var support;
var async;
var helper;
var driver;
var database;
var procedureHelper;
var parsedJSON;

var demos = [
// open connection, simple query and close.
Expand All @@ -37,9 +48,25 @@ var demos = [
event
];

async.series(demos, function() {
console.log("demo has finished.");
});
supp.GlobalConn.init(sql, function (co) {
conn_str = co.conn_str;
support = co.support;
procedureHelper = new support.ProcedureHelper(conn_str);
procedureHelper.setVerbose(false);
async = co.async;
helper = co.helper;
driver = co.driver;
database = co.database;
parsedJSON = helper.getJSON();

console.log(conn_str);
async.series(demos, function() {
console.log("demo has finished.");
});
}
// to override an auto discovered sqllocaldb str assign above and uncomment below.
// , test_conn_str
);

function event(done) {

Expand Down Expand Up @@ -186,9 +213,9 @@ function query(done) {
query_timeout: 2
};

conn.query(queryObj, function (err, res) {
conn.query(queryObj, function (err) {
assert.check(err != null);
assert.check(err.message.indexOf('Query timeout expired') > 0)
assert.check(err.message.indexOf('Query timeout expired') > 0);
async_done();
});
},
Expand Down Expand Up @@ -254,8 +281,7 @@ function procedure(done) {
def = def.replace(/<name>/g, sp_name);
console.log("create a procedure " + sp_name);
console.log(def);
var ph = new support.ProcedureHelper();
ph.createProcedure(sp_name, def, function() {
procedureHelper.createProcedure(sp_name, def, function() {
async_done();
})
},
Expand Down Expand Up @@ -347,6 +373,34 @@ function connection(done) {
})
}

function empSelectSQL() {

return `SELECT [BusinessEntityID]
,[NationalIDNumber]
,[LoginID]
,[OrganizationNode]
,[OrganizationLevel]
,[JobTitle]
,[BirthDate]
,[MaritalStatus]
,[Gender]
,[HireDate]
,[SalariedFlag]
,[VacationHours]
,[SickLeaveHours]
,[CurrentFlag]
,[rowguid]
,[ModifiedDate]
FROM [scratch].[dbo].[Employee]
WHERE BusinessEntityID = ?`;
}

function empDeleteSQL() {

return `DELETE FROM [scratch].[dbo].[Employee]
WHERE BusinessEntityID = ?`;
}

function prepared(done) {

// create and populate table - fetch prepared statements to select and delete records for employee table.
Expand All @@ -355,8 +409,23 @@ function prepared(done) {

var async = new support.Async();
var assert = new support.Assert();
var statements = null;

var statements = {
select : null,
delete : null,
};

var table_name = "Employee";

var conn = null;

function employeePrepare(query, done) {
conn.prepare(query, function (err, ps) {
assert.ifError(err);
done(ps);
});
}

var fns = [

function(async_done) {
Expand All @@ -375,17 +444,51 @@ function prepared(done) {
});
},

function(async_done) {
console.log("preparing a select and delete statement.");
support.prepareEmployee(conn, function (prepared) {
assert.check(prepared != null, "prepared statement object is null.");
assert.check(prepared.select != null, "prepared select is null");
assert.check(prepared.delete != null, "prepared delete is null");
statements = prepared;
// drop / create an Employee table.
function (async_done) {
helper.dropCreateTable({
name: table_name
}, function () {
async_done();
});
},

// insert test set using bulk insert
function (async_done) {
var tm = conn.tableMgr();
tm.bind(table_name, function (bulkMgr) {
bulkMgr.insertRows(parsedJSON, function () {
async_done();
});
});
},

// prepare a select statement.
function (async_done) {
console.log("preparing a select statement.");
employeePrepare(empSelectSQL(), function (ps) {
statements.select = ps;
async_done();
})
},

// prepare a delete statement.
function (async_done) {
console.log("preparing a delete statement.");
employeePrepare(empDeleteSQL(), function (ps) {
statements.delete = ps;
async_done();
})
},

function(async_done) {
console.log("check statements.");
assert.check(statements != null, "prepared statement object is null.");
assert.check(statements.select != null, "prepared select is null");
assert.check(statements.delete != null, "prepared delete is null");
async_done();
},

function(async_done) {
var id = 1;
console.log("use prepared statement to fetch " + id);
Expand Down

0 comments on commit a5c86df

Please sign in to comment.