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
c1750896
Commit
c1750896
authored
Oct 16, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some examples.
parent
a0fbf99b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
1 deletion
+64
-1
example_test.go
example_test.go
+64
-1
No files found.
example_test.go
View file @
c1750896
...
...
@@ -9,8 +9,71 @@ import (
func
ExampleOpen
()
{
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
if
err
!=
nil
{
// ...
panic
(
err
)
}
defer
db
.
Close
()
fmt
.
Printf
(
"%d
\n
"
,
db
.
TotalChanges
())
}
// <nil>
func
ExampleExec
()
{
db
,
_
:=
sqlite
.
Open
(
":memory:"
)
defer
db
.
Close
()
err
:=
db
.
Exec
(
"CREATE TABLE test(id INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL)"
)
fmt
.
Println
(
err
)
}
// true <nil>
func
ExamplePrepare
()
{
db
,
_
:=
sqlite
.
Open
(
":memory:"
)
defer
db
.
Close
()
stmt
,
err
:=
db
.
Prepare
(
"SELECT 1 where 1 = ?"
,
1
)
if
err
!=
nil
{
panic
(
err
)
}
defer
stmt
.
Finalize
()
fmt
.
Println
(
stmt
.
Next
())
}
// OK
func
ExampleNext
()
{
db
,
_
:=
sqlite
.
Open
(
":memory:"
)
defer
db
.
Close
()
stmt
,
err
:=
db
.
Prepare
(
"SELECT 1, 'test'"
)
defer
stmt
.
Finalize
()
var
ok
bool
for
ok
,
err
=
stmt
.
Next
();
ok
;
ok
,
err
=
stmt
.
Next
()
{
fmt
.
Println
(
"OK"
)
}
if
err
!=
nil
{
panic
(
err
)
}
}
// 1 test
func
ExampleScan
()
{
db
,
_
:=
sqlite
.
Open
(
":memory:"
)
defer
db
.
Close
()
stmt
,
_
:=
db
.
Prepare
(
"SELECT 1, 'test'"
)
defer
stmt
.
Finalize
()
var
id
int
var
name
string
for
sqlite
.
Must
(
stmt
.
Next
())
{
stmt
.
Scan
(
&
id
,
&
name
)
fmt
.
Println
(
id
,
name
)
}
}
// 1 test
func
ExampleNamedScan
()
{
db
,
_
:=
sqlite
.
Open
(
":memory:"
)
defer
db
.
Close
()
stmt
,
_
:=
db
.
Prepare
(
"SELECT 1 as id, 'test' as name"
)
defer
stmt
.
Finalize
()
var
id
int
var
name
string
for
sqlite
.
Must
(
stmt
.
Next
())
{
stmt
.
NamedScan
(
"name"
,
&
name
,
"id"
,
&
id
)
fmt
.
Println
(
id
,
name
)
}
}
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