|< 1 2 >| | 16 Einträge, 2 Seiten |
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
#! /usr/bin/perl
use strict;
use warnings;
use DBI ':sql_types';
my $dbh = DBI->connect('DBI:ODBC:driver=Microsoft Access-Treiber (*.mdb);dbq=db1.mdb',user,pass);
my $col = 'Testcol';
my $statement = "INSERT INTO table (`$col`) VALUES(?)";
my $coltype = get_type($col,$dbh);
$coltype = 'SQL_'.$coltype;
my $sth = $dbh->prepare($statement);
for(2..1000){
my $var = <STDIN>;
chomp $var;
$sth->bind_param(1,$var,$coltype);
$sth->execute($var) or die $dbh->errstr();
}
sub get_type{
my ($name,$dbh) = @_;
my ($sthcolinfo) = $dbh->column_info(undef,undef,undef,$name);
my $hashref = $sthcolinfo->fetchrow_hashref();
return $hashref->{TYPE_NAME};
}
DBI::st=HASH(0x3e9c2dc)->bind_param(...): attribute parameter 'SQL_INTEGER' is not a hash ref at C:/access.pl line 19
use DBI qw(:sql_types);
Quote\n\nThe SQL_INTEGER and other related constants can be
imported using use DBI qw(:sql_types); See "DBI Constants" for more information.
$sth->bind_param(1, $value, { TYPE => SQL_INTEGER });
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
#! /usr/bin/perl
use strict;
use warnings;
use DBI ':sql_types';
my $dbh = DBI->connect('DBI:ODBC:driver=Microsoft Access-Treiber (*.mdb);dbq=db1.mdb',user,pass);
my $col = 'Testcol';
my $statement = "INSERT INTO table (`$col`) VALUES(?)";
my $coltype = get_type($col,$dbh);
$coltype = 'SQL_'.$coltype;
my $sth = $dbh->prepare($statement);
for(2..1000){
my $var = <STDIN>;
chomp $var;
no strict 'refs';
$sth->bind_param(1,$var,&{"DBI::$coltype"});
use strict 'refs';
$sth->execute($var) or die $dbh->errstr();
}
sub get_type{
my ($name,$dbh) = @_;
my ($sthcolinfo) = $dbh->column_info(undef,undef,undef,$name);
my $hashref = $sthcolinfo->fetchrow_hashref();
return $hashref->{TYPE_NAME};
}
1
2
3
4
5
6
7
8
9
10
#! /usr/bin/perl
use strict;
use warnings;
use lib qw(.);
use DbiTest;
use DBI ':sql_types';
my $col = 'Testcol';
DbiTest->new($col);
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
package DbiTest;
use strict;
use warnings;
use DBI ':sql_types';
sub new{
my ($class,$col) = @_;
my $dbh = DBI->connect('DBI:ODBC:driver=Microsoft Access-Treiber (*.mdb);dbq=db1.mdb',user,pass);
my $statement = "INSERT INTO table (`$col`) VALUES(?)";
my $coltype = get_type($col,$dbh);
$coltype = 'SQL_'.$coltype;
my $sth = $dbh->prepare($statement);
for(2..1000){
my $var = <STDIN>;
chomp $var;
no strict 'refs';
$sth->bind_param(1,$var,&{"DBI::$coltype"});
use strict 'refs';
$sth->execute($var) or die $dbh->errstr();
}
}
sub get_type{
my ($name,$dbh) = @_;
my ($sthcolinfo) = $dbh->column_info(undef,undef,undef,$name);
my $hashref = $sthcolinfo->fetchrow_hashref();
return $hashref->{TYPE_NAME};
}
1;
Usage: SQL_LONGVARCHAR() at DbiTest line 21
$sth->bind_param(1,$var,&{"DBI::$coltype"});
Usage: SQL_LONGVARCHAR() at DbiTest line 21
$sth->bind_param(1,$var,&{"DBI::$coltype"}());
|< 1 2 >| | 16 Einträge, 2 Seiten |