Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to get information?

Posted on 2004-10-02
16
Medium Priority
?
189 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
ID: 12209006
what's usage of this character!!? -- > `
I think it's invalid character for field name
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12209098
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
ID: 12209211
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209221
>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
ID: 12209246
aren't you in mistake about ` and ' characters ?
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12209350
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
ID: 12209408
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
ID: 12210698
Well, that's "Unknown column '1' in 'field list'", so there is no column named '1' to be taken...
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12211450
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
ID: 12211755
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
ID: 12212449

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
ID: 12213082
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
ID: 12213379

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 1500 total points
ID: 12214926
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
ID: 12215323

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
ID: 12220546

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

581 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