Connect an SQL to c++ project in visual studio 2015 - c++

I'm writting a tic-tac-toe game in c++ and I want to create a hight scores view. The problem is I'm new to DB and now just theory of SQL.
So, how can I add a simple SQL table to my c++ project?
(id INTEGER PRIMARY KEY, name TEXT, hightScore INTEGER)
Looks like just adding to project SQL script file and creating this table not gonna work. How to connect it with my cpp files? Where and how I'll be able to make an INSERT after each new game was played?
Thanks in advance!

To have a simple table you'll need to have a database to set the table up within. The library you will use to communicate with the database is going to depend on which database you are running.
Setting up the needed libraries usually means installing them and updating your linker. This will require some research and effort on your part to make it work, depending on what your particular configuration is.
some ideas:
(for mysql there is mysql/mysql.h which is a free library. )
How to make #include <mysql.h> work?
(for other SQL databases (not free))
http://www.sqlapi.com/
(possible free alternative to sqlapi )
Free alternative to SQLAPI++?
Hopefully that will get you started in the right direction! Good luck.

I have researched about c++ database connectivity and i could find following ways to connect to SQL server database from c++ project.
Using Microsoft's ODBC connection method. Which is a little bit complicate method and requires thorough research to use further.
Ref: https://www.techhowtos.com/programming/how-to-connect-to-sql-server-from-visual-c-plus-plus/
Using SQLAP++ Library which is very convenient way to connect to a databse . It Requires to purchase one time license to use commercially.
Using CPPCMS project's CppDB library.

Related

How to create a database in Clion using C++?

I have a already created game and want to include a login system using a real database, no files. The game is written in C++ with SFML in Clion. I am also on Linux Mint.
I am new to this so I am wondering how to go about it. What kind of tools would i use? Hope this question is not to close asking for recommendation. I just don't know where to start.
Easiest way is to use SQLite. You can read about it here - https://www.sqlite.org/capi3ref.html
But if you want "real" SQL database, you can go with MySQL - http://dev.mysql.com/doc/refman/5.7/en/c-api-function-overview.html

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.

How to create offline database to be used with c++

I saw already some questions with similar topic but my one is more of a beginner question.
I have already some experience with C++ and Microsoft Access but never came across how to actualy create or (if its not possible) than how to use an offline database similar to Access.
For example:
MS Access has its own tables etc... so I am about to build a program that will need offline database.
I think that to use simple txt files would not be the right way... What is my next option? Is there a way how all other programmers do it? Or would I just have to use one of the database providers like MySQL?
I think some people use SQLite for this purpose. I don't know that much about it, but you can learn more here:
http://www.sqlite.org/about.html
If you are on a Microsoft stack, then you may want to give a try to SQL Server Compact.
Alternatively, you may want to use SQLite; it is not so integrated in the Microsoft ecosystem, but it is Open Source, and is widely used.
You can use the ODBC driver and link it with your database source file. Just read this:
http://msdn.microsoft.com/en-us/library/ca6axakh%28v=vs.80%29.aspx
After setup your source use odbc api in your c++ code in order to make your queries. Also you can try to use ORM solutions in order to access your database.
http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software
+1 for sqlite
If you're not actually interested in doing SQL-like queries, you could look at
Serialization (e.g. boost)
Boost Property Tree (focuses on structured config data, AFAICT)
LevelDB (highperformance key-value store by google)
Cf. also hints on memory-mapping standard containers here:
LevelDB vs. std::map

Making SQL query from C++

I have connected to an MS Access database from my project. Now I want to make a query, for example to take out data from third and fourth column.
How can I write SQL query in C++/CPP, using visual studio 2008?
If you're using a framework like MFC, Qt, or wxWidgets, you probably want to use the database connection classes they already include.
If you're not using one of those, you probably want to look into another library specifically for the purpose, such as DTL or SOCI.
You can obviously write your own code to talk to the database via something like OLE DB or ODBC, but they both involve quite a lot of boiler-plate, so a library helps out a lot.

Getting started with SQL express from a c++ console application

Right now I am writing a little c++ console program using VS2010 Express. The next thing I want to do is to access a SQL database from within this program.
I've downloaded SQL server 2008 express. I've managed to set up a little db using the db gui.
My question now is, how do I access this db from within my program. Which header files do I need, how do I connect? About the basic tempering with the db itself I have found many tutorials, but this tiny bit that closes the gap between a program and the connection to the db drives me nuts... If any one has a nice tip to a tutorial or book, please let me know.
I've also tried to start a new project in VS, and was hoping to find some kind of setup wizard for a "sql project" that would get me one the way but did not find such a wiz...
Microsoft doesn't provide much for SQL connectivity from C++ console applications. There are a number of libraries such as SOCI and DTL that can help though.