[Lazarus] Friendly Error message
Allan E. Registos
allan.registos at smpc.steniel.com.ph
Wed Apr 16 07:18:50 CEST 2014
Hi all,
Another noob db question, is there anything I can do make this error more friendly?:
>In file 'ink_settings_unit1.pas' at line 65:
>INK_SQL.SQL.Text := 'INSERT INTO ink_settings(id, setting_type, basebalance_date, latest_data) ' +
?
I have this code structure for updating/inserting data:
try
result := false;
Try
InitializeDB();
//Not using StartTransaction for db is already active
SQLStr:='UPDATE ink_settings SET latest_data=0 WHERE setting_type=''%s''';
SQLStr:= Format(SQLStr,[INK_SETTING_TYPE]);
INK_SQL.SQL.Text := SQLStr;
INK_SQL.ExecSQL;
DateSTR:=FormatDateTime('MM-DD-YYYY hh:mm:ss',NewBaseDate);
NEW_INK_SETTINGID := GetTablePrimaryID('ink_settings') + 1;
//Insert new base date
INK_SQL.SQL.Text := 'INSERT INTO ink_settings(id, setting_type, basebalance_date, latest_data) ' +
' VALUES (:NEWID,:SETTING_TYPE,:NEWDATE,:LATEST_DATA)';
INK_SQL.Params.ParamByName('NEWID').AsInteger := NEW_INK_SETTINGID;
INK_SQL.Params.ParamByName('SETTING_TYPE').AsString := INK_SETTING_TYPE;
INK_SQL.Params.ParamByName('NEWDATE').AsString := DateSTR;
INK_SQL.Params.ParamByName('LATEST_DATA').AsInteger := INK_LATEST_DATA;
INK_SQL.ExecSQL;
INK_TRANSACTION.Commit;
result := True;
except
on e: exception do // Catch my exception
begin
raise exception.Create('Error: ' + e.Message);
end;
end;
finally
FreeDB();
end;
Where InitializeDB() code:
procedure InitializeDB();
begin
INK_DB := TPQConnection.Create(nil);
INK_SQL := TSQLQuery.Create(nil);
INK_TRANSACTION := TSQLTransaction.Create(nil);
INK_DATASOURCE := TDatasource.Create(nil);
if not INK_DB.Connected then
begin
INK_DB.HostName := DATABASE_HOST;
INK_DB.DatabaseName := DATABASE_NAME;
INK_DB.UserName := DATABASE_USER;
INK_DB.Password := DATABASE_PASSWORD;
INK_DB.Connected := True;
INK_SQL.database := INK_DB;
INK_TRANSACTION.DataBase := INK_DB;
INK_TRANSACTION.Active := True;
INK_DATASOURCE.DataSet := INK_SQL;
INK_SQL.Transaction := INK_TRANSACTION;
end;
end;
Thank you for any ideas...
Regards,
Allan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140416/ddafd5c0/attachment-0002.html>
More information about the Lazarus
mailing list