Board index » delphi » D5:BDE. ORDER BY (column name = SQL-keyword)

D5:BDE. ORDER BY (column name = SQL-keyword)

I'm building a generalized browser that works with descendents of TDataSet.

However, I ran into an interesting snag when I built the test case shown
below.

It uses the demo ANIMALS.DBF table which contains a column named "SIZE."

Everything works well unless that column is chosen in which the following
exception is raised:

Invalid use of keyword.
Token: "SIZE"
Line Number: 4

Is there some general technique to use when a column name "happens" to be
the name of a SQL-keyword -- other than kludging the code to prevent those
cases?

An inquiring mind wants to know...

Keith S. Brown

{}PROCEDURE   TdlgMainTest.PRI_BuildQuery(asFldName,asDir:STRING);
{}{}PROCEDURE SetQry(asFldName:STRING);
    VAR
      ls      : STRING;
    BEGIN
      WITH qryTest,SQL DO BEGIN
        Clear;
        Add('SELECT *');
        Add('FROM ANIMALS');
        Add('ORDER BY');
        ls := Trim(Format('%s %s',[asFldName,fsDir]));
        Add(ls);
      END {WITH};
{}{}END {SetQry};

  BEGIN
    fsFldName := asFldName;
    fsDir     := asDir;
    WITH qryTest,SQL DO BEGIN
      Active := FALSE;
      SetQry(fsFldName);
      TRY
        Active := TRUE;
      EXCEPT
        Active := FALSE;
        fsDir  := '';
        SetQry('"'+fsFldName+'"');
        Active := TRUE;
      END {TRY};
    END {WITH};
{}END {PRI_BuildQuery};

 

Re:D5:BDE. ORDER BY (column name = SQL-keyword)


"TableName"."ColumnName" or TableAlias."ColumnName" will work for
local SQL.

On Mon, 8 Jul 2002 03:35:03 -0500, "KSS: Keith Brown"

Quote
<chairou...@ghg.net> wrote:
>I'm building a generalized browser that works with descendents of TDataSet.

>However, I ran into an interesting snag when I built the test case shown
>below.

>It uses the demo ANIMALS.DBF table which contains a column named "SIZE."

>Everything works well unless that column is chosen in which the following
>exception is raised:

>Invalid use of keyword.
>Token: "SIZE"
>Line Number: 4

>Is there some general technique to use when a column name "happens" to be
>the name of a SQL-keyword -- other than kludging the code to prevent those
>cases?

>An inquiring mind wants to know...

>Keith S. Brown

>{}PROCEDURE   TdlgMainTest.PRI_BuildQuery(asFldName,asDir:STRING);
>{}{}PROCEDURE SetQry(asFldName:STRING);
>    VAR
>      ls      : STRING;
>    BEGIN
>      WITH qryTest,SQL DO BEGIN
>        Clear;
>        Add('SELECT *');
>        Add('FROM ANIMALS');
>        Add('ORDER BY');
>        ls := Trim(Format('%s %s',[asFldName,fsDir]));
>        Add(ls);
>      END {WITH};
>{}{}END {SetQry};

>  BEGIN
>    fsFldName := asFldName;
>    fsDir     := asDir;
>    WITH qryTest,SQL DO BEGIN
>      Active := FALSE;
>      SetQry(fsFldName);
>      TRY
>        Active := TRUE;
>      EXCEPT
>        Active := FALSE;
>        fsDir  := '';
>        SetQry('"'+fsFldName+'"');
>        Active := TRUE;
>      END {TRY};
>    END {WITH};
>{}END {PRI_BuildQuery};

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Re:D5:BDE. ORDER BY (column name = SQL-keyword)


Thanks,

I'll give that a shot.

Keith.

Quote
"Bill Todd" <b...@notthis.dbginc.com> wrote in message

news:kv1jiuolsabjam62aoa1jei9tuelvngrgq@4ax.com...
Quote
> "TableName"."ColumnName" or TableAlias."ColumnName" will work for
> local SQL.

> On Mon, 8 Jul 2002 03:35:03 -0500, "KSS: Keith Brown"
> <chairou...@ghg.net> wrote:

> >I'm building a generalized browser that works with descendents of
TDataSet.

> >However, I ran into an interesting snag when I built the test case shown
> >below.

> >It uses the demo ANIMALS.DBF table which contains a column named "SIZE."

> >Everything works well unless that column is chosen in which the following
> >exception is raised:

> >Invalid use of keyword.
> >Token: "SIZE"
> >Line Number: 4

> >Is there some general technique to use when a column name "happens" to be
> >the name of a SQL-keyword -- other than kludging the code to prevent
those
> >cases?

> >An inquiring mind wants to know...

> >Keith S. Brown

> >{}PROCEDURE   TdlgMainTest.PRI_BuildQuery(asFldName,asDir:STRING);
> >{}{}PROCEDURE SetQry(asFldName:STRING);
> >    VAR
> >      ls      : STRING;
> >    BEGIN
> >      WITH qryTest,SQL DO BEGIN
> >        Clear;
> >        Add('SELECT *');
> >        Add('FROM ANIMALS');
> >        Add('ORDER BY');
> >        ls := Trim(Format('%s %s',[asFldName,fsDir]));
> >        Add(ls);
> >      END {WITH};
> >{}{}END {SetQry};

> >  BEGIN
> >    fsFldName := asFldName;
> >    fsDir     := asDir;
> >    WITH qryTest,SQL DO BEGIN
> >      Active := FALSE;
> >      SetQry(fsFldName);
> >      TRY
> >        Active := TRUE;
> >      EXCEPT
> >        Active := FALSE;
> >        fsDir  := '';
> >        SetQry('"'+fsFldName+'"');
> >        Active := TRUE;
> >      END {TRY};
> >    END {WITH};
> >{}END {PRI_BuildQuery};

> --
> Bill (TeamB)
> (TeamB cannot respond to questions received via email)

Other Threads