C Looking for a portable C++ API for accessing a database

I'm not sure that this is the right forum for this question, but if it is not, I trust that the forum owners will redirect it appropriately.

I'm looking for a pre-existing C++ API for accessing a database, rather than having to write my own. Presently we are using an SQLite database, but I don't want to write the application with SQLite-specific calls, because at some point we might want to change to MySQL or Postgres or perhaps even a commercial product.

Within the FreeBSD ports system, I see databases/dbconnect , but from what I can see from taking a quick look at it, databases/dbconnect is not totally portable. I might be mistaken, it doesn't seem to be well documented.

I stumbled across a commercial product called SQLAPI++, but the source code costs $249 and I don't know if it is worth anything. You can download a binary test version for nothing, which claims to work on FreeBSD 8; I can't get the test program to run on FreeBSD10, it depends on a version of libstdc++.so that does not exist on this system.

That the test version claims to work on FreeBSD 8, but not on FreeBSD10, makes me suspect that the product is not being actively maintained, that the "lifetime support" that they promise for the cost of two licenses might be provided by people who are dead, or serving a life sentence in a California prison for first-degree murder, or otherwise not available when you need them.

Which is not to say that I require lifetime support, I don't, I just want a well-behaved and well-documented portable C++ API for database access. What do you recommend? As always, thank you in advance for any and all replies.
 
Last edited by a moderator:
....
That the test version claims to work on FreeBSD 8, but not on FreeBSD10, makes me suspect that the product is not being actively maintained, that the "lifetime support" that they promise for the cost of two licenses might be provided by people who are dead, or serving a life sentence in a California prison for first-degree murder, or otherwise not available when you need them..
FreeBSD 8 comes with lang/gcc as the default compiler whereas FreeBSD 10 uses lang/clang. This may be the reason why you were not able to run a binary compiled for FreeBSD 8 (clarification needed, not sure how good is the binary compability between FreeBSD 8 & FreeBSD 10).

llvm has stdc++ instead of gcc's libstdc++ as its standard c++ library.

Here is a good history of llvm/clang.
 
tobik: I built databases/libgdamm5, but how do I use it? I cannot find any documentation on it.

fnoyanisi: I built lang/gcc, and I am still getting an error message when I try to run one of the SQLAPI++ test programs:
Code:
[jay /opt/SQLAPI/bin]$ ./sqltest
Shared object "libstdc++.so.6" not found, required by "sqltest"
[jay /opt/SQLAPI/bin]$
 
Fnoyanisl: I built lang/gcc, and I am still getting
an error message when I try to run one of the
SQLAPI++ test programs:
Code:
[jay /opt/SQLAPI/bin]$ ./sqltest
Shared object "libstdc++.so.6" not found, required by "sqltest"
[jay /opt/SQLAPI/bin]$

What does below command give you?
% locate libstdc++
You need to have an updated locate(1) database (see locate.updatedb(8))

If you have all paths are OK and still getting an error message about your shared object, then it comes to "GCC's backward compatibility issue".
 
After building lang/gcc, locate libstdc++.so now reports the following:
Code:
/compat/linux/usr/lib/libstdc++.so.5
/compat/linux/usr/lib/libstdc++.so.5.0.7
/compat/linux/usr/lib/libstdc++.so.6
/compat/linux/usr/lib/libstdc++.so.6.0.13
/usr/local/bootstrap-openjdk/jre/lib/amd64/libstdc++.so.6
/usr/local/lib/gcc48/libstdc++.so
/usr/local/lib/gcc48/libstdc++.so.6
/usr/local/lib/gcc48/libstdc++.so.6.0.19
/usr/local/lib/gcc48/libstdc++.so.6.0.19-gdb.py

