Difference between revisions of "Truxton relation save"
Jump to navigation
Jump to search
| (One intermediate revision by the same user not shown) | |||
| Line 3: | Line 3: | ||
=Syntax= | =Syntax= | ||
<source lang="C"> | <source lang="C"> | ||
| − | + | int truxton_relation_save( uint64_t relation_handle ); | |
</source> | </source> | ||
| Line 10: | Line 10: | ||
The relation object to write to the database. | The relation object to write to the database. | ||
This handle comes from calling <code>[[truxton_relation_create]]()</code>. | This handle comes from calling <code>[[truxton_relation_create]]()</code>. | ||
| + | |||
| + | =Return value= | ||
| + | A non-zero value on success, zero on failure. | ||
=Sample= | =Sample= | ||
| Line 39: | Line 42: | ||
// Commit the data to the database | // Commit the data to the database | ||
| − | truxton_relation_save( relation ); | + | if ( truxton_relation_save( relation ) == 0 ) |
| + | { | ||
| + | printf( "Cannot save relation to the database\n" ); | ||
| + | } | ||
| + | |||
truxton_relation_destroy( relation ); | truxton_relation_destroy( relation ); | ||
} | } | ||
</source> | </source> | ||
Latest revision as of 08:58, 26 January 2021
This commits the information in the relation object to the [Relation] table in the database.
Syntax
int truxton_relation_save( uint64_t relation_handle );
Parameters
relation_handle
The relation object to write to the database.
This handle comes from calling truxton_relation_create().
Return value
A non-zero value on success, zero on failure.
Sample
void set_primary_photo( uint64_t truxton, uint64_t media, uint64_t child_file )
{
char media_id[ 65 ];
char file_id[ 65 ];
truxton_media_get_id( media, media_id, sizeof( media_id ) );
truxton_child_file_get_id( child_file, file_id, sizeof( file_id ) );
uint64_t relation = truxton_relation_create( truxton );
// Now tell Truxton that child_file (A object) is the primary photo of media (B object)
truxton_relation_set_relation( relation, RELATION_PRIMARY_PHOTO );
// Set the A object, A is a file
truxton_relation_set_a_id( relation, file_id );
truxton_relation_set_a_type( relation, OBJECT_TYPE_FILE );
// Set the B object, B is a piece of media
truxton_relation_set_b_id( relation, media_id );
truxton_relation_set_b_type( relation, OBJECT_TYPE_MEDIA );
// Set the source object, source is a piece of media
truxton_relation_set_source_id( relation, media_id );
truxton_relation_set_source_type( relation, OBJECT_TYPE_MEDIA );
// Commit the data to the database
if ( truxton_relation_save( relation ) == 0 )
{
printf( "Cannot save relation to the database\n" );
}
truxton_relation_destroy( relation );
}