Sort fields by field_position vs field_name What do you prefer? lazarus / 16-Databases ---------------------------------------------------------------------- KoBraSoft · 2023-10-30 08:35 Hi, what sort order do you prefer for displaying database fields in your favorite RAD (Lazarus  ) tool? Sort fields by field_position or field_name? Firebird is able to sort fields by field_position. By default the field position is the creation order, but it can be changed. As far as I know, other major RDBMs have similar features. For example, if  create this table: CREATE TABLE CUSTOMER ( ID integer NOT NULL, CUSTOMER_NAME varchar(200), ADDRESS_LINE varchar(200), PLZ varchar(20), CITY varchar(200), EMAIL varchar(50), BANK varchar(50), BIC varchar(50), IBAN varchar(50), CONSTRAINT PK_CUSTOMER_0 PRIMARY KEY (ID) ); The fields in Database tools like flamerobin show up like this: ID, CUSTOMER_NAME, ADDRESS_LINE, PLZ, CITY, EMAIL, BANK, BIC, IBAN In lazarus sqldb they show up in alphabetical order: ADDRESS_LINE, BANK, BIC, CITY, CUSTOMER_NAME, EMAIL, IBAN, ID, PLZ ---------------------------------------------------------------------- rvk · 2023-10-30 08:42 Quote from: KoBraSoft on October 30, 2023, 09:35:04 amIn lazarus sqldb they show up in alphabetical order: WHERE exactly are the fields listed in alphabetical order? In TFields they are just not sorted, just like flamerobin. Then it's up to the programmer to display them to the user (as is done in flamerobin). ---------------------------------------------------------------------- KoBraSoft · 2023-10-30 08:54 Create a new project in Lazarus, add IBConnection, SQLTransaction and SQLQuery and set necessary properties. Open "Edit all SQL statements" by right click on SQLQuery. Select table CUSTOMER in "Table and Fields" ---------------------------------------------------------------------- rvk · 2023-10-30 09:12 Quote from: KoBraSoft on October 30, 2023, 09:54:55 amOpen "Edit all SQL statements" by right click on SQLQuery. Ha, ok. Yes, there they are alphabetical. I never use those screens and create the SQL statements myself without the visual aids. (I NEVER even set the connected to true in the IDE because when you forget it is set to true it can lead to all sort of unexpected side- effects.) But yes. The order there seems to be a matter of preference (by the developers). In the TDBEdit pulldown for DataFields it is normal that that Combobox is sorted (and preferred because you select one field) and Comboxes are always sorted. But in a view with all fields, like in "Edit all SQL statements" it might seem counter intuitive, because you probably already designed your table to group certain fields together. (For me that also wouldn't be a problem because I prefix fields that belong together with the same tag, so they are listed together when they are displayed alphabetically.) BTW. If you have that many fields you also might think about database design and database normalization. But that depends on the number of fields per table and structure of your database. BTW #2. If you use SELECT * FROM TABLE you do get an unsorted list of fields in your resultset. So for programming it yourself it shouldn't matter. ---------------------------------------------------------------------- Zvoni · 2023-10-30 09:17 Quote from: KoBraSoft on October 30, 2023, 09:54:55 amCreate a new project in Lazarus, add IBConnection, SQLTransaction and SQLQuery and set necessary properties. Open "Edit all SQL statements" by right click on SQLQuery. Select table CUSTOMER in "Table and Fields" Without testing, probably because https://www.freepascal.org/docs- html/fcl/db/tdataset.getfieldnames.html returns a TStrings, which is probably sorted, or because TFields has a private Member FFieldList which is a TFPList, and that one is sorted. Take your pick ---------------------------------------------------------------------- rvk · 2023-10-30 09:27 Quote from: Zvoni on October 30, 2023, 10:17:16 amWithout testing, probably because https://www.freepascal.org/docs- html/fcl/db/tdataset.getfieldnames.html returns a TStrings, which is probably sorted, This is not the case (luckily). Quote from: Zvoni on October 30, 2023, 10:17:16 amor because TFields has a private Member FFieldList which is a TFPList, and that one is sorted.At least for TDataset.TFields itself, this is not the case. It's unsorted. I think it's just the TListview that's unsorted when filling it in the Lazarus  IDE. ---------------------------------------------------------------------- Zvoni · 2023-10-30 09:56 Quote from: rvk on October 30, 2023, 10:27:40 amQuote from: Zvoni on October 30, 2023, 10:17:16 amWithout testing, probably because https://www.freepascal.org/docs- html/fcl/db/tdataset.getfieldnames.html returns a TStrings, which is probably sorted, This is not the case (luckily). Quote from: Zvoni on October 30, 2023, 10:17:16 amor because TFields has a private Member FFieldList which is a TFPList, and that one is sorted.At least for TDataset.TFields itself, this is not the case. It's unsorted. I think it's just the TListview that's unsorted when filling it in the Lazarus  IDE. I'll take your word for it, since i don't use the "visual" DB- Components ---------------------------------------------------------------------- KoBraSoft · 2023-10-30 10:25 pls see: https://gitlab.com/freepascal.org/fpc/source/-/issues/40488 ---------------------------------------------------------------------- KoBraSoft · 2023-10-30 10:33 Quote from: rvk on October 30, 2023, 10:12:05 amI never use those screens and create the SQL statements myself without the visual aids. I suppose most of highly sophisticated coders does not use tools like this. But for beginners it could be helpful. That's what makes a RAD tool.