(Parenthetically, it is interesting that the find command could not be used to determine what port must be built to provide that file:)
Code:
[jay /usr/ports]$ find . -depth 3 -name pkg-plist | xargs grep libstdc++\\.so\\.
./java/bootstrap-openjdk/pkg-plist:%%LIBSTDCXX%%%%JDK_ROOT%%/jre/lib/%%ARCH%%/libstdc++.so.6
./misc/compat5x/pkg-plist:lib/compat/libstdc++.so.4
./misc/compat5x/pkg-plist:%%AMD64%%lib32/compat/libstdc++.so.4
./emulators/i386-wine-devel/pkg-plist:%%OSREL8%%lib32/libstdc++.so.6
./emulators/linux_base-c6/pkg-plist:usr/lib/libstdc++.so.5
./emulators/linux_base-c6/pkg-plist:usr/lib/libstdc++.so.5.0.7
./emulators/linux_base-c6/pkg-plist:usr/lib/libstdc++.so.6
./emulators/linux_base-c6/pkg-plist:usr/lib/libstdc++.so.6.0.13
./emulators/linux_base-f10/pkg-plist:usr/lib/libstdc++.so.5
./emulators/linux_base-f10/pkg-plist:usr/lib/libstdc++.so.5.0.7
./emulators/linux_base-f10/pkg-plist:usr/lib/libstdc++.so.6
./emulators/linux_base-f10/pkg-plist:usr/lib/libstdc++.so.6.0.10
./math/wingz3/pkg-plist:Wingz3/lib/libc5/libstdc++.so.27.1.4
./math/wingz3/pkg-plist:Wingz3/lib/libc5/libstdc++.so.27
./net/spideroak/pkg-plist:%%DATADIR%%/libstdc++.so.6
./games/linux-etqw-demo-server/pkg-plist:lib/etqw-demo-server/libstdc++.so.6
./games/linux-etqw-server/pkg-plist:lib/etqw-server/libstdc++.so.6
./www/opera/pkg-plist:%%LIBSTDC%%lib/opera/libstdc++.so.6
even though, now that the port has been built:
Code:
[jay /usr/ports]$ pkg which /usr/local/lib/gcc48/libstdc++.so
/usr/local/lib/gcc48/libstdc++.so was installed by package gcc-4.8.4_3
[jay /usr/ports]$
so that is highly curious.

Nevertheless, I am still unable to run the test programs that came with the binary-only free version of SQLAPI++:
Code:
[jay /usr/ports]$ /opt/SQLAPI/bin/sqltest
Shared object "libstdc++.so.6" not found, required by "sqltest"
[jay /usr/ports]$
nor would I be able to otherwise use the product, because it is their own library that suffers from the unresolved dependency:
Code:
[jay /usr/ports]$ ldd /opt/SQLAPI/lib/libsqlapi.so
/opt/SQLAPI/lib/libsqlapi.so:
    libstdc++.so.6 => not found (0)
    libm.so.5 => /usr/lib32/libm.so.5 (0x282bd000)
    libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0x282e7000)
    libc.so.7 => /usr/lib32/libc.so.7 (0x2806f000)
[jay /usr/ports]$
So, how is it that I have a libstdc++.so.6 in /usr/local/lib/gcc48, and yet the system is unable to find it? And what is the point of having the file, if the system is unable to find it? Invoking ldconfig /usr/local/lib/gcc48 as root -- in case you were about to suggest that -- has no effect; nor does setting an LD_LIBRARY_PATH environment variable. Is the system perhaps demanding a 32-bit version of the library, and detecting that the installed version does not qualify? That seems to me, at present, to be the most likely explanation, in which case, how do I obtain a 32-bit version of libstdc++.so.6? As always, thank you in advance for any and all replies.
 
Friends, I have run into a brick wall at a very early stage. I am trying to build the trivial sample program at http://www.gtkmm.org/docs/libgnomedbmm-3.0/docs/tutorial/html/ch03s05.html. I get a compiler error telling me that libgnomedbmm.h is not found. This is true; no such file exists. Nor is there any unbuilt port which offers to provide such a file:
Code:
[jay /usr/ports]$ find . -depth 3 -name pkg-plist | xargs grep gnomedbmm.h 
[jay /usr/ports]$
Nor can I accomplish anything by removing from my tiny program the line which includes that nonexistent file:
Code:
[jay@keyo ~/database]$ make main 
c++ -I/usr/local/include/gtk-2.0 -I/usr/local/include/gtkmm-2.4 -I/usr/local/include/gdkmm-2.4 -I/usr/local/include/giomm-2.4 -I/usr/local/lib/gtkmm-2.4/include -I/usr/local/lib/giomm-2.4/include -I/usr/local/lib/gdkmm-2.4/include -I/usr/local/lib/pangomm-1.4/include -I/usr/local/include/libgdamm-5.0  -I/usr/local/lib/libgdamm-5.0/include -I/usr/local/include/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include/libgda-5.0 -I/usr/local/include/libgda-5.0/libgda -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/cairomm-1.0 -I/usr/local/include/freetype2 -I/usr/local/include/pangomm-1.4 -I/usr/local/include/atk-1.0 -I/usr/local/include/atkmm-1.6 -lgdamm-5.0 -lglibmm-2.4 -lsigc-2.0 -lgda-5.0 -lgobject-2.0 -lgthread-2.0 -pthread -lglib-2.0 -lintl -L/usr/local/lib -lxml2 main.cc  -o main
main.cc:9:10: error: no member named 'Db' in namespace 'Gnome'
  Gnome::Db::init("Example", "1.0", argc, argv);
  ~~~~~~~^
