<commit_before>package pgclient

import (
	"database/sql"
	"strconv"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Driver tests", func() {
	var db *sql.DB

	BeforeEach(func() {
		if dbURL != "" {
			var err error
			db, err = sql.Open("transicator", dbURL)
			Expect(err).Should(Succeed())
		}
	})

	AfterEach(func() {
		if db != nil {
			db.Exec("truncate table client_test")
			db.Close()
		}
	})

	It("Basic connect", func() {
		if db == nil {
			return
		}

		err := db.Ping()
		Expect(err).Should(Succeed())
	})

	It("Basic SQL", func() {
		if db == nil {
			return
		}

		result, err := db.Exec("insert into client_test (id) values (1)")
		Expect(err).Should(Succeed())
		Expect(result.RowsAffected()).Should(BeEquivalentTo(1))

		rows, err := db.Query("select id from client_test")
		Expect(err).Should(Succeed())
		cols, err := rows.Columns()
		Expect(err).Should(Succeed())
		Expect(len(cols)).Should(Equal(1))
		Expect(cols[0]).Should(Equal("id"))

		hasNext := rows.Next()
		Expect(hasNext).Should(BeTrue())
		var rowVal int
		err = rows.Scan(&rowVal)
		Expect(err).Should(Succeed())
		Expect(rowVal).Should(Equal(1))
		hasNext = rows.Next()
		Expect(hasNext).Should(BeFalse())
		err = rows.Close()
		Expect(err).Should(Succeed())
	})

	It("Select with args", func() {
		if db == nil {
			return
		}

		_, err := db.Exec(`
			insert into client_test (id, int, double)
			values($1, $2, $3)`, 1, 123, 3.14)
		Expect(err).Should(Succeed())

		rows, err := db.Query(`
			select id, int, double from client_test
			where id = $1`, 1)
		Expect(err).Should(Succeed())
		cols, err := rows.Columns()
		Expect(err).Should(Succeed())
		Expect(len(cols)).Should(Equal(3))
		Expect(cols[0]).Should(Equal("id"))
		Expect(cols[1]).Should(Equal("int"))
		Expect(cols[2]).Should(Equal("double"))

		hasNext := rows.Next()
		Expect(hasNext).Should(BeTrue())
		var id int
		var i int
		var d float64
		err = rows.Scan(&id, &i, &d)
		Expect(err).Should(Succeed())
		Expect(id).Should(Equal(1))
		Expect(i).Should(Equal(123))
		Expect(d).Should(Equal(3.14))
		hasNext = rows.Next()
		Expect(hasNext).Should(BeFalse())
		err = rows.Close()
		Expect(err).Should(Succeed())
	})

	It("Select multiple rows", func() {
		if db == nil {
			return
		}

		stmt, err := db.Prepare(`
		insert into client_test (id, int, double)
		values($1, $2, $3)`)
		Expect(err).Should(Succeed())

		for i := 0; i < 10; i++ {
			_, err = stmt.Exec(i, 123, 3.14)
			Expect(err).Should(Succeed())
		}

		err = stmt.Close()
		Expect(err).Should(Succeed())

		rows, err := db.Query("select id from client_test")
		Expect(err).Should(Succeed())
<commit_msg>Improve PG client test coverage a bit.<commit_after>package pgclient

import (
	"database/sql"
	"strconv"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Driver tests", func() {
	var db *sql.DB

	BeforeEach(func() {
		if dbURL != "" {
			var err error
			db, err = sql.Open("transicator", dbURL)
			Expect(err).Should(Succeed())
		}
	})

	AfterEach(func() {
		if db != nil {
			db.Exec("truncate table client_test")
			db.Close()
		}
	})

	It("Basic connect", func() {
		if db == nil {
			return
		}

		err := db.Ping()
		Expect(err).Should(Succeed())
	})

	It("Basic SQL", func() {
		if db == nil {
			return
		}

		result, err := db.Exec("insert into client_test (id) values (1)")
		Expect(err).Should(Succeed())
		Expect(result.RowsAffected()).Should(BeEquivalentTo(1))

		rows, err := db.Query("select id from client_test")
		Expect(err).Should(Succeed())
		cols, err := rows.Columns()
		Expect(err).Should(Succeed())
		Expect(len(cols)).Should(Equal(1))
		Expect(cols[0]).Should(Equal("id"))

		hasNext := rows.Next()
		Expect(hasNext).Should(BeTrue())
		var rowVal int
		err = rows.Scan(&rowVal)
		Expect(err).Should(Succeed())
		Expect(rowVal).Should(Equal(1))
		hasNext = rows.Next()
		Expect(hasNext).Should(BeFalse())
		err = rows.Close()
		Expect(err).Should(Succeed())
	})

	It("Empty", func() {
		if db == nil {
			return
		}

		_, err := db.Exec("")
		Expect(err).Should(Succeed())

		rows, err := db.Query("")
		Expect(err).Should(Succeed())
		Expect(rows.Next()).Should(BeFalse())
		err = rows.Close()
		Expect(err).Should(Succeed())
	})

	It("Select with args", func() {
		if db == nil {
			return
		}

		_, err := db.Exec(`
			insert into client_test (id, string, int, double)
			values($1, $2, $3, $4)`, 1, nil, 123, 3.14)
		Expect(err).Should(Succeed())

		rows, err := db.Query(`
			select id, string, int, double from client_test
			where id = $1`, 1)
		Expect(err).Should(Succeed())
		cols, err := rows.Columns()
		Expect(err).Should(Succeed())
		Expect(len(cols)).Should(Equal(4))
		Expect(cols[0]).Should(Equal("id"))
		Expect(cols[1]).Should(Equal("string"))
		Expect(cols[2]).Should(Equal("int"))
		Expect(cols[3]).Should(Equal("double"))

		hasNext := rows.Next()
		Expect(hasNext).Should(BeTrue())
		var id int
		var vc string
		var i int
		var d float64
		err = rows.Scan(&id, &vc, &i, &d)
		Expect(err).Should(Succeed())
		Expect(id).Should(Equal(1))
		Expect(vc).Should(BeEmpty())
		Expect(i).Should(Equal(123))
		Expect(d).Should(Equal(3.14))
		hasNext = rows.Next()
		Expect(hasNext).Should(BeFalse())
		err = rows.Close()
		Expect(err).Should(Succeed())
	})

	It("Select multiple rows", func() {
		if db == nil {
			return
		}

		stmt, err := db.Prepare(`
		insert into client_test (id, int, double)
		values($1, $2, $3)`)
		Expect(err).Should(Succeed())

		for i := 0; i < 10; i++ {
			_, err = stmt.Exec(i, 123, 3.14)
			Expect(err).Should(Succeed())
		}

		err = stmt.Close()
		Expect(err).Should(Succeed())

		rows, err := db.Query("select id from client_test")
		Expect(err).Should(Succeed())

{'fraction_non_alphanumeric': 0.19849466129879223, 'fraction_numerical': 0.015053387012077717, 'mean_word_length': 3.8341793570219966, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5735861', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2167, 'n_words': 437}