Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » What do I need to download / configure to use MySql with U++?
What do I need to download / configure to use MySql with U++? [message #38350] Wed, 12 December 2012 02:01 Go to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Do I need the official C++ connector too? Or just the MySql Server?

Thanks
Re: What do I need to download / configure to use MySql with U++? [message #38367 is a reply to message #38350] Wed, 12 December 2012 17:01 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
I link my exe against MySQL Connector C.
Re: What do I need to download / configure to use MySql with U++? [message #38780 is a reply to message #38367] Wed, 16 January 2013 21:12 Go to previous message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi Lectus and Zsolt,

Sorry for late reply.

I connect directly to MySql using server include, bin and lib files.

See native connection example:

Using native connection to MySql
1. Prologue

There are two ways to connect to MySql database using U++ - either through the ODBC layer or directly using MySql libray. Using ODBC is the easier way. The direct connection is more tricky but is more reliable when database is very large and has a lot of records.

2. Database Schema

TABLE_(test_table)
	INT_(id)PRIMARY_KEY AUTO_INCREMENT
	STRING_(value,50)
END_TABLE

3. Example code

#include <MySql/MySql.h>

using namespace Upp;

#define SCHEMADIALECT <MySql/MySqlSchema.h>
#define MODEL <NativeMySql/NativeMySql.sch>
#include <Sql/sch_header.h>
#include <Sql/sch_source.h>
#include <Sql/sch_schema.h>

CONSOLE_APP_MAIN{
	MySqlSession session;
	// edit the connection parameters if necessary
	if(session.Connect("root",NULL,"test")){
		Cout() << "Connected\n";
		SQL = session;
		
		SqlSchema sch(MY_SQL);
		All_Tables(sch);
		// create the table if necessary
		SqlPerformScript(sch.Upgrade());
		SqlPerformScript(sch.Attributes());
		SQL.ClearError();
		
		try {
			// insert some random data
			SQL & Insert(test_table)(value, Uuid::Create().ToString());
			// fetch some data
			SQL & Select(id,value).From(test_table)
			                      .OrderBy(Descending(id))
			                      .Limit(5);
			while(SQL.Fetch())
				Cout() << AsString(SQL[0]) << ": " << AsString(SQL[1]) << "\n";
		}
		catch(SqlExc &ex) {
			Cerr() << "ERROR: " << ex << "\n";
			SetExitCode(1);
		}
	} else {
		Cerr() <<"ERROR: Unable to connect to database\n";
		SetExitCode(1);
	}
	SetExitCode(0);
}

4. Build Method setting

You have to set correct paths in you build method. In Build methods dialog (Setup > Build methods...), choose your build method (e.g. MSC9) from the list on the left and then add the MySQL server installation paths into the three tabs on the right side of the dialog. 

On PATH tab add C:\Program Files\MySQL\MySQL Server 5.5\bin


On INCLUDE tab add C:\Program Files\MySQL\MySQL Server 5.5\include


And on LIB tab add C:\Program Files\MySQL\MySQL Server 5.5\lib


Note that the paths might be slightly different, depending on you system setup and the version of MySQL server installed.

5. Main package configuration

This is a crucial step. To link correctly with the MySql library, you must set the ".MYSQLDLL" build flag.



Note: Multithreading is not required, even though mysqlclient.lib is a multithreaded library (according to information shown in MySql website).



Screenshots are available in Theide help topics (see MySql: Native connection).

Hope this could be helpful

Regards

Biobytes
Previous Topic: Can U++ communicate with a MSACCESS database?
Next Topic: How to use Sqlite BLOB type in U++ schema files?
Goto Forum:
  


Current Time: Thu Apr 18 03:00:28 CEST 2024

Total time taken to generate the page: 0.06662 seconds