<commit_before>package database

import (
	"database/sql"
	"errors"
	"fmt"
	_ "github.com/alexbrainman/odbc"
	"github.com/blackss2/utility/convert"
	"github.com/cznic/ql"
	_ "github.com/denisenkom/go-mssqldb"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/ziutek/mymysql/godrv"
	"runtime"
	"strings"
)

type Database struct {
	inst       *sql.DB
	instQL     *ql.DB
	connString string
	driver     string
}

func (db *Database) Open(driver string, connString string) error {
	db.driver = driver
	db.connString = connString
	runtime.SetFinalizer(db, func(f interface{}) {
		f.(*Database).Close()
	})
	return db.executeOpen()
}

func (db *Database) executeOpen() error {
	var err error
	if db.driver == "ql" {
		if db.connString == "mem" {
			db.instQL, err = ql.OpenMem()
		} else {
			opt := &ql.Options{}
			opt.CanCreate = true
			db.instQL, err = ql.OpenFile(db.connString, opt)
		}
	} else {
		db.inst, err = sql.Open(db.driver, db.connString)
	}
	return err
}

func (db *Database) Close() error {
	var err error

	if db.inst != nil {
		err = db.inst.Close()
	} else if db.instQL != nil {
		err = db.instQL.Close()
	}
	return err
}

type Rows struct {
	inst    *sql.Rows
	qlRows  [][]interface{}
	qlIndex int
	isFirst bool
	isNil   bool
	Cols    []string
}

func (db *Database) prepare(queryStr string, retCount int) (*sql.Stmt, error) {
	stmt, err := db.inst.Prepare(queryStr)<commit_msg>remove temp ql file<commit_after>package database

import (
	"database/sql"
	"errors"
	"fmt"
	_ "github.com/alexbrainman/odbc"
	"github.com/blackss2/utility/convert"
	"github.com/cznic/ql"
	_ "github.com/denisenkom/go-mssqldb"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/ziutek/mymysql/godrv"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

type Database struct {
	inst       *sql.DB
	instQL     *ql.DB
	connString string
	driver     string
}

func (db *Database) Open(driver string, connString string) error {
	db.driver = driver
	db.connString = connString
	runtime.SetFinalizer(db, func(f interface{}) {
		f.(*Database).Close()
	})
	return db.executeOpen()
}

func (db *Database) executeOpen() error {
	var err error
	if db.driver == "ql" {
		if db.connString == "mem" {
			db.instQL, err = ql.OpenMem()
		} else {
			opt := &ql.Options{}
			opt.CanCreate = true

			filepath.Walk("./", func(path string, fi *os.FileInfo, err error) error {
				if !fi.IsDir() {
					if fi.Size() == 0 && len(fi.Name()) == 41 && fi.Name()[0] == "." {
						os.Remove(path)
					}
				}
				return nil
			})

			db.instQL, err = ql.OpenFile(db.connString, opt)
		}
	} else {
		db.inst, err = sql.Open(db.driver, db.connString)
	}
	return err
}

func (db *Database) Close() error {
	var err error

	if db.inst != nil {
		err = db.inst.Close()
	} else if db.instQL != nil {
		err = db.instQL.Close()
	}
	return err
}

type Rows struct {
	inst    *sql.Rows
	qlRows  [][]interface{}
	qlIndex int
	isFirst bool
	isNil   bool
	Cols    []string
}

func (db *Database) prepare(queryStr string, retCount int) (*sql.Stmt, error) {
	stmt, err := db.inst.Prepare(queryStr)
{'fraction_non_alphanumeric': 0.15228093206432555, 'fraction_numerical': 0.001969149983590417, 'mean_word_length': 3.2333333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1834669', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1197, 'n_words': 271}