<commit_before>package mysql

// driver specific test. general database/sql tests are in ./sqltest.

import (
	"./sqltest"
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"testing"
	"time"
)

const (
	dsn1 = "mysql://gopher1@localhost"
	dsn2 = "mysql://gopher2:secret@localhost:3306/test"
	dsn3 = "mysqls://gopher1@localhost?ssl-insecure-skip-verify"
)

func TestTypes(t *testing.T) {
	db, err := sql.Open("mysql", dsn2)
	if err != nil {
		t.Fatal(err)
	}
	defer db.Close()

	var blob_size = 16 * 1024 * 1024
	var max_allowed_packet int

	if err := db.QueryRow("select @@max_allowed_packet").Scan(&max_allowed_packet); err != nil {
		t.Fatal(err)
	}
	if max_allowed_packet < blob_size {
		t.Error("max_allowed_packet=16M is needed in my.cnf to test blobs fully")
		blob_size = max_allowed_packet
	}

	var typeTests = []struct {
		def  string
		sval string
		val  interface{}
	}{
		{"varchar(6)", "'abc\000'", "abc\000"},
		{"char(6)", "'abc\000'", "abc\000"},
		{"varchar(6) character set utf8", "'åäöαβγ'", "åäöαβγ"},
		{"tinyint", "127", int8(127)},
		{"smallint", "32767", int16(32767)},
		{"mediumint", "8388607", int32(8388607)},
		{"int", "2147483647", int32(2147483647)},
		{"int unsigned", "4294967295", uint32(4294967295)},
		{"bigint", "9223372036854775807", int64(9223372036854775807)},
		{"float", "0.123456", float32(0.123456)},
		{"double", "0.12345678901234", 0.123456789012345},
		{"decimal(7,6)", "0.123456", float32(0.123456)},
		{"bool", "true", true},
		{"bit(10)", "256", []byte{1, 0}},
		{"timestamp", "'2001-02-03 01:02:03'", time.Date(2001, 2, 3, 1, 2, 3, 0, time.UTC)},
		{"datetime", "'1111-02-03 01:02:03'", time.Date(1111, 2, 3, 1, 2, 3, 0, time.UTC)},
		{"datetime", "'2001-02-03 00:02:03'", time.Date(2001, 2, 3, 1, 2, 3, 0, time.FixedZone("", +3600))},
		{"date", "'2222-02-03'", time.Date(2222, 2, 3, 0, 0, 0, 0, time.UTC)},
		// pending support for time.Duration in database/sql:
		//{"time", "'-100:01:59'", time.Duration(-(100*time.Hour + 1*time.Minute + 59*time.Second))},
		{"enum('a', 'b')", "'b'", "b"},
		{"set('a', 'b')", "'b'", "b"},
		{"binary(5)", "'abc'", []byte{'a', 'b', 'c', 0, 0}},
		{"blob", "'blob'", []byte("blob")},
		{"text", "'text'", "text"},
		{"varchar(8000)", "n/a", strings.Repeat(".", 8000)},
		{"longblob", "n/a", bytes.Repeat([]byte{'.'}, blob_size)},
		{"longtext", "n/a", strings.Repeat(".", blob_size)},
	}

	for _, tt := range typeTests {
		for _, mode := range []string{"string", "arg", "stmt"} {<commit_msg>only compare 14 digits in float64 tests<commit_after>package mysql

// driver specific test. general database/sql tests are in ./sqltest.

import (
	"./sqltest"
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"testing"
	"time"
)

const (
	dsn1 = "mysql://gopher1@localhost"
	dsn2 = "mysql://gopher2:secret@localhost:3306/test"
	dsn3 = "mysqls://gopher1@localhost?ssl-insecure-skip-verify"
)

func TestTypes(t *testing.T) {
	db, err := sql.Open("mysql", dsn2)
	if err != nil {
		t.Fatal(err)
	}
	defer db.Close()

	var blob_size = 16 * 1024 * 1024
	var max_allowed_packet int

	if err := db.QueryRow("select @@max_allowed_packet").Scan(&max_allowed_packet); err != nil {
		t.Fatal(err)
	}
	if max_allowed_packet < blob_size {
		t.Error("max_allowed_packet=16M is needed in my.cnf to test blobs fully")
		blob_size = max_allowed_packet
	}

	var typeTests = []struct {
		def  string
		sval string
		val  interface{}
	}{
		{"varchar(6)", "'abc\000'", "abc\000"},
		{"char(6)", "'abc\000'", "abc\000"},
		{"varchar(6) character set utf8", "'åäöαβγ'", "åäöαβγ"},
		{"tinyint", "127", int8(127)},
		{"smallint", "32767", int16(32767)},
		{"mediumint", "8388607", int32(8388607)},
		{"int", "2147483647", int32(2147483647)},
		{"int unsigned", "4294967295", uint32(4294967295)},
		{"bigint", "9223372036854775807", int64(9223372036854775807)},
		{"float", "0.123456", float32(0.123456)},
		{"double", "0.12345678901234", 0.12345678901234},
		{"decimal(7,6)", "0.123456", float32(0.123456)},
		{"bool", "true", true},
		{"bit(10)", "256", []byte{1, 0}},
		{"timestamp", "'2001-02-03 01:02:03'", time.Date(2001, 2, 3, 1, 2, 3, 0, time.UTC)},
		{"datetime", "'1111-02-03 01:02:03'", time.Date(1111, 2, 3, 1, 2, 3, 0, time.UTC)},
		{"datetime", "'2001-02-03 00:02:03'", time.Date(2001, 2, 3, 1, 2, 3, 0, time.FixedZone("", +3600))},
		{"date", "'2222-02-03'", time.Date(2222, 2, 3, 0, 0, 0, 0, time.UTC)},
		// pending support for time.Duration in database/sql:
		//{"time", "'-100:01:59'", time.Duration(-(100*time.Hour + 1*time.Minute + 59*time.Second))},
		{"enum('a', 'b')", "'b'", "b"},
		{"set('a', 'b')", "'b'", "b"},
		{"binary(5)", "'abc'", []byte{'a', 'b', 'c', 0, 0}},
		{"blob", "'blob'", []byte("blob")},
		{"text", "'text'", "text"},
		{"varchar(8000)", "n/a", strings.Repeat(".", 8000)},
		{"longblob", "n/a", bytes.Repeat([]byte{'.'}, blob_size)},
		{"longtext", "n/a", strings.Repeat(".", blob_size)},
	}

	for _, tt := range typeTests {
		for _, mode := range []string{"string", "arg", "stmt"} {
{'fraction_non_alphanumeric': 0.25085153275896616, 'fraction_numerical': 0.1400520937687838, 'mean_word_length': 4.602693602693603, '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': '3043986', 'n_tokens_mistral': 2555, 'n_tokens_neox': 2063, 'n_words': 452}