Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sqlite3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
node-sqlite3
Commits
a26b79dc
Commit
a26b79dc
authored
Feb 28, 2011
by
Konstantin Käfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure that the callback is called when preparing for Database# functions
parent
09b55954
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
234 additions
and
18 deletions
+234
-18
.gitignore
.gitignore
+4
-0
sqlite3.js
lib/sqlite3.js
+22
-15
statement.cc
src/statement.cc
+5
-2
database_fail.test.js
test/database_fail.test.js
+202
-0
each.test.js
test/each.test.js
+1
-1
No files found.
.gitignore
View file @
a26b79dc
build/
build/
TODO
wiki
lib/sqlite3_bindings.node
\ No newline at end of file
lib/sqlite3.js
View file @
a26b79dc
...
@@ -3,48 +3,55 @@ var sqlite3 = module.exports = exports = require('./sqlite3_bindings');
...
@@ -3,48 +3,55 @@ var sqlite3 = module.exports = exports = require('./sqlite3_bindings');
var
Database
=
sqlite3
.
Database
;
var
Database
=
sqlite3
.
Database
;
var
Statement
=
sqlite3
.
Statement
;
var
Statement
=
sqlite3
.
Statement
;
function
errorCallback
(
args
)
{
if
(
typeof
args
[
args
.
length
-
1
]
===
'function'
)
{
var
callback
=
args
[
args
.
length
-
1
];
return
function
(
err
)
{
if
(
err
)
callback
(
err
);
};
}
}
// Database#prepare(sql, [bind1, bind2, ...], [callback])
// Database#prepare(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
prepare
=
function
(
sql
)
{
Database
.
prototype
.
prepare
=
function
(
sql
)
{
var
callback
,
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
if
(
!
params
.
length
||
(
params
.
length
===
1
&&
typeof
params
[
0
]
===
'function'
))
{
if
(
!
params
.
length
||
(
params
.
length
===
1
&&
typeof
params
[
0
]
===
'function'
))
{
return
new
Statement
(
this
,
sql
,
params
[
0
]);
return
new
Statement
(
this
,
sql
,
params
[
0
]);
}
}
else
{
else
{
var
statement
=
new
Statement
(
this
,
sql
,
function
(
err
)
{
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
if
(
err
&&
typeof
params
[
params
.
length
-
1
]
===
'function'
)
{
params
[
params
.
length
-
1
](
err
);
}
});
return
statement
.
bind
.
apply
(
statement
,
params
);
return
statement
.
bind
.
apply
(
statement
,
params
);
}
}
};
};
// Database#run(sql, [bind1, bind2, ...], [callback])
// Database#run(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
run
=
function
(
sql
)
{
Database
.
prototype
.
run
=
function
(
sql
)
{
var
statement
=
new
Statement
(
this
,
sql
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
statement
.
run
.
apply
(
statement
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)).
finalize
();
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
statement
.
run
.
apply
(
statement
,
params
).
finalize
();
return
this
;
return
this
;
}
}
// Database#get(sql, [bind1, bind2, ...], [callback])
// Database#get(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
get
=
function
(
sql
)
{
Database
.
prototype
.
get
=
function
(
sql
)
{
var
statement
=
new
Statement
(
this
,
sql
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
statement
.
get
.
apply
(
statement
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)).
finalize
();
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
statement
.
get
.
apply
(
statement
,
params
).
finalize
();
return
this
;
return
this
;
}
}
// Database#all(sql, [bind1, bind2, ...], [callback])
// Database#all(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
all
=
function
(
sql
)
{
Database
.
prototype
.
all
=
function
(
sql
)
{
var
statement
=
new
Statement
(
this
,
sql
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
statement
.
all
.
apply
(
statement
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)).
finalize
();
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
statement
.
all
.
apply
(
statement
,
params
).
finalize
();
return
this
;
return
this
;
}
}
// Database#each(sql, [bind1, bind2, ...], [callback])
// Database#each(sql, [bind1, bind2, ...], [callback]
, [complete]
)
Database
.
prototype
.
each
=
function
(
sql
)
{
Database
.
prototype
.
each
=
function
(
sql
)
{
var
statement
=
new
Statement
(
this
,
sql
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
statement
.
each
.
apply
(
statement
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)).
finalize
();
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
statement
.
each
.
apply
(
statement
,
params
).
finalize
();
return
this
;
return
this
;
}
}
...
...
src/statement.cc
View file @
a26b79dc
...
@@ -687,8 +687,11 @@ void Statement::AsyncEach(EV_P_ ev_async *w, int revents) {
...
@@ -687,8 +687,11 @@ void Statement::AsyncEach(EV_P_ ev_async *w, int revents) {
if
(
async
->
completed
)
{
if
(
async
->
completed
)
{
if
(
!
async
->
completed_callback
.
IsEmpty
()
&&
if
(
!
async
->
completed_callback
.
IsEmpty
()
&&
async
->
completed_callback
->
IsFunction
())
{
async
->
completed_callback
->
IsFunction
())
{
Local
<
Value
>
argv
[]
=
{
Integer
::
New
(
async
->
retrieved
)
};
Local
<
Value
>
argv
[]
=
{
TRY_CATCH_CALL
(
async
->
stmt
->
handle_
,
async
->
completed_callback
,
1
,
argv
);
Local
<
Value
>::
New
(
Null
()),
Integer
::
New
(
async
->
retrieved
)
};
TRY_CATCH_CALL
(
async
->
stmt
->
handle_
,
async
->
completed_callback
,
2
,
argv
);
}
}
delete
async
;
delete
async
;
w
->
data
=
NULL
;
w
->
data
=
NULL
;
...
...
test/database_fail.test.js
0 → 100644
View file @
a26b79dc
var
sqlite3
=
require
(
'sqlite3'
);
var
assert
=
require
(
'assert'
);
exports
[
'test Database#get prepare fail'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
get
(
'SELECT id, txt FROM foo'
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#all prepare fail'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
all
(
'SELECT id, txt FROM foo'
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#run prepare fail'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
run
(
'SELECT id, txt FROM foo'
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#each prepare fail'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
each
(
'SELECT id, txt FROM foo'
,
function
(
err
,
row
)
{
assert
.
ok
(
false
,
"this should not be called"
);
},
function
(
err
,
num
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#each prepare fail without completion handler'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
each
(
'SELECT id, txt FROM foo'
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
else
{
assert
.
ok
(
false
,
'this should not be called'
)
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#get prepare fail with param binding'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
get
(
'SELECT id, txt FROM foo WHERE id = ?'
,
1
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#all prepare fail with param binding'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
all
(
'SELECT id, txt FROM foo WHERE id = ?'
,
1
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#run prepare fail with param binding'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
run
(
'SELECT id, txt FROM foo WHERE id = ?'
,
1
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#each prepare fail with param binding'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
each
(
'SELECT id, txt FROM foo WHERE id = ?'
,
1
,
function
(
err
,
row
)
{
assert
.
ok
(
false
,
"this should not be called"
);
},
function
(
err
,
num
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
exports
[
'test Database#each prepare fail with param binding without completion handler'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
var
completed
=
false
;
db
.
each
(
'SELECT id, txt FROM foo WHERE id = ?'
,
1
,
function
(
err
,
row
)
{
if
(
err
)
{
assert
.
equal
(
err
.
message
,
'SQLITE_ERROR: no such table: foo'
);
assert
.
equal
(
err
.
errno
,
sqlite3
.
ERROR
);
assert
.
equal
(
err
.
code
,
'SQLITE_ERROR'
);
completed
=
true
;
}
else
{
assert
.
ok
(
false
,
'this should not be called'
)
}
});
beforeExit
(
function
()
{
assert
.
ok
(
completed
);
});
};
test/each.test.js
View file @
a26b79dc
...
@@ -30,7 +30,7 @@ exports['test Statement#each with complete callback'] = function(beforeExit) {
...
@@ -30,7 +30,7 @@ exports['test Statement#each with complete callback'] = function(beforeExit) {
db
.
each
(
'SELECT id, txt FROM foo LIMIT 0, ?'
,
total
,
function
(
err
,
row
)
{
db
.
each
(
'SELECT id, txt FROM foo LIMIT 0, ?'
,
total
,
function
(
err
,
row
)
{
if
(
err
)
throw
err
;
if
(
err
)
throw
err
;
retrieved
++
;
retrieved
++
;
},
function
(
num
)
{
},
function
(
err
,
num
)
{
assert
.
equal
(
retrieved
,
num
);
assert
.
equal
(
retrieved
,
num
);
completed
=
true
;
completed
=
true
;
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment