db_value.h File Reference
`#include "config.h"`
`#include "db_type.h"`
`#include "db_enum.h"`
`#include <stdlib.h>`

Go to the source code of this file.

## Data Structures

struct | db_value
struct | db_value_set

## Macros

#define | DB_VALUE_EMPTY { DB_TYPE_EMPTY, 0, NULL, 0, 0, 0, 0, 0, NULL }

## Typedefs

typedef struct db_value | db_value_t
typedef struct db_value_set | db_value_set_t

## Functions

db_value_t * | db_value_new (void)
void | db_value_free (db_value_t *value)
void | db_value_reset (db_value_t *value)
int | db_value_copy (db_value_t *value, const db_value_t *from_value)
int | db_value_cmp (const db_value_t *value_a, const db_value_t *value_b, int *result)
db_type_t | db_value_type (const db_value_t *value)
const db_type_int32_t * | db_value_int32 (const db_value_t *value)
const db_type_uint32_t * | db_value_uint32 (const db_value_t *value)
const db_type_int64_t * | db_value_int64 (const db_value_t *value)
const db_type_uint64_t * | db_value_uint64 (const db_value_t *value)
const char * | db_value_text (const db_value_t *value)
int | db_value_enum_value (const db_value_t *value, int *enum_value)
int | db_value_not_empty (const db_value_t *value)
int | db_value_to_int32 (const db_value_t *value, db_type_int32_t *to_int32)
int | db_value_to_uint32 (const db_value_t *value, db_type_uint32_t *to_uint32)
int | db_value_to_int64 (const db_value_t *value, db_type_int64_t *to_int64)
int | db_value_to_uint64 (const db_value_t *value, db_type_uint64_t *to_uint64)
int | db_value_to_text (const db_value_t *value, char **to_text)
int | db_value_to_enum_value (const db_value_t *value, int *to_int, const db_enum_t *enum_set)
int | db_value_from_int32 (db_value_t *value, db_type_int32_t from_int32)
int | db_value_from_uint32 (db_value_t *value, db_type_uint32_t from_uint32)
int | db_value_from_int64 (db_value_t *value, db_type_int64_t from_int64)
int | db_value_from_uint64 (db_value_t *value, db_type_uint64_t from_uint64)
int | db_value_from_text (db_value_t *value, const char *from_text)
int | db_value_from_text2 (db_value_t *value, const char *from_text, size_t size)
int | db_value_from_enum_value (db_value_t *value, int enum_value, const db_enum_t *enum_set)
int | db_value_set_primary_key (db_value_t *value)
db_value_set_t * | db_value_set_new (size_t size)
db_value_set_t * | db_value_set_new_copy (const db_value_set_t *from_value_set)
void | db_value_set_free (db_value_set_t *value_set)
size_t | db_value_set_size (const db_value_set_t *value_set)
const db_value_t * | db_value_set_at (const db_value_set_t *value_set, size_t at)
db_value_t * | db_value_set_get (db_value_set_t *value_set, size_t at)

## Macro Definition Documentation

## DB_VALUE_EMPTY

#define DB_VALUE_EMPTY { DB_TYPE_EMPTY, 0, NULL, 0, 0, 0, 0, 0, NULL }

Definition at line 60 of file db_value.h.

## Typedef Documentation

## db_value_set_t

typedef struct db_value_set db_value_set_t

Definition at line 36 of file db_value.h.

## db_value_t

typedef struct db_value db_value_t

Definition at line 35 of file db_value.h.

## Function Documentation

## db_value_cmp()

int db_value_cmp | ( | const db_value_t * | value_a,
|  | const db_value_t * | value_b,
|  | int * | result
| ) |  |

Compare two database values A and B. Sets `result` with less than, equal to, or greater than zero if A is found, respectively, to be less than, to match, or be greater than B.

Parameters

  [in] | value_a | a db_value_t pointer.
  [in] | value_b | a db_value_t pointer.
  [out] | result | an integer pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 102 of file db_value.c.

Referenced by key_data_cmp(), policy_key_cmp(), test_class_db_value(), test_database_operations_read_object2(), and test_database_operations_read_object2_2().

## db_value_copy()

int db_value_copy | ( | db_value_t * | value,
|  | const db_value_t * | from_value
| ) |  |

Copy the contant from one database value into another.

Parameters

  [in] | value | a db_value_t pointer to copy to.
  [in] | from_value | a db_value_t pointer to copy from.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 77 of file db_value.c.

Referenced by hsm_key_copy(), hsm_key_set_policy_id(), key_data_copy(), key_data_set_hsm_key_id(), key_data_set_zone_id(), key_dependency_copy(), key_dependency_set_from_key_data_id(), key_dependency_set_to_key_data_id(), key_dependency_set_zone_id(), key_state_copy(), key_state_set_key_data_id(), policy_copy(), policy_key_copy(), policy_key_set_policy_id(), test_class_db_value(), test_database_operations_create_object2(), test_database_operations_create_object2_2(), test_database_operations_create_object3(), test_database_operations_create_object3_2(), zone_db_copy(), and zone_db_set_policy_id().

## db_value_enum_value()

int db_value_enum_value | ( | const db_value_t * | value,
|  | int * | enum_value
| ) |  |

Sets `enum_value` with the integer value of an enumeration database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | enum_value | an integer pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 332 of file db_value.c.

Referenced by test_class_db_value().

## db_value_free()

void db_value_free | ( | db_value_t * | value | ) |

Delete a database value.

Parameters

  [in] | value | a db_value_t pointer.

Definition at line 51 of file db_value.c.

Referenced by clean_suite_classes(), test2_free(), test_class_db_value(), and test_free().

## db_value_from_enum_value()

int db_value_from_enum_value | ( | db_value_t * | value,
|  | int | enum_value,
|  | const db_enum_t * | enum_set
| ) |  |

Set the database value to an enumeration value based on an integer value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | enum_value | an integer pointer.
  [in] | enum_set | a db_enum_t array that MUST end with NULL.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 572 of file db_value.c.

Referenced by test_class_db_value().

## db_value_from_int32()

int db_value_from_int32 | ( | db_value_t * | value,
|  | db_type_int32_t | from_int32
| ) |  |

Set the database value to a 32bit integer value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_int32 | a db_type_int32_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 479 of file db_value.c.

Referenced by test_class_db_clause(), and test_class_db_value().

## db_value_from_int64()

int db_value_from_int64 | ( | db_value_t * | value,
|  | db_type_int64_t | from_int64
| ) |  |

Set the database value to a 64bit integer value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_int64 | a db_type_int64_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 505 of file db_value.c.

Referenced by test_class_db_value().

## db_value_from_text()

int db_value_from_text | ( | db_value_t * | value,
|  | const char * | from_text
| ) |  |

Set the database value to a text value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_text | a character pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 531 of file db_value.c.

Referenced by test_class_db_value().

## db_value_from_text2()

int db_value_from_text2 | ( | db_value_t * | value,
|  | const char * | from_text,
|  | size_t | size
| ) |  |

Set the database value to a text value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_text | a character pointer.
  [in] | size | a size_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 550 of file db_value.c.

## db_value_from_uint32()

int db_value_from_uint32 | ( | db_value_t * | value,
|  | db_type_uint32_t | from_uint32
| ) |  |

Set the database value to an unsigned 32bit integer value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_uint32 | a db_type_uint32_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 492 of file db_value.c.

Referenced by test_class_db_value().

## db_value_from_uint64()

int db_value_from_uint64 | ( | db_value_t * | value,
|  | db_type_uint64_t | from_uint64
| ) |  |

Set the database value to an unsigned 64bit integer value.

Parameters

  [in] | value | a db_value_t pointer.
  [in] | from_uint64 | a db_type_uint64_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 518 of file db_value.c.

Referenced by test_class_db_value().

## db_value_int32()

const db_type_int32_t* db_value_int32 | ( | const db_value_t * | value | ) |

