Skip Headers
Oracle® Objects for OLE C++ Class Library Developer's Guide
10g Release 2 (10.2)

Part Number B14308-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

GetName Method

Applies To

ODatabase

OField

OParameter

OSession

Description

This method returns the object's name.

Usage

const char *GetName(void) const

Remarks

Various objects can be referred to, in one context or another, by name.

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 closed.

Return Value

A pointer to a string if successful; NULL if not.

Example

An example of the uses and pitfalls of GetName:

// we have connection information from a caller:
//    dname - database name
//    connect - username/password
ODatabase odb;
odb.Open(dname, connect);
if (!odb.IsOpen())
    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);
if (!dyn.IsOpen())
    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!
*/