Truxton file type save

From truxwiki.com
Revision as of 09:37, 26 January 2021 by Sam (talk | contribs) (→‎Sample)
Jump to navigation Jump to search

This will commit the data in the file type object to the database. It will write a record to the [FileType] table.

Syntax

int truxton_file_type_save( uint64_t file_type );

Parameters

file_type

The handle to the file type object. This handle comes from calling truxton_file_type_create().

Return value

A non-zero value on success, zero on failure.

Remarks

This API will commit the file type to the database. If you did not call truxton_file_type_set_id(), this api will find an unused value for the identifier and store it. You can retrieve the automatically generated value by calling truxton_file_type_get_id().

Sample

 1 void create_file_type(void)
 2 {
 3    uint64_t truxton = truxton_create();
 4 
 5    uint64_t file_type = truxton_file_type_create( truxton );
 6 
 7    truxton_file_type_set_short_name( file_type, "My Type" );
 8    truxton_file_type_set_long_name( file_type, "A new custom type derived from XML" );
 9    truxton_file_type_set_parent_id( file_type, Type_XML );
10    truxton_file_type_set_extension( file_type, "xm2" );
11    truxton_file_type_set_mime_type( file_type, "text/xml" );
12 
13    if ( truxton_file_type_save( file_type ) == 0 )
14    {
15       printf("Cannot save file type to the database.\n");
16    }
17 
18    uint64_t new_id = truxton_file_type_get_id( file_type );
19 
20    if ( new_id == 0 )
21    {
22       printf( "Failed to create new file type\n" );
23    }
24    else
25    {
26       printf( "Created new file type as id %" PRIu64 "\n", new_id );
27    }
28 
29    truxton_file_type_destroy( file_type );
30    truxton_destroy( truxton );
31 }