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
a9cc58e0
Commit
a9cc58e0
authored
Mar 19, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a check to ensure we don't step after a prepare if there are placeholders/bindings
parent
11883bc0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
38 deletions
+43
-38
speedtest.js
speedtest.js
+20
-20
sqlite.js
sqlite.js
+10
-11
sqlite3_bindings.cc
sqlite3_bindings.cc
+13
-7
No files found.
speedtest.js
View file @
a9cc58e0
...
...
@@ -17,38 +17,38 @@ function readTest(db, callback) {
if
(
callback
)
callback
(
db
);
}
else
{
// puts("got a row" + inspect(arguments));
rows
++
;
}
});
}
function
writeTest
(
db
,
callback
)
{
var
t0
=
new
Date
;
var
count
=
i
=
100000
;
function
innerFunction
()
{
db
.
query
(
"INSERT INTO t1 VALUES (1)"
,
function
(
row
)
{
if
(
!
i
--
)
{
// end of results
var
dt
=
((
new
Date
)
-
t0
)
/
1000
;
puts
(
"**** "
+
count
+
" insertions in "
+
dt
+
"s ("
+
(
count
/
dt
)
+
"/s)"
);
if
(
callback
)
callback
(
db
);
}
else
{
innerFunction
();
}
});
}
innerFunction
();
function
writeTest
(
db
,
i
,
callback
)
{
db
.
query
(
"INSERT INTO t1 VALUES (1)"
,
function
(
row
)
{
if
(
!
i
--
)
{
// end of results
var
dt
=
((
new
Date
)
-
t0
)
/
1000
;
puts
(
"**** "
+
count
+
" insertions in "
+
dt
+
"s ("
+
(
count
/
dt
)
+
"/s)"
);
if
(
callback
)
callback
(
db
);
}
else
{
writeTest
(
db
,
i
--
,
callback
);
}
});
}
var
count
=
100000
;
var
t0
;
db
.
open
(
":memory:"
,
function
()
{
puts
(
inspect
(
arguments
));
puts
(
"open cb"
);
db
.
query
(
"CREATE TABLE t1 (alpha INTEGER)"
,
function
()
{
puts
(
"create table callback"
+
inspect
(
arguments
));
writeTest
(
db
,
readTest
);
// writeTest(db, readTest);
t0
=
new
Date
;
writeTest
(
db
,
count
,
readTest
);
});
});
sqlite.js
View file @
a9cc58e0
...
...
@@ -57,20 +57,19 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
// Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll just chain them via the event loop
function
_setBindingsByIndex
(
db
,
statement
,
bindings
,
nextCallback
,
rowCallback
,
bindIndex
)
{
statement
,
bindings
,
nextCallback
,
rowCallback
,
bindIndex
)
{
puts
(
"setting bindings"
);
if
(
!
bindings
.
length
)
{
nextCallback
(
db
,
statement
,
rowCallback
);
return
;
}
if
(
!
bindings
.
length
)
{
nextCallback
(
db
,
statement
,
rowCallback
);
return
;
}
bindIndex
=
bindIndex
||
1
;
var
value
=
bindings
.
shift
();
bindIndex
=
bindIndex
||
1
;
var
value
=
bindings
.
shift
();
statement
.
bind
(
bindIndex
,
value
,
function
()
{
_setBindingsByIndex
(
statement
,
bindings
,
nextCallback
,
rowCallback
,
bindIndex
+
1
);
});
statement
.
bind
(
bindIndex
,
value
,
function
()
{
_setBindingsByIndex
(
db
,
statement
,
bindings
,
nextCallback
,
rowCallback
,
bindIndex
+
1
);
});
}
function
_queryDone
(
db
,
statement
)
{
...
...
sqlite3_bindings.cc
View file @
a9cc58e0
...
...
@@ -329,10 +329,8 @@ protected:
Local
<
Value
>
argv
[
2
];
int
argc
=
0
;
bool
err
=
false
;
if
(
req
->
result
!=
SQLITE_OK
)
{
err
=
true
;
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
"Error preparing statement"
));
argc
=
1
;
}
...
...
@@ -383,15 +381,22 @@ protected:
req
->
result
=
rc
;
req
->
int1
=
-
1
;
if
(
rc
==
SQLITE_OK
)
{
// This might be a INSERT statement. Let's try to get the first row.
// This is to optimize out further calls to the thread pool.
// This might be a INSERT statement. Let's try to get the first row.
// This is to optimize out further calls to the thread pool. This is only
// possible in the case where there are no variable placeholders/bindings
// in the SQL.
if
(
rc
==
SQLITE_OK
&&
!
sqlite3_bind_parameter_count
(
prep_req
->
stmt
))
{
// if (rc == SQLITE_OK) {
rc
=
sqlite3_step
(
prep_req
->
stmt
);
req
->
int1
=
rc
;
if
(
rc
==
SQLITE_DONE
)
{
rc
=
sqlite3_finalize
(
prep_req
->
stmt
);
prep_req
->
stmt
=
NULL
;
assert
(
rc
==
SQLITE_OK
);
}
else
{
rc
=
sqlite3_reset
(
prep_req
->
stmt
);
}
}
return
0
;
...
...
@@ -850,7 +855,7 @@ protected:
sqlite3_stmt
*
stmt
=
*
sto
;
int
rc
;
if
(
step_req
->
first_rc
<
0
)
{
if
(
step_req
->
first_rc
!=
-
1
)
{
rc
=
req
->
result
=
step_req
->
first_rc
;
}
else
{
rc
=
req
->
result
=
sqlite3_step
(
stmt
);
...
...
@@ -903,7 +908,8 @@ protected:
}
}
}
else
if
(
SQLITE_DONE
)
{
else
if
(
rc
==
SQLITE_DONE
)
{
// printf("no more results");
// no more results
}
else
{
...
...
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