From 3e451201601ae0970473bba2a2a2949f43f1c8ca Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 12 Aug 2021 13:37:02 +0800 Subject: [PATCH] Fix test --- Makefile | 10 ++-------- dialects/db2.go | 14 ++++++++++++-- .../engine_db2_test.go | 2 +- test_db2.sh | 11 ----------- 4 files changed, 15 insertions(+), 22 deletions(-) rename xorm_db2_test.go => integrations/engine_db2_test.go (91%) delete mode 100755 test_db2.sh diff --git a/Makefile b/Makefile index 04e456fd..c979b05a 100644 --- a/Makefile +++ b/Makefile @@ -162,19 +162,13 @@ $(DB2_DRIVER_DIR): .PNONY: test-db2 test-db2: go-check $(DB2_DRIVER_DIR) - CGO_CFLAGS=-I$(DB2_DRIVER_DIR)/include \ - CGO_LDFLAGS=-L$(DB2_DRIVER_DIR)/lib \ - DYLD_LIBRARY_PATH=$(DYLD_LIBRARY_PATH):$(DB2_DRIVER_DIR)/lib \ - $(GO) test -race -db=go_ibm_db -tags=db2 -cache=$(TEST_CACHE_ENABLE) \ + $(GO) test $(INTEGRATION_PACKAGES) -v -tags=db2 -db=go_ibm_db -cache=$(TEST_CACHE_ENABLE) \ -conn_str="HOSTNAME=$(TEST_DB2_HOST);DATABASE=$(TEST_DB2_DBNAME);PORT=$(TEST_DB2_PORT);UID=$(TEST_DB2_USERNAME);PWD=$(TEST_DB2_PASSWORD)" \ -coverprofile=db2.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-db2\#% test-db2\#%: go-check - CGO_CFLAGS=-I$(DB2_DRIVER_DIR)/include \ - CGO_LDFLAGS=-L$(DB2_DRIVER_DIR)/lib \ - DYLD_LIBRARY_PATH=$(DYLD_LIBRARY_PATH):$(DB2_DRIVER_DIR)/lib \ - $(GO) test -race -run $* -db=go_ibm_db -tags=db2 -cache=$(TEST_CACHE_ENABLE) \ + $(GO) test $(INTEGRATION_PACKAGES) -v -run $* -db=go_ibm_db -tags=db2 -cache=$(TEST_CACHE_ENABLE) \ -conn_str="HOSTNAME=$(TEST_DB2_HOST);DATABASE=$(TEST_DB2_DBNAME);PORT=$(TEST_DB2_PORT);UID=$(TEST_DB2_USERNAME);PWD=$(TEST_DB2_PASSWORD)" \ -coverprofile=db2.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic diff --git a/dialects/db2.go b/dialects/db2.go index 7b420e51..0a106d06 100644 --- a/dialects/db2.go +++ b/dialects/db2.go @@ -57,6 +57,10 @@ func (db *db2) SQLType(c *schemas.Column) string { case schemas.TinyInt: res = schemas.SmallInt return res + case schemas.UnsignedBigInt: + res = schemas.BigInt + case schemas.UnsignedInt: + res = schemas.BigInt case schemas.Bit: res = schemas.Boolean return res @@ -180,9 +184,9 @@ func (db *db2) SetQuotePolicy(quotePolicy QuotePolicy) { func (db *db2) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) { if len(db.uri.Schema) == 0 { - return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE tablename = ?`, tableName) + return db.HasRecords(queryer, ctx, `SELECT tabname FROM syscat.tables WHERE tabname = ?`, tableName) } - return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE schemaname = ? AND tablename = ?`, + return db.HasRecords(queryer, ctx, `SELECT tabname FROM syscat.tables WHERE tabschema = ? AND tabname = ?`, db.uri.Schema, tableName, ) } @@ -196,6 +200,12 @@ func (db *db2) ModifyColumnSQL(tableName string, col *schemas.Column) string { db.uri.Schema, tableName, col.Name, db.SQLType(col)) } +// DropTableSQL returns drop table SQL +func (db *db2) DropTableSQL(tableName string) (string, bool) { + quote := db.Quoter().Quote + return fmt.Sprintf("DROP TABLE %s", quote(tableName)), false +} + func (db *db2) DropIndexSQL(tableName string, index *schemas.Index) string { quote := db.Quoter().Quote idxName := index.Name diff --git a/xorm_db2_test.go b/integrations/engine_db2_test.go similarity index 91% rename from xorm_db2_test.go rename to integrations/engine_db2_test.go index cb0cea5d..8bbc72f6 100644 --- a/xorm_db2_test.go +++ b/integrations/engine_db2_test.go @@ -4,7 +4,7 @@ // +build db2 -package xorm +package integrations import ( _ "github.com/ibmdb/go_ibm_db" diff --git a/test_db2.sh b/test_db2.sh deleted file mode 100755 index fee570d0..00000000 --- a/test_db2.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -go get -d github.com/ibmdb/go_ibm_db -export DB2HOME=$GOPATH/src/github.com/ibmdb/go_ibm_db/installer -cur="$PWD" -cd $DB2HOME && go run setup.go -export CGO_CFLAGS=-I$DB2HOME/include -export CGO_LDFLAGS=-L$DB2HOME/lib -export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$DB2HOME/clidriver/lib -cd $cur -go test -db=go_ibm_db -tags=db2 -conn_str="HOSTNAME=localhost;DATABASE=testdb;PORT=50000;UID=db2inst1;PWD=123#2@23" \ No newline at end of file