Configure libraries for database

Windows specific questions.
Post Reply
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Configure libraries for database

Post by jlwellman »

Trying to install freebasic to work with MySQL or PostgreSQL. Can't get libraries to work. I've tried converting using gendef and dlltools but no luck

It appears to compile fine but get the unable to start correctly and halts with the ....7B error
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

Hmm, no replies.

I'm just using the examples provided with freebasic for MySQL, PostreSQL and SQLite3 and have downloaded and installed all three database engines. Everything is 64 bit, started out with 32 bit version and nothing worked so I changed all over to 64 bit.

Found 10 year old post talking about converting libraries using Gendef and dlltools to convert the libs provided with each database to freebasic xxx.dll.a files. The example programs compiled but only get a runtime error that unable to start correctly and halts with the ....7B error
Imortis
Moderator
Posts: 1871
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Configure libraries for database

Post by Imortis »

Please provide the code that and the error message you are getting.
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

It's the sample code provided with freebasic (current example is from the compile of PostgreSQL_test.bas). It compiles with no errors (using WinFBE) and runs the exe and I get this error message; "the application was unable to start correctly (0cx000007b)".

I've converted libpq.dll from the Postgresql lib directory to postgresql.dll.a using GENDEF to get a *.def file and used DLLTOOLS to get *.dll.a file and moved to the freebasic lib directory, as well as main freebasic dir.
Imortis
Moderator
Posts: 1871
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Configure libraries for database

Post by Imortis »

That is a windows error code. If you do a Google search for that error code you get an explanation that says it is usually caused by an out of date .Net framework or C redistributable library. It is more likely that you are trying to use a newer version of the library than the example was written for.
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

OK, I Win11 was fully updated. I did notice the .Net 3.5 wasn't active but the current 4.8 was. I checked the 3.5 box and installed it.

I've now uninstalled all DB engines and freebasic. Doing new installs of 32 bit for freebasic and MySQL. If the example freebasic provides in it's current package isn't compatible with the current MySql, I don't know how to fix that.
St_W
Posts: 1598
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Configure libraries for database

Post by St_W »

The MySQL headers that come with FreeBasic seem to be quite old and only seem to be compatible with 32-bit FreeBasic (as they're not included in the 64-bit package).

Thus I tried to quickly translate the latest headers and tested them on 64-bit Windows 10 using FreeBasic 1.09 64-bit. I chose the MariaDB library over MySQL as it has replaced MySQL in most places and acts as a drop-in replacement being highly compatible.
Find the latest version of the native libraries here: https://mariadb.com/downloads/connectors/

And the include file for FreeBasic here:
https://github.com/swurzinger/fbbinding ... mariadb.bi

I just tested the MySQL example application shipped with FreeBasic (just include mariadb.bi instead of mysql/mysql.bi). The simple example executing a simple SHOW TABLES query worked, but there may be issues with the headers with more complex use cases or on other operating systems.

To use the headers make sure you have the libmariadb.dll and libmariadb.lib next to your .bas/.exe to compile/run it (or specify the library folder accordingly).
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

Thanks, I will give that a shot.
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

OK, made those changes and installed MariaDB.

changed the Mysql_test.bas to use mariadb.bi
all maria libs are in the same example dir

now I get this error

G:\WinFBE_Suite\toolchains\FB\examples\database\mysql_test.bas -o G:\WinFBE_Suite\toolchains\FB\examples\database\mysql_test.asm (main module)
G:\WinFBE_Suite\toolchains\FB\examples\database\mysql_test.bas(5) error 4: Duplicated definition, NULL in '#define NULL 0'


I can find #DEFINE NULL 0 only once in the mysql_test.bas file, nothing in the bi file. So I'm not sure where it is duplicated at. I think I'm understanding why no one is using freebasic with databases
St_W
Posts: 1598
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Configure libraries for database

Post by St_W »

Just remove the duplicate definition from the mysql_test.bas, it's already defined in crt/stddef.bi, included via mariadb.bi -> crt/ctype.bi -> crt/stddef.bi

Typically one uses an ORM nowadays and doesn't write queries and fetching logic manually. FreeBasic, being similar to C and something like a system programming language, most likely isn't the right choice if you want to do that. As always it depends on what you want to use it for - there are certainly valid use cases for accessing a database with FreeBasic (like in a resource-constrained environment or when it's used as interface to an external system).
jlwellman
Posts: 7
Joined: Jul 22, 2022 2:52

Re: Configure libraries for database

Post by jlwellman »

Thanks, got it working.

I'm an old man and structured programming works much easier for me. I know the new way is all about object programming but to me, that's to time consuming.

Thanks again
Post Reply