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
31c54053
Commit
31c54053
authored
Mar 09, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add db.close()
parent
4f3a5774
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
22 deletions
+72
-22
sqlite3_bindings.cc
sqlite3_bindings.cc
+66
-15
test2.js
test2.js
+6
-7
No files found.
sqlite3_bindings.cc
View file @
31c54053
...
@@ -80,9 +80,8 @@ public:
...
@@ -80,9 +80,8 @@ public:
t
->
InstanceTemplate
()
->
SetInternalFieldCount
(
1
);
t
->
InstanceTemplate
()
->
SetInternalFieldCount
(
1
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"open"
,
Open
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"open"
,
Open
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"printIt"
,
PrintIt
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"changes"
,
Changes
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"close"
,
Close
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"close"
,
Close
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"changes"
,
Changes
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"lastInsertRowid"
,
LastInsertRowid
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"lastInsertRowid"
,
LastInsertRowid
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"prepare"
,
Prepare
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"prepare"
,
Prepare
);
...
@@ -169,15 +168,6 @@ protected:
...
@@ -169,15 +168,6 @@ protected:
return
0
;
return
0
;
}
}
static
Handle
<
Value
>
PrintIt
(
const
Arguments
&
args
)
{
HandleScope
scope
;
Sqlite3Db
*
dbo
=
ObjectWrap
::
Unwrap
<
Sqlite3Db
>
(
args
.
This
());
sqlite3
*
db
=
*
dbo
;
return
Undefined
();
}
static
Handle
<
Value
>
Open
(
const
Arguments
&
args
)
{
static
Handle
<
Value
>
Open
(
const
Arguments
&
args
)
{
HandleScope
scope
;
HandleScope
scope
;
...
@@ -219,12 +209,73 @@ protected:
...
@@ -219,12 +209,73 @@ protected:
return
scope
.
Close
(
result
);
return
scope
.
Close
(
result
);
}
}
// TODO: libeio'fy
struct
close_request
{
Persistent
<
Function
>
cb
;
Sqlite3Db
*
dbo
;
};
static
int
EIO_AfterClose
(
eio_req
*
req
)
{
ev_unref
(
EV_DEFAULT_UC
);
HandleScope
scope
;
struct
close_request
*
close_req
=
(
struct
close_request
*
)(
req
->
data
);
Local
<
Value
>
argv
[
1
];
bool
err
=
false
;
if
(
req
->
result
)
{
err
=
true
;
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
"Error closing database"
));
}
TryCatch
try_catch
;
close_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
err
?
1
:
0
,
argv
);
if
(
try_catch
.
HasCaught
())
{
FatalException
(
try_catch
);
}
close_req
->
cb
.
Dispose
();
free
(
close_req
);
close_req
->
dbo
->
Unref
();
return
0
;
}
static
int
EIO_Close
(
eio_req
*
req
)
{
struct
close_request
*
close_req
=
(
struct
close_request
*
)(
req
->
data
);
Sqlite3Db
*
dbo
=
close_req
->
dbo
;
int
rc
=
req
->
result
=
sqlite3_close
(
*
dbo
);
dbo
->
db_
=
NULL
;
return
0
;
}
static
Handle
<
Value
>
Close
(
const
Arguments
&
args
)
{
static
Handle
<
Value
>
Close
(
const
Arguments
&
args
)
{
HandleScope
scope
;
HandleScope
scope
;
Sqlite3Db
*
db
=
ObjectWrap
::
Unwrap
<
Sqlite3Db
>
(
args
.
This
());
CHECK
(
sqlite3_close
(
*
db
));
REQ_FUN_ARG
(
0
,
cb
);
db
->
db_
=
NULL
;
Sqlite3Db
*
dbo
=
ObjectWrap
::
Unwrap
<
Sqlite3Db
>
(
args
.
This
());
struct
close_request
*
close_req
=
(
struct
close_request
*
)
calloc
(
1
,
sizeof
(
struct
close_request
));
if
(
!
close_req
)
{
V8
::
LowMemoryNotification
();
return
ThrowException
(
Exception
::
Error
(
String
::
New
(
"Could not allocate enough memory"
)));
}
close_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
close_req
->
dbo
=
dbo
;
eio_custom
(
EIO_Close
,
EIO_PRI_DEFAULT
,
EIO_AfterClose
,
close_req
);
ev_ref
(
EV_DEFAULT_UC
);
dbo
->
Ref
();
return
Undefined
();
return
Undefined
();
}
}
...
...
test2.js
View file @
31c54053
...
@@ -74,17 +74,16 @@ function test_simple() {
...
@@ -74,17 +74,16 @@ function test_simple() {
puts
(
'prepare callback'
);
puts
(
'prepare callback'
);
puts
(
inspect
(
arguments
));
puts
(
inspect
(
arguments
));
// assertCallsFunction(statement.step, function (err, statement) {
// });
statement
.
step
(
function
()
{
statement
.
step
(
function
()
{
puts
(
'query callback'
);
puts
(
'query callback'
);
puts
(
inspect
(
arguments
));
puts
(
inspect
(
arguments
));
statement
.
step
(
function
()
{
statement
.
step
(
function
()
{
puts
(
'query callback'
);
puts
(
'query callback'
);
puts
(
inspect
(
arguments
));
puts
(
inspect
(
arguments
));
db
.
close
(
function
()
{
test_prepare
(
);
puts
(
"closed database"
);
});
});
});
});
});
});
});
});
});
...
...
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