Get a pointer for the 32bit integer in a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a db_type_int32_t pointer or NULL on error, if empty or not a 32bit integer value. TODO: unit test

Definition at line 277 of file db_value.c.

## db_value_int64()

const db_type_int64_t* db_value_int64 | ( | const db_value_t * | value | ) |

Get a pointer for the 64bit integer in a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a db_type_int64_t pointer or NULL on error, if empty or not a 64bit integer value. TODO: unit test

Definition at line 299 of file db_value.c.

## db_value_new()

db_value_t* db_value_new | ( | void |  | ) |

Create a new database value.

Returns
  a db_value_t pointer or NULL on error.

Definition at line 40 of file db_value.c.

Referenced by test2_new(), test_class_db_value(), and test_new().

## db_value_not_empty()

int db_value_not_empty | ( | const db_value_t * | value | ) |

Check if a database value is not empty.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  DB_ERROR_* if empty, otherwise DB_OK.

Definition at line 347 of file db_value.c.

Referenced by hsm_key_list_new_get_by_policy_id(), hsm_key_set_policy_id(), key_data_get_hsm_key(), key_data_get_zone(), key_data_list_new_get_by_zone_id(), key_data_set_hsm_key_id(), key_data_set_zone_id(), key_dependency_get_from_key_data(), key_dependency_list_new_get_by_zone_id(), key_dependency_set_from_key_data_id(), key_dependency_set_to_key_data_id(), key_dependency_set_zone_id(), key_state_list_new_get_by_key_data_id(), key_state_set_key_data_id(), policy_get_policy_keys(), policy_key_list_new_get_by_policy_id(), policy_key_set_policy_id(), test_class_db_value(), zone_db_get_key_dependencies(), zone_db_get_keys(), zone_db_get_policy(), zone_db_set_policy_id(), and zone_list_db_new_get_by_policy_id().

## db_value_reset()

void db_value_reset | ( | db_value_t * | value | ) |

Reset a database value, releasing all interal resources and marking it empty.

Parameters

  [in] | value | a db_value_t pointer.

Definition at line 60 of file db_value.c.

Referenced by clean_suite_database_operations(), database_version_free(), hsm_key_free(), hsm_key_set_policy_id(), key_data_free(), key_data_set_hsm_key_id(), key_data_set_zone_id(), key_dependency_free(), key_dependency_set_from_key_data_id(), key_dependency_set_to_key_data_id(), key_dependency_set_zone_id(), key_state_free(), key_state_set_key_data_id(), policy_free(), policy_key_free(), policy_key_reset(), policy_key_set_policy_id(), test_class_db_value(), test_database_operations_create_object2(), test_database_operations_create_object2_2(), test_database_operations_create_object3(), test_database_operations_create_object3_2(), zone_db_free(), and zone_db_set_policy_id().

## db_value_set_at()

const db_value_t* db_value_set_at | ( | const db_value_set_t * | value_set,
|  | size_t | at
| ) |  |

Get a read only database value at a position in a database value set.

Parameters

  [in] | value_set | a db_value_set_t pointer.
  [in] | at | a size_t.

Returns
  a db_value_t pointer or NULL on error.

Definition at line 742 of file db_value.c.

Referenced by test_class_db_value_set().

## db_value_set_free()

void db_value_set_free | ( | db_value_set_t * | value_set | ) |

Delete a database value set and all values within the set.

Parameters

  [in] | value_set | a db_value_set_t pointer.

Definition at line 697 of file db_value.c.

Referenced by clean_suite_classes(), and test_class_end().

## db_value_set_get()

db_value_t* db_value_set_get | ( | db_value_set_t * | value_set,
|  | size_t | at
| ) |  |

Get a writable database value at a position in a database value set.

Parameters

  [in] | value_set | a db_value_set_t pointer.
  [in] | at | a size_t.

Returns
  a db_value_t pointer or NULL on error.

Definition at line 756 of file db_value.c.

