List:MySQL++« Previous MessageNext Message »
From:Dovid Kopel Date:November 17 2004 3:25pm
Subject:How to write Mysql++ in OOP
View as plain text  
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I finally fixed the segfaults I was having, though the only way I can
execute a query is by having the Query object in the same method as the
Connection object. I declared the Connection as private in my header but
when I try to run the "query.store()" I get "Error: MySQL server has
gone away" which sounds like a problem with the connection. Forgive me,
I am a PHP programmer who has Java experience. I'm teaching myself Java
to write a db app. I'm probably doing a declaration wrong or something
at a simple level. Thank you in advance.

#include "mysql.h"
#include <mysql++.h>
#include <iomanip>

using namespace std;
using namespace mysqlpp;
database::database(const char *db_db, const char *db_host, const char
*db_user, const char *db_passwd)
{
	try
	{
		Connection con(db_db, db_host, db_user, db_passwd);
		Query query = con.query();
		query << "SHOW TABLES";
		cout << "Query: " << query.preview() << endl;
		Result res = query.store();
		cout << "Records Found: " << res.size() << endl;
	}
	catch (BadQuery& er)
	{
		cerr << "Error: " << er.error << endl;
	}
}

int database::connect(const char *db_db, const char *db_host, const char
*db_user, const char *db_passwd)
{
	try
	{
		Connection con(db_db, db_host, db_user, db_passwd);
	}
	catch (BadQuery& er)
	{
		cerr << "Error: " << er.error << endl;
	}
	cout << "Connected..." << endl;
	return(0);
}

int database::exquery(const char *myquery)
{
	try
	{
		Query query = con.query();
		query << myquery;
		cout << "Query: " << query.preview() << endl;
		Result res = query.store();
		cout << "Records Found: " << res.size() << endl;
	}
	catch (BadQuery& er)
	{ // handle any connection or
~                          // query errors that may come up
		cerr << "Error: " << er.error << endl;
		return -1;
	}
	return(0);
}

- --
- -=mUnky=-
- -Dovid Kopel
(516)-655-0489
munky@stripped
http://www.munkys.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBm21mCecRKprSbsERAjEmAJ9DjiB0vDBrKCBrsUsw2BoWrXVd6gCfWZIj
gwYqjt+1Qvp2L6YvA7nEp8w=
=NhsZ
-----END PGP SIGNATURE-----

Thread
How to write Mysql++ in OOPDovid Kopel17 Nov
  • Re: How to write Mysql++ in OOPEarl Miles17 Nov
  • Re: How to write Mysql++ in OOPWarren Young18 Nov