diff --git a/dialects/dialect.go b/dialects/dialect.go index a336a087..283da150 100644 --- a/dialects/dialect.go +++ b/dialects/dialect.go @@ -171,7 +171,7 @@ func (db *Base) DropSequenceSQL(seqName string) (string, error) { } // DropTableSQL returns drop table SQL -func (db *Base) DropTableSQL(tableName, autoincrCol string) (string, bool) { +func (db *Base) DropTableSQL(tableName string) (string, bool) { quote := db.dialect.Quoter().Quote return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName)), true } diff --git a/dialects/mssql.go b/dialects/mssql.go index 6244ce6d..cd19afb9 100644 --- a/dialects/mssql.go +++ b/dialects/mssql.go @@ -421,7 +421,7 @@ func (db *mssql) AutoIncrStr() string { return "IDENTITY" } -func (db *mssql) DropTableSQL(tableName, autoincrCol string) (string, bool) { +func (db *mssql) DropTableSQL(tableName string) (string, bool) { return fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+ "object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+ "DROP TABLE \"%s\"", tableName, tableName), true diff --git a/dialects/oracle.go b/dialects/oracle.go index 5137f6bd..6c1bdc79 100644 --- a/dialects/oracle.go +++ b/dialects/oracle.go @@ -615,7 +615,7 @@ func (db *oracle) IsReserved(name string) bool { return ok } -func (db *oracle) DropTableSQL(tableName, autoincrCol string) (string, bool) { +func (db *oracle) DropTableSQL(tableName string) (string, bool) { return fmt.Sprintf("DROP TABLE %s", db.quoter.Quote(tableName)), false } diff --git a/dialects/postgres.go b/dialects/postgres.go index 3fe71dcc..e810d803 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -947,12 +947,6 @@ func (db *postgres) SQLType(c *schemas.Column) string { return res } -func (db *postgres) Features() *DialectFeatures { - return &DialectFeatures{ - AutoincrMode: IncrAutoincrMode, - } -} - func (db *postgres) ColumnTypeKind(t string) int { switch strings.ToUpper(t) { case "DATETIME", "TIMESTAMP": diff --git a/dialects/sqlite3.go b/dialects/sqlite3.go index 731b87f1..4ff9a39e 100644 --- a/dialects/sqlite3.go +++ b/dialects/sqlite3.go @@ -207,12 +207,6 @@ func (db *sqlite3) SetQuotePolicy(quotePolicy QuotePolicy) { } } -func (db *sqlite3) Features() *DialectFeatures { - return &DialectFeatures{ - AutoincrMode: IncrAutoincrMode, - } -} - func (db *sqlite3) SQLType(c *schemas.Column) string { switch t := c.SQLType.Name; t { case schemas.Bool: diff --git a/internal/statements/insert.go b/internal/statements/insert.go index 8583b3b8..43d3c69a 100644 --- a/internal/statements/insert.go +++ b/internal/statements/insert.go @@ -100,11 +100,11 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{}) if needSeq { if len(args) > 0 { if _, err := buf.WriteString(","); err != nil { - return "", nil, err + return nil, err } } if _, err := buf.WriteString(utils.SeqName(tableName) + ".nextval"); err != nil { - return "", nil, err + return nil, err } } if len(exprs) > 0 { @@ -112,7 +112,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{}) return nil, err } if err := exprs.WriteArgs(buf); err != nil { - return "", nil, err + return nil, err } } @@ -144,11 +144,11 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{}) if needSeq { if hasInsertColumns { if _, err := buf.WriteString(","); err != nil { - return "", nil, err + return nil, err } } if _, err := buf.WriteString(utils.SeqName(tableName) + ".nextval"); err != nil { - return "", nil, err + return nil, err } } diff --git a/session_insert.go b/session_insert.go index f6846a9d..5ea1dd66 100644 --- a/session_insert.go +++ b/session_insert.go @@ -284,7 +284,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) { if err != nil { return 0, err } - sqlStr = session.engine.dialect.Quoter().Replace(sqlStr) + var sqlStr = session.engine.dialect.Quoter().Replace(buf.String()) handleAfterInsertProcessorFunc := func(bean interface{}) { if session.isAutoCommit { diff --git a/session_schema.go b/session_schema.go index ef0850cb..500e2a0c 100644 --- a/session_schema.go +++ b/session_schema.go @@ -148,14 +148,11 @@ func (session *Session) DropTable(beanOrTableName interface{}) error { } func (session *Session) dropTable(beanOrTableName interface{}) error { - var tableName, autoIncrementCol string + var tableName string switch beanOrTableName.(type) { case *schemas.Table: table := beanOrTableName.(*schemas.Table) tableName = table.Name - if table.AutoIncrColumn() != nil { - autoIncrementCol = table.AutoIncrColumn().Name - } case string: tableName = beanOrTableName.(string) default: @@ -169,12 +166,9 @@ func (session *Session) dropTable(beanOrTableName interface{}) error { } else { tableName = table.Name } - if table.AutoIncrColumn() != nil { - autoIncrementCol = table.AutoIncrColumn().Name - } } - sqlStr, checkIfExist := session.engine.dialect.DropTableSQL(tableName, autoIncrementCol) + sqlStr, checkIfExist := session.engine.dialect.DropTableSQL(tableName) if !checkIfExist { exist, err := session.engine.dialect.IsTableExist(session.getQueryer(), session.ctx, tableName) if err != nil { @@ -189,10 +183,7 @@ func (session *Session) dropTable(beanOrTableName interface{}) error { if _, err := session.exec(sqlStr); err != nil { return err } -<<<<<<< HEAD -======= ->>>>>>> 1805a60 (Fix test) if session.engine.dialect.Features().AutoincrMode == dialects.IncrAutoincrMode { return nil }