github.com/team-ide/go-dialect@v1.9.20/dialect/mapping.oracle.go (about)

     1  package dialect
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  func NewMappingOracle() (mapping *SqlMapping) {
     9  	mapping = &SqlMapping{
    10  		dialectType: TypeOracle,
    11  
    12  		OwnerNamePackChar:  "\"",
    13  		TableNamePackChar:  "\"",
    14  		ColumnNamePackChar: "\"",
    15  		SqlValuePackChar:   "'",
    16  		SqlValueEscapeChar: "'",
    17  	}
    18  
    19  	mapping.IndexNameMaxLen = 30
    20  
    21  	appendOracleSql(mapping)
    22  
    23  	mapping.PackPageSql = func(selectSql string, pageSize int, pageNo int) (pageSql string) {
    24  		pageSql = `SELECT * FROM(SELECT ROWNUM rn,t.* FROM(` + selectSql + `) t WHERE ROWNUM <=` + strconv.Itoa(pageSize*pageNo) + ")"
    25  		pageSql += `WHERE rn>=` + strconv.Itoa(pageSize*(pageNo-1)+1)
    26  		return
    27  	}
    28  	mapping.ReplaceSqlVariable = func(sqlInfo string, args []interface{}) (variableSql string) {
    29  		strList := strings.Split(sqlInfo, "?")
    30  		if len(strList) < 1 {
    31  			variableSql = sqlInfo
    32  			return
    33  		}
    34  		variableSql = strList[0]
    35  		for i := 1; i < len(strList); i++ {
    36  			variableSql += ":" + strconv.Itoa(i)
    37  			variableSql += strList[i]
    38  		}
    39  		return
    40  	}
    41  
    42  	for _, one := range oracleColumnTypeList {
    43  		mapping.AddColumnTypeInfo(one)
    44  	}
    45  
    46  	for _, one := range oracleIndexTypeList {
    47  		mapping.AddIndexTypeInfo(one)
    48  	}
    49  
    50  	return
    51  }
    52  
    53  var (
    54  	oracleIndexTypeList []*IndexTypeInfo
    55  )
    56  
    57  func appendOracleIndexType(indexType *IndexTypeInfo) {
    58  	oracleIndexTypeList = append(oracleIndexTypeList, indexType)
    59  }
    60  
    61  func init() {
    62  	appendOracleIndexType(&IndexTypeInfo{Name: "", Format: "INDEX",
    63  		NotSupportDataTypes: []string{"CLOB", "BLOB"},
    64  	})
    65  	appendOracleIndexType(&IndexTypeInfo{Name: "INDEX", Format: "INDEX",
    66  		NotSupportDataTypes: []string{"CLOB", "BLOB"},
    67  	})
    68  	appendOracleIndexType(&IndexTypeInfo{Name: "NORMAL", Format: "INDEX",
    69  		NotSupportDataTypes: []string{"CLOB", "BLOB"},
    70  	})
    71  	appendOracleIndexType(&IndexTypeInfo{Name: "UNIQUE", Format: "UNIQUE",
    72  		NotSupportDataTypes: []string{"CLOB", "BLOB"},
    73  		IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) {
    74  			indexTypeFormat = "UNIQUE INDEX"
    75  			return
    76  		},
    77  	})
    78  	appendOracleIndexType(&IndexTypeInfo{Name: "FULLTEXT", Format: "FULLTEXT", IsExtend: true,
    79  		IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) {
    80  			return
    81  		},
    82  	})
    83  	appendOracleIndexType(&IndexTypeInfo{Name: "SPATIAL", Format: "SPATIAL", IsExtend: true,
    84  		IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) {
    85  			return
    86  		},
    87  	})
    88  }