statement

## statement statement |

## Functions

librdf_statement * | librdf_new_statement ()
librdf_statement * | librdf_new_statement_from_statement ()
librdf_statement * | librdf_new_statement_from_statement2 ()
librdf_statement * | librdf_new_statement_from_nodes ()
void | librdf_statement_init ()
void | librdf_statement_clear ()
void | librdf_free_statement ()
librdf_node * | librdf_statement_get_subject ()
void | librdf_statement_set_subject ()
librdf_node * | librdf_statement_get_predicate ()
void | librdf_statement_set_predicate ()
librdf_node * | librdf_statement_get_object ()
void | librdf_statement_set_object ()
int | librdf_statement_is_complete ()
unsigned char * | librdf_statement_to_string ()
void | librdf_statement_print ()
int | librdf_statement_equals ()
int | librdf_statement_match ()
size_t | librdf_statement_encode ()
size_t | librdf_statement_encode2 ()
size_t | librdf_statement_encode_parts ()
size_t | librdf_statement_encode_parts2 ()
size_t | librdf_statement_decode ()
size_t | librdf_statement_decode2 ()
size_t | librdf_statement_decode_parts ()
int | librdf_statement_write ()

## Types and Values

typedef | librdf_statement
enum | librdf_statement_part

## Description

## Functions

### librdf_new_statement ()

    librdf_statement *
    librdf_new_statement (librdf_world *world);

Constructor - create a new empty librdf_statement.

#### Parameters

world | redland world object |

#### Returns

a new librdf_statement or NULL on failure

### librdf_new_statement_from_statement ()

    librdf_statement *
    librdf_new_statement_from_statement (librdf_statement *statement);

Copy constructor - create a new librdf_statement from an existing librdf_statement. Creates a deep copy - changes to original statement nodes are not reflected in the copy.

#### Parameters

statement | librdf_statement to copy |

#### Returns

a new librdf_statement with copy or NULL on failure

### librdf_new_statement_from_statement2 ()

    librdf_statement *
    librdf_new_statement_from_statement2 (librdf_statement *statement);

Copy constructor - create a new librdf_statement from an existing librdf_statement. Creates a shallow copy - changes to original statement nodes are reflected in the copy.

#### Parameters

statement | librdf_statement to copy |

#### Returns

a new librdf_statement with copy or NULL on failure

### librdf_new_statement_from_nodes ()

    librdf_statement *
    librdf_new_statement_from_nodes (librdf_world *world,
                                     librdf_node *subject,
                                     librdf_node *predicate,
                                     librdf_node *object);

Constructor - create a new librdf_statement from existing librdf_node objects.

The node objects become owned by the new statement (or freed on error).

#### Parameters

world | redland world object |
subject | librdf_node |
predicate | librdf_node |
object | librdf_node |

#### Returns

a new librdf_statement with copy or NULL on failure

### librdf_statement_init ()

    void
    librdf_statement_init (librdf_world *world,
                           librdf_statement *statement);

Initialise a statically declared librdf_statement.

This MUST be called on a statically declared librdf_statement to initialise it properly. It is the responsibility of the user of the statically allocated librdf_statement to deal with deallocation of any statement parts (subject, predicate, object).

#### Parameters

world | redland world object |
statement | librdf_statement object |

### librdf_statement_clear ()

    void
    librdf_statement_clear (librdf_statement *statement);

Empty a librdf_statement of nodes.

#### Parameters

statement | librdf_statement object |

### librdf_free_statement ()

    void
    librdf_free_statement (librdf_statement *statement);

Destructor - destroy a librdf_statement.

#### Parameters

statement | librdf_statement object |

### librdf_statement_get_subject ()

    librdf_node *
    librdf_statement_get_subject (librdf_statement *statement);

Get the statement subject.

This method returns a SHARED pointer to the subject which must be copied by the caller if needed.

#### Parameters

statement | librdf_statement object |

#### Returns

a pointer to the librdf_node of the statement subject -

### librdf_statement_set_subject ()

    void
    librdf_statement_set_subject (librdf_statement *statement,
                                  librdf_node *node);

Set the statement subject.

The subject passed in becomes owned by the statement object and must not be used by the caller after this call.

#### Parameters

statement | librdf_statement object |
node | librdf_node of subject |

### librdf_statement_get_predicate ()

    librdf_node *
    librdf_statement_get_predicate (librdf_statement *statement);

