/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#ifndef DDDATACONNECTION_H
#define DDDATACONNECTION_H

#include <ddthreadmutex.h>
#include <mysql.h>


class dddataquery;
class dddatastore;
class ddwebitem;
class ddwebcgi;
class dddataconnection;
class dditem;

/// dddataconnection
/**
	
	Ex DDDBConnection, diesmal KISS: Keine Felder, Keine States (wurden ja eh nicht benutzt)
	Stattdessen kapselt die Connection den MySql-Kram.
	
	Die Aufteilung in connection und reader verhindert, das read() vor execute aufgerufen werden kann,
	Allerdings werden dazu dann zwei spinnlocks gebraucht.
	
	
	@see dddatastore& 
	
	
	FIX! stored procs & cursors!

*/

class dddataconnection : public ddbaseobject
{

friend class dddatastore;

public: 
	
	dddataconnection();
	dddataconnection( const ddstring& connectstring );
	dddataconnection( const ddstring& db, const ddstring& host, const ddstring& user="", const ddstring& pass="" );

	~dddataconnection();
	
	inline bool operator!() const
	{
		return _connected;
	}
	
	void     			close();

  void      		connect( const ddstring& connectstring );
  void      		connect( const ddstring& db, const ddstring& host, const ddstring& user="", const ddstring& pass="" );
    
protected:
 	
	bool					_connected;
	ddthreadmutex _lock;
	MYSQL 				_mysql;
	
};


#endif
