This method returns the object's name.
const char *GetName(void) const
Various objects can be referred to, in one context or another, by name.
· The name of a database object is the database name used for connecting to an
· The name of a field is the field name in the SQL query that created the
dynaset to which the field is attached.
· The parameter name is the name that is used (with the ":name" syntax) in SQL
statements; it is specified when the parameter is created by way of OParameterCollection::Add.
· The session name is either an internally generated string (for a default
session) or the name specified by the user when the session is created.
GetName returns a pointer to a null-terminated string containing the name.
The actual memory that the pointer points to is managed by the object. It
should not be freed by the caller; it will be freed when the object is destroyed or
A pointer to a string if successful; NULL if not.
An example of the uses and pitfalls of GetName:
// we have connection information from a caller:
// dname - database name
// connect - username/password
return; // the user gave us a bad connect
// odb.GetName will equal dname
// we also have an SQL statement called sqlstmt
// open a dynaset with it
ODynaset dyn(odb, sqlstmt);
return; // user gave us a bad SQL statement
// What is the name of the first field in the dynaset?
OField f1 = dyn.GetField(0);
const char *fieldname = f1.GetName();
// that works fine
// what if we skipped the declaration of f1?
const char *fname2 = dyn.GetField(0).GetName();
What object is GetName run on? The temporary OField object returned by
dyn.GetField(0). It will successfully return a name with GetName() and then go out of
scope. So GetName() will return a non-NULL pointer that is pointing to freed
memory. Watch out!