// Same as sql.Db.Exec or sql.Tx.Exec depends on if transaction has began
770323
func (q *Qbs) Exec(query string, args ...interface{}) (sql.Result, error) {
	defer q.Reset()
	query = q.Dialect.substituteMarkers(query)
	q.log(query, args...)
	stmt, err := q.prepare(query)
	if err != nil {
		return nil, q.updateTxError(err)
	}
	result, err := stmt.Exec(args...)
	if err != nil {
		return nil, q.updateTxError(err)
	}
	return result, nil
}
160531
func (r *DB) Transaction(callback func() error) (err error) {
	var tries int

	// Perform transaction statements
	tries = 0
	for {
		// Start transaction
		if err = r.Begin(); err != nil {
			return
		}

		if err = callback(); err == nil {
			break
		}

		tries++
		if tries > 3 {
			log.Printf("Retried transaction %d times, aborting", tries-1)
			break
		}

		// Break out if the causer is not a MySQL error
		cause, ok := (errors.Cause(err)).(*mysql.MySQLError)
		if !ok {
			log.Printf("Returned error cause is not a MySQLError, %#v", err)
			break
		}

		// restart transaction:
		//   - 1205: lock within transaction (unit tested),
		//   - 1213: deadlock found
		if cause.Number == 1205 || cause.Number == 1213 {
			log.Printf("Restarting transaction (try=%d): %s", tries, cause)
			r.Rollback()
			time.Sleep(50 * time.Millisecond)
			continue
		}
		log.Println("Can't handle transaction error")
		break
	}

	if err != nil {
		r.Rollback()
		return err
	}
	return r.Commit()
}
614679
func finishTransaction(ctx context.Context, exec sqlexec.SQLExecutor, err error) error {
	if err == nil {
		_, err = exec.Execute(ctx, "commit")
	} else {
		_, err1 := exec.Execute(ctx, "rollback")
		terror.Log(errors.Trace(err1))
	}
	return errors.Trace(err)
}
660459
func (s *Stmt) MustExec(args ...interface{}) sql.Result {
	return MustExec(&qStmt{s}, "", args...)
}
736561
func (r *DB) Exec(query string, args ...interface{}) (res sql.Result, err error) {
	exec := func() (sql.Result, error) {
		if r.Tx != nil {
			return r.Tx.ExecContext(r.ctx, query, args...)
		}
		return r.DB.ExecContext(r.ctx, query, args...)
	}

	r.Log(func() {
		res, err = exec()
	}, query, args...)

	return res, errors.Wrap(err, "exec query failed")
}
1306528
func (tx *Tx) Exec(query interface{}, args ...interface{}) (sql.Result, error) {
	return tx.ExecContext(tx.Context(), query, args...)
}
489229
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
	list := make([]namedValue, len(args))
	for i, v := range args {
		list[i] = namedValue{
			Ordinal: i + 1,
			Value:   v,
		}
	}
	return s.exec(context.Background(), list)
}
1076741
func (db *DB) MustExecute(stmt Executable, args ...interface{}) sql.Result {
	s, params, err := db.compile(stmt)
	if err != nil {
		log.Panicf(
			"aspect: failed to compile (%s): %s",
			stmt,
			err,
		)
	}
	if len(args) == 0 {
		args = params.args
	}
	result, err := db.conn.Exec(s, args...)
	if err != nil {
		log.Panicf(
			"aspect: failed to exec (%s) with parameters (%v): %s",
			s,
			args,
			err,
		)
	}
	return result
}
887053
func (me *Database) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
	me.Trace("EXEC", query, args...)
	return me.Db.ExecContext(ctx, query, args...)
}
819570
func (s *Stmt) Exec(args []driver.Value) (r driver.Result, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("fatalf error: %s", r)
			return
		}
	}()
	defer s.conn.mutex.Unlock()

	if s.query == "" {
		return nil, fmt.Errorf("empty statement")
	}

	var finalQuery string

	// replace $* by arguments in query string
	finalQuery = replaceArguments(s.query, args)
	log.Info("Exec <%s>\n", finalQuery)

	// Send query to server
	err = s.conn.conn.WriteExec(finalQuery)
	if err != nil {
		log.Warning("Exec: Cannot send query to server: %s", err)
		return nil, fmt.Errorf("Cannot send query to server: %s", err)
	}

	// Get answer from server
	lastInsertedID, rowsAffected, err := s.conn.conn.ReadResult()
	if err != nil {
		return nil, err
	}

	// Create a driver.Result
	return newResult(lastInsertedID, rowsAffected), nil
}
1344600
func (m *GenericDriver) Exec(script string) (time.Duration, error) {
	start := time.Now()

	err := transaction(m.DB, func(tx *sql.Tx) error {
		_, err := tx.Exec(script)
		return err
	})

	return time.Since(start), err
}
1303189
func (scope *Scope) Exec() *Scope {
	defer scope.trace(NowFunc())

	if !scope.HasError() {
		if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
			if count, err := result.RowsAffected(); scope.Err(err) == nil {
				scope.db.RowsAffected = count
			}
		}
	}
	return scope
}
1252360
func (tx *Tx) Exec(query string, args ...interface{}) (Result, error) {
	dc, err := tx.grabConn()
	if err != nil {
		return nil, err
	}

	if execer, ok := dc.ci.(driver.Execer); ok {
		dargs, err := driverArgs(nil, args)
		if err != nil {
			return nil, err
		}
		dc.Lock()
		resi, err := execer.Exec(query, dargs)
		dc.Unlock()
		if err == nil {
			return driverResult{dc, resi}, nil
		}
		if err != driver.ErrSkip {
			return nil, err
		}
	}

	dc.Lock()
	si, err := dc.ci.Prepare(query)
	dc.Unlock()
	if err != nil {
		return nil, err
	}
	defer withLock(dc, func() { si.Close() })

	return resultFromStatement(driverStmt{dc, si}, args...)
}
537391
func (c *Connection) TransactionActive() bool {
	c.dbMu.RLock()
	defer c.dbMu.RUnlock()
	if c.db == nil {
		return false
	}
	return c.db.TransactionActive()
}
226862
func (q *Queryx) Exec() error {
	if q.err != nil {
		return q.err
	}
	return q.Query.Exec()
}
1147314
func (tx *TX) Execute(stmt Executable, args ...interface{}) (sql.Result, error) {
	s, params, err := tx.compile(stmt)
	if err != nil {
		return nil, err
	}

	// Use any arguments given to Query() over compiled arguments
	if len(args) == 0 {
		args = params.args
	}
	return tx.Exec(s, args...)
}
639721
func (db *DB) Exec(query interface{}, args ...interface{}) (sql.Result, error) {
	return db.ExecContext(db.Context(), query, args...)
}