[Lazarus] Friendly Error message[fixed]

Allan E. Registos allan.registos at smpc.steniel.com.ph
Wed Apr 16 07:38:01 CEST 2014


On Wednesday, 16 April, 2014 01:18 PM, Allan E. Registos wrote:
> 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.

>      //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
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140416/95b989fc/attachment-0003.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-ide.org/pipermail/lazarus/attachments/20140416/95b989fc/attachment-0003.bin>


More information about the Lazarus mailing list