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
85370baf
Commit
85370baf
authored
Mar 05, 2017
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NamedValue
parent
96e70462
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
driver.go
driver.go
+1
-1
driver_test.go
driver_test.go
+33
-2
No files found.
driver.go
View file @
85370baf
...
@@ -356,7 +356,7 @@ func (s *Stmt) bindNamedValue(args []driver.NamedValue) error {
...
@@ -356,7 +356,7 @@ func (s *Stmt) bindNamedValue(args []driver.NamedValue) error {
return
err
return
err
}
}
}
else
{
}
else
{
index
,
err
:=
s
.
BindParameterIndex
(
v
.
Name
)
index
,
err
:=
s
.
BindParameterIndex
(
":"
+
v
.
Name
)
// TODO "$" and "@"
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
driver_test.go
View file @
85370baf
...
@@ -23,6 +23,7 @@ const (
...
@@ -23,6 +23,7 @@ const (
"UPDATE test SET name = 'El Barto' WHERE name = 'Bart';"
+
"UPDATE test SET name = 'El Barto' WHERE name = 'Bart';"
+
"DELETE FROM test WHERE name = 'Bart';"
"DELETE FROM test WHERE name = 'Bart';"
insert
=
"INSERT INTO test (name) VALUES (?)"
insert
=
"INSERT INTO test (name) VALUES (?)"
insert_named
=
"INSERT INTO test (name) VALUES (:name)"
query
=
"SELECT * FROM test WHERE name LIKE ?"
query
=
"SELECT * FROM test WHERE name LIKE ?"
)
)
...
@@ -104,6 +105,19 @@ func TestSqlInsert(t *testing.T) {
...
@@ -104,6 +105,19 @@ func TestSqlInsert(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
}
}
func
TestSqlInsertNamed
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
result
,
err
:=
db
.
Exec
(
insert_named
,
sql
.
Named
(
"name"
,
"Bart"
))
checkNoError
(
t
,
err
,
"Error updating data: %s"
)
id
,
err
:=
result
.
LastInsertId
()
checkNoError
(
t
,
err
,
"Error while calling LastInsertId: %s"
)
assert
.
Equal
(
t
,
int64
(
1
),
id
,
"lastInsertId"
)
changes
,
err
:=
result
.
RowsAffected
()
checkNoError
(
t
,
err
,
"Error while calling RowsAffected: %s"
)
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
}
func
TestSqlExecWithIllegalCmd
(
t
*
testing
.
T
)
{
func
TestSqlExecWithIllegalCmd
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
...
@@ -160,6 +174,23 @@ func TestSqlPrepare(t *testing.T) {
...
@@ -160,6 +174,23 @@ func TestSqlPrepare(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
}
}
func
TestSqlPrepareNamed
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
stmt
,
err
:=
db
.
Prepare
(
insert_named
)
checkNoError
(
t
,
err
,
"Error while preparing stmt: %s"
)
defer
checkSqlStmtClose
(
stmt
,
t
)
result
,
err
:=
stmt
.
Exec
(
sql
.
Named
(
"name"
,
"Bart"
))
checkNoError
(
t
,
err
,
"Error while executing stmt: %s"
)
id
,
err
:=
result
.
LastInsertId
()
checkNoError
(
t
,
err
,
"Error while calling LastInsertId: %s"
)
assert
.
Equal
(
t
,
int64
(
3
),
id
,
"lastInsertId"
)
changes
,
err
:=
result
.
RowsAffected
()
checkNoError
(
t
,
err
,
"Error while calling RowsAffected: %s"
)
assert
.
Equal
(
t
,
int64
(
1
),
changes
,
"rowsAffected"
)
}
func
TestRowsWithStmtClosed
(
t
*
testing
.
T
)
{
func
TestRowsWithStmtClosed
(
t
*
testing
.
T
)
{
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
db
:=
sqlCreate
(
ddl
+
dml
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
defer
checkSqlDbClose
(
db
,
t
)
...
...
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