Database Access Libraries for C++ - c++

Background:
I have an application written in native C++ which uses the wxWidgets toolkit's wxODBC database access library which is being removed from all future versions of wxWidgets . I need to replace this with another database access method that supports the assumptions and contraints outlined below. I don't require that the replacement use native DBMS APIs or ODBC under the hood, but it must meet the contraints outlined below.
Assumptions/Constraints
The library must:
Support Native (i.e. unmanaged) C++
32-bit Windows 2000/XP/2003
Visual Studio 2005
Microsoft SQL Server 2000 and 2005
Oracle 9 and 10
Run-time Performance greater than or equal to wxODBC
Single programmer API supporting multiple DBMS (e.g. don't want to write different code for using different DBMS)
Nice but Optional:
64-bit Windows operating systems
32-bit and/or 64-bit Linux operating systems
Microsoft SQL Server 2008
Oracle 11
MySQL
Any additional DBMS
Visual Studio 2008
Open Source
Runtime Performance near or equal to native DBMS API
Question:
What good libraries are available - either free, open source or pay - that support multiple DBMS from a single API including Oracle and Microsoft SQL Server and can be used from native C++?
Please describe any past experiences you have had - good OR bad - with a given library and why you are making your recommendation for or against a given library, especially in regards to the assumptions and contraints above.
See Also:
https://stackoverflow.com/questions/74141/good-orm-for-c-solutions

I use SQLAPI++. Well worth a look.
http://www.sqlapi.com/

A library is http://otl.sourceforge.net/
An employer of mine used it.
I can't tell you how its performance compares with wxODBC, but it might fit your requirements.

You can use SOCI http://soci.sourceforge.net or also Wt::Dbo, http://www.webtoolkit.eu and look at the Wt::Dbo component.

You can check Debea - SQL Database Access and ORM for C++. It has API for wxWidgets built-in.

Qt is also an option. It supports the connections to the servers you want, and quite simple to use.
http://doc.trolltech.com/4.4/sql-driver.html#supported-databases
When using Qt, you don't need to build against all Qt. You can for example just use the SQL part, and leave the whole GUI part outside.
Since it has been recently LGPL-ed, you can also use it for a proprietary application.

Related

C++ manipulating mdb database

I want to create an app based on the content of a .mdb file, I searched for libraries to do that in native but they all needed requirements, I want a way to read these files using native code(C++) only, so I could use the library in multiple platforms.
Thx,
Regards
The .mdb file format is specific to the Microsoft Access ("Jet") database engine, which is proprietary and specific to Windows. (Furthermore, it is an evolving file-format, although it does not seem to continue to be in active development now.) There is one, and only one, "correct" way to use it, and that is: to use Microsoft's library and surrounding framework, on Microsoft's operating system.
If, indeed, you need to use a "file-based SQL engine," "on multiple platforms," then I would cordially suggest that you instead use a database file format that was specifically designed for such purposes: SQLite.
Mind you, the two are not the same. They're the product of two entirely different design teams who had different purposes in mind. The SQLite team knowingly did not adhere strictly to the SQL standard. But, what they did do was to create a public domain(!) database engine, which uses a single file, and which was specifically designed to be cross-platform. Meanwhile, the Jet team designed their engine specifically, and solely, in support of the Access (and Excel) products of their company.

How to use SQLite within a WinRT DLL?

I am trying to develop a WinRT DLL which uses SQLite to write database.
But it seems like some win32 APIs in SQLite source code are not supported by metro, such as, LoadLibraryW, GetTempPathA.
Is there any way to compile SQLite source code or use SQLite with WinRT DLL?
Well you could always link sqlite3 statically and define new functions for accessing files etc via sqlite3_vfs.
In VS2012 there is an extension now called SQLite for Windows Runtime. You can download and install this via Visual Studio (requires a restart of the IDE). Then, go to your WinRT project, Add a Reference, under "Windows" choose "Extensions" and you should see it.
There's a winrt branch of SQLite now that only uses supported API. On top of that, we implemented SQLite3-WinRT, a WinRT component that allows using SQLite in any of the WinRT languages.
rename sqlite3.c to sqlite3.cpp
replace LoadLibrary with LoadPackagedLibrary
Fix lots of syntax errors.
From the SQLite site
SQLite version 3.7.13 adds support for WinRT and metro style applications for Microsoft Windows 8. The 3.7.13 release is coming sooner than is usual after the previous release in order to get this new capability into the hands of developers. To use SQLite in a metro style application, compile with the -DSQLITE_OS_WINRT flag. Because of the increased application security and safety requirements of WinRT, all database filenames should be full pathnames. Note that SQLite is not capable of accessing databases outside the installation directory and application data directory. This restriction is another security and safety feature of WinRT. Apart from these restrictions, SQLite should work exactly the same on WinRT as it does on every other system.
Tim Heuer provides a walk-through of building a metro app using SQLite on his blog
Let me add some remarks on using sqlite/winrt that may save you some headaches:
Winrt allows you to write only to specific folder (c:\users\<user>\My documents\<app>). You have to put your DB here. (Trivial in managed environment.)
Time from time Sqlite uses temp files. (Complex queries that need transient indices, vacuum etc.) These files also must be created in the app folder, but sqlite won't do this unless you set it with temp_store_directory pragma. If you don't do this, you may get random user bug reports.
Note that above pragma is officially deprecated. Ignore this. Native coders might be tempted to use global variable sqlite3_temp_directory instead (encouraged way), but the current binary release (dll) does not publish this variable. (You can do it yourself, but then change sqlite sources and use _declspec(dllexport) attribute; def file does not work.)
Don't rely too much on sqlite file operations. The implementation is not particularly good. For example testing of write access will succeed even if you don't have write permissions.
Apart from this there seem to be no problems with winrt. More advanced users might supply their own (better) winrt driver. It is not too difficult...

Connecting to a SQL Server Compact Edition (.sdf) from an MFC application

I'm building an MFC app in Visual Studio 2008 which classifies textures and I need some sort of lightweight database to hold the characteristics (just some doubles and strings) which can be:
Carried around with the app on different computers
Be able to perform queries on it from the app (searches , updates ,inserts ,etc)
Currently I'm looking into SQL Server Compact Edition because it was very easy to create from Visual Studio (I also need only one table). But I;m having a hard time connecting and updating the database from C++.
This is what I've found on MSDN regarding C++ and SQLCE:
public:
void createSqlCeConnection(){
SqlCeConnection* myConnection = new SqlCeConnection();
myConnection->ConnectionString = "DataSource = blabla.sdf";
MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));
}
Unfortunately my experience with .NET apps is pretty limited.
Hopefully you bright minds could tell me if I'm on the right path and what links and includes should I add for this to work with an C++ MFC projects.
For C++ applications, you're going to want to use the OLE DB Provider for SQL CE. For example, take a look here for a code snippet on initializing a Session (you might have to explicitly click the C++ tab in the Examples section).

