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
245e67ab
Commit
245e67ab
authored
Jul 06, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some helpers to Conn.
parent
b4ee45b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
sqlite.go
sqlite.go
+52
-0
No files found.
sqlite.go
View file @
245e67ab
...
...
@@ -320,6 +320,58 @@ func (c *Conn) Exec(cmd string, args ...interface{}) error {
return
nil
}
// ExecDml helps executing DML statement:
// (1) it binds the specified args,
// (2) it executes the statement,
// (3) it returns the number of rows that were changed or inserted or deleted.
func
(
c
*
Conn
)
ExecDml
(
cmd
string
,
args
...
interface
{})
(
changes
int
,
err
error
)
{
s
,
err
:=
c
.
Prepare
(
cmd
)
if
err
!=
nil
{
return
-
1
,
err
}
defer
s
.
Finalize
()
return
s
.
ExecDml
(
args
...
)
}
// Insert is like ExecDml but returns the autoincremented rowid.
func
(
c
*
Conn
)
Insert
(
cmd
string
,
args
...
interface
{})
(
rowid
int64
,
err
error
)
{
n
,
err
:=
c
.
ExecDml
(
cmd
,
args
...
)
if
err
!=
nil
{
return
-
1
,
err
}
if
n
==
0
{
// No change => no insert...
return
-
1
,
nil
}
return
c
.
LastInsertRowid
(),
nil
}
// Select helps executing SELECT statement:
// (1) it binds the specified args,
// (2) it steps on the rows returned,
// (3) it delegates scanning to a callback function.
// The callback function is invoked for each result row coming out of the statement.
func
(
c
*
Conn
)
Select
(
query
string
,
rowCallbackHandler
func
(
s
*
Stmt
)
error
,
args
...
interface
{})
error
{
s
,
err
:=
c
.
Prepare
(
query
)
if
err
!=
nil
{
return
err
}
defer
s
.
Finalize
()
return
s
.
Select
(
rowCallbackHandler
,
args
...
)
}
// SelectById helps executing SELECT statement that is expected to return only one row.
// Args are for scanning (not binding).
// Returns false if there is no matching row.
// No check is done to ensure that no more than one row is returned by the statement.
func
(
c
*
Conn
)
SelectById
(
query
string
,
id
interface
{},
args
...
interface
{})
(
found
bool
,
err
error
)
{
s
,
err
:=
c
.
Prepare
(
query
,
id
)
if
err
!=
nil
{
return
false
,
err
}
defer
s
.
Finalize
()
return
s
.
SelectOneRow
(
args
...
)
}
// Exists returns true if the specified query returns at least one row.
func
(
c
*
Conn
)
Exists
(
query
string
,
args
...
interface
{})
(
bool
,
error
)
{
s
,
err
:=
c
.
Prepare
(
query
,
args
...
)
...
...
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