Get the statement predicate.

This method returns a SHARED pointer to the predicate which must be copied by the caller if needed.

#### Parameters

statement | librdf_statement object |

#### Returns

a pointer to the librdf_node of the statement predicate -

### librdf_statement_set_predicate ()

    void
    librdf_statement_set_predicate (librdf_statement *statement,
                                    librdf_node *node);

Set the statement predicate.

The predicate passed in becomes owned by the statement object and must not be used by the caller after this call.

#### Parameters

statement | librdf_statement object |
node | librdf_node of predicate |

### librdf_statement_get_object ()

    librdf_node *
    librdf_statement_get_object (librdf_statement *statement);

Get the statement object.

This method returns a SHARED pointer to the object which must be copied by the caller if needed.

#### Parameters

statement | librdf_statement object |

#### Returns

a pointer to the librdf_node of the statement object -

### librdf_statement_set_object ()

    void
    librdf_statement_set_object (librdf_statement *statement,
                                 librdf_node *node);

Set the statement object.

The object passed in becomes owned by the statement object and must not be used by the caller after this call.

#### Parameters

statement | librdf_statement object |
node | librdf_node of object |

### librdf_statement_is_complete ()

    int
    librdf_statement_is_complete (librdf_statement *statement);

Check if statement is a complete and legal RDF triple.

Checks that all subject, predicate, object fields are present and they have the allowed node types.

#### Parameters

statement | librdf_statement object |

#### Returns

non 0 if the statement is complete and legal

### librdf_statement_to_string ()

    unsigned char *
    librdf_statement_to_string (librdf_statement *statement);

`librdf_statement_to_string` is deprecated and should not be used in newly-written code.

Format the librdf_statement as a string.

Formats the statement as a newly allocate string that must be freed by the caller.

`Deprecated` : Use `librdf_statement_write()` to write to raptor_iostream which can be made to write to a string. Use a librdf_serializer to write proper syntax formats.

#### Parameters

statement | the statement |

#### Returns

the string or NULL on failure.

### librdf_statement_print ()

    void
    librdf_statement_print (librdf_statement *statement,
                            FILE *fh);

Pretty print the statement to a file descriptor.

This method is for debugging and the format of the output should not be relied on.

#### Parameters

statement | the statement |
fh | file handle |

### librdf_statement_equals ()

    int
    librdf_statement_equals (librdf_statement *statement1,
                             librdf_statement *statement2);

Check if two statements are equal.

#### Parameters

statement1 | first librdf_statement |
statement2 | second librdf_statement |

#### Returns

non 0 if statements are equal

### librdf_statement_match ()

    int
    librdf_statement_match (librdf_statement *statement,
                            librdf_statement *partial_statement);

Match a statement against a 'partial' statement.

A partial statement is where some parts of the statement - subject, predicate or object can be empty (NULL). Empty parts match against any value, parts with values must match exactly. Node matching is done via `librdf_node_equals()`

#### Parameters

statement | statement |
partial_statement | statement with possible empty parts |

#### Returns

non 0 on match

### librdf_statement_encode ()

    size_t
    librdf_statement_encode (librdf_statement *statement,
                             unsigned char *buffer,
                             size_t length);

`librdf_statement_encode` is deprecated and should not be used in newly-written code.

Serialise a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

`Deprecated` : Use `librdf_statement_encode2()`

#### Parameters

statement | the statement to serialise |
buffer | the buffer to use |
length | buffer size |

#### Returns

the number of bytes written or 0 on failure.

### librdf_statement_encode2 ()

    size_t
    librdf_statement_encode2 (librdf_world *world,
                              librdf_statement *statement,
                              unsigned char *buffer,
                              size_t length);

Serialise a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

#### Parameters

world | redland world |
statement | the statement to serialise |
buffer | the buffer to use |
length | buffer size |

#### Returns

the number of bytes written or 0 on failure.

### librdf_statement_encode_parts ()

    size_t
    librdf_statement_encode_parts (librdf_statement *statement,
                                   librdf_node *context_node,
                                   unsigned char *buffer,
                                   size_t length,
                                   librdf_statement_part fields);

`librdf_statement_encode_parts` is deprecated and should not be used in newly-written code.

Serialise parts of a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