Can I make a rather native C++ app with Android?

I'm interested in the following features:
Writing an app for Android Market that is written completely in C++ (a port of existing product actually).
Use fast screen-buffer pixel pushing (or rather using OpenGL ES for this).
Grab user input and direct it to C++ code.
Is it legal to write such an app for Market? Is Market policy somehow strict to such things?
As of NDK r5 with Android 2.3 (Gingerbread) this is possible, although I assume only devices to support natives apps must have Gingerbread on them.
From the native-activity sample:
The Android SDK provides a helper class, NativeActivity, that allows you to write a completely
native activity. With a native activity, it is possible to write a completely native application.
NativeActivity handles the communication between the Android framework and your
native code, so you do not have to subclass it or call its methods. All you need to do is declare
your application to be native in your AndroidManifest.xml file and begin creating your native
application.
It is really not my cup of tea but there is something called Android NDK (Native Development Kit) to use if you want to write your program in C. Not sure how the C++ compiler support is though.
As far as I know your app can be almost 100% native code but keep in mind that by walking that way you will probably have a hard time supporting the different CPUs out there in Android hardware. If you need to bootstrap the native code so that it is started from java it is probably not a very big problem for you.
I found a few different tutorials when googling for "Android NDK". This one is a very minimalistic Hello World. Obviously you want something much more than a library that returns a string to java but it is a good first start and you will probably have to do all of the things described. Do a search using NDK and Android as keywords and you get a good selection. I see no reason to list them here as such lists tends to be outdated and broken within a year or so.
I guess the official Android Developer site from Google will stay put and be updated on new releases of the platform, it has a link to the current NDK.
With Gingerbread (Android 2.3) it looks like you can build your entire app in C++.
cf:
http://phandroid.com/2011/01/11/android-developers-blog-awesome-ndk-leads-to-awesome-apps/
"
With the latest version of the NDK, r5, many big improvements have been made to coincide with the release of Gingerbread. The most major is the ability to code a native application for Android 2.3 entirely in C++. This means even programmers and developers with no Java knowledge won’t have to implement a single line of that code..."
Can't vouch for the veracity of this blogger, however, from what I have read, it appears you can do this
There is no 100% native solution but what I think you are looking for is the Android NDK (Native Development Kit)
From their site "Please note that the NDK does not enable you to develop native-only applications. Android's primary runtime remains the Dalvik virtual machine."
I believe it lets you make calls to your own native code from an Android application
I have personally never used it for my games, but I am sure it would help on a lot of things (like being able to manage my own memory and not have "lag" do to the garbage collector)
conversations in this thread can help you.
http://groups.google.com/group/android-ndk/browse_thread/thread/50362904ae0574cf
essence is,
It is possible to make Native only apps and Android Market doesn't restrict you either.
But with limited support for native development, there is high chance of using some of the non standard functionality which might break in future releases.
http://developer.android.com/guide/basics/what-is-android.html
"The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language."
http://arstechnica.com/open-source/news/2009/06/android-goes-beyond-java-gains-native-cc-dev-kit.ars
In general, you don't. There is some limited C++ support through JNI, but it is mostly intended to supplement Java code, not replace it. There's no framework/API support (AFAIK) for C++, so doing this isn't really an option.

In native C++, how does one use a SqlCe .sdf database?

Is there a simple way, without .NET?
I've found some libraries but none for SqlCe 3.5. There is http://sqlcehelper.codeplex.com/ but it's far from done, since a major feature like using a password is not yet implemented. I've looked at the source and it uses OLEdb to handle the database.
The official Microsoft Northwind example (that is shipped with SQL Compact 3.1, but not with 3.5) also doesn't work, I've tried setting it up with no success.
Actually I don't have a sample working code. Was anyone able to set it up paired with a passworded .sdf?
What are the alternatives?
Thanks.
Several months ago, I compared certain database implementations for our desktop application. Using SqlCE with native C++ code is awful. If I remember right, some of native examples contains "goto" type jumps, hard to bind data and so on. If you have a choice then use SQLite.