Recent

Author Topic: Typhoon relational database  (Read 8937 times)

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Typhoon relational database
« on: January 22, 2022, 02:55:17 pm »
Update:
Now ty.pas got it's own repository at gitlab. https://gitlab.com/funlw65/typhoon-pas
The following changes were made:
- ty.pas unit got reworked to accept static or dynamic/shared libraries. By default, it will include the static library - you have to define TYPHOON_STATIC before including ty unit in your main program;
- the graphical application and the raylib units were removed;
- the tytest.pas console app got reworked to be a little more useful;
- the README.md file is now, hopefully, more comprehensive.

Original Post:
This is a little precious database engine (you will agree with me if you read de docs) written in C language. I used it many years ago in a project, then forgot about it. Nowadays I'm glad to find out that it still compiles ok in a Linux environment (Debian 10 and derivatives and gcc 8.3.0) So I wrote a quick database application to test it and to familiarize myself also with raylib/raygui graphical libraries. A small pigeon breeds database, which can be downloaded and tested from here:

https://gitlab.com/funlw65/squabdb-c

The README.md contains a screenshot of the main form of the application and links to the C libraries used. So, I started converting the app in FreePascal language, and it seems that the typhoon database can be easily converted/interfaced for Pascal using h2pas utility. Well, I'm not expert on this matter and there still are two functions that I was not able to translate them, but it will not affect the project.
« Last Edit: August 25, 2022, 12:18:05 am by funlw65 »
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Typhoon relational database
« Reply #1 on: January 24, 2022, 09:25:03 am »
For completeness sake (untested!)
Code: Pascal  [Select][+][-]
  1. Type
  2.   TProcKeyBuild:Procedure (_para1:Pchar; _para2:longword; _para3:longword);
  3.   TProcSetErr  :Procedure (_para1:longint; _para2:longint);
  4.  
  5. //Function d_keybuild(_para1:Procedure (_para1:Pchar; _para2:longword; _para3:longword)): integer;cdecl;external cDllName;
  6. Function d_keybuild(_para1:TProcKeyBuild): integer;cdecl;external cDllName;
  7.  
  8. //Function d_seterrfn(_para1:Procedure (_para1:longint; _para2:longint)): integer;cdecl;external cDllName;
  9. Function d_seterrfn(_para1:TProcSetErr): integer;cdecl;external cDllName;
  10.  
But i'm weary of this conversion in general. Use ctypes for conversions
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

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #2 on: January 26, 2022, 08:10:00 pm »
Thank you Zvoni, I appreciate! I had some things to do, but done now and I will start in translating the app to pascal. Actually, most of it is done, as I wrote it for the qdbm database first, hit some walls then translated the pascal app in C, then in the end changed the database engine to typhoon and now back to pascal :P
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #3 on: February 03, 2022, 06:04:03 am »
Done! Not fully tested, but I think is ok.

https://gitlab.com/funlw65/squabdb-pas

Inside the code is a little useful "gadget", deactivated as a comment :) 
The app comes with two themes, dark and light.
« Last Edit: December 18, 2022, 02:27:51 am by funlw65 »
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Typhoon relational database
« Reply #4 on: February 03, 2022, 08:33:38 am »
Very interesting.  :)

I could compile and run successfully the C demo (with the static lib, on Linux Mageia). Very nice! (By the way, it was very easy to install raylib.)

For the Pascal demo, I have to find how to build libtyphoon.so.

Could you share the binary, or explain how you built it?
« Last Edit: February 03, 2022, 08:37:25 am by Roland57 »
My projects are on Gitlab and on Codeberg.

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Typhoon relational database
« Reply #5 on: February 03, 2022, 08:45:51 am »
Again reminding the OP: Use Ctypes for the bindings!
You might get lucky that the native Pascal-Types are correct for your intended Target, another User trying to use it for a different target might start a nuclear rocket in North Korea
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

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #6 on: February 03, 2022, 04:04:25 pm »
Again reminding the OP: Use Ctypes for the bindings!
You might get lucky that the native Pascal-Types are correct for your intended Target, another User trying to use it for a different target might start a nuclear rocket in North Korea

