This commit is contained in:
Lunny Xiao 2021-08-12 09:20:43 +08:00
parent ffaf88ae1a
commit b5665ba1a7
8 changed files with 37 additions and 31 deletions

View File

@ -171,9 +171,9 @@ func (db *Base) DropSequenceSQL(seqName string) (string, error) {
} }
// DropTableSQL returns drop table SQL // DropTableSQL returns drop table SQL
func (db *Base) DropTableSQL(tableName, autoincrCol string) ([]string, bool) { func (db *Base) DropTableSQL(tableName, autoincrCol string) (string, bool) {
quote := db.dialect.Quoter().Quote quote := db.dialect.Quoter().Quote
return []string{fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName))}, true return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName)), true
} }
// HasRecords returns true if the SQL has records returned // HasRecords returns true if the SQL has records returned
@ -333,16 +333,8 @@ func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool)
} }
} }
<<<<<<< HEAD
if !col.DefaultIsEmpty { if !col.DefaultIsEmpty {
<<<<<<< HEAD
if _, err := bd.WriteString(" DEFAULT "); err != nil { if _, err := bd.WriteString(" DEFAULT "); err != nil {
=======
=======
if col.Default != "" {
>>>>>>> 98251fc (Fix test)
if _, err := bd.WriteString("DEFAULT "); err != nil {
>>>>>>> ab9b694 (Fix test)
return "", err return "", err
} }
if col.Default == "" { if col.Default == "" {

View File

@ -421,10 +421,10 @@ func (db *mssql) AutoIncrStr() string {
return "IDENTITY" return "IDENTITY"
} }
func (db *mssql) DropTableSQL(tableName, autoincrCol string) ([]string, bool) { func (db *mssql) DropTableSQL(tableName, autoincrCol string) (string, bool) {
return []string{fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+ return fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+
"object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+ "object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+
"DROP TABLE \"%s\"", tableName, tableName)}, true "DROP TABLE \"%s\"", tableName, tableName), true
} }
func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string { func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {

View File

@ -598,6 +598,14 @@ func (db *oracle) ColumnTypeKind(t string) int {
} }
} }
func (db *oracle) IsSequenceExist(ctx context.Context, queryer core.Queryer, seqName string) (bool, error) {
var cnt int
if err := queryer.QueryRowContext(ctx, "SELECT COUNT(*) FROM user_sequences WHERE sequence_name = :1", seqName).Scan(&cnt); err != nil {
return false, err
}
return cnt > 0, nil
}
func (db *oracle) AutoIncrStr() string { func (db *oracle) AutoIncrStr() string {
return "AUTO_INCREMENT" return "AUTO_INCREMENT"
} }
@ -607,14 +615,8 @@ func (db *oracle) IsReserved(name string) bool {
return ok return ok
} }
func (db *oracle) DropTableSQL(tableName, autoincrCol string) ([]string, bool) { func (db *oracle) DropTableSQL(tableName, autoincrCol string) (string, bool) {
var sqls = []string{ return fmt.Sprintf("DROP TABLE %s", db.quoter.Quote(tableName)), false
fmt.Sprintf("DROP TABLE %s", db.quoter.Quote(tableName)),
}
if autoincrCol != "" {
sqls = append(sqls, fmt.Sprintf("DROP SEQUENCE %s", OracleSeqName(tableName)))
}
return sqls, false
} }
func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error) { func (db *oracle) CreateTableSQL(ctx context.Context, queryer core.Queryer, table *schemas.Table, tableName string) (string, bool, error) {

View File

@ -876,6 +876,12 @@ func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) {
} }
} }
func (db *postgres) Features() *DialectFeatures {
return &DialectFeatures{
AutoincrMode: IncrAutoincrMode,
}
}
func (db *postgres) SQLType(c *schemas.Column) string { func (db *postgres) SQLType(c *schemas.Column) string {
var res string var res string
switch t := c.SQLType.Name; t { switch t := c.SQLType.Name; t {

View File

@ -207,6 +207,12 @@ func (db *sqlite3) SetQuotePolicy(quotePolicy QuotePolicy) {
} }
} }
func (db *sqlite3) Features() *DialectFeatures {
return &DialectFeatures{
AutoincrMode: IncrAutoincrMode,
}
}
func (db *sqlite3) SQLType(c *schemas.Column) string { func (db *sqlite3) SQLType(c *schemas.Column) string {
switch t := c.SQLType.Name; t { switch t := c.SQLType.Name; t {
case schemas.Bool: case schemas.Bool:

View File

@ -168,8 +168,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
} }
} }
if len(table.AutoIncrement) > 0 { if len(table.AutoIncrement) > 0 && statement.dialect.URI().DBType == schemas.POSTGRES {
if statement.dialect.URI().DBType == schemas.POSTGRES {
if _, err := buf.WriteString(" RETURNING "); err != nil { if _, err := buf.WriteString(" RETURNING "); err != nil {
return nil, err return nil, err
} }
@ -177,7 +176,6 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
return nil, err return nil, err
} }
} }
}
return buf, nil return buf, nil
} }

View File

@ -91,7 +91,6 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr interface{}) (int64, e
colMultiPlaces []string colMultiPlaces []string
args []interface{} args []interface{}
cols []*schemas.Column cols []*schemas.Column
insertCnt int
) )
for i := 0; i < size; i++ { for i := 0; i < size; i++ {

View File

@ -174,7 +174,7 @@ func (session *Session) dropTable(beanOrTableName interface{}) error {
} }
} }
sqlStrs, checkIfExist := session.engine.dialect.DropTableSQL(tableName, autoIncrementCol) sqlStr, checkIfExist := session.engine.dialect.DropTableSQL(tableName, autoIncrementCol)
if !checkIfExist { if !checkIfExist {
exist, err := session.engine.dialect.IsTableExist(session.getQueryer(), session.ctx, tableName) exist, err := session.engine.dialect.IsTableExist(session.getQueryer(), session.ctx, tableName)
if err != nil { if err != nil {
@ -189,7 +189,10 @@ func (session *Session) dropTable(beanOrTableName interface{}) error {
if _, err := session.exec(sqlStr); err != nil { if _, err := session.exec(sqlStr); err != nil {
return err return err
} }
<<<<<<< HEAD
=======
>>>>>>> 1805a60 (Fix test)
if session.engine.dialect.Features().AutoincrMode == dialects.IncrAutoincrMode { if session.engine.dialect.Features().AutoincrMode == dialects.IncrAutoincrMode {
return nil return nil
} }