Truxton relation get source id

From truxwiki.com
Jump to navigation Jump to search

This retrieves the GUID of the source object of the relation. This corresponds to the [SourceID] column of the [Relation] table.

Syntax

void truxton_relation_get_source_id( uint64_t relation_handle, char * destination_string, size_t max_size );

Parameters

relation_handle

This handle comes from calling truxton_relation_create()

destination_string

The string to be written to.

max_size

The maximum number of characters that can be written to destination_string.

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.