Hi Zvoni,

I have yet to learn what and how to do that :( ... I said I am not skilled in this. If I awakened some interest in typhoon database, then than would be an accomplished goal...
 
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Typhoon relational database
« Reply #7 on: February 03, 2022, 04:06:46 pm »
https://wiki.freepascal.org/Creating_bindings_for_C_libraries#Manual_conversion_of_C_headers_to_Pascal
Quote
Note that one should use the ctypes unit together with the types that it declares to convert C headers instead of trying to use the basic Pascal types directly. This ensures that the bindings are correct in all platforms, as the C types might have different sizes on different architectures and operating systems.
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

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #8 on: February 03, 2022, 04:21:29 pm »
Very interesting.  :)

I could compile and run successfully the C demo (with the static lib, on Linux Mageia). Very nice! (By the way, it was very easy to install raylib.)

For the Pascal demo, I have to find how to build libtyphoon.so.

Could you share the binary, or explain how you built it?

Hi Roland57,


For the dynamic raylib, this one must include inside also raygui...
You have to clone the GLFW project from github and compile and install it as a shared library - it gives you a link to their home page for the compiling instructions. Follow them.
After that, get the raylib 4 release, unzip it and go to the src subfolder and edit the Makefile.
There, you have to activate using the external GLFW, activate the shared compilation and the inclusion of the raygui... can't remember now if there are more, but all you need is there in the Makefile. I think this is also something that Gunko must resolve/explain for use of its distro of Ray4Laz...

For the dynamic typhoon. Just execute configure to obtain the Makefile file and edit it to include the -fPIC option in CFLAGS vatiable (I included it after -shared option which must be included as well) . Then, after compilation, execute the following command:

Code: Bash  [Select][+][-]
  1. gcc -shared -o libtyphoon.so ansi.o bt_del.o bt_funcs.o bt_io.o bt_open.o cmpfuncs.o os.o readdbd.o record.o sequence.o ty_auxfn.o ty_find.o ty_ins.o ty_io.o ty_log.o ty_open.o ty_refin.o ty_repl.o ty_util.o unix.o vlr.o

How looks CFLAGS in my Makefile:
Code: Text  [Select][+][-]
  1. CFLAGS          = -g -Wall -shared -fPIC -Wstrict-prototypes -Wmissing-prototypes -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE $(DEFINES)
  2.  
« Last Edit: February 03, 2022, 04:39:14 pm by funlw65 »
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #9 on: February 03, 2022, 04:27:13 pm »
https://wiki.freepascal.org/Creating_bindings_for_C_libraries#Manual_conversion_of_C_headers_to_Pascal
Quote
Note that one should use the ctypes unit together with the types that it declares to convert C headers instead of trying to use the basic Pascal types directly. This ensures that the bindings are correct in all platforms, as the C types might have different sizes on different architectures and operating systems.

Thank you Zvoni, I will look into it and redo the header...
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Typhoon relational database
« Reply #10 on: February 03, 2022, 06:44:40 pm »
@funlw65

Thanks. I will try to do that.
My projects are on Gitlab and on Codeberg.

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #11 on: February 03, 2022, 07:47:37 pm »
@funlw65

Thanks. I will try to do that.

I realized that you need detailed instructions to make that raylib library that can work also with Ray4Laz that Gunko has it in the works (the one that includes raygui as well). So let me try to write the required steps:

So, apart of compiling GLFW 3.4 (from the repo and, if you have a previous version installed in your system, uninstall it) as dynamic lib, you have to do the following:

1. Get the 4.0 distro of raylib and unzip it in your home folder;
2. Inside the main folder of the raylib, go to src/extras subfolder as we need to prepare raygui.h and physac.h headers.
3. Copy them into .c sources:
  cp raygui.h raygui.c
  cp physac.h physac.c
4. Copy the resulted .c files into the src subfolder (up one level in the tree structure of the folders).
 so you are here now: $HOME/raylib_main_folder/src
