Truxton relation get relation

From truxwiki.com
Jump to navigation Jump to search

This retrieves the type of relation between the two objects in Truxton. This corresponds to the [RelationTypeID] column of the [Relation] table.

Syntax

uint64_t truxton_relation_get_relation( uint64_t relation_handle );

Parameters

relation_handle

This handle comes from calling truxton_relation_create()

Return value

The type of the object as stored in the [RelationTypeID] column in the [Relation] table. It should also be one of the defined constant values and present in the [ID] column of the [RelationType] reference table in the database.

Sample

void dump_relation(uint64_t relation_handle)
{
   uint64_t value = 0;
   char guid_string[ 65 ];

   value = truxton_relation_get_a_type( relation_handle );
   truxton_relation_get_a_id( relation_handle, guid_string, sizeof( guid_string ) );
   printf( "A (%" PRIu64 ") %s is a ", value, guid_string );

   value = truxton_relation_get_relation( relation_handle );
   printf( "%" PRIu64 " of ", value );

   value = truxton_relation_get_b_type( relation_handle );
   truxton_relation_get_b_id( relation_handle, guid_string, sizeof( guid_string ) );
   printf( "B (%" PRIu64 ") %s is a ", value, guid_string );

   value = truxton_relation_get_source_type( relation_handle );
   truxton_relation_get_source_id( relation_handle, guid_string, sizeof( guid_string ) );

   printf( "Source (%" PRIu64 ") is %s\n", value, guid_string );   
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.