# classname_new (OID)

> This function creates a new instance of a database object with an OID.

### Prototype

>         MCO_RET	classname_new(	/*IN*/ mco_trans_h t,
>                       /*IN*/ dbname_oid *oid,
>                       /*OUT*/ classname * handle );

### Arguments

t | A `MCO_READ_WRITE` transaction handle returned by`mco_trans_start()`
oid | The address of a variable of generated typedef dbname_oid which specifies the OID of the object to be allocated
handle | The address of a variable of type ``class handle``

### Description

> This function will reserve space for a new instance of the class and return a reference to the instance. This form of classname_new() is only valid for classes declared with an OID.

### Return Codes

MCO_S_OK | The instance was reserved successfully
MCO_S_DUPLICATE | The OID value is not unique
MCO_E_ACCESS | The transaction handle is `MCO_READ_ONLY`
MCO_E_TRANSACT | A transaction error occurred
MCO_E_NOMEM | Database memory allocation error

### Example

>         Schema snippet:

>         struct SimpleId
>         {
>             uint2 id;
>         };
>         declare oid SimpleId[10000];

>         Application snippet:

>         const char * dbname = "SimpleDb";

>         int main(int argc, char* argv[])
>         {
>             mco_db_h db;
>             MCO_RET rc;
>             mco_trans_t       t;
>             SimpleId simple_id;
>             ...

>             simple_id.id= 99;
>             mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
>             if ( MCO_S_OK != rc )
>             {
>                 A a;
>                 rc = A_new( t, &simple_id, &a );

>                 ...
>             }
>         }

Related Topics