コード例 #1
0
func (c *Conn) closeDBConn(co *client.SqlConn, rollback bool) {
	// since we have DDL, and when server is not in autoCommit,
	// we do not release the connection and will reuse it later
	if c.isInTransaction() || !c.isAutoCommit() {
		return
	}

	if rollback {
		co.Rollback()
	}

	co.Close()
}
コード例 #2
0
func (c *Conn) handleComStmtPrepare(sqlstmt string) error {
	if c.schema == nil {
		return NewDefaultError(ER_NO_DB_ERROR)
	}

	s := new(Stmt)

	var err error
	s.s, err = sql.Parse(sqlstmt)
	if err != nil {
		return fmt.Errorf(`prepare parse sql "%s" error`, sqlstmt)
	}

	s.sqlstmt = sqlstmt

	var co *client.SqlConn
	co, err = c.schema.node.getMasterConn()
	// TODO tablename for select
	if err != nil {
		return fmt.Errorf("prepare error %s", err)
	}

	if err = co.UseDB(c.schema.db); err != nil {
		co.Close()
		return fmt.Errorf("parepre error %s", err)
	}

	if t, err := co.Prepare(sqlstmt); err != nil {
		co.Close()
		return fmt.Errorf("parepre error %s", err)
	} else {
		s.params = t.ParamNum()
		s.types = make([]byte, 0, s.params*2)
		s.columns = t.ColumnNum()
		s.bid = t.ID()
		s.cstmt = t
	}

	s.id = c.stmtId
	c.stmtId++

	if err = c.writePrepare(s); err != nil {
		return err
	}

	s.ClearParams()

	c.stmts[s.id] = s

	return nil
}