Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
26e4aa2d
Commit
26e4aa2d
authored
Jun 13, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync driver with Russ Cox impl.
parent
57cd7e0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
driver.go
driver.go
+24
-24
No files found.
driver.go
View file @
26e4aa2d
...
@@ -17,7 +17,7 @@ import (
...
@@ -17,7 +17,7 @@ import (
)
)
func
init
()
{
func
init
()
{
sql
.
Register
(
"sqlite3"
,
&
Driver
{})
sql
.
Register
(
"sqlite3"
,
&
impl
{})
if
os
.
Getenv
(
"SQLITE_LOG"
)
!=
""
{
if
os
.
Getenv
(
"SQLITE_LOG"
)
!=
""
{
ConfigLog
(
func
(
d
interface
{},
err
error
,
msg
string
)
{
ConfigLog
(
func
(
d
interface
{},
err
error
,
msg
string
)
{
log
.
Printf
(
"%s: %s, %s
\n
"
,
d
,
err
,
msg
)
log
.
Printf
(
"%s: %s, %s
\n
"
,
d
,
err
,
msg
)
...
@@ -26,37 +26,37 @@ func init() {
...
@@ -26,37 +26,37 @@ func init() {
ConfigMemStatus
(
false
)
ConfigMemStatus
(
false
)
}
}
//
Driver
is an adapter to database/sql/driver
//
impl
is an adapter to database/sql/driver
type
Driver
struct
{
type
impl
struct
{
}
}
type
conn
Impl
struct
{
type
conn
struct
{
c
*
Conn
c
*
Conn
}
}
type
stmt
Impl
struct
{
type
stmt
struct
{
s
*
Stmt
s
*
Stmt
rowsRef
bool
// true if there is a rowsImpl associated to this statement that has not been closed.
rowsRef
bool
// true if there is a rowsImpl associated to this statement that has not been closed.
pendingClose
bool
pendingClose
bool
}
}
type
rowsImpl
struct
{
type
rowsImpl
struct
{
s
*
stmt
Impl
s
*
stmt
columnNames
[]
string
// cache
columnNames
[]
string
// cache
}
}
// Open opens a new database connection.
// Open opens a new database connection.
// ":memory:" for memory db,
// ":memory:" for memory db,
// "" for temp file db
// "" for temp file db
func
(
d
*
Driver
)
Open
(
name
string
)
(
driver
.
Conn
,
error
)
{
func
(
d
*
impl
)
Open
(
name
string
)
(
driver
.
Conn
,
error
)
{
c
,
err
:=
Open
(
name
,
OpenUri
,
OpenNoMutex
,
OpenReadWrite
,
OpenCreate
)
c
,
err
:=
Open
(
name
,
OpenUri
,
OpenNoMutex
,
OpenReadWrite
,
OpenCreate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
c
.
BusyTimeout
(
time
.
Duration
(
10
)
*
time
.
Second
)
c
.
BusyTimeout
(
time
.
Duration
(
10
)
*
time
.
Second
)
return
&
conn
Impl
{
c
},
nil
return
&
conn
{
c
},
nil
}
}
// PRAGMA schema_version may be used to detect when the database schema is altered
// PRAGMA schema_version may be used to detect when the database schema is altered
func
(
c
*
conn
Impl
)
Exec
(
query
string
,
args
[]
driver
.
Value
)
(
driver
.
Result
,
error
)
{
func
(
c
*
conn
)
Exec
(
query
string
,
args
[]
driver
.
Value
)
(
driver
.
Result
,
error
)
{
// https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices
// https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices
var
iargs
[]
interface
{}
var
iargs
[]
interface
{}
if
len
(
args
)
>
0
{
if
len
(
args
)
>
0
{
...
@@ -72,42 +72,42 @@ func (c *connImpl) Exec(query string, args []driver.Value) (driver.Result, error
...
@@ -72,42 +72,42 @@ func (c *connImpl) Exec(query string, args []driver.Value) (driver.Result, error
}
}
// TODO How to know that the last Stmt has done an INSERT? An authorizer?
// TODO How to know that the last Stmt has done an INSERT? An authorizer?
func
(
c
*
conn
Impl
)
LastInsertId
()
(
int64
,
error
)
{
func
(
c
*
conn
)
LastInsertId
()
(
int64
,
error
)
{
return
c
.
c
.
LastInsertRowid
(),
nil
return
c
.
c
.
LastInsertRowid
(),
nil
}
}
// TODO How to know that the last Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
// TODO How to know that the last Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
func
(
c
*
conn
Impl
)
RowsAffected
()
(
int64
,
error
)
{
func
(
c
*
conn
)
RowsAffected
()
(
int64
,
error
)
{
return
int64
(
c
.
c
.
Changes
()),
nil
return
int64
(
c
.
c
.
Changes
()),
nil
}
}
func
(
c
*
conn
Impl
)
Prepare
(
query
string
)
(
driver
.
Stmt
,
error
)
{
func
(
c
*
conn
)
Prepare
(
query
string
)
(
driver
.
Stmt
,
error
)
{
s
,
err
:=
c
.
c
.
Prepare
(
query
)
s
,
err
:=
c
.
c
.
Prepare
(
query
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
&
stmt
Impl
{
s
:
s
},
nil
return
&
stmt
{
s
:
s
},
nil
}
}
func
(
c
*
conn
Impl
)
Close
()
error
{
func
(
c
*
conn
)
Close
()
error
{
return
c
.
c
.
Close
()
return
c
.
c
.
Close
()
}
}
func
(
c
*
conn
Impl
)
Begin
()
(
driver
.
Tx
,
error
)
{
func
(
c
*
conn
)
Begin
()
(
driver
.
Tx
,
error
)
{
if
err
:=
c
.
c
.
Begin
();
err
!=
nil
{
if
err
:=
c
.
c
.
Begin
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
c
,
nil
return
c
,
nil
}
}
func
(
c
*
conn
Impl
)
Commit
()
error
{
func
(
c
*
conn
)
Commit
()
error
{
return
c
.
c
.
Commit
()
return
c
.
c
.
Commit
()
}
}
func
(
c
*
conn
Impl
)
Rollback
()
error
{
func
(
c
*
conn
)
Rollback
()
error
{
return
c
.
c
.
Rollback
()
return
c
.
c
.
Rollback
()
}
}
func
(
s
*
stmt
Impl
)
Close
()
error
{
func
(
s
*
stmt
)
Close
()
error
{
if
s
.
rowsRef
{
// Currently, it never happens because the sql.Stmt doesn't call driver.Stmt in this case
if
s
.
rowsRef
{
// Currently, it never happens because the sql.Stmt doesn't call driver.Stmt in this case
s
.
pendingClose
=
true
s
.
pendingClose
=
true
return
nil
return
nil
...
@@ -115,11 +115,11 @@ func (s *stmtImpl) Close() error {
...
@@ -115,11 +115,11 @@ func (s *stmtImpl) Close() error {
return
s
.
s
.
Finalize
()
return
s
.
s
.
Finalize
()
}
}
func
(
s
*
stmt
Impl
)
NumInput
()
int
{
func
(
s
*
stmt
)
NumInput
()
int
{
return
s
.
s
.
BindParameterCount
()
return
s
.
s
.
BindParameterCount
()
}
}
func
(
s
*
stmt
Impl
)
Exec
(
args
[]
driver
.
Value
)
(
driver
.
Result
,
error
)
{
func
(
s
*
stmt
)
Exec
(
args
[]
driver
.
Value
)
(
driver
.
Result
,
error
)
{
if
err
:=
s
.
bind
(
args
);
err
!=
nil
{
if
err
:=
s
.
bind
(
args
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -130,16 +130,16 @@ func (s *stmtImpl) Exec(args []driver.Value) (driver.Result, error) {
...
@@ -130,16 +130,16 @@ func (s *stmtImpl) Exec(args []driver.Value) (driver.Result, error) {
}
}
// TODO How to know that this Stmt has done an INSERT? An authorizer?
// TODO How to know that this Stmt has done an INSERT? An authorizer?
func
(
s
*
stmt
Impl
)
LastInsertId
()
(
int64
,
error
)
{
func
(
s
*
stmt
)
LastInsertId
()
(
int64
,
error
)
{
return
s
.
s
.
c
.
LastInsertRowid
(),
nil
return
s
.
s
.
c
.
LastInsertRowid
(),
nil
}
}
// TODO How to know that this Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
// TODO How to know that this Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
func
(
s
*
stmt
Impl
)
RowsAffected
()
(
int64
,
error
)
{
func
(
s
*
stmt
)
RowsAffected
()
(
int64
,
error
)
{
return
int64
(
s
.
s
.
c
.
Changes
()),
nil
return
int64
(
s
.
s
.
c
.
Changes
()),
nil
}
}
func
(
s
*
stmt
Impl
)
Query
(
args
[]
driver
.
Value
)
(
driver
.
Rows
,
error
)
{
func
(
s
*
stmt
)
Query
(
args
[]
driver
.
Value
)
(
driver
.
Rows
,
error
)
{
if
s
.
rowsRef
{
if
s
.
rowsRef
{
return
nil
,
errors
.
New
(
"Previously returned Rows still not closed"
)
return
nil
,
errors
.
New
(
"Previously returned Rows still not closed"
)
}
}
...
@@ -150,7 +150,7 @@ func (s *stmtImpl) Query(args []driver.Value) (driver.Rows, error) {
...
@@ -150,7 +150,7 @@ func (s *stmtImpl) Query(args []driver.Value) (driver.Rows, error) {
return
&
rowsImpl
{
s
,
nil
},
nil
return
&
rowsImpl
{
s
,
nil
},
nil
}
}
func
(
s
*
stmt
Impl
)
bind
(
args
[]
driver
.
Value
)
error
{
func
(
s
*
stmt
)
bind
(
args
[]
driver
.
Value
)
error
{
for
i
,
v
:=
range
args
{
for
i
,
v
:=
range
args
{
if
err
:=
s
.
s
.
BindByIndex
(
i
+
1
,
v
);
err
!=
nil
{
if
err
:=
s
.
s
.
BindByIndex
(
i
+
1
,
v
);
err
!=
nil
{
return
err
return
err
...
...
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