Subject | Re: [firebird-support] locate O'Connor |
---|---|
Author | Helen Borrie |
Post date | 2005-09-28T00:45:48Z |
At 11:51 PM 27/09/2005 +0000, you wrote:
sql.strings[2]:='where upper(Last_Name)='
+ QuotedStr(uppercase(dbeditLastName.Text));
Actually (off-topic here) better than that is
with MyDataset do
begin
SQL.Add('SELECT...whatever');
SQL.('where upper(Last_name) = :UpperLastName');
Prepare;
ParamByName('UpperLastName').AsString :=
QuotedStr(uppercase(OtherDataset.FieldByName('Last_Name').AsString));
Open;
end;
i.e.
1. Use params
2. Use the proper methods with TStrings
3. Don't read parameter values from the Text property of data-aware controls: read the dataset itself
and (even better)
4. If MyDataset is a design-time object that is going to be re-used over and over, apply the parameterised SQL strings to the SQL property in the IDE. This avoids constantly re-assigning the SQL that causes expensive unpreparing and repreparing. Merely slotting in fresh values for params doesn't require the statement to be re-prepared. "Prepare once, execute often" saves network traffic and processing cycles. It's easier to maintain, as well.
with MyDataset do
begin
if not Prepared then Prepare;
ParamByName('UpperLastName').AsString :=
QuotedStr(uppercase(OtherDataset.FieldByName('Last_Name').AsString));
Open;
end;
./hb
>FB 1.5.2 B:4731Apostrophes have to be "doubled", just as in Delphi itself. Since you are using Delphi, just use the QuotedStr() function:
>
>sql.strings[2]:='where
>upper(Last_Name)='+#39+uppercase(dbeditLastName.Text)+#39+' ';
>
>errors when dbeditLastName.Text contains an apostrophe (single quote)
>in the name, as in O'Connor. The query reports that "Connor" is an
>unknown token.
sql.strings[2]:='where upper(Last_Name)='
+ QuotedStr(uppercase(dbeditLastName.Text));
Actually (off-topic here) better than that is
with MyDataset do
begin
SQL.Add('SELECT...whatever');
SQL.('where upper(Last_name) = :UpperLastName');
Prepare;
ParamByName('UpperLastName').AsString :=
QuotedStr(uppercase(OtherDataset.FieldByName('Last_Name').AsString));
Open;
end;
i.e.
1. Use params
2. Use the proper methods with TStrings
3. Don't read parameter values from the Text property of data-aware controls: read the dataset itself
and (even better)
4. If MyDataset is a design-time object that is going to be re-used over and over, apply the parameterised SQL strings to the SQL property in the IDE. This avoids constantly re-assigning the SQL that causes expensive unpreparing and repreparing. Merely slotting in fresh values for params doesn't require the statement to be re-prepared. "Prepare once, execute often" saves network traffic and processing cycles. It's easier to maintain, as well.
with MyDataset do
begin
if not Prepared then Prepare;
ParamByName('UpperLastName').AsString :=
QuotedStr(uppercase(OtherDataset.FieldByName('Last_Name').AsString));
Open;
end;
./hb