Jump to content
  • Advertisement
Sign in to follow this  
Narusegawa

Database

This topic is 4966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure if this is the right place to ask this, but here goes anyway. I checked the FAQ first and couldn't find an answer and checked this forum too. I'm fairly new to C++, and I'm used to doing things with Databases in Delphi and VB6. Does anyone know of a fairly easily useable class/library for accessing MySQL and MSSQL databases and being able to iterate through a Dataset. In Delphi I had ADOConnections, ADOQuerys and ADODatasource's. I'd simply specify the database type and login credentials to the connection and initiate it. I'd link the Datasource to the Query and Query to the Connection. Then when I ran a select * from scheme.slcustm the datasource would be filled. I'd then do something like
ADOConnection.Connect;
ADOQuery.Connection := ADOConnection;
ADOQuery.Close;
ADOQuery.SQL.Text := "select * from scheme.slcustm";
ADOQuery.Open;

while not ADODatasource_Cust.Dataset.EOF do
begin
  ShowMessage(ADODatasource_Cust.Dataset.FieldByName('accountid').AsString);
  ADODatasource_Cust.Dataset.Next;
end


That's just a simple showing a message to the user for each result. Thanks kindly in advance

Share this post


Link to post
Share on other sites
Advertisement
Sadly I don't have much experience with MySql and I'm using a proprietary DBLib object when I need to access my SQLServer for our tools. But, if I remember well, MySQL comes with a C++ example (although I can't remember the exact name at this time) using a connectivity class they give with the database.

You can also check CodeProject. They have examples (with source code) for connecting to databases.

Gizz

Share this post


Link to post
Share on other sites
I'm trying to be able to use it non-specific database really. With ADOConnection I just give it what database I will be connecting to, MySQL, MSSQL, Oracle. And it will load the appropriate driver and connect. All the code that I write is the same for each database. It'd be a pain to have to rewrite a program if I changed from my database to another.

Share this post


Link to post
Share on other sites
The object I use can be use on any DB that support the DBLib protocol, I just happen to use it only on a MS SQL Server.

If you look at CodeProject examples, you should find Classes that use ADO and ODBC.

Gizz

Share this post


Link to post
Share on other sites
If you're using MFC you can use the CDatabase object which creates an ODBC connection to whatever database source you want to use it with.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrEvil
If you're using MFC you can use the CDatabase object which creates an ODBC connection to whatever database source you want to use it with.


Is there a cross-platform coutnerpart to the CDatabase?

Share this post


Link to post
Share on other sites
Gizz, do you have an example of your object at hand?

I've been trying various classes from CodeProject but seem to encounter lots of problems. Or they require MFC which I don't want to use. Plus I'm not using Visual C++ I'm using Dev-C++.

Thanks

Share this post


Link to post
Share on other sites
It is mostly a wrapper around all the dblib calls. Examples can be found in the msdn documentation or their website MSDN and search for dblib or here's a link to one of the function dblogin. But please do remember that DBLib is being dumped in favor of ODBC (at least by microsoft) and thus you should probably use ODBC instead of DBLib.

Sadly this wrapper was left to my last employer.

Gizz

Share this post


Link to post
Share on other sites
I use a kind of sneaky method for connecting to a MySQL database from my C code. I actually use Winsock to open up a regular HTTP connection, and then request a PHP page which contains the database code I want to use. It then spits out a "web page" which is actually just the data that needs to be returned to my program. This works seemlessly for me so far, and is much faster than you'd think it would be. I even do it synchronously, and you don't even notice a delay. I don't know if PHP supports other database types besides MySQL, but I thought I'd toss this idea out anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tubular
I use a kind of sneaky method for connecting to a MySQL database from my C code. I actually use Winsock to open up a regular HTTP connection, and then request a PHP page which contains the database code I want to use. It then spits out a "web page" which is actually just the data that needs to be returned to my program.

Why not just use the C or C++ api in the first place?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!