main.cc:11:28: error: no member named 'Client' in namespace 'Gnome::Gda'
  Glib::RefPtr<Gnome::Gda::Client> client = Gnome::Gda::Client::create();
               ~~~~~~~~~~~~^
main.cc:11:36: error: C++ requires a type specifier for all declarations
  Glib::RefPtr<Gnome::Gda::Client> client = Gnome::Gda::Client::create();
                                   ^~~~~~
main.cc:11:57: error: no member named 'Client' in namespace 'Gnome::Gda'
  Glib::RefPtr<Gnome::Gda::Client> client = Gnome::Gda::Client::create();
                                            ~~~~~~~~~~~~^
main.cc:21:25: error: no member named 'execute_select_command' in 'Gnome::Gda::Connection'
    model = connection->execute_select_command("SELECT * FROM products");
            ~~~~~~~~~~  ^
main.cc:42:10: error: no member named 'Db' in namespace 'Gnome'
  Gnome::Db::Grid grid(model);
  ~~~~~~~^
main.cc:47:14: error: use of undeclared identifier 'grid'
  window.add(grid);
             ^
7 errors generated.
*** Error code 1

Stop.
make: stopped in /usr/home/jay/database
[jay@keyo ~/database]$
So, what am I doing wrong? And, to return to the larger question, where do I find a functional portable C++ API for accessing a relational database? As always, thank you in advance for any and all replies.
 
Friends, I have run into a brick wall at a very early stage. I am trying to build the trivial sample program at http://www.gtkmm.org/docs/libgnomedbmm-3.0/docs/tutorial/html/ch03s05.html. I get a compiler error telling me that libgnomedbmm.h is not found. This is true; no such file exists. Nor is there any unbuilt port which offers to provide such a file:
Code:
[jay /usr/ports]$ find . -depth 3 -name pkg-plist | xargs grep gnomedbmm.h
[jay /usr/ports]$
This looks like a Gnome related question rather than being a FreeBSD related one. Having said that, I consulted Google and she told me it might in fact be libgnomedbmm.h, not gnomedbmm.h

Nor can I accomplish anything by removing from my tiny program the line which includes that nonexistent file:
You did not meant it, right?
 
Last edited by a moderator:
Nor is there any unbuilt port which offers to provide such a file:
Code:
[jay /usr/ports]$ find . -depth 3 -name pkg-plist | xargs grep gnomedbmm.h 
[jay /usr/ports]$
Keep in mind this might not find the file you're looking for. A port can also dynamically generate a pkg-plist, so the pkg-plist file itself may not exist.

There should be some pkg-query(8) kung-fu that can look for it in the package repository. But I can't seem to find it on short notice.
 
fnoyanisi: the grep for gnomedbmm.h would also find libgnomedbmm.h, so that was not the problem. Unfortunately, I know of no way other than the find | xargs grep technique for determining which uninstalled port provides a needed file (which can be done so easily on Linux with yum provides or apt-file find, and on Solaris with pkg search). If a port dynamically generates its pkg-plist, as SirDice informed us it can do (it was news to me), then the find | xargs grep technique fails, and if there is a pkg-query technique for finding the port that provides libgnomedbmm.h, I seek enlightenment
 
I never found a way to compile the example that included libgnomedbmm.h, and that problem remains unsolved. I was able to compile a different example that I found elsewhere, which includes libgdamm.h, and that is the API that I have been using, provided by databases/libgdamm5 (which, parenthetically, despite the name of the port, claims to be version libgdamm-4.99.8, not version 5).

For a week, all was well, and I developed a program that connected to an SQLite3 database (although "connected" is not really the right word when you're using SQLIte3). Now it is time to put away our childhood toys, however, and move on to MySQL. I upgraded my SQLite3 database to a MySQL database, which the MySQL server is ably serving to all properly authenticated clients, with cunning and vigor. In my application, in the invocation of Gnome::Gda::Connection::eek:pen_from_string, I changed the first argument from "SQLite" to "MySQL". When I run my new application, however, it bails with the succinct error message:
Code:
No provider 'MySQL' installed
and indeed the gda-sql-5.0 -L command suggests the same thing:
Code:
[jay /usr/home/jay/database]$ gda-sql-5.0 -L
** Message: Remote error from secret service: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.secrets was not provided by any .service files
Provider    | Description                    
------------+--------------------------------
Berkeley-DB | Provider for Berkeley databases
SQLite      | Provider for SQLite databases  
Web         | Provider for web server proxies
(3 rows)
[jay /usr/home/jay/database]$
So how do I access a MySQL database from the Gnome database API on FreeBSD? make config from within databases/libgdamm5 offers only one option, Berkeley DB support, and make config from within databases/libgdamm states that there are "No options to configure". As always, thank you in advance for any and all replies.
 
Back
Top