Why is this not working on SQLite
Why is this not working on SQLite
I have the following code that takes values from one table with value form one week and updates another table with values for a whole year.
The code works just fine on MS Access and MySQL but on SQLite it won't update because of the QueryUpdate.ParamByName('flddayspecial').AsBoolean := False;
If I remove this, everything runs as it should.
procedure CalendarYearUpdate(aYear: integer; aMonth : integer = 0);
var
Query: TUniQuery;
QueryUpdate: TUniQuery;
DayNumber: integer;
DayNormal: double;
begin
Query := TUniQuery.Create(Nil);
QueryUpdate := TUniQuery.Create(Nil);
try
Query.Connection := frmDBConn.conDBserver;
QueryUpdate.Connection := frmDBConn.conDBserver;
Query.SQL.Clear;
Query.SQL.Add('SELECT * FROM ' + TableCalendarWeek);
Query.SQL.Add('WHERE (fldemployer = :fldemployer)');
Query.ParamByName('fldemployer').AsString := Employer.GUID;
Query.Execute;
StatusShow(Application.MainForm, Query.RecordCount, 0, 'Opdaterer kalender. Vent venligst.....');
try
while Not Query.Eof do
begin
DayNumber := Query.FieldByName('flddaynumber').AsInteger;
DayNormal := Query.FieldByName('flddaynormal').AsFloat;
QueryUpdate.SQL.Clear;
QueryUpdate.SQL.Add('UPDATE ' + TableCalendarYear);
QueryUpdate.SQL.Add('SET flddaynormal = :flddaynormal');
QueryUpdate.SQL.Add('WHERE (flddaynumber = :flddaynumber)');
QueryUpdate.SQL.Add('AND (flddayspecial = :flddayspecial)');
QueryUpdate.SQL.Add('AND (fldemployer = :fldemployer)');
QueryUpdate.SQL.Add('AND (fldyear = :fldyear)');
if aMonth > 0 then
begin
QueryUpdate.SQL.Add('AND (fldmonth = :fldmonth)');
QueryUpdate.ParamByName('fldmonth').AsInteger := aMonth;
end;
QueryUpdate.ParamByName('flddaynumber').AsInteger := DayNumber;
QueryUpdate.ParamByName('flddaynormal').AsFloat := DayNormal;
QueryUpdate.ParamByName('flddayspecial').AsBoolean := False;
QueryUpdate.ParamByName('fldemployer').AsString := Employer.GUID;
QueryUpdate.ParamByName('fldyear').AsInteger := aYear;
QueryUpdate.Execute;
Query.Next;
StatusPos(Query.RecNo);
end;
except
on E: exception do
begin
Query.Next;
StatusPos(Query.RecNo);
Logfile.Error('CalendarYearUpdate: ' + E.Message);
end
end;
finally
Query.Free;
QueryUpdate.Free;
StatusHide;
end;
end;
The code works just fine on MS Access and MySQL but on SQLite it won't update because of the QueryUpdate.ParamByName('flddayspecial').AsBoolean := False;
If I remove this, everything runs as it should.
procedure CalendarYearUpdate(aYear: integer; aMonth : integer = 0);
var
Query: TUniQuery;
QueryUpdate: TUniQuery;
DayNumber: integer;
DayNormal: double;
begin
Query := TUniQuery.Create(Nil);
QueryUpdate := TUniQuery.Create(Nil);
try
Query.Connection := frmDBConn.conDBserver;
QueryUpdate.Connection := frmDBConn.conDBserver;
Query.SQL.Clear;
Query.SQL.Add('SELECT * FROM ' + TableCalendarWeek);
Query.SQL.Add('WHERE (fldemployer = :fldemployer)');
Query.ParamByName('fldemployer').AsString := Employer.GUID;
Query.Execute;
StatusShow(Application.MainForm, Query.RecordCount, 0, 'Opdaterer kalender. Vent venligst.....');
try
while Not Query.Eof do
begin
DayNumber := Query.FieldByName('flddaynumber').AsInteger;
DayNormal := Query.FieldByName('flddaynormal').AsFloat;
QueryUpdate.SQL.Clear;
QueryUpdate.SQL.Add('UPDATE ' + TableCalendarYear);
QueryUpdate.SQL.Add('SET flddaynormal = :flddaynormal');
QueryUpdate.SQL.Add('WHERE (flddaynumber = :flddaynumber)');
QueryUpdate.SQL.Add('AND (flddayspecial = :flddayspecial)');
QueryUpdate.SQL.Add('AND (fldemployer = :fldemployer)');
QueryUpdate.SQL.Add('AND (fldyear = :fldyear)');
if aMonth > 0 then
begin
QueryUpdate.SQL.Add('AND (fldmonth = :fldmonth)');
QueryUpdate.ParamByName('fldmonth').AsInteger := aMonth;
end;
QueryUpdate.ParamByName('flddaynumber').AsInteger := DayNumber;
QueryUpdate.ParamByName('flddaynormal').AsFloat := DayNormal;
QueryUpdate.ParamByName('flddayspecial').AsBoolean := False;
QueryUpdate.ParamByName('fldemployer').AsString := Employer.GUID;
QueryUpdate.ParamByName('fldyear').AsInteger := aYear;
QueryUpdate.Execute;
Query.Next;
StatusPos(Query.RecNo);
end;
except
on E: exception do
begin
Query.Next;
StatusPos(Query.RecNo);
Logfile.Error('CalendarYearUpdate: ' + E.Message);
end
end;
finally
Query.Free;
QueryUpdate.Free;
StatusHide;
end;
end;