Skip to content

Commit

Permalink
fixed fields problems with empty results
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giammarchi committed May 27, 2014
1 parent b0ac5b0 commit 94ec325
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- 0.8
- 0.10
git:
depth: 1
Expand Down
2 changes: 1 addition & 1 deletion build/dblite.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function dblite() {
// converting the CSV into an Array of rows
result = dontParseCSV ? str : parseCSV(str);
// if there were headers/fields and we have a result ...
if (headers && isArray(result)) {
if (headers && isArray(result) && result.length) {
// ... and fields is not defined
if (fields == null) {
// fields is the row 0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.1",
"version": "0.4.2",
"license" : "MIT",
"engine": "node >= 0.6.0",
"name": "dblite",
Expand Down
2 changes: 1 addition & 1 deletion src/dblite.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function dblite() {
// converting the CSV into an Array of rows
result = dontParseCSV ? str : parseCSV(str);
// if there were headers/fields and we have a result ...
if (headers && isArray(result)) {
if (headers && isArray(result) && result.length) {
// ... and fields is not defined
if (fields == null) {
// fields is the row 0
Expand Down
25 changes: 25 additions & 0 deletions test/dblite.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ wru.test([
.on('close', Object)
;
}
},{
name: 'selecting empty results with manual fields works as expected',
test: function () {
dblite(':memory:')
.query('CREATE TABLE whatever (v TEXT)')
.query('SELECT * FROM whatever', {v:String}, wru.async(function (rows) {
wru.assert('invoked corectly', rows.length === 0);
this.close();
}))
.on('close', Object)
;
}
},{
name: 'selecting empty results with automatic fields works as expected',
test: function () {
dblite(':memory:')
.query('.headers ON')
.query('CREATE TABLE whatever (v TEXT)')
.query('SELECT * FROM whatever', wru.async(function (rows) {
wru.assert('invoked corectly', rows.length === 0);
this.close();
}))
.on('close', Object)
;
}
},{
name: 'notifies inserts or other operations too',
test: function () {
Expand Down

0 comments on commit 94ec325

Please sign in to comment.