Пример #1
0
// Set the value of the variable.
func cursorVarSetValue(v *Variable, pos uint, value interface{}) error {
	x, ok := value.(*Cursor)
	if !ok {
		return fmt.Errorf("requires *Cursor, got %T", value)
	}
	if uint(len(v.cursors)) <= pos {
		return fmt.Errorf("can't set cursor at pos %d in array of %d length",
			pos, len(v.cursors))
	}

	var err error
	v.cursors[pos] = x
	if !x.isOwned {
		if err = x.freeHandle(); err != nil {
			return err
		}
		x.isOwned = true
		if err = x.allocateHandle(); err != nil {
			return err
		}
	}
	C.cursorVarsetHandle(v.getHandle(pos),
		x.handle)

	x.statementType = -1
	return nil
}
Пример #2
0
// cursorVarInitialize Initializes the (cursor) variable.
func cursorVarInitialize(v *Variable, cur *Cursor) error {
	var tempCursor *Cursor
	var err error
	var j int

	v.connection = cur.connection
	v.cursors = make([]*Cursor, v.allocatedElements)
	debug("cursorVarInitialize conn=%x ae=%d typ.Name=%s\n", v.connection, v.allocatedElements, v.typ.Name)
	for i := uint(0); i < v.allocatedElements; i++ {
		tempCursor = v.connection.NewCursor()
		if err = tempCursor.allocateHandle(); err != nil {
			return err
		}
		v.cursors[int(i)] = tempCursor
		j = int(i * v.typ.size)
		C.cursorVarsetHandle(unsafe.Pointer(&v.dataBytes[j]),
			tempCursor.handle)
		debug("set position %d(%d) in dataBytes to %x [%s]", i, j,
			v.dataBytes[j:j+int(v.typ.size)], v.typ.size)
	}

	return nil
}