Oracle Objects for OLE C++ Class Library
Release 9.2

Part Number A95896-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents

Master Index

Feedback

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.

· The name of a database object is the database name used for connecting to an Oracle database.

· 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 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!

*/


 
Oracle
Copyright © 1998, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents

Master Index

Feedback