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
e2cdbf1e
Commit
e2cdbf1e
authored
Dec 07, 2009
by
Eric Fredricksen
Committed by
Eric Fredricksen
Dec 07, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better conformance to HTML5 for transaction()
parent
0b8aece4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
sqlite.js
sqlite.js
+4
-2
test.js
test.js
+17
-2
No files found.
sqlite.js
View file @
e2cdbf1e
...
...
@@ -57,8 +57,10 @@ DatabaseSync.prototype.query = function (sql, bindings, callback) {
function
SQLTransactionSync
(
db
,
txCallback
,
errCallback
,
successCallback
)
{
this
.
database
=
db
;
this
.
executeSql
=
function
(
sqlStatement
,
arguments
,
callback
)
{
// TODO: Somehow SQL errors are being eaten
return
db
.
query
(
sqlStatement
,
arguments
,
callback
)[
0
];
var
result
=
db
.
query
(
sqlStatement
,
arguments
,
callback
)[
0
];
result
.
rows
=
{
item
:
function
(
index
)
{
return
result
[
index
];
},
length
:
result
.
length
};
return
result
;
}
db
.
query
(
"BEGIN TRANSACTION"
);
...
...
test.js
View file @
e2cdbf1e
...
...
@@ -6,6 +6,14 @@ var sqlite = require("./sqlite");
posix
.
unlink
(
'test.db'
);
function
asserteq
(
v1
,
v2
)
{
if
(
v1
!=
v2
)
{
sys
.
puts
(
sys
.
inspect
(
v1
));
sys
.
puts
(
sys
.
inspect
(
v2
));
}
process
.
assert
(
v1
==
v2
);
}
var
db
=
sqlite
.
openDatabaseSync
(
'test.db'
);
db
.
query
(
"CREATE TABLE egg (a,y,e)"
);
...
...
@@ -37,13 +45,20 @@ db.query("SELECT e FROM egg WHERE a = ?", [5], function (rows) {
});
db
.
transaction
(
function
(
tx
)
{
tx
.
executeSql
(
"CREATE TABLE tex (t,e,x)"
);
tx
.
executeSql
(
"INSERT INTO tex (t,e,x) VALUES (?,?,?)"
,
[
"this"
,
"is"
,
"SQL"
]);
var
i
=
tx
.
executeSql
(
"INSERT INTO tex (t,e,x) VALUES (?,?,?)"
,
[
"this"
,
"is"
,
"Sparta"
]);
asserteq
(
i
.
rowsAffected
,
1
);
var
s
=
tx
.
executeSql
(
"SELECT * FROM tex"
);
asserteq
(
s
.
rows
.
length
,
1
);
asserteq
(
s
.
rows
.
item
(
0
).
t
,
"this"
);
asserteq
(
s
.
rows
.
item
(
0
).
e
,
"is"
);
asserteq
(
s
.
rows
.
item
(
0
).
x
,
"Sparta"
);
});
db
.
query
(
"CREATE TABLE test (x,y,z)"
,
function
()
{
db
.
query
(
"INSERT INTO test (x,y) VALUES (?,?)"
,
[
5
,
10
]);
db
.
query
(
"INSERT INTO test (x,y,z) VALUES ($x, $y, $z)"
,
{
$x
:
1
,
$y
:
2
,
$z
:
3
});
...
...
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