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
68dcc132
Commit
68dcc132
authored
Apr 21, 2016
by
Dane Springmeyer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #518 from briangreenery/master
Add support for sqlite3_interrupt
parents
96da7da8
8b0bb91d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
database.cc
src/database.cc
+20
-0
database.h
src/database.h
+4
-0
interrupt.test.js
test/interrupt.test.js
+69
-0
No files found.
src/database.cc
View file @
68dcc132
...
@@ -23,6 +23,7 @@ NAN_MODULE_INIT(Database::Init) {
...
@@ -23,6 +23,7 @@ NAN_MODULE_INIT(Database::Init) {
Nan
::
SetPrototypeMethod
(
t
,
"serialize"
,
Serialize
);
Nan
::
SetPrototypeMethod
(
t
,
"serialize"
,
Serialize
);
Nan
::
SetPrototypeMethod
(
t
,
"parallelize"
,
Parallelize
);
Nan
::
SetPrototypeMethod
(
t
,
"parallelize"
,
Parallelize
);
Nan
::
SetPrototypeMethod
(
t
,
"configure"
,
Configure
);
Nan
::
SetPrototypeMethod
(
t
,
"configure"
,
Configure
);
Nan
::
SetPrototypeMethod
(
t
,
"interrupt"
,
Interrupt
);
NODE_SET_GETTER
(
t
,
"open"
,
OpenGetter
);
NODE_SET_GETTER
(
t
,
"open"
,
OpenGetter
);
...
@@ -224,6 +225,8 @@ void Database::Work_BeginClose(Baton* baton) {
...
@@ -224,6 +225,8 @@ void Database::Work_BeginClose(Baton* baton) {
assert
(
baton
->
db
->
pending
==
0
);
assert
(
baton
->
db
->
pending
==
0
);
baton
->
db
->
RemoveCallbacks
();
baton
->
db
->
RemoveCallbacks
();
baton
->
db
->
closing
=
true
;
int
status
=
uv_queue_work
(
uv_default_loop
(),
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
baton
->
request
,
Work_Close
,
(
uv_after_work_cb
)
Work_AfterClose
);
&
baton
->
request
,
Work_Close
,
(
uv_after_work_cb
)
Work_AfterClose
);
assert
(
status
==
0
);
assert
(
status
==
0
);
...
@@ -249,6 +252,8 @@ void Database::Work_AfterClose(uv_work_t* req) {
...
@@ -249,6 +252,8 @@ void Database::Work_AfterClose(uv_work_t* req) {
Baton
*
baton
=
static_cast
<
Baton
*>
(
req
->
data
);
Baton
*
baton
=
static_cast
<
Baton
*>
(
req
->
data
);
Database
*
db
=
baton
->
db
;
Database
*
db
=
baton
->
db
;
db
->
closing
=
false
;
Local
<
Value
>
argv
[
1
];
Local
<
Value
>
argv
[
1
];
if
(
baton
->
status
!=
SQLITE_OK
)
{
if
(
baton
->
status
!=
SQLITE_OK
)
{
EXCEPTION
(
Nan
::
New
(
baton
->
message
.
c_str
()).
ToLocalChecked
(),
baton
->
status
,
exception
);
EXCEPTION
(
Nan
::
New
(
baton
->
message
.
c_str
()).
ToLocalChecked
(),
baton
->
status
,
exception
);
...
@@ -351,6 +356,21 @@ NAN_METHOD(Database::Configure) {
...
@@ -351,6 +356,21 @@ NAN_METHOD(Database::Configure) {
info
.
GetReturnValue
().
Set
(
info
.
This
());
info
.
GetReturnValue
().
Set
(
info
.
This
());
}
}
NAN_METHOD
(
Database
::
Interrupt
)
{
Database
*
db
=
Nan
::
ObjectWrap
::
Unwrap
<
Database
>
(
info
.
This
());
if
(
!
db
->
open
)
{
return
Nan
::
ThrowError
(
"Database is not open"
);
}
if
(
db
->
closing
)
{
return
Nan
::
ThrowError
(
"Database is closing"
);
}
sqlite3_interrupt
(
db
->
_handle
);
info
.
GetReturnValue
().
Set
(
info
.
This
());
}
void
Database
::
SetBusyTimeout
(
Baton
*
baton
)
{
void
Database
::
SetBusyTimeout
(
Baton
*
baton
)
{
assert
(
baton
->
db
->
open
);
assert
(
baton
->
db
->
open
);
assert
(
baton
->
db
->
_handle
);
assert
(
baton
->
db
->
_handle
);
...
...
src/database.h
View file @
68dcc132
...
@@ -104,6 +104,7 @@ protected:
...
@@ -104,6 +104,7 @@ protected:
_handle
(
NULL
),
_handle
(
NULL
),
open
(
false
),
open
(
false
),
locked
(
false
),
locked
(
false
),
closing
(
false
),
pending
(
0
),
pending
(
0
),
serialize
(
false
),
serialize
(
false
),
debug_trace
(
NULL
),
debug_trace
(
NULL
),
...
@@ -151,6 +152,8 @@ protected:
...
@@ -151,6 +152,8 @@ protected:
static
NAN_METHOD
(
Configure
);
static
NAN_METHOD
(
Configure
);
static
NAN_METHOD
(
Interrupt
);
static
void
SetBusyTimeout
(
Baton
*
baton
);
static
void
SetBusyTimeout
(
Baton
*
baton
);
static
void
RegisterTraceCallback
(
Baton
*
baton
);
static
void
RegisterTraceCallback
(
Baton
*
baton
);
...
@@ -171,6 +174,7 @@ protected:
...
@@ -171,6 +174,7 @@ protected:
sqlite3
*
_handle
;
sqlite3
*
_handle
;
bool
open
;
bool
open
;
bool
closing
;
bool
locked
;
bool
locked
;
unsigned
int
pending
;
unsigned
int
pending
;
...
...
test/interrupt.test.js
0 → 100644
View file @
68dcc132
var
sqlite3
=
require
(
'..'
);
var
assert
=
require
(
'assert'
);
describe
(
'interrupt'
,
function
()
{
it
(
'should interrupt queries'
,
function
(
done
)
{
var
query
=
'with t (n) as (values (1),(2),(3),(4),(5),(6),(7),(8)) '
+
'select last.n '
+
'from t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t as last'
;
var
interrupted
=
false
;
var
saved
=
null
;
var
db
=
new
sqlite3
.
Database
(
':memory:'
,
function
()
{
db
.
each
(
query
,
function
(
err
)
{
if
(
!
interrupted
)
{
interrupted
=
true
;
db
.
interrupt
();
}
else
if
(
err
)
{
saved
=
err
;
}
});
db
.
close
(
function
()
{
if
(
saved
)
{
assert
.
equal
(
saved
.
message
,
'SQLITE_INTERRUPT: interrupted'
);
assert
.
equal
(
saved
.
errno
,
sqlite3
.
INTERRUPT
);
assert
.
equal
(
saved
.
code
,
'SQLITE_INTERRUPT'
);
done
();
}
else
{
done
(
new
Error
(
'Completed query without error, but expected error'
));
}
});
});
});
it
(
'should throw if interrupt is called before open'
,
function
(
done
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
assert
.
throws
(
function
()
{
db
.
interrupt
();
},
(
/Database is not open/
));
db
.
close
();
done
();
});
it
(
'should throw if interrupt is called after close'
,
function
(
done
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
);
db
.
close
(
function
()
{
assert
.
throws
(
function
()
{
db
.
interrupt
();
},
(
/Database is not open/
));
done
();
});
});
it
(
'should throw if interrupt is called during close'
,
function
(
done
)
{
var
db
=
new
sqlite3
.
Database
(
':memory:'
,
function
()
{
db
.
close
();
assert
.
throws
(
function
()
{
db
.
interrupt
();
},
(
/Database is closing/
));
done
();
});
});
});
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