Commit 501f69b8 authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

COMP: Move private implementation details out of vtkMySQLDatabase and into a...

COMP: Move private implementation details out of vtkMySQLDatabase and into a PIMPL class, to eliminate errors compiling client-server wrappers.
parent 6b5a5daf
......@@ -17,6 +17,7 @@
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
#include "vtkMySQLDatabase.h"
#include "vtkMySQLDatabasePrivate.h"
#include "vtkMySQLQuery.h"
#include "vtkSQLDatabaseSchema.h"
......@@ -28,19 +29,16 @@
#include <vtksys/ios/sstream>
#include <assert.h>
#include <mysql.h>
#define VTK_MYSQL_DEFAULT_PORT 3306
vtkCxxRevisionMacro(vtkMySQLDatabase, "1.19");
vtkCxxRevisionMacro(vtkMySQLDatabase, "1.20");
vtkStandardNewMacro(vtkMySQLDatabase);
// ----------------------------------------------------------------------
vtkMySQLDatabase::vtkMySQLDatabase()
vtkMySQLDatabase::vtkMySQLDatabase() :
Private(new vtkMySQLDatabasePrivate())
{
this->Connection = NULL;
mysql_init(& this->NullConnection);
this->Tables = vtkStringArray::New();
this->Tables->Register(this);
this->Tables->Delete();
......@@ -74,6 +72,8 @@ vtkMySQLDatabase::~vtkMySQLDatabase()
this->SetConnectOptions( 0 );
this->Tables->UnRegister(this);
delete this->Private;
}
// ----------------------------------------------------------------------
......@@ -108,7 +108,7 @@ bool vtkMySQLDatabase::IsSupported(int feature)
case VTK_SQL_FEATURE_PREPARED_QUERIES:
{
if (mysql_get_client_version() >= 40108 &&
mysql_get_server_version(& this->NullConnection) >= 40100)
mysql_get_server_version(& this->Private->NullConnection) >= 40100)
{
return true;
}
......@@ -144,10 +144,10 @@ bool vtkMySQLDatabase::Open()
return true;
}
assert(this->Connection == NULL);
assert(this->Private->Connection == NULL);
this->Connection =
mysql_real_connect( &this->NullConnection,
this->Private->Connection =
mysql_real_connect( &this->Private->NullConnection,
this->GetHostName(),
this->GetUserName(),
this->GetPassword(),
......@@ -155,10 +155,10 @@ bool vtkMySQLDatabase::Open()
this->GetServerPort(),
0, 0);
if (this->Connection == NULL)
if (this->Private->Connection == NULL)
{
vtkErrorMacro(<<"Open() failed with error: "
<< mysql_error(& this->NullConnection));
<< mysql_error(& this->Private->NullConnection));
return false;
}
else
......@@ -177,15 +177,15 @@ void vtkMySQLDatabase::Close()
}
else
{
mysql_close(this->Connection);
this->Connection = NULL;
mysql_close(this->Private->Connection);
this->Private->Connection = NULL;
}
}
// ----------------------------------------------------------------------
bool vtkMySQLDatabase::IsOpen()
{
return (this->Connection != NULL);
return (this->Private->Connection != NULL);
}
// ----------------------------------------------------------------------
......@@ -208,12 +208,12 @@ vtkStringArray* vtkMySQLDatabase::GetTables()
else
{
MYSQL_RES* tableResult = mysql_list_tables(
this->Connection, NULL );
this->Private->Connection, NULL );
if ( ! tableResult )
{
vtkErrorMacro(<<"GetTables(): MySQL returned error: "
<< mysql_error(this->Connection));
<< mysql_error(this->Private->Connection));
return this->Tables;
}
......@@ -251,12 +251,12 @@ vtkStringArray* vtkMySQLDatabase::GetRecord(const char *table)
}
MYSQL_RES *record =
mysql_list_fields(this->Connection, table, 0);
mysql_list_fields(this->Private->Connection, table, 0);
if (!record)
{
vtkErrorMacro(<<"GetRecord: MySQL returned error: "
<< mysql_error(this->Connection));
<< mysql_error(this->Private->Connection));
return results;
}
......@@ -273,12 +273,12 @@ vtkStringArray* vtkMySQLDatabase::GetRecord(const char *table)
bool vtkMySQLDatabase::HasError()
{
return (mysql_errno(this->Connection)!=0);
return (mysql_errno(this->Private->Connection)!=0);
}
const char* vtkMySQLDatabase::GetLastErrorText()
{
return mysql_error(this->Connection);
return mysql_error(this->Private->Connection);
}
// ----------------------------------------------------------------------
......
......@@ -34,15 +34,10 @@
#include "vtkSQLDatabase.h"
#ifdef _WIN32
# include <winsock.h> // mysql.h relies on the typedefs from here
#endif
#include <mysql.h> // needed for MYSQL typedefs
class vtkSQLQuery;
class vtkMySQLQuery;
class vtkStringArray;
class vtkMySQLDatabasePrivate;
class VTK_IO_EXPORT vtkMySQLDatabase : public vtkSQLDatabase
{
......@@ -174,9 +169,6 @@ private:
vtkStringArray *Tables;
vtkStringArray *Record;
MYSQL NullConnection;
MYSQL *Connection;
char* DatabaseType;
char* HostName;
char* UserName;
......@@ -185,6 +177,10 @@ private:
int ServerPort;
char* ConnectOptions;
//BTX
vtkMySQLDatabasePrivate* const Private;
//ETX
vtkMySQLDatabase(const vtkMySQLDatabase &); // Not implemented.
void operator=(const vtkMySQLDatabase &); // Not implemented.
};
......
#ifndef __vtkMySQLDatabasePrivate_h
#define __vtkMySQLDatabasePrivate_h
#ifdef _WIN32
# include <winsock.h> // mysql.h relies on the typedefs from here
#endif
#include <mysql.h> // needed for MYSQL typedefs
class vtkMySQLDatabasePrivate
{
public:
vtkMySQLDatabasePrivate() :
Connection(NULL)
{
mysql_init(&this->NullConnection);
}
MYSQL NullConnection;
MYSQL *Connection;
};
#endif // __vtkMySQLDatabasePrivate_h
......@@ -15,6 +15,7 @@
#include "vtkMySQLQuery.h"
#include "vtkMySQLDatabase.h"
#include "vtkMySQLDatabasePrivate.h"
#include <vtkObjectFactory.h>
#include <vtkStringArray.h>
#include <vtkVariant.h>
......@@ -58,7 +59,7 @@ public:
// ----------------------------------------------------------------------
vtkCxxRevisionMacro(vtkMySQLQuery, "1.2");
vtkCxxRevisionMacro(vtkMySQLQuery, "1.3");
vtkStandardNewMacro(vtkMySQLQuery);
// ----------------------------------------------------------------------
......@@ -110,7 +111,7 @@ vtkMySQLQuery::Execute()
return false;
}
MYSQL *db = dbContainer->Connection;
MYSQL *db = dbContainer->Private->Connection;
assert(db != NULL);
vtkDebugMacro(<<"Execute(): Query ready to execute.");
......@@ -209,7 +210,7 @@ vtkMySQLQuery::GetFieldType(int column)
return VTK_VOID;
}
MYSQL *db = dbContainer->Connection;
MYSQL *db = dbContainer->Private->Connection;
assert(db != NULL);
MYSQL_FIELD *field = mysql_fetch_field_direct(this->Internals->Result,
......@@ -320,7 +321,7 @@ vtkMySQLQuery::NextRow()
this->SetLastErrorText("Database is closed.");
return VTK_VOID;
}
MYSQL *db = dbContainer->Connection;
MYSQL *db = dbContainer->Private->Connection;
assert(db != NULL);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment