Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix internal handling of canFreeHandle on ODBCResult::New()
ODBCResult instances which are created from an ODBCStatement instance should not be allowed to destroy themselves (or free the hSTMT to be more specific) because the ODBCStatement can still be used to do stuff with that hSTMT. Only ODBCResult instances that are created from an ODBCConnection instance are allowed to actually destroy the hSTMT. Previously, we were not properly derefencing the canFreeHandle flag passed to ODBCResult::New() so it was evaluating to true in every case. This was causing the ODBCResult::CloseSync() method to always destroy the handle and thus cause the behaviour described in #32.
- Loading branch information
1 parent
abbd3d6
commit 0855800
Showing
4 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
var common = require("./common") | ||
, odbc = require("../") | ||
, db = new odbc.Database() | ||
, assert = require("assert") | ||
; | ||
|
||
var count = 0; | ||
var iterations = 10; | ||
|
||
db.open(common.connectionString, function(err) { | ||
if(err) { | ||
console.log(err) | ||
|
||
return finish(1); | ||
} | ||
|
||
common.createTables(db, function (err, data) { | ||
if (err) { | ||
console.log(err); | ||
|
||
return finish(2); | ||
} | ||
|
||
var stmt = db.prepareSync("insert into " + common.tableName + " (colint, coltext) VALUES (?, ?)"); | ||
assert.equal(stmt.constructor.name, "ODBCStatement"); | ||
|
||
recursive(stmt); | ||
}); | ||
}); | ||
|
||
function finish(retValue) { | ||
console.log("finish exit value: %s", retValue); | ||
|
||
db.close(function (err) { | ||
if (err) console.log (err); | ||
|
||
process.exit(retValue || 0); | ||
}); | ||
} | ||
|
||
function recursive (stmt) { | ||
try { | ||
var result = stmt.bindSync([4, 'hello world']); | ||
assert.equal(result, true); | ||
} | ||
catch (e) { | ||
console.log(e.message); | ||
finish(3); | ||
} | ||
|
||
stmt.execute(function (err, result) { | ||
if (err) { | ||
console.log(err.message); | ||
|
||
return finish(4); | ||
} | ||
|
||
result.closeSync(); | ||
count += 1; | ||
|
||
console.log("count %s, iterations %s", count, iterations); | ||
|
||
if (count <= iterations) { | ||
setTimeout(function(){ | ||
recursive(stmt); | ||
},100); | ||
} | ||
else { | ||
console.log(db.querySync("select * from " + common.tableName)); | ||
|
||
common.dropTables(db, function () { | ||
return finish(0); | ||
}); | ||
} | ||
}); | ||
} |