-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy path55utf8.t
107 lines (78 loc) · 3.1 KB
/
55utf8.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use strict;
use warnings;
use DBI;
use Test::More;
use vars qw($test_dsn $test_user $test_password);
use vars qw($COL_NULLABLE $COL_KEY);
use lib 't', '.';
require 'lib.pl';
my $dbh;
eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0 });};
if ($@) {
plan skip_all => "no database connection";
}
#
# DROP/CREATE PROCEDURE will give syntax error for these versions
#
if ($dbh->{mysql_serverversion} < 50000) {
plan skip_all =>
"SKIP TEST: You must have MySQL version 5.0 and greater for this test to run";
}
# Tested with TiDB v8.5.1.
if ($dbh->{'mysql_serverinfo'} =~ 'TiDB') {
plan skip_all =>
"SKIP TEST: TiDB doesn't support GEOMETRY data type";
}
plan tests => 16 * 2;
for my $mysql_server_prepare (0, 1) {
$dbh= DBI->connect("$test_dsn;mysql_server_prepare=$mysql_server_prepare;mysql_server_prepare_disable_fallback=1", $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0 });
ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_t55utf8");
my $create =<<EOT;
CREATE TABLE dbd_mysql_t55utf8 (
name VARCHAR(64) CHARACTER SET utf8,
bincol BLOB,
shape GEOMETRY,
binutf VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin,
profile TEXT CHARACTER SET utf8
)
EOT
ok $dbh->do($create);
my $utf8_str = "\x{0100}dam"; # "Adam" with a macron.
my $quoted_utf8_str = "'\x{0100}dam'";
my $blob = "\x{c4}\x{80}dam"; # same as utf8_str but not utf8 encoded
my $quoted_blob = "'\x{c4}\x{80}dam'";
cmp_ok $dbh->quote($utf8_str), 'eq', $quoted_utf8_str, 'testing quoting of utf 8 string';
cmp_ok $dbh->quote($blob), 'eq', $quoted_blob, 'testing quoting of blob';
#ok $dbh->{mysql_enable_utf8}, "mysql_enable_utf8 survive connect()";
$dbh->{mysql_enable_utf8}=1;
# GeomFromText() is deprecated as of MySQL 5.7.6, use ST_GeomFromText() instead
my $geomfromtext = $dbh->{mysql_serverversion} >= 50706 ? 'ST_GeomFromText' : 'GeomFromText';
my $query = <<EOI;
INSERT INTO dbd_mysql_t55utf8 (name, bincol, shape, binutf, profile)
VALUES (?, ?, $geomfromtext('Point(132865 501937)'), ?, ?)
EOI
ok $dbh->do($query, {}, $utf8_str, $blob, $utf8_str, $utf8_str), "INSERT query $query\n";
# AsBinary() is deprecated as of MySQL 5.7.6, use ST_AsBinary() instead
my $asbinary = $dbh->{mysql_serverversion} >= 50706 ? 'ST_AsBinary' : 'AsBinary';
$query = "SELECT name,bincol,$asbinary(shape), binutf, profile FROM dbd_mysql_t55utf8 LIMIT 1";
my $sth = $dbh->prepare($query) or die "$DBI::errstr";
ok $sth->execute;
my $ref;
$ref = $sth->fetchrow_arrayref ;
ok defined $ref;
cmp_ok $ref->[0], 'eq', $utf8_str;
cmp_ok $ref->[3], 'eq', $utf8_str;
cmp_ok $ref->[4], 'eq', $utf8_str;
SKIP: {
eval {use Encode;};
skip "Can't test is_utf8 tests 'use Encode;' not available", 2, if $@;
ok !Encode::is_utf8($ref->[1]), "blob was made utf8!.";
ok !Encode::is_utf8($ref->[2]), "shape was made utf8!.";
}
cmp_ok $ref->[1], 'eq', $blob, "compare $ref->[1] eq $blob";
ok $sth->finish;
ok $dbh->do("DROP TABLE dbd_mysql_t55utf8");
ok $dbh->disconnect;
}