Recent

Author Topic: Small DBMS project and How to code  (Read 3266 times)

Researching

  • Full Member
  • ***
  • Posts: 121
Small DBMS project and How to code
« on: May 19, 2023, 08:17:04 pm »
Here plan to post questions arising during making a small DBMS.
SCOPE:
IN: import files of txt, csv, xml, MySQL3
input: user's edits, settings
OUT: preview, content export.
Processing: convert, store, edit, delete.
MVC model, Waterfall, procedural style (later may be object).
Including some parsers.

Modular source.
Approach: UI -> model -> process -> refactor

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #1 on: May 19, 2023, 08:40:06 pm »
As started here:
https://forum.lazarus.freepascal.org/index.php/topic,63397.0.html

the first topic is to prepare filling the StringGrid component with different type of source data.
Probably the overloading option will be used heavily.

The filling will be performed in three stages:
1. records in the table with ability to edit them and save
2. File with items of data parsed to Array of Records
3. Array of records (of different structure/content)
4. converted to list of records - as data type, that can be modified.
5. records written to table

Each level should be a certain function/procedure.
Coding will be "5" -> "0"

cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: Small DBMS project and How to code
« Reply #2 on: May 20, 2023, 10:13:36 am »
Hi
well, have fun... Looking forward to following your progress  :)
If you need help/assistance, just hollar  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #3 on: May 20, 2023, 09:30:37 pm »
Some questions:

1. What is better to use?

Have to use similar data structures and procedures/functions for different data models and preview.
options to use:
-- modular distribution: corresponding data and processing in appropriate modules
-- single module with different or dynamic data structures and functions/procedures overloading
-- OOP structure with objects recognizing they're corresponding data structure.

2. is it correct to use dynamic array for storing up to 1000+ signs in string in an array element?
What are limits for data structures in x32 architecture for dynamic array and list/queue?

There will be internal representation of data:
a) array with selection from file
b) queue with selection from that array, where the sequence will change: insertions, deletions, moved items.

Finally these data will be shown in StringGrid, edited and written back to file.
Between the file and array there will be a parsing with selection.
Between array and file there should be rewriting of certain positions in the file and append of file.
Indeed each record in file must be with ID.

3. need a "HowTo":
How to prepare functions in Console app, to easy include them into GUI app?
Example:
a) have a console "header" file that tests external module for in/out
b) include that module in GUI app.



« Last Edit: May 21, 2023, 12:05:49 am by Researching »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Small DBMS project and How to code
« Reply #4 on: May 21, 2023, 05:05:02 am »
1. What is better to use?

OOP is good for the cases that have many of items that share similar features. It is often used in writing GUI components. For example in my GLGUI library, it has these classes: TgRectangle and TgText. if someday I want to add a new feature 'Rotate', I only need to create the property and write the code in the parent class of them, then I will get TgRectangle.Rotate and TgText.Rotate.

A single module is good for grouping functions and procedures that deal with same thing. For example in my GLGUI, there are some functions that deal with color, image and geometry calculations like BGRAtoRGBA, GetRGB, CalcVectorNormal and FlipVertical. Most of those functions were created and used when I wrote GLGUI, but because they were not tightly depended in GLGUI, I split them out as a new module 'Geometry' so I can reuse the code for other projects in the future.

Modular distribution
is good for complex and large projects. I usually start with a single module but when it grows too large, it will be easier to maintain if I split it to multiple modules.

2. is it correct to use dynamic array for storing up to 1000+ signs in string in an array element?

That's okay but you may want to consider TStringList, TList or maybe TQueue:

https://wiki.freepascal.org/Data_Structures,_Containers,_Collections#Run_time_library_.28RTL.29

What are limits for data structures in x32 architecture for dynamic array and list/queue?

Correct me if I am wrong, I believe dynamic array in 32-bit system can consist as much as 2147483647 (32-bit integer) items, but you have make sure your system has enough free memory.

How to prepare functions in Console app ...

I do not write console programs, not much I can say.
« Last Edit: May 21, 2023, 05:12:55 am by Handoko »

cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: Small DBMS project and How to code
« Reply #5 on: May 21, 2023, 09:59:37 am »
Hi
I would definitely choose an OOP-based approach with inheritance and devised in a modular design. That way you can easily write a quick console-test-app, to test your finished module/unit/class(es), as you go along and then step by step add those modules to your gui-app, until you've got your finished 1.st version of your application.
Start with the basics i.e.: your internal data-container, I would go with TCollection & TCollectionItem as base to descend from, because there you get a lot of functionality and "ID" and "Displayname" properties for free. To complement them I would decorate*) a TQueue from "contnrs" unit to use your objects. Now you have a skeleton to build on. Put all of this in a separate folder under your project-dir e.g.: "Bom"**) and write a small console app to fill in some test-data, in the same directory or in a "Test"-dir under it.
Now in your project-dir you probably have an application with a form, that will eventually be your finished app. In that add "Bom" to your search path, so that you can use your business-objects there as well, in the gui app you consider your gui layout and start putting it together alongside your coding the business-objects. Before long you'll have to contemplate how your storage backend should look, which you'll of course put in project-dir -> "Storage"-dir, so that you can have a "ReadData" and "UpdateData" -module to link in your internal data structure, but for now, I think you've got a bit of work to do.  ;)
Edit:
*) Decorate means create a class that uses the TQueue internally, but
   surfaces the items as your own defined objects, that way you don't have to
   typecast as much... and you can add functionality.
