Skip to main content
gamedev.net
🔒 Locked

C++ and SQL

Started by OpenGL_Guru Jan 9, 2007 at 9:22 AM 12 replies 1k views
Original Post
OpenGL_Guru
OpenGL_Guru
hi all. i have a GUI that i wrote in C++ and need to transfer this information to a database. my manager is actually going to help me out on this one since this is more of his realm but i was wanting to go ahead and get a head start. i haven't really done any SQL stuff before.. not professionally that is(i am not counting school) and was wanting to know whats the best resources online(or any resource) that would give me a good head start? i have heard before that C++(using Visual.NET) and SQL dont play nice together but thats just what i have heard in the past. thanks in advance!
heh
Evil Steve
Evil Steve
It depends on the SQL server exactly. I use MySQL, and the C libs for it are pretty straightforwards to use.
OpenGL_Guru
OpenGL_Guru
Quote:
Original post by Evil Steve
It depends on the SQL server exactly. I use MySQL, and the C libs for it are pretty straightforwards to use.


i think we are using SQL Lite
heh
OpenGL_Guru
OpenGL_Guru
i was wrong. just got to talk to the boss. we are using just mySQL.

he said he knows SQL has a good C interface and would rather not use any 3rd party C++ wrapper.

basically i just need to be able to write stuff to a database and read from it working in Visual Studio.NET 2003. the SQL server is already running and functional. are there any quirks with mySQL and this IDE?

thanks!
heh
OpenGL_Guru
OpenGL_Guru
i guess i should just edit the last post but ill add something else.

i just downloaded and installed the sql OBDC Connector 5.0 for windows.

i also noticed that in the .NET environment there is a tools->Connect to Database. i dont think the boss wants to do this..like windows keeping up with it because then he is afraid it wont be portable. he is looking to embed the sql connect and commands in .NET itself.

isnt there just a mySQL.connect or something like that? then all i need to do is start inserting tables?

THANKS!

[Edited by - OpenGL_Guru on January 12, 2007 8:18:37 AM]
heh
Bregma
Bregma
Quote:
Original post by OpenGL_Guru
i just downloaded and installed the sql OBDC Connector 5.0 for windows.

i also noticed that in the .NET environment there is a tools->Connect to Database. i dont think the boss wants to do this..like windows keeping up with it because then he is afraid it wont be portable. he is looking to embed the sql connect and commands in .NET itself.


Um, .NET isn't portable (and don't let people convince you Mono makes it portable). Your best bet, if you want portability, is to use ODBC. Write your GUI in .NET using ODBC to talk to any popular RDBMS. If you move your GUI to another platform, use whatever (Cocoa, KDE, Gnome, Java, Oberon3) and ODBC to talk to your RDBMS.

There's really no other portable way.

--smw
Stephen M. Webb
Professional Free Software Developer
OpenGL_Guru
OpenGL_Guru
Quote:
Original post by Anonymous Poster
simply use ODBC and your stuff should be fairly portable and easy to get to work under Win32, too.
There's tons of excellent info on the mySQL website


ok i didnt go through the tools->connect to database. instead i went to admin tools and adding the database info myself, including password, data source etc etc.

i did a test and it worked perfect -- it connected without any hitches.

now in my code in my .cpp file i included this line...

using Microsoft.Data.Odbc;........string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +            "SERVER=localhost;" +            "DATABASE=test;" +            "UID=venu;" +            "PASSWORD=venu;" +            "OPTION=3"; OdbcConnection MyConnection = new OdbcConnection(MyConString); MyConnection.Open();


but i get compiler errors:

error C2143: syntax error : missing ';' before '.'
error C2873: 'Microsoft' : symbol cannot be used in a using-declaration

i get a lot more but i think that its all from the first couple of errors. do i need to include anything in my header file or in my project properties??

thanks again!
heh
Telastyn
Telastyn
Quote:
Original post by Bregma
Quote:
Original post by OpenGL_Guru
i just downloaded and installed the sql OBDC Connector 5.0 for windows.

i also noticed that in the .NET environment there is a tools->Connect to Database. i dont think the boss wants to do this..like windows keeping up with it because then he is afraid it wont be portable. he is looking to embed the sql connect and commands in .NET itself.


Um, .NET isn't portable (and don't let people convince you Mono makes it portable). Your best bet, if you want portability, is to use ODBC. Write your GUI in .NET using ODBC to talk to any popular RDBMS. If you move your GUI to another platform, use whatever (Cocoa, KDE, Gnome, Java, Oberon3) and ODBC to talk to your RDBMS.

There's really no other portable way.

--smw


http://www.mono-project.com/MySQL

I can't speak to the MySQL provider, but the Sybase provider works like a charm off of unix systems. Not to say Mono is to the level of the Microsoft releases, but to say something like this is absolutely not portable is simply false. It might be infeasible if you need certain features, and it might be if your boss wants to avoid Mono (for even unreasonable reasons), if you can't distribute/install the dll... but it also might be a good option.
OpenGL_Guru
OpenGL_Guru
i think i might be leaving out a certain header file because of the error i get about trying to use namespace in the code above.

anyone know what i might need to do? thanks!
heh
OpenGL_Guru
OpenGL_Guru
i make sure that i have Microsoft.Data.obdc.dll in my .NET folder. i also went into my project properties->C++ and under:
Resolve #using references i browse for the Microsoft.Data.obdc.dll and add that in. then in my workspace under References i also add it.. yet i get an error when doing this:

//in class.cpp
 using namespace System;using namespace Microsoft.Data.Odbc;


Quote:

: error C2871: 'System' : a namespace with this name does not exist
: error C2143: syntax error : missing ';' before '.'
: error C2871: 'Microsoft' : a namespace with this name does not exist
: error C2059: syntax error : '.'


i cant even resolve the system namespace. any help on what i need to include?
heh
Emmanuel Deloget
Emmanuel Deloget
Using Visual C++ .NET doesn't mean that your C++ program automagically supports .NET - as a matter of fact, only Managed C++ program does, and it seems that you are not working on a Managed C++ program.

So: what are you trying to do exactly, in what environment, with which tools?
Bregma
Bregma
Quote:
Original post by OpenGL_Guru
error C2143: syntax error : missing ';' before '.'
error C2873: 'Microsoft' : symbol cannot be used in a using-declaration


(1) I don't think you want a using directive here. I don't know the syntax of the C++/RTL language but I suspect you want to use 'import' here to include .NET assemblies?
(2) don't try to concatenate const char arrays with the '+' operator.
#include <string>using namespace std;int main(){  string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};"                       "SERVER=localhost;"                       "DATABASE=test;"                       "UID=venu;"                       "PASSWORD=venu;"                       "OPTION=3";}


--smw
Stephen M. Webb
Professional Free Software Developer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.