is there any database transaction mechanism in MFC/C++? - c++

I want to make sure that if any error occurs during the database processing phase, program will know it need to roll back the whole process.
any good ORM in MFC/C++ for doing this ?

The MFC _ConnectionPtr object has BeginTrans, CommitTrans and RollbackTrans methods.
http://msdn.microsoft.com/en-us/library/ms675942(VS.85).aspx
I wouldn't call it good though, you'd need to wrap it.

This has nothing to do with ORM. You want basic transaction functionality
If you're using MFC, then most likely you're working with your database either via CDatabase (ODBC), CDaoWorkspace/CDaoDatabase (DAO), or CDataConnection/CSession (OLE DB). If so, you should use CDatabase::Rollback, CDaoWorkspace::Rollback, or CSession::Abort, respectively.

If you're connecting to a transactional database, like SQL Server, Oracle, PostgreSQL, Firebird, some of MySQL's data engines, etc. then they will have an API for transactions. Similarly, some non-SQL databases also have transactional semantics and an associated API (like Berkeley DB). Since you don't mention what database you're using, I really don't know what else to say.

Debea Database Library is an ORM for C++ - http://debea.net/

Related

File based database for C++

I want to use a database in my application. But it should not be a server-based database(like MySQL). Is there any file based database systems for C++ ? It is better if you can suggest a non-relational database. like XML file based ...
Why, yes, there is. Try SQLite.
you can try this:
ZWinSQL
This C++ library provides a thin wrapper to use D. R. Hipp's SQLite, which is a single file based SQL database. ZWinSql does not much more than allow you to create, modify and query a database, contained in a single, local file, using standard SQL commands.
I'm not sure what you mean by file-based database. For example, Informix and MySQL keep their data in files.
However, you mentioned non-relational database, so I suggest you start with couchdb or mongoDB.
SQL lite is an excellent relational database, and, if you are already used to SQL, would be a very good choice IMHO. I have not yet ventured into any production code with a non-relational database, but just looking at key structure makes me realize a lot of thinking above and beyond regular SQL database table design would be involved before I'd feel safe just throwing data into a non-relational database.
if you are not looking for relational database maybe http://soprano.sourceforge.net is something that might suit you. it can be set up to work with local files directly

using sql without any server

I have a question regarding SQL. Is there any way to connect to a database without a server into sql (no localhost or anything). I want to use SQL for a resource management in c++. I found the API but I need to know if that's possible, so I can use it like that.
Try SQLite.
SQLite is a sql-like database system that saves the database state to a single file somewhere on the file system, as opposed to requiring a full server. It does not have the full performance optimisations in SQL terms of full servers such as Postgres or MySQL; however, it does not require the overhead of a server.
Theres many options, one I know of is SQL Server Compact
Here's a link to microsoft's API for accessing SQL Server Compact via C++

Why does django community encourage the use of Postgres over Mysql?

Django community seems to encourage the use of Postgres, I understand that in a big project you probably don't want to use SQLite or such, but i don't know why they don't like Mysql that much.
just a quick example - Djangobook page 9:
We’re quite fond of PostgreSQL ourselves, for reasons outside the scope of this book, so we mention it first. However, all those engines will work equally well with Django.
Postgres name is always associated with Django - just like Mysql is always associated with php
Best answer might be given to this quiestion is from those who writes the Framework...
But from what you can get from documentation is:
By default, Django starts a transaction when a database connection is first used and commits the result at the end of the request/response handling. The PostgreSQL backends normally operate the same as any other Django backend in this respect.
Django have a strong Transection control, and using a powerful free DBMS that have strong transection control is a plus...
Also, previous versions of Mysql (before mysql 5.0), MySql have some integrity problems. Also MySql's fast storage engine MyISAM do not support foreign keys and transections. So using MyISAM have important minuses that its pluses...
And a wiki for why Postgres is better than Mysql. Its quite old but it is good.
I have never used PostgreSQL myself, so I can't really say much about the advantages it is supposed to have over MySQL.
But from what I've gathered, transaction handling is better supported by PostgreSQL out of the box. If you use MySQL, changes are that you will use MyISAM as storage engine, which doesn't support transactions.
https://docs.djangoproject.com/en/dev/topics/db/transactions/#transactions-in-mysql
Maybe the Django devs just got sick and tired of having to deal with bug reports where transactions didn't work, but the problem was due to MyISAM and not Django.
The South developers (the most used database schema migration framework for Django) apparently aren't to fond of MySQL either, which this message suggests that I've seen quite often with MySQL:
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had to
! leave it in an interim state between migrations.
[...]
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
I've always used Postgres whenever possible, partly because of maturity and because of the PostGIS extensions that add spatial data capabilities to the database. Even if I don't think I'm going to want spatial data in my application at the beginning its much easier to add it on if your DB supports it, rather than have to tear out MySQL at a late stage and replace it with PostGIS.
I think there is a spatial extension to MySQL now, so you might be able to do spatial operations in that now. But Postgres just does it and has been doing it for years.
Or I could spend $$$$$ for Oracle Spatial, I suppose...

