Reputation: 319
I want to make Insert SQL Statement in Delphi using BDE Paradox which is
value_a := 0,123;
value_b := 0,234;
value_c := 0,345;
insert into mst_value values (value_a, value_b, value_c);
it shows the error like 'invalid SQL parameter' after debugging, it shows that the sql complete syntax like
insert into mst_value values (0,123, 0,234, 0,345)
which is supposed to be dot but comma in the decimal, so I format it using formatfloat('#.###
, value_a), ...` it still using comma, after change the regional setting on Control Panel to English, the SQL parameter is correct, this is because the currency or number format there is just like 123,123,123.00, so, how can I format the decimal number but from another country e.g Indonesia with the format like 123,123,123,123.00 not 123.123.123,00. thanks before...
Upvotes: 4
Views: 3347
Reputation: 596833
I am with Arioch on this. You should use a parameterized query instead. That will let the DB engine handle the formatting for you, eg:
value_a := 0,123;
value_b := 0,234;
value_c := 0,345;
Query.SQL.Text := 'insert into mst_value values (:value_a, :value_b, :value_c)';
Query.ParamByName('value_a').AsFloat := value_a;
Query.ParamByName('value_a').AsFloat := value_b;
Query.ParamByName('value_a').AsFloat := value_c;
Query.ExecSQL;
Upvotes: 1
Reputation: 16055
how do you make string like that ? "insert into mst_value values (0,123, 0,234, 0,345) "
It is aking for SQL Injection, that wouldallow anyone to break into your program.
Use TQuery.Params instead, with strict datatype checking.
More reasoning on this in comments at http://issuetracker.delphi-jedi.org/view.php?id=5916
Upvotes: 2
Reputation: 72626
Try in this way, before calling the formatFloat function, you can set appropriate value for Delphi's variable ThousandsSeparator and DecimalSeparator :
FormatFloat( "$##.000", value_a );
Upvotes: 2