<commit_before>package jet

import (
	"database/sql"
	"fmt"
	"strings"
)

type runner struct {
	db     *sql.DB
	tx     *sql.Tx
	stmt   *sql.Stmt
	qo     queryObject
	conv   ColumnConverter
	expand bool
	txnId  string
	query  string
	args   []interface{}
	errors []error
	logger *Logger
	lru    *lruCache
}

func (r *runner) copy() *runner {
	c := new(runner)
	*c = *r
	return c
}

func (r *runner) prepare(query string) Queryable {
	if r.lru == nil {
		r.lru = newLRUCache(20)
	}
	lruKey := r.txnId + query
	r.stmt = r.lru.get(lruKey)
	r.query = query
	if r.stmt == nil {
		var err error
		r.stmt, err = r.qo.Prepare(query)
		if err != nil {
			r.onErr(err)
			// panic(err)
		} else {
			r.lru.set(lruKey, r.stmt)
		}
	}
	return r
}

func (r *runner) onErr(err error) error {
	if err != nil {
		r.errors = append(r.errors, err)
		r.lru.reset()
	}
	return err
}

func (r *runner) Query(query string, args ...interface{}) Queryable {
	if r.expand {
		query, args = substituteMapAndArrayMarks(query, args...)
	}
	r.args = args
	return r.prepare(query)
}

func (r *runner) Run() error {
	return r.Rows(nil)
}

func (r *runner) Rows(v interface{}, maxRows ...int64) error {
	if len(r.errors) > 0 {
		return r.errors[0]
	}
	// Determine max rows
	var max int64 = -1
	if len(maxRows) > 0 {
		max = maxRows[0]
	}
	if r.Logger() != nil {
		r.logQuery()
	}
	var (
		rows *sql.Rows
		err  error
	)
	if v == nil {
		_, err = r.stmt.Exec(r.args...)
		return r.onErr(err)

	} else {
		rows, err = r.stmt.Query(r.args...)
		if err != nil {
			return r.onErr(err)
		}
		defer rows.Close()<commit_msg>log before prepare to catch erroneous statements<commit_after>package jet

import (
	"database/sql"
	"fmt"
	"strings"
)

type runner struct {
	db     *sql.DB
	tx     *sql.Tx
	stmt   *sql.Stmt
	qo     queryObject
	conv   ColumnConverter
	expand bool
	txnId  string
	query  string
	args   []interface{}
	errors []error
	logger *Logger
	lru    *lruCache
}

func (r *runner) copy() *runner {
	c := new(runner)
	*c = *r
	return c
}

func (r *runner) prepare(query string) Queryable {
	if r.lru == nil {
		r.lru = newLRUCache(20)
	}
	lruKey := r.txnId + query
	r.stmt = r.lru.get(lruKey)
	r.query = query
	if r.Logger() != nil {
		r.logQuery()
	}
	if r.stmt == nil {
		var err error
		r.stmt, err = r.qo.Prepare(query)
		if err != nil {
			r.onErr(err)
			// panic(err)
		} else {
			r.lru.set(lruKey, r.stmt)
		}
	}
	return r
}

func (r *runner) onErr(err error) error {
	if err != nil {
		r.errors = append(r.errors, err)
		r.lru.reset()
	}
	return err
}

func (r *runner) Query(query string, args ...interface{}) Queryable {
	if r.expand {
		query, args = substituteMapAndArrayMarks(query, args...)
	}
	r.args = args
	return r.prepare(query)
}

func (r *runner) Run() error {
	return r.Rows(nil)
}

func (r *runner) Rows(v interface{}, maxRows ...int64) error {
	if len(r.errors) > 0 {
		return r.errors[0]
	}
	// Determine max rows
	var max int64 = -1
	if len(maxRows) > 0 {
		max = maxRows[0]
	}
	var (
		rows *sql.Rows
		err  error
	)
	if v == nil {
		_, err = r.stmt.Exec(r.args...)
		return r.onErr(err)

	} else {
		rows, err = r.stmt.Query(r.args...)
		if err != nil {
			return r.onErr(err)
		}
		defer rows.Close()
{'fraction_non_alphanumeric': 0.15413416536661467, 'fraction_numerical': 0.006864274570982839, 'mean_word_length': 2.6892980437284235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6358754', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1346, 'n_words': 351}