Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-04

Friendly Error message

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Allan E. Registos

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.freepascal.org/pipermail/lazarus/attachments/20140416/ddafd5c0/attachment.html>

Reply by email

Allan E. Registos
to Allan E. Registos
Allan E. Registos wrote 26 lines
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;

Ok, the culprit is the above line! My bad. Removing the line fixes my problem, it was using the same update and insert connections.

Show quoted text 64 lines
//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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140416/95b989fc/attachment-0001.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4267 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140416/95b989fc/attachment-0001.bin>

Reply by email