Connect to oracle database with C++ - c++

I am looking for a way to connect to an remote oracle database and read some data from table within a c++ console application.
Can some one give me some hints.
Thnx.

soci, http://soci.sourceforge.net, is a reasonably modern C++ interface that uses the Oracle call interface. And can also connect to other databases ...

The official Oracle website proposes several resources. Amongst others:
Oracle C++ Call Interface
Develop C and C++ Applications with Oracle Database 11g Using OCI
Just google, there are really plenty of tutorials around.

You can either use the Oracle C++ Call Interface (native API) or the Open DataBase Connectivity API. If you want a more high-level wrapper, there are some more convenient interfaces in libraries such as Qt.

Unless it's study purpose or strict requirement with ORACLE DB, I'd suggest you to work with generic classes/services provided with various Microsoft Framework.
Data Access Programming
MFC Database classes
ATL Database classes
Of course ORCACLE C++ IF is also available.

You can use OCCI: http://www.oracle.com/technetwork/database/features/oci/index-090820.html
or OCI: http://www.oracle.com/technetwork/database/features/oci/index.html
or one of many other APIs available.. It really depends on the type of thing you're going to use it for.. You should find a lot of information about the pros/cons of the various APIs through google..

You can try: CODBC. It is an API for Pro*C. Pro*C is a very decent way to connect Oracle and C++.

Currently (2021) actively developed is also OCILIB, I was able to setup the test example in short time.

Related

Can I use an ADO.NET library in C++ to read Oracle DB?

Apologies if this is a bit of a vague question; I'll try to word it as appropriately as I can.
Basically I have a C++ application that currently runs off of a back-end MSSQL (SQL Server 2014) database. To ease in database communication and building the entity model we assembled our own set of C++ classes that wrap up the native ADO.NET calls; we have created it in such a way that the developer simply needs to supply details for a connection string and it is assembled as part of the connection method like so:
string.Format(_T("DRIVER=SQL Server;SERVER=%s\\%s;UID=%s;PWD=%s;DATABASE=%s"),string,strConnInstance,strUser,strPassword,strDatabase);
We now have a requirement to read from an oracle database, and we wonder if we can use the same connection libraries. I assume that we will need to tweak the connection string (e.e.g the driver would need to read something different). I believe I have read that Oracle connection can be faciliated through use of an ODBC driver? Would it simply be a case of installing the relevant driver (if so, which?) and changing the "Driver" argument in the connection string (if so, to what?).
If it is not quite this simple, is there any other way it can be done, or are we looking at a redevelopment?
Thanks in advance!
The answer is yes you can use ADO.NET to connect to Oracle. There's plenty of people out there on stack overflow already doing it...
https://stackoverflow.com/search?q=oracle+ado.net
Oracle has a page for the db provider...
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
Microsoft has a page talking about it...
https://msdn.microsoft.com/en-us/library/77d8yct7(v=vs.110).aspx
Oracle even has examples using Entity Framework...
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/EntityFrameworkOBE/EntityFrameworkOBE.htm
http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51odt-453447.html
There's heaps of resources out there.

Which are suitable local database (easy to handle with C++) for a small data set

The computer has already been installed ORACLE. But I didn't try ORACLE before, I just use sqlite...So, for now I want to create a database locally, and just insert one table. I want to use a test C++ program to read and write in this database. Is there something useful for using API about this? BTW, in the computer I saw SQL plus and SQL developer, but I didn't find the DBCA, which I know can be used to create table...help me, thanks a lot!!
BTW, my supervisor wants to me to test different kinds of database, which will be written in my report. So I want to test different kinds of databases, for the data is quite small, just 100 lines in a table is enough, but it will be applied in a big program, so I need to try different kinds of database locally, and not difficult for me to use C++ API...Because I just know little about database. I need some suggestions, thank a lot!
While I wouldn't recommend Oracle for handling small data sets, I do have a pointer to C++ API documentation.
http://www.oracle.com/pls/db112/portal.portal_db?selected=5&frame=
... and scroll to the bottom of the page for links to further information.
There's a choice of either using C++ with Oracle OCI API, or using C++ with Oracle Pro*C precompiler. The precompiler actually does produce code that uses the OCI API.
I have done some work with the Pro*C precompiler (using C as the implementation language, though, not C++), and it wasn't too bad. OCI tends to be quite low-level, but apparently writing direct OCI code has its uses, too.