Referenced by test_class_db_value_set().

## db_value_set_new()

db_value_set_t* db_value_set_new | ( | size_t | size | ) |

Create a new set of database value.

Parameters

  [in] | size | a size_t.

Returns
  a db_value_set_t pointer or NULL on error.

Definition at line 622 of file db_value.c.

Referenced by test_class_db_value_set().

## db_value_set_new_copy()

db_value_set_t* db_value_set_new_copy | ( | const db_value_set_t * | from_value_set | ) |

Create a new set of database value that is a copy of another.

Parameters

  [in] | from_value_set | a db_value_set_t pointer.

Returns
  a db_value_set_t pointer or NULL on error.

Definition at line 670 of file db_value.c.

## db_value_set_primary_key()

int db_value_set_primary_key | ( | db_value_t * | value | ) |

Mark the database as a primary key.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 595 of file db_value.c.

Referenced by test_class_db_value().

## db_value_set_size()

size_t db_value_set_size | ( | const db_value_set_t * | value_set | ) |

Get the size of database value set.

Parameters

  [in] | value_set | a db_value_set_t pointer.

Returns
  a size_t.

Definition at line 734 of file db_value.c.

Referenced by test_class_db_value_set().

## db_value_text()

const char* db_value_text | ( | const db_value_t * | value | ) |

Get a character pointer for the text in a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a character pointer or NULL on error, if empty or not a text value.

Definition at line 321 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_to_enum_value()

int db_value_to_enum_value | ( | const db_value_t * | value,
|  | int * | to_int,
|  | const db_enum_t * | enum_set
| ) |  |

Get the integer enumeration representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_int | an integer pointer.
  [in] | enum_set | a db_enum_t array that MUST end with NULL.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 438 of file db_value.c.

Referenced by test_class_db_value().

## db_value_to_int32()

int db_value_to_int32 | ( | const db_value_t * | value,
|  | db_type_int32_t * | to_int32
| ) |  |

Get the 32bit integer representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_int32 | a db_type_int32_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 357 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_to_int64()

int db_value_to_int64 | ( | const db_value_t * | value,
|  | db_type_int64_t * | to_int64
| ) |  |

Get the 64bit integer representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_int64 | a db_type_int64_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 387 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_to_text()

int db_value_to_text | ( | const db_value_t * | value,
|  | char ** | to_text
| ) |  |

Get the character representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_text | a character pointer pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 417 of file db_value.c.

Referenced by test_class_db_value().

## db_value_to_uint32()

int db_value_to_uint32 | ( | const db_value_t * | value,
|  | db_type_uint32_t * | to_uint32
| ) |  |

Get the unsigned 32bit integer representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_uint32 | a db_type_uint32_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 372 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_to_uint64()

int db_value_to_uint64 | ( | const db_value_t * | value,
|  | db_type_uint64_t * | to_uint64
| ) |  |

Get the unsigned 64bit integer representation of the database value.

Parameters

  [in] | value | a db_value_t pointer.
  [out] | to_uint64 | a db_type_uint64_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 402 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_type()

db_type_t db_value_type | ( | const db_value_t * | value | ) |

Get the type of a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a db_type_t.

Definition at line 269 of file db_value.c.

Referenced by __check_id(), and test_class_db_value().

## db_value_uint32()

const db_type_uint32_t* db_value_uint32 | ( | const db_value_t * | value | ) |

Get a pointer for the unsigned 32bit integer in a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a db_type_uint32_t pointer or NULL on error, if empty or not an unsigned 32bit integer value. TODO: unit test

Definition at line 288 of file db_value.c.

## db_value_uint64()

const db_type_uint64_t* db_value_uint64 | ( | const db_value_t * | value | ) |

Get a pointer for the unsigned 64bit integer in a database value.

Parameters

  [in] | value | a db_value_t pointer.

Returns
  a db_type_uint64_t pointer or NULL on error, if empty or not an unsigned 64bit integer value. TODO: unit test

Definition at line 310 of file db_value.c.