Sign in to follow this  

Database

This topic is 4803 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
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
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
If the database is remote, then HTTP proxying might be the only way you can get out through a corporate firewall.

Also, there are lots of "free hosts" that let you run MySQL with PHP on some arbitrary web page.

Because of the way that HTTP is made to work, but other things blocked off, in modern corporate networks, it may be that all application networking will slowly migrate to tunneling on ports 80 and 443. Thus, 30 years from now, someone will delve into the depths of networking, and ask "why is there this port number field, when it's always set to 80?" :-)

Share this post


Link to post
Share on other sites

This topic is 4803 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this