Difference between revisions of "Truxton artifact save"
Jump to navigation
Jump to search
(→Sample) |
|||
| Line 16: | Line 16: | ||
=Sample= | =Sample= | ||
| − | <source lang="C" highlight=" | + | <source lang="C" highlight="10"> |
void create_artifact(void) | void create_artifact(void) | ||
{ | { | ||
uint64_t truxton = truxton_create(); | uint64_t truxton = truxton_create(); | ||
| − | uint64_t artifact= truxton_artifact_create(truxton); | + | uint64_t artifact = truxton_artifact_create( truxton ); |
truxton_artifact_set_name( artifact, "Ducky Momo Server" ); | truxton_artifact_set_name( artifact, "Ducky Momo Server" ); | ||
| − | |||
| − | |||
| − | + | // Commit the data to the database | |
| + | if ( truxton_artifact_save( artifact ) == 0 ) | ||
| + | { | ||
| + | printf( "Cannot save data to the database.\n" ); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | truxton_artifact_tag( artifact, "Too Young", "Yes, yes I am", 1 ); | ||
| − | + | char id[ 65 ]; | |
| − | + | truxton_artifact_get_id( artifact, id, sizeof( id ) ); | |
| − | truxton_artifact_destroy( | + | printf( "Artifact ID is %s\n", id ); |
| − | truxton_destroy(truxton); | + | } |
| + | |||
| + | truxton_artifact_destroy( artifact ); | ||
| + | truxton_destroy( truxton ); | ||
} | } | ||
</source> | </source> | ||
Revision as of 09:08, 26 January 2021
This saves an artifact object.
The data in the artifact object will be written to the [Entity] table in the database.
Syntax
int truxton_artifact_save(uint64_t artifact_handle);
Parameters
artifact_handle
The artifact instance.
This handle comes from calling truxton_artifact_create().
Return value
A non-zero value on success, zero on failure.
Sample
void create_artifact(void)
{
uint64_t truxton = truxton_create();
uint64_t artifact = truxton_artifact_create( truxton );
truxton_artifact_set_name( artifact, "Ducky Momo Server" );
// Commit the data to the database
if ( truxton_artifact_save( artifact ) == 0 )
{
printf( "Cannot save data to the database.\n" );
}
else
{
truxton_artifact_tag( artifact, "Too Young", "Yes, yes I am", 1 );
char id[ 65 ];
truxton_artifact_get_id( artifact, id, sizeof( id ) );
printf( "Artifact ID is %s\n", id );
}
truxton_artifact_destroy( artifact );
truxton_destroy( truxton );
}