5. Now we have to introduce one line of code to the raygui.c. Open it in an editor, and below
 #define RAYGUI_VERSION  "3.0"
line, insert the following line:
 #define RAYGUI_IMPLEMENTATION
6. Save the modification.
7. Now we need to prepare the Makefile as below (I will include part of my Makefile for clarity):

Code: Text  [Select][+][-]
  1. # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
  2. RAYLIB_LIBTYPE       ?= SHARED
  3.  
  4. # Build mode for library: DEBUG or RELEASE
  5. RAYLIB_BUILD_MODE    ?= RELEASE
  6.  
  7. # Build output name for the library
  8. RAYLIB_LIB_NAME      ?= raylib
  9.  
  10. # Define resource file for DLL properties
  11. RAYLIB_RES_FILE      ?= ./raylib.dll.rc.data
  12.  
  13. # Define raylib platform
  14. # Options:  PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  15. PLATFORM             ?= PLATFORM_DESKTOP
  16.  
  17. # Include raylib modules on compilation
  18. # NOTE: Some programs like tools could not require those modules
  19. RAYLIB_MODULE_AUDIO  ?= TRUE
  20. RAYLIB_MODULE_MODELS ?= TRUE
  21. RAYLIB_MODULE_RAYGUI ?= TRUE
  22. RAYLIB_MODULE_PHYSAC ?= TRUE
  23.  
  24. RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/extras
  25. RAYLIB_MODULE_PHYSAC_PATH ?= $(RAYLIB_SRC_PATH)/extras
  26.  
  27. # Use external GLFW library instead of rglfw module
  28. USE_EXTERNAL_GLFW    ?= TRUE
  29.  

7.a On short, RAYLIB_LIBTYPE should be SHARED, RAYLIB_MODULE_RAYGUI should be TRUE, RAYLIB_MODULE_PHYSAC should be TRUE and USE_EXTERNAL_GLFW should be TRUE.

8. Save the modifications in the Makefile and compile from here (execute make command). You should get the required .so library, that contains both raygui and physac headers, required also for the upcoming new version and examples of Ray4Laz package...

9. Execute
 sudo make install
and you are good to go.
« Last Edit: February 03, 2022, 08:07:54 pm by funlw65 »
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #12 on: February 03, 2022, 11:52:06 pm »
Updated ty.pas in the first post with ctypes... hopefully, is right? The demo compiles nicely and runs well (tested navigating between keys, searching key, modifying record).

ty.pas is also in the demo's repo... if you get the repo, you have it.
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Typhoon relational database
« Reply #13 on: February 04, 2022, 03:24:21 am »
@funlw65

Thank you very much for all these informations. I will try all that ASAP.

If you have time and desire, it could be a good idea to make a simple demo (not using raylib), so that we can test easily the Typhoon bindings.

Regards.

Roland
My projects are on Gitlab and on Codeberg.

funlw65

  • Full Member
  • ***
  • Posts: 148
    • Visual Pin Configurator for Nucleo 64pin boards
Re: Typhoon relational database
« Reply #14 on: February 04, 2022, 03:51:26 am »
There is tytest.pas in the repository, but only for a few functions and I thought I would make something similar to MushRoomsDatabase by Jurassic Pork, but for fpc only, using raylib/raygui as an alternative to the classic GUI interfaces.

Anyway, one needs to read the documentation that typhoon comes with, how to define the structure of a database using the provided language (DDL), then how to use the specific tools to create the database and the .h header with the record definitions that must be translated with h2pas, etc.

Is a quite capable classic database, similar to .DBF but a little complex at the beginning (but only regarding database definitions, because the functions are quite straight forward), and probably not too beginner friendly, so I had to dress her in an attractive GUI interface.

It helps much if playing with the C example that comes with typhoon... 
FreePascal 3.2.2, C 10.2.1, D 1.24 under Linux(init,musl,glibc), DragonflyBSD, NetBSD
gui: gtk2, qt5, raylib4.x+raygui3.x, nanovg 
tui: freevision, tvision2, termbox2+widgets, finalcut
db: typhoon-1.11...

 

TinyPortal © 2005-2018