mco_register_collations

Register collation functions with the runtime.

Prototype

 
    MCO_RET mco_register_collations(	/*IN*/ const_char * dbname, 
                       /*IN*/ mco_collation_funcs_h colls);
 

Arguments

dbname The name of the database

colls

A mco_collation_funcs_t structure. Normally this is a call to the generated function dbname_get_collations() which returns a mco_collation_funcs_t structure initialized with the addresses of a compare and hash function for the specified collation. Stubs for these two collation functions are generated by mcocompand can then be customized as needed. Note that after generating a collation file (call it colldb_coll.c) the next time mcocomp is run on this schema a new collation file (colldb_coll.c,new) will be generated with stub functions. This is to avoid overwriting any customizations added to the first collation file.

Description

This function registers collation functions with the runtime when a specific collation order is required for the database. Two callback functions are required: one that is called by the runtime when two database fields (treated as character arrays) are compared, and the second generates a hash

Return Codes

MCO_S_OK Collation functions successfully registered

MCO_E_INSTANCES_LIMIT

Registry is full

Example

 
    Schema file snippet:
        
 
    declare database colldb;
     
    class Record
    {
        string name;
        uint4  value;
 
        unique tree <name collate C1> tcoll;
    };
     
    Collation file (colldb_coll.c) snippet:
        
     
 
    /* collation compare function */
    int2  C1_collation_compare ( mco_collate_h c1, uint2 len1, mco_collate_h c2, uint2 len2)
    {
        /* TODO: add your implementation here */
        
        return 0;
    }
     
    Application snippet:
        
 
    const char * dbname = "colldb";
     
    int main(int argc, char* argv[])
    {
        mco_db_h db;
        MCO_RET rc;
        char *mem = malloc( DBSIZE );
         
         
        if( (rc = mco_runtime_start()) != MCO_S_OK)
            exit(-1);
             
        rc = mco_db_open( dbname, simpledb_get_dictionary(), mem, DBSIZE, (uint2)PAGESIZE );
         
        if( (MCO_S_OK == rc)
        {
            /* register alloc callback */
            mco_register_collations( dbname, colldb_get_collations() );
        
                             
            /* connect to database */
            rc = mco_db_connect(dbName, &db);
            ...
        }
        ...
    }
     
 

Related Topics Link IconRelated Topics