Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Christian Butz
VTK
Commits
0667b2d8
Commit
0667b2d8
authored
Jun 16, 2011
by
Marcus D. Hanwell
Committed by
Kitware Robot
Jun 16, 2011
Browse files
Merge topic 'io-sql-callbacks'
91b76333
ENH: Register SQL database callbacks for factories.
parents
d0f44995
91b76333
Changes
6
Hide whitespace changes
Inline
Side-by-side
IO/vtkMySQLDatabase.cxx
View file @
0667b2d8
...
...
@@ -33,8 +33,42 @@
#define VTK_MYSQL_DEFAULT_PORT 3306
vtkStandardNewMacro
(
vtkMySQLDatabase
)
;
vtkStandardNewMacro
(
vtkMySQLDatabase
)
// Registration of MySQL dynamically with the vtkSQLDatabase factory method.
vtkSQLDatabase
*
MySQLCreateFunction
(
const
char
*
URL
)
{
vtkstd
::
string
urlstr
(
URL
?
URL
:
""
);
vtkstd
::
string
protocol
,
unused
;
vtkMySQLDatabase
*
db
=
0
;
if
(
vtksys
::
SystemTools
::
ParseURLProtocol
(
urlstr
,
protocol
,
unused
)
&&
protocol
==
"mysql"
)
{
db
=
vtkMySQLDatabase
::
New
();
db
->
ParseURL
(
URL
);
}
return
db
;
}
class
vtkMySQLDatabaseRegister
{
public:
vtkMySQLDatabaseRegister
()
{
vtkSQLDatabase
::
RegisterCreateFromURLCallback
(
MySQLCreateFunction
);
}
~
vtkMySQLDatabaseRegister
()
{
vtkSQLDatabase
::
UnRegisterCreateFromURLCallback
(
MySQLCreateFunction
);
}
};
// Remove ifndef in VTK 6.0: only register callback in old layout.
#ifndef VTK_USE_MYSQL
static
vtkMySQLDatabaseRegister
mySQLDataBaseRegister
;
#endif
// ----------------------------------------------------------------------
vtkMySQLDatabase
::
vtkMySQLDatabase
()
:
...
...
IO/vtkMySQLDatabase.h
View file @
0667b2d8
...
...
@@ -174,16 +174,16 @@ public:
// Returns true on success and false on failure.
bool
DropDatabase
(
const
char
*
dbName
);
protected:
vtkMySQLDatabase
();
~
vtkMySQLDatabase
();
// Description:
// Overridden to determine connection parameters given the URL.
// This is called by CreateFromURL() to initialize the instance.
// Look at CreateFromURL() for details about the URL format.
virtual
bool
ParseURL
(
const
char
*
url
);
protected:
vtkMySQLDatabase
();
~
vtkMySQLDatabase
();
private:
// We want this to be private, a user of this class
// should not be setting this for any reason
...
...
IO/vtkODBCDatabase.cxx
View file @
0667b2d8
...
...
@@ -50,8 +50,43 @@
// ----------------------------------------------------------------------------
vtkStandardNewMacro
(
vtkODBCDatabase
);
// ----------------------------------------------------------------------------
// Registration of ODBC dynamically with the vtkSQLDatabase factory method.
vtkSQLDatabase
*
ODBCCreateFunction
(
const
char
*
URL
)
{
vtkstd
::
string
urlstr
(
URL
?
URL
:
""
);
vtkstd
::
string
protocol
,
unused
;
vtkODBCDatabase
*
db
=
0
;
if
(
vtksys
::
SystemTools
::
ParseURLProtocol
(
urlstr
,
protocol
,
unused
)
&&
protocol
==
"odbc"
)
{
db
=
vtkODBCDatabase
::
New
();
db
->
ParseURL
(
URL
);
}
return
db
;
}
class
vtkODBCDatabaseRegister
{
public:
vtkODBCDatabaseRegister
()
{
vtkSQLDatabase
::
RegisterCreateFromURLCallback
(
ODBCCreateFunction
);
}
~
vtkODBCDatabaseRegister
()
{
vtkSQLDatabase
::
UnRegisterCreateFromURLCallback
(
ODBCCreateFunction
);
}
};
// Remove ifndef in VTK 6.0: only register callback in old layout.
#ifndef VTK_USE_ODBC
static
vtkODBCDatabaseRegister
ODBCDataBaseRegister
;
#endif
// ----------------------------------------------------------------------------
static
vtkStdString
GetErrorMessage
(
SQLSMALLINT
handleType
,
SQLHANDLE
handle
,
int
*
code
=
0
)
...
...
IO/vtkODBCDatabase.h
View file @
0667b2d8
...
...
@@ -38,7 +38,7 @@
// from a configuration file (odbc.ini). That file can define an
// entire set of connection parameters and give it a single name
// called a data source name (DSN). Writing and maintaining odbc.ini
// files is beyond the scope of this header file.
// files is beyond the scope of this header file.
//
// .SECTION Caveats
//
...
...
@@ -93,7 +93,7 @@ public:
// Description:
// Close the connection to the database.
void
Close
();
// Description:
// Return whether the database has an open connection
bool
IsOpen
();
...
...
@@ -101,15 +101,15 @@ public:
// Description:
// Return an empty query on this database.
vtkSQLQuery
*
GetQueryInstance
();
// Description:
// Get the last error text from the database
const
char
*
GetLastErrorText
();
// Description:
// Get the list of tables from the database
vtkStringArray
*
GetTables
();
// Description:
// Get the list of fields for a particular table
vtkStringArray
*
GetRecord
(
const
char
*
table
);
...
...
@@ -133,11 +133,11 @@ public:
vtkSetStringMacro
(
Password
);
bool
HasError
();
// Description:
// String representing database type (e.g. "ODBC").
vtkGetStringMacro
(
DatabaseType
);
vtkStdString
GetURL
();
// Description:
...
...
@@ -149,7 +149,7 @@ public:
virtual
vtkStdString
GetColumnSpecification
(
vtkSQLDatabaseSchema
*
schema
,
int
tblHandle
,
int
colHandle
);
// Description:
// Return the SQL string with the syntax to create an index inside a
// "CREATE TABLE" SQL statement.
...
...
@@ -168,18 +168,18 @@ public:
// Returns true on success and false on failure.
bool
DropDatabase
(
const
char
*
dbName
);
protected:
vtkODBCDatabase
();
~
vtkODBCDatabase
();
vtkSetStringMacro
(
LastErrorText
);
// Description:
// This will only handle URLs of the form
// odbc://[user@]datsourcename[:port]/[dbname]. Anything
// more complicated than that needs to be set up manually.
bool
ParseURL
(
const
char
*
url
);
protected:
vtkODBCDatabase
();
~
vtkODBCDatabase
();
vtkSetStringMacro
(
LastErrorText
);
private:
vtkStringArray
*
Tables
;
vtkStringArray
*
Record
;
...
...
@@ -194,13 +194,13 @@ private:
int
ServerPort
;
vtkODBCInternals
*
Internals
;
// We want this to be private, a user of this class
// should not be setting this for any reason
vtkSetStringMacro
(
DatabaseType
);
char
*
DatabaseType
;
vtkODBCDatabase
(
const
vtkODBCDatabase
&
);
// Not implemented.
void
operator
=
(
const
vtkODBCDatabase
&
);
// Not implemented.
};
...
...
IO/vtkPostgreSQLDatabase.cxx
View file @
0667b2d8
...
...
@@ -38,6 +38,41 @@
vtkStandardNewMacro
(
vtkPostgreSQLDatabase
);
// Registration of PostgreSQL dynamically with the vtkSQLDatabase factory method.
vtkSQLDatabase
*
PostgreSQLCreateFunction
(
const
char
*
URL
)
{
vtkstd
::
string
urlstr
(
URL
?
URL
:
""
);
vtkstd
::
string
protocol
,
unused
;
vtkPostgreSQLDatabase
*
db
=
0
;
if
(
vtksys
::
SystemTools
::
ParseURLProtocol
(
urlstr
,
protocol
,
unused
)
&&
protocol
==
"psql"
)
{
db
=
vtkPostgreSQLDatabase
::
New
();
db
->
ParseURL
(
URL
);
}
return
db
;
}
class
vtkPostgreSQLDatabaseRegister
{
public:
vtkPostgreSQLDatabaseRegister
()
{
vtkSQLDatabase
::
RegisterCreateFromURLCallback
(
PostgreSQLCreateFunction
);
}
~
vtkPostgreSQLDatabaseRegister
()
{
vtkSQLDatabase
::
UnRegisterCreateFromURLCallback
(
PostgreSQLCreateFunction
);
}
};
// Remove ifndef in VTK 6.0: only register callback in old layout.
#ifndef VTK_USE_POSTGRES
static
vtkPostgreSQLDatabaseRegister
postgreSQLDataBaseRegister
;
#endif
// ----------------------------------------------------------------------
vtkPostgreSQLDatabase
::
vtkPostgreSQLDatabase
()
{
...
...
IO/vtkPostgreSQLDatabase.h
View file @
0667b2d8
...
...
@@ -71,7 +71,7 @@ public:
// Description:
// Close the connection to the database.
void
Close
();
// Description:
// Return whether the database has an open connection
bool
IsOpen
();
...
...
@@ -79,11 +79,11 @@ public:
// Description:
// Return an empty query on this database.
vtkSQLQuery
*
GetQueryInstance
();
// Description:
// Did the last operation generate an error
virtual
bool
HasError
();
// Description:
// Get the last error text from the database
const
char
*
GetLastErrorText
();
...
...
@@ -128,7 +128,7 @@ public:
return
VTK_INT_MAX
;
}
vtkGetMacro
(
ServerPort
,
int
);
// Description:
// Get a URL referencing the current database connection.
// This is not well-defined if the HostName and DatabaseName
...
...
@@ -139,7 +139,7 @@ public:
// Description:
// Get the list of tables from the database
vtkStringArray
*
GetTables
();
// Description:
// Get the list of fields for a particular table
vtkStringArray
*
GetRecord
(
const
char
*
table
);
...
...
@@ -169,7 +169,13 @@ public:
// <column name> <column type> <column attributes>
virtual
vtkStdString
GetColumnSpecification
(
vtkSQLDatabaseSchema
*
schema
,
int
tblHandle
,
int
colHandle
);
// Description:
// Overridden to determine connection parameters given the URL.
// This is called by CreateFromURL() to initialize the instance.
// Look at CreateFromURL() for details about the URL format.
virtual
bool
ParseURL
(
const
char
*
url
);
protected:
vtkPostgreSQLDatabase
();
~
vtkPostgreSQLDatabase
();
...
...
@@ -189,19 +195,13 @@ protected:
// database connection is initiated.
void
UpdateDataTypeMap
();
// Description:
// Overridden to determine connection parameters given the URL.
// This is called by CreateFromURL() to initialize the instance.
// Look at CreateFromURL() for details about the URL format.
virtual
bool
ParseURL
(
const
char
*
url
);
vtkSetStringMacro
(
DatabaseType
);
vtkSetStringMacro
(
LastErrorText
);
void
NullTrailingWhitespace
(
char
*
msg
);
bool
OpenInternal
(
const
char
*
connectionOptions
);
vtkTimeStamp
URLMTime
;
vtkPostgreSQLDatabasePrivate
*
Connection
;
vtkPostgreSQLDatabasePrivate
*
Connection
;
vtkTimeStamp
ConnectionMTime
;
vtkStringArray
*
Tables
;
char
*
DatabaseType
;
...
...
@@ -212,7 +212,7 @@ protected:
int
ServerPort
;
char
*
ConnectOptions
;
char
*
LastErrorText
;
private:
vtkPostgreSQLDatabase
(
const
vtkPostgreSQLDatabase
&
);
// Not implemented.
void
operator
=
(
const
vtkPostgreSQLDatabase
&
);
// Not implemented.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment