本文整理匯總了Golang中github.com/eaciit/cast.ToString函數的典型用法代碼示例。如果您正苦於以下問題:Golang ToString函數的具體用法?Golang ToString怎麽用?Golang ToString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ToString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
if (f.Op == "$and" || f.Op == "$or") && strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
for i, ff := range fs {
bf := ReadVariable(ff, in)
fs[i] = bf
}
f.Value = fs
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
fSlice := f.Value.([]interface{})
// nilai fSlice : [@name1 @name2]
for i := 0; i < len(fSlice); i++ {
// nilai fSlice [i] : @name1
if string(cast.ToString(fSlice[i])[0]) == "@" {
fSlice[i] = in.Get(strings.Replace(cast.ToString(fSlice[i]), "@", "", 1), "")
}
}
f.Value = fSlice
} else if string(cast.ToString(f.Value)[0]) == "@" {
f.Value = in.Get(strings.Replace(cast.ToString(f.Value), "@", "", 1), "")
}
}
return f
}
示例2: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
f.Field = strings.ToLower(f.Field)
if (f.Op == "$and" || f.Op == "$or") &&
strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
/* nilai fs : [0xc082059590 0xc0820595c0]*/
for i, ff := range fs {
/* nilai ff[0] : &{umur $gt @age} && ff[1] : &{name $eq @nama}*/
bf := ReadVariable(ff, in)
/* nilai bf[0] : &{umur $gt 25} && bf[1] : &{name $eq Kane}*/
fs[i] = bf
}
f.Value = fs
return f
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
if strings.Contains(reflect.TypeOf(f.Value).String(), "interface") {
fSlice := f.Value.([]interface{})
/*nilai fSlice : [@name1 @name2]*/
for i := 0; i < len(fSlice); i++ {
/* nilai fSlice [i] : @name1*/
if string(cast.ToString(fSlice[i])[0]) == "@" {
for key, val := range in {
if cast.ToString(fSlice[i]) == key {
fSlice[i] = val
}
}
}
}
f.Value = fSlice
} else if strings.Contains(reflect.TypeOf(f.Value).String(), "string") {
fSlice := f.Value.([]string)
for i := 0; i < len(fSlice); i++ {
if string(fSlice[i][0]) == "@" {
for key, val := range in {
if fSlice[i] == key {
fSlice[i] = val.(string)
}
}
}
}
f.Value = fSlice
}
return f
} else {
if string(cast.ToString(f.Value)[0]) == "@" {
for key, val := range in {
if cast.ToString(f.Value) == key {
f.Value = val
}
}
}
return f
}
}
return f
}
示例3: BuildFilter
func (fb *FilterBuilder) BuildFilter(f *dbox.Filter) (interface{}, error) {
fm := ""
if f.Op == dbox.FilterOpEqual {
fm = fm + f.Field + " = " + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpNoEqual {
fm = fm + f.Field + " <>" + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpGt {
fm = fm + f.Field + " > " + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpGte {
fm = fm + f.Field + " >= " + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpLt {
fm = fm + f.Field + " < " + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpLte {
fm = fm + f.Field + " <= " + StringValue(f.Value, "non")
} else if f.Op == dbox.FilterOpContains {
fm = CombineIn("LIKE ", f)
} else if f.Op == dbox.FilterOpEndWith {
fm = fm + f.Field + " LIKE '%" + cast.ToString(f.Value) + "'"
//fm = CombineIn("START ", f)
} else if f.Op == dbox.FilterOpStartWith {
fm = fm + f.Field + " LIKE '" + cast.ToString(f.Value) + "%'"
//fm = CombineIn("START ", f)
} else if f.Op == dbox.FilterOpIn {
fm = CombineIn("IN", f)
} else if f.Op == dbox.FilterOpNin {
fm = CombineIn("NOT IN", f)
} else if f.Op == dbox.FilterOpOr || f.Op == dbox.FilterOpAnd {
fs := f.Value.([]*dbox.Filter)
for _, ff := range fs {
// nilai ff : &{name $eq Roy}
bf, _ := fb.BuildFilter(ff)
// nilai bf : name = 'Roy'
if fm == "" {
fm = "(" + cast.ToString(bf)
} else {
if f.Op == dbox.FilterOpOr {
fm += " OR " + cast.ToString(bf)
} else {
fm += " AND " + cast.ToString(bf)
}
}
}
fm += ")"
} else {
//return nil, fmt.Errorf("Filter Op %s is not defined", f.Op)
}
return fm, nil
}
示例4: Connect
func (c *Connection) Connect() error {
ci := c.Info()
host := ci.Host
db := ci.Database
username := ci.UserName
pass := ci.Password
path := cast.ToString(ci.Settings["path"])
delimiter := cast.ToString(ci.Settings["delimiter"])
ConnectionString := host + "," + db + "," + username + "," + pass + "," + path + "," + delimiter
e := c.RdbmsConnect("hive", ConnectionString)
if e != nil {
return err.Error(packageName, modConnection, "Connect", e.Error())
}
return nil
}
示例5: execQueryPartUpdate
func (q *Query) execQueryPartUpdate(dt toolkit.M, Cond QueryCondition) error {
if len(dt) == 0 {
return errorlib.Error(packageName, "Query", modQuery, "data to update is not found")
}
writer := q.Connection().(*Connection).writer
reader := q.Connection().(*Connection).reader
tempHeader := []string{}
for _, val := range q.Connection().(*Connection).headerColumn {
tempHeader = append(tempHeader, val.name)
}
for {
foundChange := false
recData := toolkit.M{}
dataTemp, e := reader.Read()
for i, val := range dataTemp {
recData.Set(tempHeader[i], val)
}
if len(Cond.Find) > 0 || (len(Cond.Find) == 0 && toolkit.IdField(dt) == "") {
foundChange = Cond.getCondition(recData)
}
// Check ID IF Condition Not Found
if nameid := toolkit.IdField(dt); nameid != "" && !foundChange {
if recData.Has(nameid) && dt[nameid] == recData[nameid] {
foundChange = true
}
}
if foundChange && len(dataTemp) > 0 {
for n, v := range tempHeader {
if dt.Has(v) {
dataTemp[n] = cast.ToString(dt[v])
}
}
}
if e == io.EOF {
if dataTemp != nil {
writer.Write(dataTemp)
writer.Flush()
}
break
} else if e != nil {
return errorlib.Error(packageName, modQuery, "Update", e.Error())
}
if dataTemp != nil {
writer.Write(dataTemp)
writer.Flush()
}
}
return nil
}
示例6: BuildFilter
func (fb *FilterBuilder) BuildFilter(f *dbox.Filter) (interface{}, error) {
fm := ""
// vals := ""
//drivername := dbox.Connection
// drivername := new(Connection)
//drivername := fb.GetDriver()
// drivername := fb.Connection().(*Connection).Drivername
// fmt.Println("drivernamenya adalah : ", drivername)
if f.Op == dbox.FilterOpEqual {
fm = fm + f.Field + "= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpNoEqual {
fm = fm + f.Field + "<>'" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpGt {
fm = fm + f.Field + " > '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpGte {
fm = fm + f.Field + " >= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpLt {
fm = fm + f.Field + " < '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpLte {
fm = fm + f.Field + " <= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpIn {
fm = CombineIn("IN", f)
} else if f.Op == dbox.FilterOpNin {
fm = CombineIn("NOT IN", f)
} else if f.Op == dbox.FilterOpContains {
fm = CombineIn("NOT IN", f)
} else if f.Op == dbox.FilterOpOr || f.Op == dbox.FilterOpAnd {
// bfs := []interface{}{}
fs := f.Value.([]*dbox.Filter)
for _, ff := range fs {
bf, _ := fb.BuildFilter(ff)
// if eb == nil {
// bfs = append(bfs, bf)
// }
if fm == "" {
fm = cast.ToString(bf)
} else {
if f.Op == dbox.FilterOpOr {
fm = fm + " OR " + cast.ToString(bf)
} else {
fm = fm + " AND " + cast.ToString(bf)
}
}
}
//fm.Set(f.Op, bfs)
} else {
//return nil, fmt.Errorf("Filter Op %s is not defined", f.Op)
}
return fm, nil
}
示例7: ReadVariable
func ReadVariable(f *dbox.Filter, in toolkit.M) *dbox.Filter {
if (f.Op == "$and" || f.Op == "$or") &&
strings.Contains(reflect.TypeOf(f.Value).String(), "dbox.Filter") {
fs := f.Value.([]*dbox.Filter)
// nilai fs : [0xc082059590 0xc0820595c0]
for i, ff := range fs {
// nilai ff[0] : &{umur $gt @age} && ff[1] : &{name $eq @nama}
bf := ReadVariable(ff, in)
// nilai bf[0] : &{umur $gt 25} && bf[1] : &{name $eq Kane}
fs[i] = bf
}
f.Value = fs
return f
} else {
if reflect.TypeOf(f.Value).Kind() == reflect.Slice {
fSlice := f.Value.([]interface{})
// nilai fSlice : [@name1 @name2]
for i := 0; i < len(fSlice); i++ {
// nilai fSlice [i] : @name1
if string(cast.ToString(fSlice[i])[0]) == "@" {
for key, val := range in {
if strings.Replace(cast.ToString(fSlice[i]), "@", "", 1) == key {
fSlice[i] = val
}
}
}
}
f.Value = fSlice
return f
} else {
if string(cast.ToString(f.Value)[0]) == "@" {
for key, val := range in {
if strings.Replace(cast.ToString(f.Value), "@", "", 1) == key {
f.Value = val
}
}
}
return f
}
}
return f
}
示例8: BuildFilter
func (fb *FilterBuilder) BuildFilter(f *dbox.Filter) (interface{}, error) {
fm := ""
if f.Op == dbox.FilterOpEqual {
fm = fm + f.Field + " = " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpNoEqual {
fm = fm + f.Field + " <> " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpGt {
fm = fm + f.Field + " > " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpGte {
fm = fm + f.Field + " >= " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpLt {
fm = fm + f.Field + " < " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpLte {
fm = fm + f.Field + " <= " + rdbms.StringValue(f.Value, "oracle") + ""
} else if f.Op == dbox.FilterOpIn {
fm = CombineIn("IN", f)
} else if f.Op == dbox.FilterOpNin {
fm = CombineIn("NOT IN", f)
} else if f.Op == dbox.FilterOpContains {
fm = CombineIn("NOT IN", f)
} else if f.Op == dbox.FilterOpOr || f.Op == dbox.FilterOpAnd {
// f
fs := f.Value.([]*dbox.Filter)
for _, ff := range fs {
bf, _ := fb.BuildFilter(ff)
if fm == "" {
fm = "(" + cast.ToString(bf)
} else {
if f.Op == dbox.FilterOpOr {
fm += " OR " + cast.ToString(bf)
} else {
fm += " AND " + cast.ToString(bf)
}
}
}
fm += ")"
} else {
//return nil, fmt.Errorf("Filter Op %s is not defined", f.Op)
}
return fm, nil
}
示例9: execQueryPartUpdate
func (q *Query) execQueryPartUpdate(dt toolkit.M) error {
var e error
e = q.startWriteMode()
if e != nil {
return err.Error(packageName, modQuery, "Exec-Update: ", e.Error())
}
writer := q.writer
reader := q.reader
tempHeader := []string{}
for _, val := range q.headerColumn {
tempHeader = append(tempHeader, val.name)
}
var i int = 0
for {
i += 1
dataTemp, e := reader.Read()
if toolkit.HasMember(q.indexes, i) && len(dataTemp) > 0 {
for n, v := range tempHeader {
if dt.Has(v) {
dataTemp[n] = cast.ToString(dt[v])
}
}
}
if e == io.EOF {
if len(dataTemp) > 0 {
writer.Write(dataTemp)
writer.Flush()
}
break
} else if e != nil {
_ = q.endWriteMode()
return err.Error(packageName, modQuery, "Exec-Update:", e.Error())
}
if len(dataTemp) > 0 {
writer.Write(dataTemp)
writer.Flush()
}
}
q.execOpr = true
e = q.endWriteMode()
if e != nil {
return err.Error(packageName, modQuery, "Exec-Update: ", e.Error())
}
return nil
}
示例10: BuildFilter
func (fb *FilterBuilder) BuildFilter(f *dbox.Filter) (interface{}, error) {
fm := ""
// vals := ""
if f.Op == dbox.FilterOpEqual {
fm = fm + f.Field + "= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpNoEqual {
fm = fm + f.Field + "<>'" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpGt {
fm = fm + f.Field + " > '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpGte {
fm = fm + f.Field + " >= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpLt {
fm = fm + f.Field + " < '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpLte {
fm = fm + f.Field + " <= '" + cast.ToString(f.Value) + "'"
} else if f.Op == dbox.FilterOpOr || f.Op == dbox.FilterOpAnd {
// bfs := []interface{}{}
fs := f.Value.([]*dbox.Filter)
for _, ff := range fs {
bf, _ := fb.BuildFilter(ff)
// if eb == nil {
// bfs = append(bfs, bf)
// }
if fm == "" {
fm = cast.ToString(bf)
} else {
if f.Op == dbox.FilterOpOr {
fm = fm + " OR " + cast.ToString(bf)
} else {
fm = fm + " AND " + cast.ToString(bf)
}
}
}
//fm.Set(f.Op, bfs)
} else {
//return nil, fmt.Errorf("Filter Op %s is not defined", f.Op)
}
return fm, nil
}
示例11: execQueryPartInsert
func (q *Query) execQueryPartInsert(dt toolkit.M) error {
var e error
e = q.startWriteMode()
if e != nil {
return err.Error(packageName, modQuery, "Exec-Insert: ", e.Error())
}
if q.newheader {
q.setNewHeader(dt)
}
writer := q.writer
// reader := q.reader
dataTemp := []string{}
for _, v := range q.headerColumn {
if dt.Has(v.name) {
dataTemp = append(dataTemp, cast.ToString(dt[v.name]))
} else {
dataTemp = append(dataTemp, "")
}
}
if len(dataTemp) > 0 {
writer.Write(dataTemp)
writer.Flush()
}
q.execOpr = true
e = q.endWriteMode()
if e != nil {
return err.Error(packageName, modQuery, "Exec-Insert: ", e.Error())
}
return nil
}
示例12: Cursor
func (q *Query) Cursor(in toolkit.M) (dbox.ICursor, error) {
var e error
/*
if q.Parts == nil {
return nil, errorlib.Error(packageName, modQuery,
"Cursor", fmt.Sprintf("No Query Parts"))
}
*/
dbname := q.Connection().Info().Database
cursor := dbox.NewCursor(new(Cursor))
if q.GetDriverDB() == "hive" {
session := q.SessionHive()
cursor.(*Cursor).sessionHive = session
} else {
session := q.Session()
cursor.(*Cursor).session = session
}
cursor.(*Cursor).DateFormat = q.Connection().(*Connection).DateFormat
driverName := q.GetDriverDB()
// driverName = "oracle"
var QueryString string
/*
parts will return E - map{interface{}}interface{}
where each interface{} returned is slice of interfaces --> []interface{}
*/
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
return x.(*dbox.QueryPart).PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
fromParts, hasFrom := parts[dbox.QueryPartFrom]
procedureParts, hasProcedure := parts["procedure"]
freeQueryParts, hasFreeQuery := parts["freequery"]
idMap := toolkit.M{}
if hasFrom {
tablename := ""
tablename = fromParts.([]*dbox.QueryPart)[0].Value.(string)
selectParts, hasSelect := parts[dbox.QueryPartSelect]
var attribute string
incAtt := 0
if hasSelect {
for _, sl := range selectParts.([]*dbox.QueryPart) {
for _, fid := range sl.Value.([]string) {
if incAtt == 0 {
attribute = fid
} else {
attribute = attribute + ", " + fid
}
idMap.Set(fid, fid)
incAtt++
}
}
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasUpdate || hasInsert || hasDelete || hasSave {
return nil, errorlib.Error(packageName, modQuery, "Cursor",
"Valid operation for a cursor is select only")
}
}
aggrParts, hasAggr := parts[dbox.QueryPartAggr]
var aggrExpression string
if hasAggr {
incAtt := 0
// for _, aggr := range aggrParts.([]interface{}) {
for _, aggr := range aggrParts.([]*dbox.QueryPart) {
// qp := aggr.(*dbox.QueryPart)
/* isi qp : &{AGGR {$sum 1 Total Item}}*/
aggrInfo := aggr.Value.(dbox.AggrInfo)
/* isi Aggr Info : {$sum 1 Total Item}*/
if incAtt == 0 {
if driverName == "hive" {
aggrExpression = strings.Replace(aggrInfo.Op, "$", "", 1) + "(" +
cast.ToString(aggrInfo.Field) + ")" + " as " + aggrInfo.Alias
} else {
aggrExpression = strings.Replace(aggrInfo.Op, "$", "", 1) + "(" +
cast.ToString(aggrInfo.Field) + ")" + " as \"" + aggrInfo.Alias + "\""
}
} else {
if driverName == "hive" {
aggrExpression += ", " + strings.Replace(aggrInfo.Op, "$", "", 1) + "(" +
cast.ToString(aggrInfo.Field) + ")" + " as " + aggrInfo.Alias
//.........這裏部分代碼省略.........
示例13: setConfigParam
func (q *Query) setConfigParam() {
ci := q.Connection().(*Connection).Info()
q.newfile = ci.Settings.Get("newfile", false).(bool)
q.isUseHeader = ci.Settings.Get("useheader", false).(bool)
// set header from reader =============== }
dateformat := ci.Settings.Get("dateformat", "").(string)
q.headerColumn = make([]headerstruct, 0, 0)
tdread, e := q.reader.Read()
for i, v := range tdread {
ts := headerstruct{}
ts.name = string(i)
ts.dataType = ""
if q.isUseHeader {
ts.name = v
}
q.headerColumn = append(q.headerColumn, ts)
}
if q.isUseHeader && e == nil {
tdread, e = q.reader.Read()
}
isCheckType := true
ix := 0
for isCheckType && e != io.EOF {
isCheckType = false
for i, v := range tdread {
if v != "" {
matchNumber := false
matchFloat := false
matchDate := false
formatDate := "((^(0[0-9]|[0-9]|(1|2)[0-9]|3[0-1])(\\.|\\/|-)(0[0-9]|[0-9]|1[0-2])(\\.|\\/|-)[\\d]{4}$)|(^[\\d]{4}(\\.|\\/|-)(0[0-9]|[0-9]|1[0-2])(\\.|\\/|-)(0[0-9]|[0-9]|(1|2)[0-9]|3[0-1])$))"
matchDate, _ = regexp.MatchString(formatDate, v)
if !matchDate && dateformat != "" {
d := cast.String2Date(v, dateformat)
if d.Year() > 1 {
matchDate = true
}
}
x := strings.Index(v, ".")
if x > 0 {
matchFloat = true
v = strings.Replace(v, ".", "", 1)
}
matchNumber, _ = regexp.MatchString("^\\d+$", v)
q.headerColumn[i].dataType = "string"
if matchNumber {
q.headerColumn[i].dataType = "int"
if matchFloat {
q.headerColumn[i].dataType = "float"
}
}
if matchDate {
q.headerColumn[i].dataType = "date"
}
}
}
for _, v := range q.headerColumn {
if v.dataType == "" {
isCheckType = true
}
}
if isCheckType {
tdread, e = q.reader.Read()
}
ix++
if ix > 10 {
break
}
}
for _, v := range q.headerColumn {
if v.dataType == "" {
v.dataType = "string"
}
}
_ = q.resetReader()
// ===================== }
if ci.Settings.Has("mapheader") {
smh := ci.Settings["mapheader"].([]toolkit.M)
for i, val := range smh {
ts := headerstruct{}
for name, dt := range val {
ts.name = name
ts.dataType = cast.ToString(dt)
//.........這裏部分代碼省略.........
示例14: execQueryPartInsert
func (q *Query) execQueryPartInsert(dt toolkit.M) error {
if len(dt) == 0 {
return errorlib.Error(packageName, "Query", modQuery, "data to insert is not found")
}
writer := q.Connection().(*Connection).writer
reader := q.Connection().(*Connection).reader
dataTemp := []string{}
if q.Connection().(*Connection).setNewHeader {
q.Connection().(*Connection).SetHeaderToolkitM(dt)
q.Connection().(*Connection).setNewHeader = false
for _, v := range q.Connection().(*Connection).headerColumn {
dataTemp = append(dataTemp, v.name)
}
if len(dataTemp) > 0 {
writer.Write(dataTemp)
writer.Flush()
}
dataTemp = []string{}
}
// Check ID Before Insert
if nameid := toolkit.IdField(dt); nameid != "" {
var colsid int
for i, val := range q.Connection().(*Connection).headerColumn {
if val.name == nameid {
colsid = i
}
}
for {
dataTempSearch, e := reader.Read()
for i, val := range dataTempSearch {
if i == colsid && val == dt[nameid] {
return errorlib.Error(packageName, modQuery, "Insert", "Unique id is found")
}
}
if e == io.EOF {
break
} else if e != nil {
return errorlib.Error(packageName, modQuery, "Insert", e.Error())
}
}
}
for _, v := range q.Connection().(*Connection).headerColumn {
if dt.Has(v.name) {
dataTemp = append(dataTemp, cast.ToString(dt[v.name]))
} else {
dataTemp = append(dataTemp, "")
}
}
if len(dataTemp) > 0 {
writer.Write(dataTemp)
writer.Flush()
}
return nil
}
示例15: insertBulk
func (q *Query) insertBulk(parm toolkit.M) error {
var e error
if parm == nil {
parm = toolkit.M{}
}
driverName := q.GetDriverDB()
// driverName = "oracle"
tablename := ""
data := parm.Get("data")
var attributes string
var dataM toolkit.M
var dataMs []toolkit.M
if toolkit.IsSlice(data) {
e = toolkit.Unjson(toolkit.Jsonify(data), &dataMs)
if e != nil {
return errorlib.Error(packageName, modQuery, "Exec: data extraction", "Data encoding error: "+e.Error())
}
} else {
dataM, e = toolkit.ToM(data)
dataMs = append(dataMs, dataM)
if e != nil {
return errorlib.Error(packageName, modQuery, "Exec: data extraction", "Data encoding error: "+e.Error())
}
}
temp := ""
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
temp = toolkit.JsonString(qp)
return qp.PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
commandType := ""
_, hasInsert := parts[dbox.QueryPartInsert]
if hasInsert {
commandType = dbox.QueryPartInsert
} else {
_, e = q.ExecOut(parm)
return e
// return errorlib.Error(packageName, "Query", modQuery+".InsertBulk", "Invalid Operation")
}
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if !hasFrom {
return errorlib.Error(packageName, "Query", modQuery, "Invalid table name")
}
tablename = fromParts.([]*dbox.QueryPart)[0].Value.(string)
session := q.Session()
attributeList := extractFields(dataMs[0])
var datas []string
for _, dataVal := range dataMs {
var values string
tmp := toolkit.M{}
for _, attr := range attributeList {
tmp.Set(attr, dataVal.Get(attr))
}
values = extractDataBulk(attributeList, tmp, driverName)
// toolkit.Printf("test: \n %v \n------\n %v \n------\n %v \n------\n %v \n", attributeList, dataVal, tmp, values)
datas = append(datas, values)
}
attributes = "(" + strings.Join(attributeList, ",") + ")"
if attributes != "" && nil != datas {
var statement string
if driverName == "hive" {
/*statement = "INSERT INTO " + tablename + " VALUES " + values
e = sessionHive.Exec(statement, nil)*/
return errorlib.Error(packageName, modQuery+".Exec", commandType,
"Not Implemented Yet for HIVE")
} else {
statement = fmt.Sprintf("INSERT INTO "+tablename+" "+attributes+" VALUES %s", strings.Join(datas, ","))
_, e = session.Exec(statement)
}
if e != nil {
return errorlib.Error(packageName, modQuery+".Exec", commandType,
cast.ToString(e.Error()))
//.........這裏部分代碼省略.........