Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-04

Trim db-fieldnames, or not?

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joost van der Sluis

Hi all,

In several places you can specify a list of fieldnames, seperated by semicolons. For example: 'field1;field2'. Question is: should this be allowed: 'field1; field2'? Or should a "Field not found: ' field2'" exception occur? (Note the space)

Ie: should I add a trim(fieldname) to the code, or not? What do you guys think?

Joost.

Reply by email

Michael Van Canneyt
to Joost van der Sluis
Joost van der Sluis wrote 9 lines
Hi all, In several places you can specify a list of fieldnames, seperated by semicolons. For example: 'field1;field2'. Question is: should this be allowed: 'field1; field2'? Or should a "Field not found: ' field2'" exception occur? (Note the space) Ie: should I add a trim(fieldname) to the code, or not? What do you guys think?

IMHO, no trimming should be added, because databases can have fields with spaces. Weird, but true.

Michael.

Reply by email

Inoussa OUEDRAOGO
to Joost van der Sluis: In several places you can specify a list of fieldnames, seperated by semicolons. For…

2008/4/18, Joost van der Sluis :

Show quoted text 9 lines
Hi all, In several places you can specify a list of fieldnames, seperated by semicolons. For example: 'field1;field2'. Question is: should this be allowed: 'field1; field2'? Or should a "Field not found: ' field2'" exception occur? (Note the space) Ie: should I add a trim(fieldname) to the code, or not? What do you guys think?

Why not provide a boolean option "TrimFieldName" ?

Inoussa O.

Reply by email

Joost van der Sluis
to Michael Van Canneyt: IMHO, no trimming should be added, because databases can have fields with spaces. Weird,…

Op vrijdag 18-04-2008 om 22:06 uur [tijdzone +0200], schreef Michael Van Canneyt:

Show quoted text 15 lines
On Fri, 18 Apr 2008, Joost van der Sluis wrote: > Hi all, > > In several places you can specify a list of fieldnames, seperated by > semicolons. For example: 'field1;field2'. Question is: should this be > allowed: 'field1; field2'? Or should a "Field not found: ' field2'" > exception occur? (Note the space) > > Ie: should I add a trim(fieldname) to the code, or not? What do you guys > think? IMHO, no trimming should be added, because databases can have fields with spaces. Weird, but true.

Not at the begin or end, I hope?

Joosg

Reply by email

Joost van der Sluis
to Inoussa OUEDRAOGO: 2008/4/18, Joost van der Sluis : Why not provide a boolean option "TrimFieldName" ?…

Op zaterdag 19-04-2008 om 16:53 uur [tijdzone +0100], schreef Inoussa OUEDRAOGO:

Show quoted text 12 lines
2008/4/18, Joost van der Sluis : > Hi all, > > In several places you can specify a list of fieldnames, seperated by > semicolons. For example: 'field1;field2'. Question is: should this be > allowed: 'field1; field2'? Or should a "Field not found: ' field2'" > exception occur? (Note the space) > > Ie: should I add a trim(fieldname) to the code, or not? What do you guys > think? Why not provide a boolean option "TrimFieldName" ?

I'm building a general db-framework. Not a program-bloatification tool. ;) You can add options for everything, but that won't solve all problems. You have to make a choice, sometimes.

I won't add the trim, a programmer can add it if he wants to before he passes a fieldname.

Joost

Reply by email

Michael Van Canneyt
to Joost van der Sluis: Op vrijdag 18-04-2008 om 22:06 uur [tijdzone +0200], schreef Michael Van Canneyt: Not at…
Joost van der Sluis wrote 19 lines
Op vrijdag 18-04-2008 om 22:06 uur [tijdzone +0200], schreef Michael Van Canneyt: > > On Fri, 18 Apr 2008, Joost van der Sluis wrote: > > > Hi all, > > > > In several places you can specify a list of fieldnames, seperated by > > semicolons. For example: 'field1;field2'. Question is: should this be > > allowed: 'field1; field2'? Or should a "Field not found: ' field2'" > > exception occur? (Note the space) > > > > Ie: should I add a trim(fieldname) to the code, or not? What do you guys > > think? > > IMHO, no trimming should be added, because databases can have fields > with spaces. Weird, but true. Not at the begin or end, I hope?

Even there:

home: >fisql /home/firebird/contacts.fb
Database: /home/firebird/contacts.fb
SQL> create table test ("my field " int);
SQL> show table test;
my field INTEGER Nullable
SQL> alter table test add " another field" int;
SQL> show table test;
my field INTEGER Nullable
another field INTEGER Nullable
SQL> show table test;
my field INTEGER Nullable
another field INTEGER Nullable
SQL> select " another field" from test;

another field
==============
<null>

SQL> select "another field" from test;
Statement failed, SQLCODE = -206
Dynamic SQL Error
-SQL error code = -206
-Column unknown
-another field
-At line 1, column 24

Try and find where your query goes wrong :)

Michael.

Reply by email

Joost van der Sluis
to Michael Van Canneyt

Op zaterdag 19-04-2008 om 22:08 uur [tijdzone +0200], schreef Michael Van Canneyt:

