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
c9dd3f26
Commit
c9dd3f26
authored
Jul 23, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change #Prepare method to optionnaly Bind.
parent
efc5245d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
sqlite.go
sqlite.go
+9
-2
sqlite_test.go
sqlite_test.go
+1
-1
No files found.
sqlite.go
View file @
c9dd3f26
...
...
@@ -220,7 +220,7 @@ type Stmt struct {
cols
map
[
string
]
int
// cached columns index by name
}
func
(
c
*
Conn
)
Prepare
(
cmd
string
)
(
*
Stmt
,
os
.
Error
)
{
func
(
c
*
Conn
)
Prepare
(
cmd
string
,
args
...
interface
{}
)
(
*
Stmt
,
os
.
Error
)
{
if
c
==
nil
||
c
.
db
==
nil
{
return
nil
,
os
.
NewError
(
"nil sqlite database"
)
}
...
...
@@ -236,7 +236,14 @@ func (c *Conn) Prepare(cmd string) (*Stmt, os.Error) {
if
tail
!=
nil
&&
C
.
strlen
(
tail
)
>
0
{
t
=
C
.
GoString
(
tail
)
}
return
&
Stmt
{
c
:
c
,
stmt
:
stmt
,
tail
:
t
},
nil
s
:=
&
Stmt
{
c
:
c
,
stmt
:
stmt
,
tail
:
t
}
if
len
(
args
)
>
0
{
err
:=
s
.
Bind
(
args
)
if
err
!=
nil
{
return
s
,
err
}
}
return
s
,
nil
}
// Don't use it with SELECT or anything that returns data.
...
...
sqlite_test.go
View file @
c9dd3f26
...
...
@@ -135,7 +135,7 @@ func TestInsertWithStatement(t *testing.T) {
t
.
Errorf
(
"count should be 1000, but it is %d"
,
i
)
}
rs
,
_
:=
db
.
Prepare
(
"SELECT float_num, int_num, a_string FROM test
ORDER BY int_num LIMIT 2
"
)
rs
,
_
:=
db
.
Prepare
(
"SELECT float_num, int_num, a_string FROM test
where a_string like ? ORDER BY int_num LIMIT 2"
,
"hel%
"
)
columnCount
:=
rs
.
ColumnCount
()
if
columnCount
!=
3
{
t
.
Errorf
(
"column count error: %d <> 3"
,
columnCount
)
...
...
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