Solved

how to get information?

Posted on 2004-10-02
16
179 Views
Last Modified: 2010-04-05
on create i get error: field '`1`' not found

<-- code  -->
procedure TForm3.FormCreate(Sender: TObject);
begin
PComputerName:= StrAlloc(100); Size:= 100;
if GetComputerName(PComputerName, Size) then
pc := PcomputerName;
Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips');
Form1.AdoQuery2.ExecSQL;
Label1.Caption := Form1.Adoquery2.FieldByName('`1`').Value;
Label2.Caption := Form1.Adoquery2.FieldByName('`2.5`').Value;
Label3.Caption := Form1.Adoquery2.FieldByName('`5`').Value;
Label4.Caption := Form1.Adoquery2.FieldByName('`10`').Value;
Label5.Caption := Form1.Adoquery2.FieldByName('`20`').Value;
end;

HOW TO FIX IT?
0
Comment
Question by:selas
  • 5
  • 5
  • 3
  • +2
16 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
what's usage of this character!!? -- > `
I think it's invalid character for field name
0
 
LVL 5

Expert Comment

by:Lukasz Lach
Comment Utility
When writing:
  select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips
SQL interprets it as a field names 1, 2.5, 5, 10... These are not names of fields (as i think you didn't meant it and that kind of names are invalid anyway). If you wanted to select numbers, write:
  select 1, 2.5, 5, 10, 20, 50, 100, 500, 1000, `time` from chips
The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
i'm really mixed about :( , but when we write :
select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips

SQL interprets these as parameters , not as field names.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
>The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.

then what's differ when we write :
select time from table
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
aren't you in mistake about ` and ' characters ?
0
 
LVL 5

Expert Comment

by:Lukasz Lach
Comment Utility
no, i'm not. mind the example:

mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> select `1`;
ERROR 1054: Unknown column '1' in 'field list'
mysql>
0
 
LVL 6

Expert Comment

by:Amir Azhdari
Comment Utility
I'm agree with you about this, :)

but ERROR 1054 is because of sql interprets `1`, `2.5`, ... as parameters not as field names
0
 
LVL 5

Expert Comment

by:Lukasz Lach
Comment Utility
Well, that's "Unknown column '1' in 'field list'", so there is no column named '1' to be taken...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:Voodooman
Comment Utility
Hi

Looking a this you have created a field with the name `1`  not  '1' as some people have interpreted. These are not pseudo fields as some people have interpreted (as they would have had to be defined more clearly (1 as Integer etc..., 1 as DateTime etc...)

If you had used the ' and not the ` it would not compile anyway.....

The use of ` as a character in a fieldname is almost certainly invalid (and anyway is bad practice) all field names should contain only alpha numeric characters and underscores (spaces are allowed but frowned on).

It is also bad practice to use spaces and equally bad practice to use the '.' period (I am surprised that any database would allow this).  This has surely only been allowed in the context of the erroneous ` character.

Amir Azhdari is certainly correct in this.

Change the fieldnames to something sensible without the erroneous ` characters (these are not quotation marks - what are they - I see them every day on my keyboard and have not thought of it!) and without the Erroneous '.' periods.

Change them to (example).

1,2.5 (if you must use numbers)

Or One, TwoPointFive etc

If you must use numbers access them like this

Select [1],[2.5] etc

I would never do this myself unless absolutely forced to do so.


Voodooman
0
 

Author Comment

by:selas
Comment Utility
1, 2.5, 5, 10, 20, 50, 100, 500, 1000, time - column names

then i exec sql: select `1`, `2.5` from chips

i need to get value of column 1 and 2.5
0
 
LVL 5

Expert Comment

by:Voodooman
Comment Utility

Hi

You cant use the character ` in your SQL

Try this

select [1], [2.5],[5],[10],[20],[50],[100],[500],[1000] from chips


Voodooman
0
 

Author Comment

by:selas
Comment Utility
if i use:

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select [1],[2.5], [5], [10], [20], max(time) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

i get error in syntax...
0
 
LVL 5

Expert Comment

by:Voodooman
Comment Utility

Hi

Well I see that your problem over the field not found is cured using the [ ] - so I have answered your question.

You will get a syntax error with the new query.

max(Time) would have to be a field called time which is probably a reserved word and you could't use it anyway - perhaps max([Time]) might work.

However you can't group by a field that is not included in an aggregate of some kind - so you will have an error in the syntax.

As your original problem is solved, I suggest you accept the answer and ask another question related to your new query.

Voodooman
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 500 total points
Comment Utility
name the columns like this:
SELECT 1 AS A1, 2.5 AS A2, 5 AS A5, 10 AS A10, 20 AS A20 ...

and then use
Label1.Caption := Form1.Adoquery2.FieldByName('A1').AsString;

etc. When writing clear code and SQL, stick to some standart rules. Field names, table names, etc should be identifiers - Upper and Lower case letters and numbers and underscore("_"), starting with letter. They should not use reserved words and the name should be no longer that 27 symbols...
This can save you troubles.
0
 
LVL 5

Expert Comment

by:Voodooman
Comment Utility

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select ivede,[1],[2.5], [5], [10], [20], max([time]) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

This should work if you have a column called time and a column called ivede

Voodooman
0
 
LVL 5

Expert Comment

by:Voodooman
Comment Utility

Well it seems that giving the correct answer dosnt seem to matter anymore...... maybe thats why very few people come here compared to when I first started in 1989.

I don't what to be petty but I think selas is wrong in his acceptance of the answer of Ivanov_G.

I am disgusted is all I can say....

Voodooman

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now