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
493050a9
Commit
493050a9
authored
Feb 14, 2011
by
Konstantin Käfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename dbo to db
parent
f41e01c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
35 deletions
+36
-35
database.cc
src/database.cc
+33
-32
database.h
src/database.h
+3
-3
No files found.
src/database.cc
View file @
493050a9
...
...
@@ -24,6 +24,9 @@
using
namespace
v8
;
using
namespace
node
;
Persistent
<
FunctionTemplate
>
Database
::
constructor_template
;
void
Database
::
Init
(
v8
::
Handle
<
Object
>
target
)
{
HandleScope
scope
;
...
...
@@ -50,8 +53,8 @@ void Database::Init(v8::Handle<Object> target) {
Handle
<
Value
>
Database
::
New
(
const
Arguments
&
args
)
{
HandleScope
scope
;
Database
*
db
o
=
new
Database
();
db
o
->
Wrap
(
args
.
This
());
Database
*
db
=
new
Database
();
db
->
Wrap
(
args
.
This
());
return
args
.
This
();
}
...
...
@@ -69,14 +72,14 @@ int Database::EIO_AfterOpen(eio_req *req) {
TryCatch
try_catch
;
open_req
->
db
o
->
Unref
();
open_req
->
db
->
Unref
();
open_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
err
?
1
:
0
,
argv
);
if
(
try_catch
.
HasCaught
())
{
FatalException
(
try_catch
);
}
open_req
->
db
o
->
Emit
(
String
::
New
(
"ready"
),
0
,
NULL
);
open_req
->
db
->
Emit
(
String
::
New
(
"ready"
),
0
,
NULL
);
open_req
->
cb
.
Dispose
();
free
(
open_req
);
...
...
@@ -87,7 +90,7 @@ int Database::EIO_AfterOpen(eio_req *req) {
int
Database
::
EIO_Open
(
eio_req
*
req
)
{
struct
open_request
*
open_req
=
(
struct
open_request
*
)(
req
->
data
);
sqlite3
**
dbptr
=
open_req
->
db
o
->
GetDBPtr
();
sqlite3
**
dbptr
=
open_req
->
db
->
GetDBPtr
();
int
rc
=
sqlite3_open_v2
(
open_req
->
filename
,
dbptr
,
SQLITE_OPEN_READWRITE
...
...
@@ -102,9 +105,9 @@ int Database::EIO_Open(eio_req *req) {
// sqlite3 *db = *dbptr;
// sqlite3_commit_hook(db, CommitHook, open_req->db
o
);
// sqlite3_rollback_hook(db, RollbackHook, open_req->db
o
);
// sqlite3_update_hook(db, UpdateHook, open_req->db
o
);
// sqlite3_commit_hook(db, CommitHook, open_req->db);
// sqlite3_rollback_hook(db, RollbackHook, open_req->db);
// sqlite3_update_hook(db, UpdateHook, open_req->db);
return
0
;
}
...
...
@@ -115,7 +118,7 @@ Handle<Value> Database::Open(const Arguments& args) {
REQ_STR_ARG
(
0
,
filename
);
REQ_FUN_ARG
(
1
,
cb
);
Database
*
db
o
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
struct
open_request
*
open_req
=
(
struct
open_request
*
)
calloc
(
1
,
sizeof
(
struct
open_request
)
+
filename
.
length
());
...
...
@@ -128,12 +131,12 @@ Handle<Value> Database::Open(const Arguments& args) {
strcpy
(
open_req
->
filename
,
*
filename
);
open_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
open_req
->
db
o
=
dbo
;
open_req
->
db
=
db
;
eio_custom
(
EIO_Open
,
EIO_PRI_DEFAULT
,
EIO_AfterOpen
,
open_req
);
ev_ref
(
EV_DEFAULT_UC
);
db
o
->
Ref
();
db
->
Ref
();
return
Undefined
();
}
...
...
@@ -154,7 +157,7 @@ int Database::EIO_AfterClose(eio_req *req) {
TryCatch
try_catch
;
close_req
->
db
o
->
Unref
();
close_req
->
db
->
Unref
();
close_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
err
?
1
:
0
,
argv
);
if
(
try_catch
.
HasCaught
())
{
...
...
@@ -170,9 +173,9 @@ int Database::EIO_AfterClose(eio_req *req) {
int
Database
::
EIO_Close
(
eio_req
*
req
)
{
struct
close_request
*
close_req
=
(
struct
close_request
*
)(
req
->
data
);
Database
*
db
o
=
close_req
->
dbo
;
req
->
result
=
sqlite3_close
(
db
o
->
db_
);
db
o
->
db_
=
NULL
;
Database
*
db
=
close_req
->
db
;
req
->
result
=
sqlite3_close
(
db
->
db_
);
db
->
db_
=
NULL
;
return
0
;
}
...
...
@@ -181,7 +184,7 @@ Handle<Value> Database::Close(const Arguments& args) {
REQ_FUN_ARG
(
0
,
cb
);
Database
*
db
o
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
struct
close_request
*
close_req
=
(
struct
close_request
*
)
calloc
(
1
,
sizeof
(
struct
close_request
));
...
...
@@ -193,12 +196,12 @@ Handle<Value> Database::Close(const Arguments& args) {
}
close_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
close_req
->
db
o
=
dbo
;
close_req
->
db
=
db
;
eio_custom
(
EIO_Close
,
EIO_PRI_DEFAULT
,
EIO_AfterClose
,
close_req
);
ev_ref
(
EV_DEFAULT_UC
);
db
o
->
Ref
();
db
->
Ref
();
return
Undefined
();
}
...
...
@@ -240,7 +243,7 @@ int Database::EIO_AfterPrepareAndStep(eio_req *req) {
// if the prepare failed
if
(
req
->
result
!=
SQLITE_OK
)
{
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
sqlite3_errmsg
(
prep_req
->
db
o
->
db_
)));
String
::
New
(
sqlite3_errmsg
(
prep_req
->
db
->
db_
)));
argc
=
1
;
}
...
...
@@ -286,7 +289,7 @@ int Database::EIO_AfterPrepareAndStep(eio_req *req) {
TryCatch
try_catch
;
prep_req
->
db
o
->
Unref
();
prep_req
->
db
->
Unref
();
prep_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
if
(
try_catch
.
HasCaught
())
{
...
...
@@ -304,7 +307,7 @@ int Database::EIO_PrepareAndStep(eio_req *req) {
prep_req
->
stmt
=
NULL
;
prep_req
->
tail
=
NULL
;
sqlite3
*
db
=
prep_req
->
db
o
->
db_
;
sqlite3
*
db
=
prep_req
->
db
->
db_
;
int
rc
=
sqlite3_prepare_v2
(
db
,
prep_req
->
sql
,
-
1
,
&
(
prep_req
->
stmt
),
&
(
prep_req
->
tail
));
...
...
@@ -347,7 +350,7 @@ Handle<Value> Database::PrepareAndStep(const Arguments& args) {
REQ_FUN_ARG
(
1
,
cb
);
OPT_INT_ARG
(
2
,
mode
,
EXEC_EMPTY
);
Database
*
db
o
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
struct
prepare_request
*
prep_req
=
(
struct
prepare_request
*
)
calloc
(
1
,
sizeof
(
struct
prepare_request
)
+
sql
.
length
());
...
...
@@ -360,13 +363,13 @@ Handle<Value> Database::PrepareAndStep(const Arguments& args) {
strcpy
(
prep_req
->
sql
,
*
sql
);
prep_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
prep_req
->
db
o
=
dbo
;
prep_req
->
db
=
db
;
prep_req
->
mode
=
mode
;
eio_custom
(
EIO_PrepareAndStep
,
EIO_PRI_DEFAULT
,
EIO_AfterPrepareAndStep
,
prep_req
);
ev_ref
(
EV_DEFAULT_UC
);
db
o
->
Ref
();
db
->
Ref
();
return
Undefined
();
}
...
...
@@ -382,7 +385,7 @@ int Database::EIO_AfterPrepare(eio_req *req) {
// if the prepare failed
if
(
req
->
result
!=
SQLITE_OK
)
{
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
sqlite3_errmsg
(
prep_req
->
db
o
->
db_
)));
String
::
New
(
sqlite3_errmsg
(
prep_req
->
db
->
db_
)));
argc
=
1
;
}
else
{
...
...
@@ -403,7 +406,7 @@ int Database::EIO_AfterPrepare(eio_req *req) {
TryCatch
try_catch
;
prep_req
->
db
o
->
Unref
();
prep_req
->
db
->
Unref
();
prep_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
if
(
try_catch
.
HasCaught
())
{
...
...
@@ -420,7 +423,7 @@ int Database::EIO_Prepare(eio_req *req) {
prep_req
->
stmt
=
NULL
;
prep_req
->
tail
=
NULL
;
sqlite3
*
db
=
prep_req
->
db
o
->
db_
;
sqlite3
*
db
=
prep_req
->
db
->
db_
;
int
rc
=
sqlite3_prepare_v2
(
db
,
prep_req
->
sql
,
-
1
,
&
(
prep_req
->
stmt
),
&
(
prep_req
->
tail
));
...
...
@@ -483,7 +486,7 @@ Handle<Value> Database::Prepare(const Arguments& args) {
mode
|=
EXEC_AFFECTED_ROWS
;
}
Database
*
db
o
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
.
This
());
struct
prepare_request
*
prep_req
=
(
struct
prepare_request
*
)
calloc
(
1
,
sizeof
(
struct
prepare_request
)
+
sql
.
length
());
...
...
@@ -496,15 +499,13 @@ Handle<Value> Database::Prepare(const Arguments& args) {
strcpy
(
prep_req
->
sql
,
*
sql
);
prep_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
prep_req
->
db
o
=
dbo
;
prep_req
->
db
=
db
;
prep_req
->
mode
=
mode
;
eio_custom
(
EIO_Prepare
,
EIO_PRI_DEFAULT
,
EIO_AfterPrepare
,
prep_req
);
ev_ref
(
EV_DEFAULT_UC
);
db
o
->
Ref
();
db
->
Ref
();
return
Undefined
();
}
Persistent
<
FunctionTemplate
>
Database
::
constructor_template
;
src/database.h
View file @
493050a9
...
...
@@ -76,18 +76,18 @@ enum ExecMode
struct
open_request
{
Persistent
<
Function
>
cb
;
Database
*
db
o
;
Database
*
db
;
char
filename
[
1
];
};
struct
close_request
{
Persistent
<
Function
>
cb
;
Database
*
db
o
;
Database
*
db
;
};
struct
prepare_request
{
Persistent
<
Function
>
cb
;
Database
*
db
o
;
Database
*
db
;
sqlite3_stmt
*
stmt
;
int
mode
;
sqlite3_int64
lastInsertId
;
...
...
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