func RunTestFloatLiterals(t *testing.T, driverName, dataSourceName string) {
	defer leaktest.Check(t)()
	defer copyist.Open(t).Close()
	db, err := sql.Open("copyist_"+driverName, dataSourceName)
	require.NoError(t, err)
	defer db.Close()
	rows, err := db.Query("SELECT 1::float, 1.1::float, 1e20::float")
	require.NoError(t, err)
	rows.Next()
	require.NoError(t, rows.Err())
}
RunTestFloatLiterals tests the generation of float literal values, with and
without fractions and exponents.
package commontest
import (
	"database/sql"
	"flag"
	"io"
	"os"
	"testing"
	"time"
	"github.com/cockroachdb/copyist"
	"github.com/cockroachdb/copyist/drivertest/dockerdb"
	"github.com/fortytw2/leaktest"
	"github.com/jmoiron/sqlx"
	"github.com/stretchr/testify/require"
)
const (
	PostgresDockerArgs = "-p 26888:26257 cockroachdb/cockroach:v20.2.4 start-single-node --insecure"
	PostgresDataSourceName = "postgresql://root@localhost:26888?sslmode=disable"
)
type DataTypes struct {
	Int              int
	Str, Dec, FltArr string
	TimeZ, Time      time.Time
	Bool             bool
	Bytes            []byte
	Flt              float64
	Uuid             []byte
}
const resetScript = `
DROP TABLE IF EXISTS customers;
CREATE TABLE customers (id INT PRIMARY KEY, name TEXT);
INSERT INTO customers VALUES (1, 'Andy'), (2, 'Jay'), (3, 'Darin');
DROP TABLE IF EXISTS datatypes;
`
func RunAllTests(m *testing.M, driverName, dataSourceName, dockerArgs string) {
	flag.Parse()
	copyist.Register(driverName)
	copyist.SetSessionInit(func() {
		db, err := sql.Open(driverName, dataSourceName)
		if err != nil {
			panic(err)
		}
		defer db.Close()
		if _, err := db.Exec(resetScript); err != nil {
			panic(err)
		}
	})
	var closer io.Closer
	if copyist.IsRecording() {
		closer = dockerdb.Start(dockerArgs, driverName, dataSourceName)
	}
	code := m.Run()
	if closer != nil {
		closer.Close()
	}
	os.Exit(code)
}
func RunTestQuery(t *testing.T, driverName, dataSourceName string) {
	defer leaktest.Check(t)()
	defer copyist.Open(t).Close()
	db, err := sql.Open("copyist_"+driverName, dataSourceName)
	require.NoError(t, err)
	defer db.Close()
	t.Run("query", func(t *testing.T) {
		rows, err := db.Query("SELECT name FROM customers WHERE id=$1", 1)
		require.NoError(t, err)
		defer rows.Close()
		for rows.Next() {
			var name string
			require.NoError(t, rows.Scan(&name))
			require.Equal(t, "Andy", name)
		}
		require.NoError(t, rows.Err())
	})
	t.Run("exec", func(t *testing.T) {
		_, err = db.Exec("SELECT $1::int", 1)
		require.NoError(t, err)
	})
	t.Run("exec error", func(t *testing.T) {
		_, err = db.Exec("SELECT * FROM \"bad\t table:name\"", 1)
		require.Error(t, err)
	})
	t.Run("prepare query", func(t *testing.T) {
		stmt, err := db.Prepare("SELECT name FROM customers WHERE id=$1")
		require.NoError(t, err)
		defer stmt.Close()
		rows, err := stmt.Query(1)
		require.NoError(t, err)
		defer rows.Close()
		for rows.Next() {
			var name string
			require.NoError(t, rows.Scan(&name))
			require.Equal(t, "Andy", name)
		}
		require.NoError(t, rows.Err())
	})
	t.Run("prepare exec", func(t *testing.T) {
		stmt, err := db.Prepare("SELECT $1::int")
		require.NoError(t, err)
		defer stmt.Close()
		_, err = stmt.Exec(1)
		require.NoError(t, err)
	})
}
func RunTestMultiStatement(t *testing.T, driverName, dataSourceName string) {
	defer leaktest.Check(t)()
	defer copyist.Open(t).Close()
	db, err := sql.Open("copyist_"+driverName, dataSourceName)
	require.NoError(t, err)
	defer db.Close()
	_, err = db.Exec("SELECT 1; SELECT 2;")
	require.NoError(t, err)
	rows, err := db.Query("SELECT 1; SELECT 2;")
	require.NoError(t, err)
	defer rows.Close()
	for rows.Next() {
		var cnt int
		require.NoError(t, rows.Scan(&cnt))
		require.Equal(t, 1, cnt)
	}
}
func RunTestInsert(t *testing.T, driverName, dataSourceName string) {
	defer leaktest.Check(t)()
	defer copyist.Open(t).Close()
	db, err := sql.Open("copyist_"+driverName, dataSourceName)
	require.NoError(t, err)
	defer db.Close()
	res, err := db.Exec("INSERT INTO customers VALUES ($1, $2)", 4, "Joel")
	require.NoError(t, err)
	affected, err := res.RowsAffected()
	require.NoError(t, err)
	require.Equal(t, int64(1), affected)
	rows, err := db.Query("SELECT COUNT(*) FROM customers")
	require.NoError(t, err)
	defer rows.Close()
	for rows.Next() {
		var cnt int
		require.NoError(t, rows.Scan(&cnt))
		require.Equal(t, 4, cnt)
	}
	require.NoError(t, rows.Err())
}
func RunTestDataTypes(t *testing.T, driverName, dataSourceName string) {
	defer leaktest.Check(t)()
	defer copyist.Open(t).Close()
	db, err := sql.Open("copyist_"+driverName, dataSourceName)
	require.NoError(t, err)
	defer db.Close()
	res, err := db.Exec(`
		CREATE TABLE datatypes
		(i INT, s TEXT, tz TIMESTAMPTZ, t TIMESTAMP, b BOOL,
		 by BYTES, f FLOAT, d DECIMAL, fa FLOAT[], u UUID)
	`)
	require.NoError(t, err)
	_, err = db.Exec(`
		INSERT INTO datatypes VALUES
			(1, 'foo' || CHR(9) || CHR(10) || ' ,]', '2000-01-01T10:00:00Z', '2000-01-01T10:00:00Z',
			 true, 'ABCD', 1.1, 100.1234, ARRAY(1.1, 1.2345678901234567),
			 '8B78978B-7D8B-489E-8CA9-AC4BDC495A82'),
			(2, '', '2000-02-02T11:11:11-08:00', '2000-02-02T11:11:11-08:00', false,
			 '', -1e10, -0.0, ARRAY(), '00000000-0000-0000-0000-000000000000')
	`)
	require.NoError(t, err)
	affected, err := res.RowsAffected()
	require.NoError(t, err)
	require.Equal(t, int64(0), affected)
	var out DataTypes
	rows, err := db.Query("SELECT i, s, tz, t, b, by, f, d, fa, u FROM datatypes")
	require.NoError(t, err)
	rows.Next()
	require.NoError(t, rows.Scan(
		&out.Int, &out.Str, &out.TimeZ, &out.Time, &out.Bool, &out.Bytes,
		&out.Flt, &out.Dec, &out.FltArr, &out.Uuid))
	require.Equal(t, DataTypes{
		Int: 1, Str: "foo\t\n ,]", TimeZ: parseTime("2000-01-01T10:00:00Z", driverName),
		Time: parseTime("2000-01-01T10:00:00+00:00", driverName), Bool: true,
		Bytes: []byte{'A', 'B', 'C', 'D'}, Flt: 1.1, Dec: "100.1234",
		FltArr: "{1.1,1.2345678901234567}", Uuid: []byte("8b78978b-7d8b-489e-8ca9-ac4bdc495a82"),
	}, out)
	rows.Next()
	require.NoError(t, rows.Scan(
		&out.Int, &out.Str, &out.TimeZ, &out.Time, &out.Bool, &out.Bytes,
		&out.Flt, &out.Dec, &out.FltArr, &out.Uuid))
	require.Equal(t, DataTypes{
		Int: 2, Str: "", TimeZ: parseTime("2000-02-02T19:11:11Z", driverName),
		Time: parseTime("2000-02-02T11:11:11+00:00", driverName), Bool: false,
		Bytes: []byte{}, Flt: -1e10, Dec: "0.0", FltArr: "{}",
		Uuid: []byte("00000000-0000-0000-0000-000000000000"),
	}, out)
	require.NoError(t, rows.Err())
	rows.Close()
}