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
dd0e118b
Commit
dd0e118b
authored
Feb 21, 2011
by
Konstantin Käfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bind parameters for .prepare()
parent
96208ca5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
12 deletions
+33
-12
sqlite3.js
lib/sqlite3.js
+8
-3
statement.cc
src/statement.cc
+5
-9
prepare.test.js
test/prepare.test.js
+20
-0
prepare.db
test/support/prepare.db
+0
-0
No files found.
lib/sqlite3.js
View file @
dd0e118b
...
@@ -28,10 +28,15 @@ var Statement = sqlite3.Statement;
...
@@ -28,10 +28,15 @@ var Statement = sqlite3.Statement;
Database
.
prototype
.
prepare
=
function
(
sql
)
{
Database
.
prototype
.
prepare
=
function
(
sql
)
{
var
callback
,
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
callback
,
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
if
(
params
.
length
&&
typeof
params
[
params
.
length
-
1
]
=
==
'function'
)
{
if
(
params
.
length
&&
typeof
params
[
params
.
length
-
1
]
!
==
'function'
)
{
callback
=
params
.
pop
(
);
params
.
push
(
undefined
);
}
}
return
new
Statement
(
this
,
sql
,
params
,
callback
);
if
(
params
.
length
>
1
)
{
var
statement
=
new
Statement
(
this
,
sql
);
return
statement
.
bind
.
apply
(
statement
,
params
);
}
else
{
return
new
Statement
(
this
,
sql
,
params
.
pop
());
}
};
};
src/statement.cc
View file @
dd0e118b
...
@@ -93,19 +93,15 @@ Handle<Value> Statement::New(const Arguments& args) {
...
@@ -93,19 +93,15 @@ Handle<Value> Statement::New(const Arguments& args) {
if
(
length
<=
0
||
!
Database
::
HasInstance
(
args
[
0
]))
{
if
(
length
<=
0
||
!
Database
::
HasInstance
(
args
[
0
]))
{
return
ThrowException
(
Exception
::
TypeError
(
return
ThrowException
(
Exception
::
TypeError
(
String
::
New
(
"
First argument must be a Database object
"
)));
String
::
New
(
"
Database object expected
"
)));
}
}
else
if
(
length
<=
1
||
!
args
[
1
]
->
IsString
())
{
else
if
(
length
<=
1
||
!
args
[
1
]
->
IsString
())
{
return
ThrowException
(
Exception
::
TypeError
(
return
ThrowException
(
Exception
::
TypeError
(
String
::
New
(
"S
econd argument must be a SQL query
"
)));
String
::
New
(
"S
QL query expected
"
)));
}
}
else
if
(
length
<=
2
||
!
args
[
2
]
->
IsObject
())
{
else
if
(
length
>
2
&&
!
args
[
2
]
->
IsUndefined
()
&&
!
args
[
2
]
->
IsFunction
())
{
return
ThrowException
(
Exception
::
TypeError
(
return
ThrowException
(
Exception
::
TypeError
(
String
::
New
(
"Third argument must be an array or object of parameters"
)));
String
::
New
(
"Callback expected"
)));
}
else
if
(
length
>
3
&&
!
args
[
3
]
->
IsUndefined
()
&&
!
args
[
3
]
->
IsFunction
())
{
return
ThrowException
(
Exception
::
TypeError
(
String
::
New
(
"Fourth argument must be a function"
)));
}
}
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
[
0
]
->
ToObject
());
Database
*
db
=
ObjectWrap
::
Unwrap
<
Database
>
(
args
[
0
]
->
ToObject
());
...
@@ -115,7 +111,7 @@ Handle<Value> Statement::New(const Arguments& args) {
...
@@ -115,7 +111,7 @@ Handle<Value> Statement::New(const Arguments& args) {
Statement
*
stmt
=
new
Statement
(
db
);
Statement
*
stmt
=
new
Statement
(
db
);
stmt
->
Wrap
(
args
.
This
());
stmt
->
Wrap
(
args
.
This
());
PrepareBaton
*
baton
=
new
PrepareBaton
(
db
,
Local
<
Function
>::
Cast
(
args
[
3
]),
stmt
);
PrepareBaton
*
baton
=
new
PrepareBaton
(
db
,
Local
<
Function
>::
Cast
(
args
[
2
]),
stmt
);
baton
->
sql
=
std
::
string
(
*
String
::
Utf8Value
(
sql
));
baton
->
sql
=
std
::
string
(
*
String
::
Utf8Value
(
sql
));
db
->
Schedule
(
EIO_BeginPrepare
,
baton
,
false
);
db
->
Schedule
(
EIO_BeginPrepare
,
baton
,
false
);
...
...
test/prepare.test.js
View file @
dd0e118b
...
@@ -159,3 +159,23 @@ exports['test get() function binding'] = function(beforeExit) {
...
@@ -159,3 +159,23 @@ exports['test get() function binding'] = function(beforeExit) {
assert
.
equal
(
10
,
retrieved
,
"Didn't retrieve all rows"
);
assert
.
equal
(
10
,
retrieved
,
"Didn't retrieve all rows"
);
});
});
};
};
exports
[
'test prepare() function binding'
]
=
function
(
beforeExit
)
{
var
db
=
new
sqlite3
.
Database
(
'test/support/prepare.db'
,
sqlite3
.
OPEN_READONLY
);
var
retrieved
=
0
;
db
.
prepare
(
"SELECT txt, num, flt, blb FROM foo WHERE num = ? AND txt = ?"
,
10
,
'String 10'
).
get
(
function
(
err
,
row
)
{
if
(
err
)
throw
err
;
assert
.
equal
(
row
[
0
],
'String 10'
);
assert
.
equal
(
row
[
1
],
10
);
assert
.
equal
(
row
[
2
],
10
*
Math
.
PI
);
assert
.
equal
(
row
[
3
],
null
);
retrieved
++
;
});
beforeExit
(
function
()
{
assert
.
equal
(
1
,
retrieved
,
"Didn't retrieve all rows"
);
});
};
test/support/prepare.db
0 → 100644
View file @
dd0e118b
File added
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