Skip to content

Commit

Permalink
Fix 39 (#41)
Browse files Browse the repository at this point in the history
* fix 39

* update instance_test
  • Loading branch information
tonyyang-svail authored Jun 17, 2019
1 parent f02853a commit e3dc6c9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (*odpsConn) Close() error {

// Implements database/sql/driver.Execer. Notice result is nil
func (conn *odpsConn) Exec(query string, args []driver.Value) (driver.Result, error) {
log.Debug("--------------------------------------------------------------------------------")
log.Debugf("Exec:[%s]", query)
ins, err := conn.wait(query, args)
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gomaxcompute

import (
"database/sql"
"fmt"
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -22,6 +24,18 @@ func TestQuery(t *testing.T) {
}
}

func TestExec(t *testing.T) {
a := assert.New(t)
db, err := sql.Open("maxcompute", cfg4test.FormatDSN())
a.NoError(err)

tn := fmt.Sprintf("unitest%d", rand.Int())
_, err = db.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s(shop_name STRING);", tn))
a.NoError(err)
_, err = db.Exec(fmt.Sprintf("DROP TABLE %s;", tn))
a.NoError(err)
}

func TestQueryBase64(t *testing.T) {
a := assert.New(t)
db, err := sql.Open("maxcompute", cfg4test.FormatDSN())
Expand Down
8 changes: 8 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ func decodeInstanceResult(result []byte) (string, error) {
if err := xml.Unmarshal(result, &ir); err != nil {
return "", err
}

if ir.Result.Format == "text" {
// FIXME(tony): the result non-query statement usually in text format.
// Go's database/sql API only supports lastId and affectedRows.
log.Debug(ir.Result.Content)
return "", nil
}

if ir.Result.Format != "csv" {
return "", errors.WithStack(fmt.Errorf("unsupported format %v", ir.Result.Format))
}
Expand Down
2 changes: 1 addition & 1 deletion instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestDecodeInstanceResult(t *testing.T) {

{
_, err := decodeInstanceResult([]byte(fmt.Sprintf(s, "", "Format=\"text\"", "1,2,3")))
a.Error(err) // unsupported format text
a.NoError(err)
}

{
Expand Down

0 comments on commit e3dc6c9

Please sign in to comment.