Merge branch 'master' of github.com:go-xorm/core

This commit is contained in:
Nash Tsai 2014-04-17 20:55:22 +08:00
commit 9d0a49a52c
1 changed files with 27 additions and 4 deletions

View File

@ -27,28 +27,32 @@ type Dialect interface {
Init(*Uri, string, string) error Init(*Uri, string, string) error
URI() *Uri URI() *Uri
DBType() DbType DBType() DbType
SqlType(t *Column) string SqlType(*Column) string
SupportInsertMany() bool
QuoteStr() string QuoteStr() string
AndStr() string AndStr() string
OrStr() string
EqStr() string EqStr() string
RollBackStr() string RollBackStr() string
DropTableSql(tableName string) string
AutoIncrStr() string AutoIncrStr() string
SupportInsertMany() bool
SupportEngine() bool SupportEngine() bool
SupportCharset() bool SupportCharset() bool
IndexOnTable() bool IndexOnTable() bool
ShowCreateNull() bool ShowCreateNull() bool
DropTableSql(tableName string) string
IndexCheckSql(tableName, idxName string) (string, []interface{}) IndexCheckSql(tableName, idxName string) (string, []interface{})
TableCheckSql(tableName string) (string, []interface{}) TableCheckSql(tableName string) (string, []interface{})
ColumnCheckSql(tableName, colName string) (string, []interface{}) ColumnCheckSql(tableName, colName string) (string, []interface{})
CreateTableSql(table *Table, tableName, storeEngine, charset string) string
CreateIndexSql(tableName string, index *Index) string
GetColumns(tableName string) ([]string, map[string]*Column, error) GetColumns(tableName string) ([]string, map[string]*Column, error)
GetTables() ([]*Table, error) GetTables() ([]*Table, error)
GetIndexes(tableName string) (map[string]*Index, error) GetIndexes(tableName string) (map[string]*Index, error)
CreateTableSql(table *Table, tableName, storeEngine, charset string) string
Filters() []Filter Filters() []Filter
DriverName() string DriverName() string
@ -101,6 +105,10 @@ func (b *Base) AndStr() string {
return "AND" return "AND"
} }
func (b *Base) OrStr() string {
return "OR"
}
func (b *Base) EqStr() string { func (b *Base) EqStr() string {
return "=" return "="
} }
@ -113,6 +121,21 @@ func (db *Base) DropTableSql(tableName string) string {
return fmt.Sprintf("DROP TABLE IF EXISTS `%s`", tableName) return fmt.Sprintf("DROP TABLE IF EXISTS `%s`", tableName)
} }
func (db *Base) CreateIndexSql(tableName string, index *Index) string {
quote := db.Quote
var unique string
var idxName string
if index.Type == UniqueType {
unique = " UNIQUE"
idxName = fmt.Sprintf("UQE_%v_%v", tableName, index.Name)
} else {
idxName = fmt.Sprintf("IDX_%v_%v", tableName, index.Name)
}
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v);", unique,
quote(idxName), quote(tableName),
quote(strings.Join(index.Cols, quote(","))))
}
func (b *Base) CreateTableSql(table *Table, tableName, storeEngine, charset string) string { func (b *Base) CreateTableSql(table *Table, tableName, storeEngine, charset string) string {
var sql string var sql string
sql = "CREATE TABLE IF NOT EXISTS " sql = "CREATE TABLE IF NOT EXISTS "