Recent

Author Topic: Config Files or Database Table with one Line  (Read 1059 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Config Files or Database Table with one Line
« on: July 25, 2022, 07:31:30 am »
Hello,

I have some forms that allow the user to select a product. Now there is an option for the user to set a default suggestion. So if the user should call a form for a product, then these default suggestions must be read in. Is it better to use a database table with one row or a XML/ JSON file which stores these entries? Since it varies from form to form, I would need to have multiple tables.  I would be happy if a few programmers would share their opinion here.

Thanks in advance

dje

  • Full Member
  • ***
  • Posts: 134
Re: Config Files or Database Table with one Line
« Reply #1 on: July 25, 2022, 08:18:59 am »
TIniFIle is a no brainer. Small, simple, easy to edit via text editors.
TXMLConfig is also nice, but it pulls in all the DOM units, which can increase your exe size.
If you have a complex tree structure, then XML is the go and can be manually edited by skilled users, but its a nightmare for general users to edit.

I thought about using TDbf or TBufDataSet for my current project, but decided against it, since it is hard to expand a table and you cant "simply" edit the files in a text editor.

My 2 cents is use TInifile, ...until you can not... Then use XML.
« Last Edit: July 25, 2022, 08:21:03 am by derek.john.evans »

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Config Files or Database Table with one Line
« Reply #2 on: July 25, 2022, 08:31:36 am »
many thanks !

i was going to try it with XML but never heard of TIniFile. i'll give that one a try !

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Config Files or Database Table with one Line
« Reply #3 on: July 25, 2022, 09:37:10 am »
many thanks !

i was going to try it with XML but never heard of TIniFile. i'll give that one a try !

TIniFile is the "classic" method used since the 16-bit Windows era for undemanding applications. A good example of its current use is Firefox, which uses what is basically a .ini file to set up a mapping between a named profile and the directory which contains all of the configuration details, caches and so on.

It's strictly for key/value pairs, grouped in sections, and doesn't provide immediate support for storing arrays etc.  While that can be fairly easily grafted on, if you're going to need a substantial amount of structure I believe something like JSON would be a better choice, although I've never needed to go that far.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dseligo

  • Hero Member
  • *****
  • Posts: 1222
Re: Config Files or Database Table with one Line
« Reply #4 on: July 25, 2022, 10:18:21 am »
Is it better to use a database table with one row or a XML/ JSON file which stores these entries? Since it varies from form to form, I would need to have multiple tables.

If you already use database in your application I would use it for this too.
You don't have to use multiple tables if data is similar/same. In one application I also save some data which are form based. I put in table user name, form name and data, so I use one table for several users and forms.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: Config Files or Database Table with one Line
« Reply #5 on: July 26, 2022, 08:13:57 am »
Thanks for your Opinions !

so far i do like TIniFile the most, probably going with it.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Config Files or Database Table with one Line
« Reply #6 on: July 26, 2022, 11:45:47 am »
Expanding on the example I gave earlier of Firefox's usage.

Almost all of my company's "business logic" is contained in scripts, with are partitioned by customer, by customer area of business and so on. These days they'd probably be described as report generation, but there's a lot of fancy calculation involved with data pivoting and so on.

On each server, there is a .ini file. This contains a general section with filesystem volume serial numbers etc. (to make sure that files can't be moved around unintentionally) and a flag indicating whether this is a live or standby system.

This also indicates the location of the database server, and of various other servers which are checked regularly (DNS, email, router and so on) so that operational problems can sound an alert.

There is then a per-customer section, which indicates what database on the PostgreSQL server is dedicated to that customer, the names of the tables in that database, and so on.

Everything else is contained in database tables, including scripts which are read and executed directly.

The result of this layout is that everything that is structured- indexed by customer, site, date and so on- is in the database, while the master unstructured stuff is in the .ini file.

This has worked well for 20+ years. In particular, since the schedulers are based on database tables they can be edited remotely... the major change that I do want to get in is using Postgres's asynchronous notification facility to broadcast updates.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Config Files or Database Table with one Line
« Reply #7 on: August 01, 2022, 10:27:02 am »
Going with dseligo on that one: Use the Database (i guess it's a SQLite?)
As for how to store different defaults/configs for tables: SQLite supports JSON out of the box from 3.38 onwards
https://www.sqlite.org/json1.html
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018