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
3b2d92ba
Commit
3b2d92ba
authored
Dec 07, 2009
by
Eric Fredricksen
Committed by
Eric Fredricksen
Dec 07, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test transaction interface a little
parent
7b2cd3c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
29 deletions
+68
-29
sqlite.js
sqlite.js
+44
-28
sqlite3_bindings.cc
sqlite3_bindings.cc
+16
-1
test.js
test.js
+8
-0
No files found.
sqlite.js
View file @
3b2d92ba
/*
Copyright (c) 2009, Eric Fredricksen <e@fredricksen.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
// TODO: async
var
sys
=
require
(
"sys"
);
var
sys
=
require
(
"sys"
);
var
bindings
=
require
(
"./sqlite3_bindings"
);
var
bindings
=
require
(
"./sqlite3_bindings"
);
process
.
mixin
(
GLOBAL
,
bindings
);
process
.
mixin
(
exports
,
bindings
);
// Conform somewhat to http://dev.w3.org/html5/webdatabase/#sql
exports
.
openDatabaseSync
=
function
(
name
,
version
,
displayName
,
estimatedSize
,
creationCallback
)
{
var
db
=
new
DatabaseSync
(
name
);
if
(
creationCallback
)
creationCallback
(
db
);
return
db
;
}
var
Db
=
bindings
.
Db
;
exports
.
Db
=
Db
;
Db
.
prototype
.
query
=
function
(
sql
,
bindings
,
callback
)
{
// This is an extension of the HTML5 API
DatabaseSync
.
prototype
.
query
=
function
(
sql
,
bindings
,
callback
)
{
// TODO: error callback
if
(
typeof
(
bindings
)
==
"function"
)
{
if
(
typeof
(
bindings
)
==
"function"
)
{
var
tmp
=
bindings
;
var
tmp
=
bindings
;
bindings
=
callback
;
bindings
=
callback
;
...
@@ -18,23 +49,6 @@ Db.prototype.query = function (sql, bindings, callback) {
...
@@ -18,23 +49,6 @@ Db.prototype.query = function (sql, bindings, callback) {
}
}
// Conform to http://dev.w3.org/html5/webdatabase/#sql
var
DatabaseSync
=
Db
;
exports
.
openDatabaseSync
=
function
(
name
,
version
,
displayName
,
estimatedSize
,
creationCallback
)
{
var
db
=
new
DatabaseSync
(
name
);
if
(
creationCallback
)
creationCallback
(
db
);
return
db
;
}
// TODO: slightly differnt args
Db
.
prototype
.
executeSql
=
Db
.
prototype
.
query
;
// TODO: (big) async
// TODO: void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
// TODO: void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
// TODO: void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
// TODO: void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
...
@@ -42,20 +56,22 @@ Db.prototype.executeSql = Db.prototype.query;
...
@@ -42,20 +56,22 @@ Db.prototype.executeSql = Db.prototype.query;
function
SQLTransactionSync
(
db
,
txCallback
,
errCallback
,
successCallback
)
{
function
SQLTransactionSync
(
db
,
txCallback
,
errCallback
,
successCallback
)
{
this
.
database
=
db
;
this
.
database
=
db
;
this
.
executeSql
=
function
(
sqlStatement
,
argumets
)
{
this
.
executeSql
=
function
(
sqlStatement
,
arguments
,
callback
)
{
return
db
.
query
(
sqlStatement
,
arguments
)[
0
];
// TODO: Somehow SQL errors are being eaten
return
db
.
query
(
sqlStatement
,
arguments
,
callback
)[
0
];
}
}
this
.
query
(
"BEGIN TRANSACTION"
);
db
.
query
(
"BEGIN TRANSACTION"
);
txCallback
(
this
);
txCallback
(
this
);
this
.
query
(
"COMMIT"
);
db
.
query
(
"COMMIT"
);
if
(
sucessCallback
)
successCallback
(
this
);
if
(
suc
c
essCallback
)
successCallback
(
this
);
}
}
Db
.
prototype
.
transaction
=
function
(
txCallback
,
errCallback
,
successCallback
)
{
DatabaseSync
.
prototype
.
transaction
=
function
(
txCallback
,
errCallback
,
var
tx
=
new
Transaction
(
this
,
txCallback
,
errCallback
,
successCallback
);
successCallback
)
{
var
tx
=
new
SQLTransactionSync
(
this
,
txCallback
,
errCallback
,
successCallback
);
}
}
// TODO: readTransaction
// TODO: readTransaction
()
sqlite3_bindings.cc
View file @
3b2d92ba
/*
Copyright (c) 2009, Eric Fredricksen <e@fredricksen.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sqlite3.h>
#include <sqlite3.h>
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
...
@@ -22,7 +37,7 @@ public:
...
@@ -22,7 +37,7 @@ public:
NODE_SET_PROTOTYPE_METHOD
(
t
,
"performQuery"
,
PerformQuery
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"performQuery"
,
PerformQuery
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"close"
,
Close
);
NODE_SET_PROTOTYPE_METHOD
(
t
,
"close"
,
Close
);
target
->
Set
(
v8
::
String
::
NewSymbol
(
"D
b
"
),
t
->
GetFunction
());
target
->
Set
(
v8
::
String
::
NewSymbol
(
"D
atabaseSync
"
),
t
->
GetFunction
());
}
}
protected
:
protected
:
...
...
test.js
View file @
3b2d92ba
...
@@ -33,6 +33,14 @@ db.query("SELECT e FROM egg WHERE a = ?", [5], function (rows) {
...
@@ -33,6 +33,14 @@ db.query("SELECT e FROM egg WHERE a = ?", [5], function (rows) {
process
.
assert
(
rows
[
0
].
e
==
"E"
);
process
.
assert
(
rows
[
0
].
e
==
"E"
);
});
});
db
.
transaction
(
function
(
tx
)
{
tx
.
executeSql
(
"CREATE TABLE tex (t,e,x)"
);
tx
.
executeSql
(
"INSERT INTO tex (t,e,x) VALUES (?,?,?)"
,
[
"this"
,
"is"
,
"SQL"
]);
});
db
.
query
(
"CREATE TABLE test (x,y,z)"
,
function
()
{
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) VALUES (?,?)"
,
[
5
,
10
]);
db
.
query
(
"INSERT INTO test (x,y,z) VALUES ($x, $y, $z)"
,
{
$x
:
1
,
$y
:
2
,
$z
:
3
});
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