The fields values are or-ed combinations of: LIBRDF_STATEMENT_SUBJECT LIBRDF_STATEMENT_PREDICATE LIBRDF_STATEMENT_OBJECT or LIBRDF_STATEMENT_ALL for subject,prdicate,object fields

If context_node is given, it is encoded also

`Deprecated` : This will no longer be a public API

#### Parameters

statement | statement to serialise |
context_node | librdf_node context node (can be NULL) |
buffer | the buffer to use |
length | buffer size |
fields | fields to encode |

#### Returns

the number of bytes written or 0 on failure.

### librdf_statement_encode_parts2 ()

    size_t
    librdf_statement_encode_parts2 (librdf_world *world,
                                    librdf_statement *statement,
                                    librdf_node *context_node,
                                    unsigned char *buffer,
                                    size_t length,
                                    librdf_statement_part fields);

Serialise parts of a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

The fields values are or-ed combinations of: LIBRDF_STATEMENT_SUBJECT LIBRDF_STATEMENT_PREDICATE LIBRDF_STATEMENT_OBJECT or LIBRDF_STATEMENT_ALL for subject,prdicate,object fields

If context_node is given, it is encoded also

#### Parameters

world | redland world object |
statement | statement to serialise |
context_node | librdf_node context node (can be NULL) |
buffer | the buffer to use |
length | buffer size |
fields | fields to encode |

#### Returns

the number of bytes written or 0 on failure.

### librdf_statement_decode ()

    size_t
    librdf_statement_decode (librdf_statement *statement,
                             unsigned char *buffer,
                             size_t length);

`librdf_statement_decode` is deprecated and should not be used in newly-written code.

Decodes a statement from a buffer. (ALWAYS FAILS)

Used to decode the serialised statement as created by `librdf_statement_encode()` from the given buffer.

`Deprecated` : Replaced by `librdf_statement_decode2()` which works.

#### Parameters

statement | the statement to deserialise into |
buffer | the buffer to use |
length | buffer size |

#### Returns

0 signifying failure

### librdf_statement_decode2 ()

    size_t
    librdf_statement_decode2 (librdf_world *world,
                              librdf_statement *statement,
                              librdf_node **context_node,
                              unsigned char *buffer,
                              size_t length);

Decodes a statement + context node from a buffer.

Decodes the serialised statement (as created by `librdf_statement_encode()` ) from the given buffer. If a context node is found and context_node is not NULL, a pointer to the new librdf_node is stored in *context_node.

#### Parameters

world | redland world |
statement | the statement to deserialise into |
context_node | pointer to librdf_node context_node to deserialise into |
buffer | the buffer to use |
length | buffer size |

#### Returns

number of bytes used or 0 on failure (bad encoding, allocation failure)

### librdf_statement_decode_parts ()

    size_t
    librdf_statement_decode_parts (librdf_statement *statement,
                                   librdf_node **context_node,
                                   unsigned char *buffer,
                                   size_t length);

`librdf_statement_decode_parts` is deprecated and should not be used in newly-written code.

Decodes a statement + context node from a buffer. (ALWAYS FAILS)

Used to decode the serialised statement as created by `librdf_statement_encode()` from the given buffer.

`Deprecated` : Replaced by `librdf_statement_decode2()` which works.

#### Parameters

statement | the statement to deserialise into |
context_node | pointer to librdf_node context_node to deserialise into |
buffer | the buffer to use |
length | buffer size |

#### Returns

0 signifying failure

### librdf_statement_write ()

    int
    librdf_statement_write (librdf_statement *statement,
                            raptor_iostream *iostr);

Write the statement to an iostream

This method is for debugging and the format of the output should not be relied on.

#### Parameters

statement | the statement |
iostr | raptor iostream to write to |

#### Returns

non-0 on failure

## Types and Values

### librdf_statement

    typedef raptor_statement librdf_statement;

Redland statement class.

### enum librdf_statement_part

Flags that are or-ed to indicate statement parts.

Used in fields arguments to methods such as the public `librdf_statement_encode_parts()` `librdf_statement_decode_parts()` `librdf_new_stream_from_node_iterator()`.

#### Members

LIBRDF_STATEMENT_SUBJECT | Subject of a statement. |
LIBRDF_STATEMENT_PREDICATE | Predicate of a statement. |
LIBRDF_STATEMENT_OBJECT | Object of a statement. |
LIBRDF_STATEMENT_ALL | All parts of a statement. |