# classname_autoid_get

> This function returns the autoid of the object referenced by its class handle.

### Prototype

>         MCO_RET	classname_autoid_get(	/*IN*/classname * handle,
>                            /*OUT*/ autoid_t *oid );

### Arguments

handle | The address of a variable of type ``class handle``
oid | A pointer to an autoid_t, which will receive the autoid value of the object referenced by the handle

### Description

This function will return the autoid of the object referenced by handle.

### Return Codes

MCO_S_OK | The OID was returned successfully
MCO_E_TRANSACT | The transaction is in an error state
MCO_ERR_OBJECT_HANDLE | Invalid object handle

Example

> The following code snippets demonstrate how `classname_autoid_get()` is used to retrieve the `autoid` value of a database object.

>         Snippet from schema file:

>         class Department
>         {
>             autoid[1000];
>             string name;
>             string code;

>             unique tree<name> Iname;
>             unique tree<code> Icode;
>         };

>         class Employee
>         {
>             string name;
>             autoid_t dept;

>             unique tree<name> Iname;
>             unique tree<dept,name> Idept_name;
>         };

>         Application snippet:

>         int main(int argc, char* argv[])
>         {
>             MCO_RET rc = MCO_S_OK;
>             mco_db_h db;
>             mco_trans_h t;
>             char dept_code = "CS";
>             Department dept;

>             ...
>             rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
>             if ( MCO_S_OK == rc )
>              {
>                 rc = Department_Icode_find(t, dept_code, strlen(dept_code), &dept);
>                 if ( MCO_S_OK == rc )
>                  {
>                     Department dept;
>                     autoid_t autoid = 0;
>                     ...
>                     Department_autoid_get(&dept, &dept_id);

>                     ...
>                 }
>             }
>         }

Related Topics