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
6fa8c5c4
Commit
6fa8c5c4
authored
Nov 21, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raw implementation of an exp/sql driver for SQLite.
parent
e8891f64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
1 deletion
+134
-1
Makefile
Makefile
+2
-1
driver.go
driver.go
+132
-0
No files found.
Makefile
View file @
6fa8c5c4
...
...
@@ -15,6 +15,7 @@ CGOFILES=\
hook.go
GOFILES
=
\
date.go
date.go
\
driver.go
include
$(GOROOT)/src/Make.pkg
driver.go
0 → 100644
View file @
6fa8c5c4
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package sqlite provides access to the SQLite library, version 3.
package
sqlite
import
(
"exp/sql"
"exp/sql/driver"
"io"
)
func
init
()
{
sql
.
Register
(
"sqlite3"
,
&
Driver
{})
}
type
Driver
struct
{
}
type
connImpl
struct
{
c
*
Conn
}
type
stmtImpl
struct
{
s
*
Stmt
}
func
(
d
*
Driver
)
Open
(
name
string
)
(
driver
.
Conn
,
error
)
{
c
,
err
:=
Open
(
name
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
connImpl
{
c
},
nil
}
/*
func (c *connImpl) Exec(query string, args []interface{}) (driver.Result, error) {
if err := c.c.Exec(query, args...); err != nil {
return nil, err
}
return c, nil // FIXME RowAffected/ddlSuccess
}
// TODO How to know that the last Stmt did an INSERT?
func (c *connImpl) LastInsertId() (int64, error) {
return c.c.LastInsertRowid(), nil
}
// TODO How to know that the last Stmt did an DELETE/INSERT/UPDATE?
func (c *connImpl) RowsAffected() (int64, error) {
return int64(c.c.Changes()), nil
}
*/
func
(
c
*
connImpl
)
Prepare
(
query
string
)
(
driver
.
Stmt
,
error
)
{
s
,
err
:=
c
.
c
.
Prepare
(
query
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
stmtImpl
{
s
},
nil
}
func
(
c
*
connImpl
)
Close
()
error
{
return
c
.
c
.
Close
()
// TODO c.c = nil ?
}
func
(
c
*
connImpl
)
Begin
()
(
driver
.
Tx
,
error
)
{
if
err
:=
c
.
c
.
Begin
();
err
!=
nil
{
return
nil
,
err
}
return
c
,
nil
}
func
(
c
*
connImpl
)
Commit
()
error
{
return
c
.
c
.
Commit
()
}
func
(
c
*
connImpl
)
Rollback
()
error
{
return
c
.
c
.
Rollback
()
}
func
(
s
*
stmtImpl
)
Close
()
error
{
return
s
.
s
.
Finalize
()
}
func
(
s
*
stmtImpl
)
NumInput
()
int
{
return
s
.
s
.
BindParameterCount
();
}
func
(
s
*
stmtImpl
)
Exec
(
args
[]
interface
{})
(
driver
.
Result
,
error
)
{
err
:=
s
.
s
.
Exec
(
args
...
)
if
err
!=
nil
{
return
nil
,
err
}
return
s
,
nil
// FIXME RowAffected/ddlSuccess
}
// TODO How to know that this Stmt did an INSERT?
func
(
s
*
stmtImpl
)
LastInsertId
()
(
int64
,
error
)
{
return
s
.
s
.
c
.
LastInsertRowid
(),
nil
}
// TODO How to know that this Stmt did an DELETE/INSERT/UPDATE?
func
(
s
*
stmtImpl
)
RowsAffected
()
(
int64
,
error
)
{
return
int64
(
s
.
s
.
c
.
Changes
()),
nil
}
func
(
s
*
stmtImpl
)
Query
(
args
[]
interface
{})
(
driver
.
Rows
,
error
)
{
if
err
:=
s
.
s
.
Bind
(
args
...
);
err
!=
nil
{
return
nil
,
err
}
return
s
,
nil
}
// TODO Cache result?
func
(
s
*
stmtImpl
)
Columns
()
[]
string
{
count
:=
s
.
s
.
ColumnCount
()
cols
:=
make
([]
string
,
count
)
for
i
:=
0
;
i
<
count
;
i
++
{
cols
[
i
]
=
s
.
s
.
ColumnName
(
i
)
}
return
cols
}
func
(
s
*
stmtImpl
)
Next
(
dest
[]
interface
{})
error
{
ok
,
err
:=
s
.
s
.
Next
()
if
err
!=
nil
{
return
err
}
if
!
ok
{
return
io
.
EOF
}
return
s
.
s
.
Scan
(
dest
...
)
}
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