diff --git a/connection.go b/connection.go index 6c7f0d9..5fc94f5 100644 --- a/connection.go +++ b/connection.go @@ -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 diff --git a/connection_test.go b/connection_test.go index 749380e..995e5ef 100644 --- a/connection_test.go +++ b/connection_test.go @@ -2,6 +2,8 @@ package gomaxcompute import ( "database/sql" + "fmt" + "math/rand" "testing" "github.com/stretchr/testify/assert" @@ -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()) diff --git a/instance.go b/instance.go index d239a49..b383c84 100644 --- a/instance.go +++ b/instance.go @@ -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)) } diff --git a/instance_test.go b/instance_test.go index 74c64a7..6af0557 100644 --- a/instance_test.go +++ b/instance_test.go @@ -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) } {