Example #1
0
func getPKValuesFromColumns(columns *Node, pkIndex *schema.Index) (columnNumbers []int) {
	columnNumbers = make([]int, len(pkIndex.Columns))
	for i, _ := range columnNumbers {
		columnNumbers[i] = -1
	}
	for i, column := range columns.Sub {
		index := pkIndex.FindColumn(string(column.Value))
		if index == -1 {
			continue
		}
		columnNumbers[index] = i
	}
	return columnNumbers
}
Example #2
0
func (self *Node) execAnalyzeUpdateExpressions(pkIndex *schema.Index) (pkValues []interface{}, ok bool) {
	for i := 0; i < self.Len(); i++ {
		columnName := string(self.At(i).At(0).Value)
		if index := pkIndex.FindColumn(columnName); index != -1 {
			value := self.At(i).At(1).execAnalyzeValue()
			if value == nil {
				relog.Warning("expression is too complex %v", self.At(i).At(0))
				return nil, false
			}
			if pkValues == nil {
				pkValues = make([]interface{}, len(pkIndex.Columns))
			}
			pkValues[index] = string(value.Value)
		}
	}
	return pkValues, true
}
Example #3
0
func getInsertPKValues(columns *Node, rowList *Node, pkIndex *schema.Index) (pkValues []interface{}) {
	for i := 0; i < rowList.Len(); i++ {
		if columns.Len() != rowList.At(i).At(0).Len() { // NODE_LIST->'('->NODE_LIST
			panic(NewParserError("number of columns does not match number of values"))
		}
	}

	pkValues = make([]interface{}, len(pkIndex.Columns))
	for i := 0; i < columns.Len(); i++ {
		index := pkIndex.FindColumn(string(columns.At(i).Value))
		if index == -1 {
			continue
		}
		if rowList.Len() == 1 { // simple
			node := rowList.At(0).At(0).At(i) // NODE_LIST->'('->NODE_LIST->Value
			value := node.execAnalyzeValue()
			if value == nil {
				relog.Warning("insert is too complex %v", node)
				return nil
			}
			pkValues[index] = string(value.Value)
		} else { // composite
			values := make([]interface{}, rowList.Len())
			for j := 0; j < rowList.Len(); j++ {
				node := rowList.At(j).At(0).At(i) // NODE_LIST->'('->NODE_LIST->Value
				value := node.execAnalyzeValue()
				if value == nil {
					relog.Warning("insert is too complex %v", node)
					return nil
				}
				values[j] = string(value.Value)
			}
			pkValues[index] = values
		}
	}
	return pkValues
}