Show quoted text 40 lines
On Sat, 19 Apr 2008, Joost van der Sluis wrote: > Op vrijdag 18-04-2008 om 22:06 uur [tijdzone +0200], schreef Michael Van > Canneyt: > > > > IMHO, no trimming should be added, because databases can have fields > > with spaces. Weird, but true. > > Not at the begin or end, I hope? Even there: home: >fisql /home/firebird/contacts.fb Database: /home/firebird/contacts.fb SQL> create table test ("my field " int); SQL> show table test; my field INTEGER Nullable SQL> alter table test add " another field" int; SQL> show table test; my field INTEGER Nullable another field INTEGER Nullable SQL> show table test; my field INTEGER Nullable another field INTEGER Nullable SQL> select " another field" from test; another field ============== <null> SQL> select "another field" from test; Statement failed, SQLCODE = -206 Dynamic SQL Error -SQL error code = -206 -Column unknown -another field -At line 1, column 24 Try and find where your query goes wrong :)

That is just sick!

Joost

Reply by email

Michael Van Canneyt
to Joost van der Sluis
Joost van der Sluis wrote 44 lines
Op zaterdag 19-04-2008 om 22:08 uur [tijdzone +0200], schreef Michael Van Canneyt: > > On Sat, 19 Apr 2008, Joost van der Sluis wrote: > > > Op vrijdag 18-04-2008 om 22:06 uur [tijdzone +0200], schreef Michael Van > > Canneyt: > > > > > > IMHO, no trimming should be added, because databases can have fields > > > with spaces. Weird, but true. > > > > Not at the begin or end, I hope? > > Even there: > > home: >fisql /home/firebird/contacts.fb > Database: /home/firebird/contacts.fb > SQL> create table test ("my field " int); > SQL> show table test; > my field INTEGER Nullable > SQL> alter table test add " another field" int; > SQL> show table test; > my field INTEGER Nullable > another field INTEGER Nullable > SQL> show table test; > my field INTEGER Nullable > another field INTEGER Nullable > SQL> select " another field" from test; > > another field > ============== > <null> > > SQL> select "another field" from test; > Statement failed, SQLCODE = -206 > Dynamic SQL Error > -SQL error code = -206 > -Column unknown > -another field > -At line 1, column 24 > > Try and find where your query goes wrong :) That is just sick!

It is.
Courtesy of MS-Access users... That was the first to support it, AFAIK. (although access uses [] instead of "", as far as I remember)

Michael.

Reply by email

Inoussa OUEDRAOGO
to Joost van der Sluis: Op zaterdag 19-04-2008 om 16:53 uur [tijdzone +0100], schreef Inoussa OUEDRAOGO: I'm…

2008/4/19, Joost van der Sluis :

Show quoted text 19 lines
Op zaterdag 19-04-2008 om 16:53 uur [tijdzone +0100], schreef Inoussa OUEDRAOGO: > 2008/4/18, Joost van der Sluis : > > Hi all, > > > > In several places you can specify a list of fieldnames, seperated by > > semicolons. For example: 'field1;field2'. Question is: should this be > > allowed: 'field1; field2'? Or should a "Field not found: ' field2'" > > exception occur? (Note the space) > > > > Ie: should I add a trim(fieldname) to the code, or not? What do you guys > > think? > > Why not provide a boolean option "TrimFieldName" ? I'm building a general db-framework. Not a program-bloatification tool. ;)

If this option cause "program-bloatification", I think we do disagree on the meaning of
"program-bloatification"

..You can add options for everything, but that won't solve all problems. You have to make a choice, sometimes.

Add an option _is_ also a choice ;-)
And oh, choice is not going to solve all your problems as well ;-)

I won't add the trim, a programmer can add it if he wants to before he passes a fieldname.

IMHO it is acceptable.

Inoussa O.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: It is. Courtesy of MS-Access users... That was the first to support it, AFAIK. (although…
Michael Van Canneyt wrote 6 lines
> That is just sick! It is. Courtesy of MS-Access users... That was the first to support it, AFAIK. (although access uses [] instead of "", as far as I remember)

That's is sick! And yes, MS-Access uses the square brackets.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Marc Weustink
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
On 19/04/2008, Michael Van Canneyt wrote: > > That is just sick! > > > It is. > Courtesy of MS-Access users... That was the first to support it, AFAIK. > (although access uses [] instead of "", as far as I remember) That's is sick! And yes, MS-Access uses the square brackets.

with quoted identifiers you can do whatever you want. One of the examples I use why you don't want to use them is:

SELECT "select"
FROM "from"
WHERE "where"
and "and" BETWEEN "between" and "and"
HAVING "having"
ORDER BY "order by"

Marc

Reply by email

Graeme Geldenhuys
to Marc Weustink
Marc Weustink wrote 9 lines
with quoted identifiers you can do whatever you want. One of the examples I use why you don't want to use them is: SELECT "select" FROM "from" WHERE "where" and "and" BETWEEN "between" and "and" HAVING "having" ORDER BY "order by"

hehehe... I don't use quoted identifiers either. That example belongs on the "what the fuck" website [http://thedailywtf.com], aka "worse than failure"! :-)

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marc Weustink
to Graeme Geldenhuys
Graeme Geldenhuys wrote 14 lines
Marc Weustink wrote: > with quoted identifiers you can do whatever you want. One of the > examples I use why you don't want to use them is: > > SELECT "select" > FROM "from" > WHERE "where" > and "and" BETWEEN "between" and "and" > HAVING "having" > ORDER BY "order by" hehehe... I don't use quoted identifiers either. That example belongs on the "what the fuck" website [http://thedailywtf.com], aka "worse than failure"! :-)

:)
They only have production code, this is an example I use :) I haven't seen this in production yet (other wtfs I did see though)

Marc

Reply by email