**) Business Object Modules i.e.: the "Controller" in MVC
HTH
Regards Benny
« Last Edit: May 21, 2023, 10:09:50 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #6 on: May 21, 2023, 05:09:20 pm »
And another question:
1. How to automatically resize StringGrid rows to fit the text?
UPD:
there will be some items of text: ho to make cells fit the text (adjust height) instead of being just equal or fixed?

2. How to dynamically load different components?
for ex.
a) File>open -> load/show file opening components
b) File>import -> load/show file import components and settings
c) Settings>Profile ->load/show profile settings components
And "OnChange" - free Memory from previous components

d) Another option would be to show full-screen dialogs with scroll and appropriate functions.

3. Actual need: Change the whole window content for different tasks.
Either Redraw the Form1, or show dialogs, or use TPageControl?
which is preferred for memory and CPU limited device?
« Last Edit: May 22, 2023, 11:36:31 pm by Researching »

cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: Small DBMS project and How to code
« Reply #7 on: May 22, 2023, 01:31:24 pm »
Hi
1) Please be more specific...
2) a: use a TOpenDialog*)...
    b: use a TOpenDialog*) with different properties.
    c: "Settings" is a choice between a TTabSheet or a dialog. see 3)
    d: please be more specific...
3) I would go with TPageControl/TTabSheets + Tframes, combined with a few
    necessary dialogs.
*) If you were to follow my design idea, you will have pluggable backend
    engines, so it's just a matter of choosing the right plugin for opening own
    format or importing foreign formats, depending on e.g.: file-extension.
    For import, you just alter the filter in the dialog to those formats you
    support and link the appropriate "ReadData"-engine to your internal
    container. Of course you'll have to write a plugin-manager, but that's
    easily done and then you can boast in this forum, you have a reason for
    using "FreeAndNil"  ;)
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #8 on: June 06, 2023, 06:32:32 pm »
Hi
    c: "Settings" is a choice between a TTabSheet or a dialog. see 3)
Where to find the component "TabSheet"?
Quote
3) I would go with TPageControl/TTabSheets + Tframes, combined with a few
    necessary dialogs.
How much memory will this component use? Wil it load all the functionality at once or load only the opened tab?
For the sake of memory usage - would prefer to use dialog windows as a main window: Main Form -> call and load Dialog -> close dialog and free the memory

Quote
*) If you were to follow my design idea, you will have pluggable backend
    engines, so it's just a matter of choosing the right plugin for opening own
    format or importing foreign formats, depending on e.g.: file-extension.
    For import, you just alter the filter in the dialog to those formats you
    support and link the appropriate "ReadData"-engine to your internal
    container. Of course you'll have to write a plugin-manager, but that's
    easily done and then you can boast in this forum, you have a reason for
    using "FreeAndNil"  ;)
What is the concept of your design?

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #9 on: June 06, 2023, 07:43:24 pm »
QUESTION:
How to adopt the window size to screen size?

Example: procedure in a submodule, there is a procedure "prcdFormSizeToScreen();"
How to point it to the Form1?
Unit_Form1:

.....
Form1.OnCreate(....);
procedure prcdFormSize to Screen(.???????)

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Small DBMS project and How to code
« Reply #10 on: June 06, 2023, 09:22:42 pm »
Have you tried:

Code: Pascal  [Select][+][-]
  1.   Form1.WindowState := wsMaximized;

cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: Small DBMS project and How to code
« Reply #11 on: June 06, 2023, 09:37:50 pm »
Hi
Ok, here goes:
Q1) TTabsheets come from TPageControl, place one on your form and right-click on it and choose "Add page", then it creates a new tabsheet for you.
Q2) Dialogs are mighty fine and you can design them as you like, beware of too many dialogs, users might find them annoying.
Q3) See attached picture...
Q4) In "TForm1.FormCreate" add these lines:
Code: Pascal  [Select][+][-]
  1.   Width:= Screen.Width;
  2.   Height:= Screen.Height;
  3.  
...or try Handoko's tip, should work too.
That's about it, for now anyway  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Small DBMS project and How to code
« Reply #12 on: June 07, 2023, 08:07:38 am »
QUESTION:
How to adopt the window size to screen size?

Example: procedure in a submodule, there is a procedure "prcdFormSizeToScreen();"
How to point it to the Form1?
Unit_Form1:

.....
Form1.OnCreate(....);
procedure prcdFormSize to Screen(.???????)
Pass a Reference to your Form1 to your procedure

Aircode
Code: Pascal  [Select][+][-]
  1. //In Sub-Module
  2. Procedure prcdFormSizeToScreen(var AForm:TForm);
  3. Begin
  4.   AForm.WindowState:=wsMaximized;
  5. End;
  6.  
  7. //In Your Unit_Form1
  8. Uses SubModule;
  9.  
  10. //In FormCreate
  11. Begin
  12.    prcdFormSizeToScreen(Self);
  13. End;
  14.  
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

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #13 on: June 08, 2023, 09:11:34 pm »
Have you tried:
Code: Pascal  [Select][+][-]
  1.   Form1.WindowState := wsMaximized;

Thanks, I will try this :)
And still there is a question of how to pass component or object to an outer procedure in another module for processing.

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #14 on: June 08, 2023, 09:27:13 pm »
QUESTION:
How to adopt the window size to screen size?

Example: procedure in a submodule, there is a procedure "prcdFormSizeToScreen();"
Pass a Reference to your Form1 to your procedure
Code: Pascal  [Select][+][-]
  1. //CODE WAS HERE

Thank you for reply.

May I ask for more?

Let's say there are three modules.
the first - of Form1
the second - say it "Interface Tuner"
the third - "forms processor"

how to call a procedure located in the third module, from the second module, telling it to process a form from the first module?




 

TinyPortal © 2005-2018