(CodeLib-Manager)
Registriert seit: 27. Nov 2008
Ort: Delmenhorst
2.379 Beiträge
|
Finde Fehler in SQL-Statement nicht.
31. Jul 2009, 10:50
Datenbank: Firebird • Version: 2.1 • Zugriff über: Zeos
Hi ihr,
Irgendwie bin ich heute blind. Ich suche seit einer geschlagenen Stunde den Fehler in meinem Statement und finde ihn nicht. Hier erstmal die Abfrage:
INSERT INTO EXPENSES (ID INTEGER, EXP_TYPE INTEGER, EXP_VALUE FLOAT, EXP_CATEGORY INTEGER, EXP_COMMENT CHAR(255) CHARACTER SET NONE, EXP_USER INTEGER, EXP_DAY INTEGER, EXP_MONTH INTEGER, EXP_YEAR INTEGER) VALUES (:id, :exp_type, :exp_value, :exp_category, :exp_comment, :exp_user, :exp_day, :exp_month, :exp_year);
Im Quelltext sieht es dann so aus:
Delphi-Quellcode:
TDGHBEntry = packed record
EntryType: TEntryType;
Value: Double;
Categorie: String;
Comment: String;
User: String;
ID: String;
Date: TDateTime;
end;
//[...]
procedure TDGHBDatabase.AddEntry(Entry: TDGHBEntry);
var
InsertCategoryQuery : TZQuery;
GetUserIDQuery: TZQuery;
GetCategoryIDQuery: TZQuery;
UserID: Integer;
CategoryID: Integer;
CurrDay,
CurrMonth,
CurrYear: Word;
begin
InsertCategoryQuery := TZQuery.Create( nil);
GetUserIDQuery := TZQuery.Create( nil);
GetCategoryIDQuery := TZQuery.Create( nil);
with GetUserIDQuery do
begin
Connection := fConnection;
ParamCheck := true;
SQL.Text := ' SELECT ID FROM USERS WHERE USER_NAME = :user';
ParamByName(' user').AsString := Entry.User;
Open;
UserID := FieldByName(' ID').AsInteger;
end;
with GetCategoryIDQuery do
begin
Connection := fConnection;
ParamCheck := true;
SQL.Text := ' SELECT ID FROM CATEGORIES WHERE CATEGORIE_NAME = :cat';
ParamByName(' cat').AsString := Entry.Categorie;
Open;
CategoryID := FieldByName(' ID').AsInteger;
end;
with InsertCategoryQuery do
begin
Connection := fConnection;
ParamCheck := true;
{CREATE TABLE EXPENSES (ID INTEGER, EXP_TYPE INTEGER, EXP_VALUE FLOAT, EXP_CATEGORY INTEGER, EXP_COMMENT CHAR(255) CHARACTER SET NONE, EXP_USER INTEGER, EXP_DAY INTEGER, EXP_MONTH INTEGER, EXP_YEAR INTEGER);}
SQL.Text := ' INSERT INTO EXPENSES (ID INTEGER, EXP_TYPE INTEGER, EXP_VALUE FLOAT, EXP_CATEGORY INTEGER, EXP_COMMENT CHAR(255) CHARACTER SET NONE, EXP_USER INTEGER, EXP_DAY INTEGER, EXP_MONTH INTEGER, EXP_YEAR INTEGER)' +
' VALUES (:id, :exp_type, :exp_value, :exp_category, :exp_comment, :exp_user, :exp_day, :exp_month, :exp_year);';
ParamByName(' exp_type').AsInteger := Integer(Entry.EntryType);
ParamByName(' exp_value').AsFloat := Entry.Value;
ParamByName(' exp_category').AsInteger := UserID;
ParamByName(' exp_comment').AsString := ' ';
ParamByName(' exp_user').AsInteger := CategoryID;
DecodeDate(Entry.Date, CurrYear, CurrMonth, CurrDay);
ParamByName(' exp_day').AsInteger := CurrDay;
ParamByName(' exp_month').AsInteger := CurrMonth;
ParamByName(' exp_year').AsInteger := CurrYear;
ExecSQL;
end;
InsertCategoryQuery.Free;
GetUserIDQuery.Free;
GetCategoryIDQuery.Free;
end;
Und das sagt mein Programm zu dem Statement:
Code:
---------------------------
dghb
---------------------------
SQL Error: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 26 INTEGER. Error Code: -104. Invalid token The SQL: INSERT INTO EXPENSES (ID INTEGER, EXP_TYPE INTEGER, EXP_VALUE FLOAT, EXP_CATEGORY INTEGER, EXP_COMMENT CHAR(255) CHARACTER SET NONE, EXP_USER INTEGER, EXP_DAY INTEGER, EXP_MONTH INTEGER, EXP_YEAR INTEGER) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);;
---------------------------
OK
---------------------------
Ich seh einfach den Wald vor lauter Bäumen nicht mehr... Aus der Fehlermeldung lese ich, dass er mit dem Wort "INTEGER" nix mehr anfangen kann. Kann doch nicht sein, oder?
米斯蘭迪爾 "In einer Zeit universellen Betruges wird das Aussprechen der Wahrheit zu einem revolutionären Akt." -- 1984, George Orwell
|