Sqlite3 ORM for C++ implementing lazyloading

What would you suggest to use in the following scenario:
Desktop application in C++
Cross platform (might use wxwidgets)
Sqlite3 DB (no concurrent accesses by different users)
Would like some kind of configurable lazy loading mechanism, meaning certain parts of an object can be loaded at different moments.
I would like to use an ORM to reduce CRUD code, is there any of them that fits the bill?
Do I need to write my own ORM?
Thank you and best regards.
ODB is a C++ ORM released under GPL (or a purchasable commercial license) that supports SQLite. It also supports lazy-loading of relationships and is cross-platform.
See http://www.codesynthesis.com/products/odb/features.xhtml for details.
Qt is an excellent cross-platform development environment, and someone's written an ORM which goes well with it.
Can you elaborate on the requirements for lazy loading?

Is there a database access library for C and/or C++ with a similar interface to Perl's DBI?

I'm willing to write a subset of Perl's DBI interface for libodbc (or unixODBC) in C++.
I believe doing so will allow me concentrate better on my goal.
BTW, I prefer avoiding to reinvent the wheel, if of course something similar is already out there.
NVM, no odbc interface, but it is DBI like (seeing as DBI doesn't use odbc except in DBD::ODBC)
libdbi - http://libdbi.sourceforge.net/
libdbi implements a
database-independent abstraction layer
in C, similar to the DBI/DBD layer in
Perl. Writing one generic set of code,
programmers can leverage the power of
multiple databases and multiple
simultaneous database connections by
using this framework.
In order to utilize the libdbi
framework, you need to install drivers
for a particular type of database. The
drivers officially supported by libdbi
are split off into the libdbi-drivers
project. The current version of libdbi
(0.8.3) is supposed to work with any
0.8.x release of libdbi-drivers. Currently the following database
engines are supported:
* Firebird/Interbase
* FreeTDS (provides access to MS SQL Server and Sybase)
* MySQL
* PostgreSQL
* SQLite/SQLite3
I don't know a DB API that looks like DBI. Go for it - but add it to the libodbc project as a wrapper API rather than start a brand new project.
good luck.

C++ Program communicating with MySQL Database

Does anyone know of a simple way for a C++ program to communicate directly with a MySQL database? I have looked at MySQL++ and found it to be very confusing. If anyone knows of a very simple way of doing this, please let me know.
Thanks
P.S. I am developing on a Windows machine. PHP and MySQL web web application setup. C++ setup to talk to the serial port. Thus why I need a way for C++ to talk to the MySQL database directly.
There are quite a few database API wrappers but my favourite - and the one I recommend - is the SOCI library. Much nicer syntax than using the raw C API.
The 'motivating' example from the SOCI website:
int id = ...;
string name;
int salary;
sql << "select name, salary from persons where id = " << id, into(name), into(salary);
The C MySQL API is just like using the PHP MySQL extension and so should be pretty familiar. If you are comfortable with C, I'd recommend that (and you don't mind mixing C in your C++).
Use the C API:
http://dev.mysql.com/doc/refman/5.0/en/c.html
MySQL has a beta release of MySQL Connector C++ that can be found Here. It's a connector written in C++ but modeled after Java's JDBC connectors. If you've used JDBC at all, this will feel almost identical. It's also cross platform and can be compiled on Linux, Windows, and Mac OS.
I have used MySQL++ with great success. I found it to be everything I was looking for in a MysQL database client library. The examples they provide are great, see here for a simple one.
If you know C++, it is much easier to use than the C library. It works great with Windows.
Use SQLAPI++ - it does SQL Server and more.
http://www.sqlapi.com/
MySQL Connector/C++ is a C++ implementation of JDBC 4.0
The reference customers who use MySQL Connector/C++ are:
- OpenOffice
- MySQL Workbench
Learn more: http://forums.mysql.com/read.php?167,221298
Are you sure that the C++ program needs to interact directly with the MySQL database?
I would suggest having the C++ program communicate with the web server using simple http requests, and let PHP handle the database. Data can be passed to a server-side PHP script via arguments, and data can be returned in XML format.
Writing: your.server.com/add_data.php?table="info"&data="0xFCBD..."
Reading: your.server.com/get_data.php?table="info"