Leser: 18
QuoteSV = PV(0xd48964) at 0xd8c130
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x18e9e20 "Blutdruckmessger\344t"\0
CUR = 18
LEN = 20
2009-10-05T12:03:25 pktmDies ist einer dieser Datensätze:
QuoteSV = PV(0xd48964) at 0xd8c130
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x18e9e20 "Blutdruckmessger\344t"\0
CUR = 18
LEN = 20
Ist das utf8?
┬ôñúäÖñâÆöàóóçàÖCú
2009-10-05T12:06:30 biancaDieses \344 kommt mir hiervon bekannt vor:[]...
2009-10-05T12:03:25 pktmAber ich habe noch nicht raus, wie ich diese Option bei DBIx::Class aktiviere. Suchen geh...
1
2
3
4
5
6
7
8
9
$schema->{$name} = $model->connect(
sub { $handle->get_handle },
{
on_connect_do => [
# "SET sql_mode='STRICT_TRANS_TABLES,STRICT_ALL_TABLES'",
],
mysql_enable_utf8 => 1,
},
);
1
2
3
4
5
6
7
8
9
10
11
12
my $dbc = $self->cfg('db') or die("Missing ...cut");
$schema1 = My::Schema->connect(
$dbc->{dsn},
$dbc->{username},
$dbc->{password},
$dbc->{attributes},
{
mysql_enable_utf8 => 1,
},
);
$schema1->storage->sql_maker->quote_char('`');
$schema1->storage->sql_maker->name_sep('.');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
my $dbc = $self->cfg('db') or die("Missing ...cut");
my $dbh = DBI->connect(
$dbc->{dsn},
$dbc->{username},
$dbc->{password},
$dbc->{attributes},
) or die("Could not connect to DB " . DBI->errstr());
my $sql = qq~
SELECT keyword
FROM keywords
...
~;
my $sth = $dbh->prepare($sql) or die("prep: " . $dbh->errstr());
my $rv = $sth->execute( $shop_id ) or die("exec: " . $dbh->errstr());
while( my $href = $sth->fetchrow_hashref() ) {
print $href->{keyword};
Devel::Peek::Dump($href->{keyword});
}
1
2
3
4
5
6
7
8
9
10
11
12
SV = PVMG(0xe29ea0) at 0xd4495c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
IV = 0
NV = 0
PV = 0x1a53670 "Blutdruckmessger\303\244t"\0 [UTF8 "Blutdruckmessger\x{e4}t"]
CUR = 19
LEN = 20
MAGIC = 0x1a52fa0
MG_VIRTUAL = &PL_vtbl_utf8
MG_TYPE = PERL_MAGIC_utf8(w)
MG_LEN = 18
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/perl -w
package MyTest;
use strict;
use warnings;
use DBI;
use Devel::Peek;
use Data::Dumper qw/Dumper/;
use Perl6::Say;
use FindBin qw/$Bin/;
use lib $Bin;
use Test::Schema;
=head2 new( $cfg_file )
=cut
sub new {
my $class = shift;
my $self = bless({}, $class);
$self->{'__CONFIG'} = {
db => {
dsn => 'DBI:mysql:test:localhost;mysql_enable_utf8=1',
username => 'test',
password => 'test',
attributes => {
autocommit => 1,
},
}, # /db
};
return $self;
} # /mew
=head2 cfg( $key? )
Reads the value for $key from the config file. If $key is omitted, the config
hash is returned at once.
=cut
sub cfg {
my $self = shift;
my $key = shift; # may be undef
if( $key ) {
return $self->{'__CONFIG'}->{$key};
}else{
return $self->{'__CONFIG'};
}
} # /cfg
=head2 schema()
Connect to a schema. Anything else than the authentication credentials is
hardcoded :-)
=cut
sub schema {
my $self = shift;
my $schema1 = $self->{'__SCHEMA'};
unless( $schema1 ) {
my $dbc = $self->cfg('db') or die("Missing configuration values: db connection attributes");
$schema1 = Test::Schema->connect(
$dbc->{dsn},
$dbc->{username},
$dbc->{password},
$dbc->{attributes},
);
$schema1->storage->sql_maker->quote_char('`');
$schema1->storage->sql_maker->name_sep('.');
$self->{'__SCHEMA'} = $schema1;
}
return $schema1;
} # /schema
=head2 with_dbic()
Get a word with special chars from test database using DBIx::Class.
=cut
sub with_dbic {
my $self = shift;
my $schema = $self->schema();
my $word = $schema->resultset('Words')->first()->word();
say STDERR $word;
Devel::Peek::Dump($word);
} # /run
=head2 with_dbi()
Get a word with special chars from test database using DBI.
=cut
sub with_dbi {
my $self = shift;
my $dbc = $self->cfg('db') or die("Missing configuration values: db connection attributes");
my $dbh = DBI->connect(
$dbc->{dsn},
$dbc->{username},
$dbc->{password},
$dbc->{attributes},
) or die("Could not connect to DB " . DBI->errstr());
my $sql = qq~
SELECT word
FROM words
LIMIT 1
~;
my $sth = $dbh->prepare($sql) or die("prep: " . $dbh->errstr());
my $rv = $sth->execute() or die("exec: " . $dbh->errstr());
while( my $href = $sth->fetchrow_hashref() ) {
my $word = $href->{word};
say STDERR $word;
Devel::Peek::Dump( $word );
}
} # /with_dbi
1;
use strict;
use warnings;
use FindBin qw/$Bin/;
use lib $Bin;
my $app = MyTest->new();
$app->with_dbic();
$app->with_dbi();
1
2
3
4
5
6
7
8
9
10
11
12
CREATE TABLE IF NOT EXISTS `words` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`word` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Daten für Tabelle `words`
--
INSERT INTO `words` (`id`, `word`) VALUES
(1, 'Größe');
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
package Test::Schema::Words;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("words");
__PACKAGE__->add_columns(
"id",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
"word",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 45,
},
);
__PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.04006 @ 2009-10-05 15:47:42
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5dRfU5LHHx2UY5/NtWqqGQ
# You can replace this text with custom content, and it will be preserved on regeneration
1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Größe
SV = PVMG(0xbed900) at 0xb0a988
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
IV = 0
NV = 0
PV = 0x159e3f0 "Gr\303\266\303\237e"\0
CUR = 7
LEN = 8
Größe
SV = PV(0xb5a500) at 0xb151d8
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x15a0870 "Gr\303\266\303\237e"\0
CUR = 7
LEN = 8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Blutdruckmessger‰t
SV = PVMG(0xc81140) at 0xba1bc0
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
IV = 0
NV = 0
PV = 0x1682050 "Blutdruckmessger\303\244t"\0 [UTF8 "Blutdruckmessger\x{e4}t"]
CUR = 19
LEN = 20
MAGIC = 0x1680ff0
MG_VIRTUAL = &PL_vtbl_utf8
MG_TYPE = PERL_MAGIC_utf8(w)
MG_LEN = 18
Blutdruckmessgerät
SV = PV(0xc005ac) at 0xba20dc
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK)
PV = 0x1680a70 "Blutdruckmessger\303\244t"\0
CUR = 19
LEN = 20
1 2 3 4 5 6 7 8 9 10
$database_handle_of{ident $new_object} = DBI->connect( qq{DBI:mysql:database=$MYSQL_TABLE; host=$MYSQL_HOST; port=$MYSQL_PORT; }, $MYSQL_USER, $MYSQL_PASSWORD ) or croak $DBI::errstr; my $drh = DBI->install_driver("mysql"); $database_handle_of{ident $new_object}->do("SET NAMES 'utf8'");
2009-10-06T10:25:34 rooootSo funktioniert es — und ich fass das auch so schnell nicht wieder an.