Lightweight integration of MySQL into a C++ Project

I am working on a cross platform that needs to use a database to store information. I was thinking because MySQL is opensource, would it be possible to remove the networking components from MySQL so that the program can directly interact with it. Is this possible, or should i just ship the install with a copy of mysql server with all the settings predefined and use a connector.
SQLite has what you need. http://www.sqlite.org/
I think in theory you could do that, but I'm not sure if the amount of work would be worth it and the chances of breaking something would be pretty high. I would just ship mySQL with your application.
Or use sqllite as suggested by someone else.
It could be possible, but I am not sure it is worth it (or else, use something like sqlite or even gdbm).
MySQL is quite robust (thousands of developers, millions of users) so in practice you should consider it won't crash.
Your own application might be less robust. It probably would crash. Then having MySQL still running ensures you that the data are in a sane state.
And you might perhaps be later interested in having some other (perhaps external) application doing SQL requests to your MySQL database, or give the ability to have the MySQL database on a remote server.

Persistence solutions for C++ (with a SQL database)?

I'm wondering what kind of persistence solutions are there for C++ with a SQL database? In addition to doing things with custom SQL (and encapsulating the data access to DAOs or something similar), are there some other (more general) solutions?
Like some general libraries or frameworks (something like Hibernate & co for Java and .NET) or something else? (Something that I haven't even thought of can also be welcome to be suggested)
EDIT: Yep, I was searching more for an ORM solution or something similar to handle sql queries and the relationships between tables and objects than for the db engine itself. Thanks for all the answers anyway!
SQLite is great: it's fast, stable, proven, and easy to use and integrate.
There is also Metakit although the learning curve is a bit steep. But I've used it with success in a professional project.
It sounds like you are looking for some ORM so that you don't have to bother with hand written SQL code.
There is a post here that goes over ORM solutions for C++.
You also did not mention the type of application you are writing, if it is a desktop application, mobile application, server application.
Mobile: You are best off using SQLite as your database engine because it can be embedded and has a small footprint.
Desktop App: You should still consider using SQLite here, but you also have the option with most desktop applications to have an always on connection to the internet in which case you may want to provide a network server for this task. I suggest using Apache + MySQL + PHP and using a lightweight ORM such as Outlet ORM, and then using standard HTTP post calls to access your resources.
Server App: You have many more options here but I still suggest using Apache + MySQL + PHP + ORM because I find it is much easier to maintain this layer in a script language than in C++.
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
SQLite + Hiberlite is a nice and promising project. though I hope to see it more actively developed. see http : // code.google.com/p/hiberlite/
I use MYSQL or SQLite.
MYSQL: Provides a server based DB that your application must dynamically connect to.
SQLite:Provides an in memory or file base DB.
Using the in memory DB is useful for quick development as setting up and configuring a DB server just for a single project is a big task. But once you have a DB server up and running it's just as easy to sue that.
In memory DB is useful for holding small DB such as configuration etc.
While for larger data sets a DB server is probably more practical.
Download from here: http://dev.mysql.com/
Download from here: http://www.sqlite.org/