本文整理汇总了Golang中github.com/xormplus/core.Column.DefaultIsEmpty方法的典型用法代码示例。如果您正苦于以下问题:Golang Column.DefaultIsEmpty方法的具体用法?Golang Column.DefaultIsEmpty怎么用?Golang Column.DefaultIsEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xormplus/core.Column
的用法示例。
在下文中一共展示了Column.DefaultIsEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetColumns
func (db *oracle) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
args := []interface{}{tableName}
s := "SELECT column_name,data_default,data_type,data_length,data_precision,data_scale," +
"nullable FROM USER_TAB_COLUMNS WHERE table_name = :1"
db.LogSQL(s, args)
rows, err := db.DB().Query(s, args...)
if err != nil {
return nil, nil, err
}
defer rows.Close()
cols := make(map[string]*core.Column)
colSeq := make([]string, 0)
for rows.Next() {
col := new(core.Column)
col.Indexes = make(map[string]int)
var colName, colDefault, nullable, dataType, dataPrecision, dataScale *string
var dataLen int
err = rows.Scan(&colName, &colDefault, &dataType, &dataLen, &dataPrecision,
&dataScale, &nullable)
if err != nil {
return nil, nil, err
}
col.Name = strings.Trim(*colName, `" `)
if colDefault != nil {
col.Default = *colDefault
col.DefaultIsEmpty = false
}
if *nullable == "Y" {
col.Nullable = true
} else {
col.Nullable = false
}
var ignore bool
var dt string
var len1, len2 int
dts := strings.Split(*dataType, "(")
dt = dts[0]
if len(dts) > 1 {
lens := strings.Split(dts[1][:len(dts[1])-1], ",")
if len(lens) > 1 {
len1, _ = strconv.Atoi(lens[0])
len2, _ = strconv.Atoi(lens[1])
} else {
len1, _ = strconv.Atoi(lens[0])
}
}
switch dt {
case "VARCHAR2":
col.SQLType = core.SQLType{core.Varchar, len1, len2}
case "NVARCHAR2":
col.SQLType = core.SQLType{core.NVarchar, len1, len2}
case "TIMESTAMP WITH TIME ZONE":
col.SQLType = core.SQLType{core.TimeStampz, 0, 0}
case "NUMBER":
col.SQLType = core.SQLType{core.Double, len1, len2}
case "LONG", "LONG RAW":
col.SQLType = core.SQLType{core.Text, 0, 0}
case "RAW":
col.SQLType = core.SQLType{core.Binary, 0, 0}
case "ROWID":
col.SQLType = core.SQLType{core.Varchar, 18, 0}
case "AQ$_SUBSCRIBERS":
ignore = true
default:
col.SQLType = core.SQLType{strings.ToUpper(dt), len1, len2}
}
if ignore {
continue
}
if _, ok := core.SqlTypes[col.SQLType.Name]; !ok {
return nil, nil, errors.New(fmt.Sprintf("unkonw colType %v %v", *dataType, col.SQLType))
}
col.Length = dataLen
if col.SQLType.IsText() || col.SQLType.IsTime() {
if !col.DefaultIsEmpty {
col.Default = "'" + col.Default + "'"
}
}
cols[col.Name] = col
colSeq = append(colSeq, col.Name)
}
return colSeq, cols, nil
}