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
88a01961
Commit
88a01961
authored
Mar 09, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asynchronize statement.finalize()
parent
31c54053
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
40 deletions
+79
-40
sqlite3_bindings.cc
sqlite3_bindings.cc
+66
-40
test2.js
test2.js
+13
-0
No files found.
sqlite3_bindings.cc
View file @
88a01961
...
@@ -94,7 +94,7 @@ protected:
...
@@ -94,7 +94,7 @@ protected:
Sqlite3Db
()
:
db_
(
NULL
)
{
}
Sqlite3Db
()
:
db_
(
NULL
)
{
}
~
Sqlite3Db
()
{
~
Sqlite3Db
()
{
sqlite3_close
(
db_
);
assert
(
db_
==
NULL
);
}
}
sqlite3
*
db_
;
sqlite3
*
db_
;
...
@@ -248,6 +248,7 @@ protected:
...
@@ -248,6 +248,7 @@ protected:
struct
close_request
*
close_req
=
(
struct
close_request
*
)(
req
->
data
);
struct
close_request
*
close_req
=
(
struct
close_request
*
)(
req
->
data
);
Sqlite3Db
*
dbo
=
close_req
->
dbo
;
Sqlite3Db
*
dbo
=
close_req
->
dbo
;
int
rc
=
req
->
result
=
sqlite3_close
(
*
dbo
);
int
rc
=
req
->
result
=
sqlite3_close
(
*
dbo
);
printf
(
"closed database, rc = %d
\n
"
,
rc
);
dbo
->
db_
=
NULL
;
dbo
->
db_
=
NULL
;
return
0
;
return
0
;
}
}
...
@@ -659,12 +660,72 @@ protected:
...
@@ -659,12 +660,72 @@ protected:
return
Undefined
();
return
Undefined
();
}
}
struct
finalize_request
{
Persistent
<
Function
>
cb
;
Statement
*
sto
;
};
static
int
EIO_AfterFinalize
(
eio_req
*
req
)
{
ev_unref
(
EV_DEFAULT_UC
);
struct
finalize_request
*
finalize_req
=
(
struct
finalize_request
*
)(
req
->
data
);
HandleScope
scope
;
TryCatch
try_catch
;
Local
<
Value
>
argv
[
1
];
printf
(
"rc for finalize = %d
\n
"
,
(
int
)
req
->
result
);
argv
[
0
]
=
Local
<
Value
>::
New
(
Undefined
());
finalize_req
->
cb
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
1
,
argv
);
if
(
try_catch
.
HasCaught
())
{
FatalException
(
try_catch
);
}
finalize_req
->
cb
.
Dispose
();
free
(
finalize_req
);
finalize_req
->
sto
->
Unref
();
return
0
;
}
static
int
EIO_Finalize
(
eio_req
*
req
)
{
struct
finalize_request
*
finalize_req
=
(
struct
finalize_request
*
)(
req
->
data
);
Statement
*
sto
=
finalize_req
->
sto
;
req
->
result
=
sqlite3_finalize
(
*
sto
);
sto
->
stmt_
=
NULL
;
return
0
;
}
static
Handle
<
Value
>
Finalize
(
const
Arguments
&
args
)
{
static
Handle
<
Value
>
Finalize
(
const
Arguments
&
args
)
{
HandleScope
scope
;
HandleScope
scope
;
Statement
*
stmt
=
ObjectWrap
::
Unwrap
<
Statement
>
(
args
.
This
());
SCHECK
(
sqlite3_finalize
(
*
stmt
));
REQ_FUN_ARG
(
0
,
cb
);
stmt
->
stmt_
=
NULL
;
//args.This().MakeWeak();
Statement
*
sto
=
ObjectWrap
::
Unwrap
<
Statement
>
(
args
.
This
());
struct
finalize_request
*
finalize_req
=
(
struct
finalize_request
*
)
calloc
(
1
,
sizeof
(
struct
finalize_request
));
if
(
!
finalize_req
)
{
V8
::
LowMemoryNotification
();
return
ThrowException
(
Exception
::
Error
(
String
::
New
(
"Could not allocate enough memory"
)));
}
finalize_req
->
cb
=
Persistent
<
Function
>::
New
(
cb
);
finalize_req
->
sto
=
sto
;
eio_custom
(
EIO_Finalize
,
EIO_PRI_DEFAULT
,
EIO_AfterFinalize
,
finalize_req
);
ev_ref
(
EV_DEFAULT_UC
);
sto
->
Ref
();
return
Undefined
();
return
Undefined
();
}
}
...
@@ -763,37 +824,6 @@ protected:
...
@@ -763,37 +824,6 @@ protected:
struct
step_request
*
step_req
=
(
struct
step_request
*
)(
req
->
data
);
struct
step_request
*
step_req
=
(
struct
step_request
*
)(
req
->
data
);
Statement
*
sto
=
step_req
->
sto
;
Statement
*
sto
=
step_req
->
sto
;
// int rc = sqlite3_step(*stmt);
// if (rc == SQLITE_ROW) {
// Local<Object> row = Object::New();
// for (int c = 0; c < sqlite3_column_count(*stmt); ++c) {
// Handle<Value> value;
// switch (sqlite3_column_type(*stmt, c)) {
// case SQLITE_INTEGER:
// value = Integer::New(sqlite3_column_int(*stmt, c));
// break;
// case SQLITE_FLOAT:
// value = Number::New(sqlite3_column_double(*stmt, c));
// break;
// case SQLITE_TEXT:
// value = String::New((const char*) sqlite3_column_text(*stmt, c));
// break;
// case SQLITE_NULL:
// default: // We don't handle any other types just now
// value = Undefined();
// break;
// }
// row->Set(String::NewSymbol(sqlite3_column_name(*stmt, c)),
// value);
// }
// return row;
// } else if (rc == SQLITE_DONE) {
// return Null();
// } else {
// return ThrowException(Exception::Error(String::New(
// sqlite3_errmsg(sqlite3_db_handle(*stmt)))));
// }
sqlite3_stmt
*
stmt
=
*
sto
;
sqlite3_stmt
*
stmt
=
*
sto
;
int
rc
=
req
->
result
=
sqlite3_step
(
stmt
);
int
rc
=
req
->
result
=
sqlite3_step
(
stmt
);
...
@@ -848,9 +878,6 @@ protected:
...
@@ -848,9 +878,6 @@ protected:
}
}
}
}
}
}
else
if
(
rc
==
SQLITE_DONE
)
{
// done case
}
else
{
else
{
step_req
->
error_msg
=
(
char
*
)
step_req
->
error_msg
=
(
char
*
)
sqlite3_errmsg
(
sqlite3_db_handle
(
*
sto
));
sqlite3_errmsg
(
sqlite3_db_handle
(
*
sto
));
...
@@ -889,7 +916,6 @@ protected:
...
@@ -889,7 +916,6 @@ protected:
};
};
};
};
Persistent
<
FunctionTemplate
>
Sqlite3Db
::
Statement
::
constructor_template
;
Persistent
<
FunctionTemplate
>
Sqlite3Db
::
Statement
::
constructor_template
;
extern
"C"
void
init
(
v8
::
Handle
<
Object
>
target
)
{
extern
"C"
void
init
(
v8
::
Handle
<
Object
>
target
)
{
...
...
test2.js
View file @
88a01961
...
@@ -80,13 +80,26 @@ function test_simple() {
...
@@ -80,13 +80,26 @@ function test_simple() {
statement
.
step
(
function
()
{
statement
.
step
(
function
()
{
puts
(
'query callback'
);
puts
(
'query callback'
);
puts
(
inspect
(
arguments
));
puts
(
inspect
(
arguments
));
statement
.
finalize
(
function
()
{
puts
(
"finalize callback"
);
db
.
close
(
function
()
{
db
.
close
(
function
()
{
puts
(
"closed database"
);
puts
(
"closed database"
);
puts
(
"close args "
+
inspect
(
arguments
));
});
});
});
});
});
});
});
});
});
});
});
}
function
test_close
()
{
db
.
open
(
"mydatabase.db"
,
function
()
{
db
.
close
(
function
()
{
puts
(
"closed database"
);
});
});
}
}
// test_close();
test_simple
();
test_simple
();
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