Schrift
[thread]13027[/thread]

Einfügen wirft Syntax Fehler

Leser: 3


<< >> 3 Einträge, 1 Seite
esskar
 2009-01-21 11:00
#118192 #118192
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
folgendes script
Code (perl): (dl )
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
#!/usr/bin/perl

use strict;
use warnings;

use DBI;
my $dsn = "DBI:mysql:database=tiet;host=maschine";
my $dbi = DBI->connect($dsn, 'foo', 'bar') or die "Unable to connect to database.";

$dbi->do("DELETE FROM tiet_instruments_group");
my $sth = $dbi->prepare("INSERT INTO tiet_instruments_group (group, groupName, instrumentType) VALUES (?, ?, ?)")
        or die $dbi->errstr;
while(my $line = <DATA>)
{
        chomp $line;
        if(my @values = $line =~ m!^(\w+)\s+([\w\s,]+?)\s+(\w+)$!)
        {
                print "@values\n";
                $sth->execute(@values)
                        or die $dbi->errstr;
        }
}

__DATA__
AFR0            Africa, Near East, Turkey               EQU
AFR1            Africa, Near East, Turkey               EQU
AGEN            Government Agencies             BON
ASI0            Asia            EQU
ASI1            Asia            EQU
ASI2            Asia            EQU
ASI3            Asia            EQU
AST0            Austria                 EQU
AST1            Austria                 EQU


scheitert mit folgender meldung:
DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL ser
ver version for the right syntax to use near 'group, groupName, instrumentType) VALUES ('AFR0', 'Africa, Near East, Turk
ey', '' at line 1 at C:\User\Sascha.Kiefer\Entwicklung\Tatweer\instrument_groups.pl line 19, <DATA> line 1.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right synta
x to use near 'group, groupName, instrumentType) VALUES ('AFR0', 'Africa, Near East, Turkey', ''

Tabelle hat folgendes schema:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
CREATE TABLE  `tiet`.`tiet_instruments_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`group` varchar(16) NOT NULL,
`baseLoad` int(10) unsigned NOT NULL default '0',
`ratio` int(10) unsigned NOT NULL default '0',
`excessTA1` double NOT NULL default '0',
`excessTA2` double NOT NULL default '0',
`excessTA3` double NOT NULL default '0',
`groupName` varchar(128) NOT NULL,
`instrumentType` varchar(16) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


hilft mir jmd auf die sprünge?
pq
 2009-01-21 11:23
#118193 #118193
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
"group" ist ein reserviertes wort, du musst es mit backticks quoten (mysql sagt dir immer in
der fehlermeldung "near ...", daran siehst du, dass es das "group" ist, was stört.)
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
esskar
 2009-01-21 11:37
#118194 #118194
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
danke. du bist die beste!
<< >> 3 Einträge, 1 Seite



View all threads created 2009-01-21 11:00.