db_object.c File Reference
`#include "db_object.h"`
`#include "db_error.h"`
`#include <stdlib.h>`

Go to the source code of this file.

## Functions

db_object_field_t * | db_object_field_new (void)
db_object_field_t * | db_object_field_new_copy (const db_object_field_t *from_object_field)
void | db_object_field_free (db_object_field_t *object_field)
int | db_object_field_copy (db_object_field_t *object_field, const db_object_field_t *from_object_field)
const char * | db_object_field_name (const db_object_field_t *object_field)
db_type_t | db_object_field_type (const db_object_field_t *object_field)
int | db_object_field_set_name (db_object_field_t *object_field, const char *name)
int | db_object_field_set_type (db_object_field_t *object_field, db_type_t type)
int | db_object_field_set_enum_set (db_object_field_t *object_field, const db_enum_t *enum_set)
int | db_object_field_not_empty (const db_object_field_t *object_field)
const db_object_field_t * | db_object_field_next (const db_object_field_t *object_field)
db_object_field_list_t * | db_object_field_list_new (void)
db_object_field_list_t * | db_object_field_list_new_copy (const db_object_field_list_t *from_object_field_list)
void | db_object_field_list_free (db_object_field_list_t *object_field_list)
int | db_object_field_list_copy (db_object_field_list_t *object_field_list, const db_object_field_list_t *from_object_field_list)
int | db_object_field_list_add (db_object_field_list_t *object_field_list, db_object_field_t *object_field)
const db_object_field_t * | db_object_field_list_begin (const db_object_field_list_t *object_field_list)
size_t | db_object_field_list_size (const db_object_field_list_t *object_field_list)
db_object_t * | db_object_new (void)
void | db_object_free (db_object_t *object)
const db_connection_t * | db_object_connection (const db_object_t *object)
const char * | db_object_table (const db_object_t *object)
const db_object_field_list_t * | db_object_object_field_list (const db_object_t *object)
int | db_object_set_connection (db_object_t *object, const db_connection_t *connection)
int | db_object_set_table (db_object_t *object, const char *table)
int | db_object_set_primary_key_name (db_object_t *object, const char *primary_key_name)
int | db_object_set_object_field_list (db_object_t *object, db_object_field_list_t *object_field_list)
int | db_object_create (const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set)
db_result_list_t * | db_object_read (const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
int | db_object_update (const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set, const db_clause_list_t *clause_list)
int | db_object_delete (const db_object_t *object, const db_clause_list_t *clause_list)
int | db_object_count (const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)

## Function Documentation

## db_object_connection()

const db_connection_t * db_object_connection | ( | const db_object_t * | object | ) |

Get the database connection of a database object.

Parameters

  [in] | object | a db_object_t pointer.

Returns
  a db_connection_t pointer or NULL on error or if no connection has been set.

Definition at line 320 of file db_object.c.

Referenced by database_version_list_next(), hsm_key_list_begin(), hsm_key_list_get_begin(), hsm_key_list_get_next(), hsm_key_list_new_copy(), hsm_key_list_new_get_by_policy_key(), hsm_key_list_next(), hsm_key_new_copy(), key_data_cache_hsm_key(), key_data_get_hsm_key(), key_data_get_zone(), key_data_list_begin(), key_data_list_get_begin(), key_data_list_get_next(), key_data_list_new_copy(), key_data_list_next(), key_data_new_copy(), key_data_retrieve_key_state_list(), key_dependency_get_from_key_data(), key_dependency_list_begin(), key_dependency_list_get_begin(), key_dependency_list_get_next(), key_dependency_list_new_copy(), key_dependency_list_next(), key_dependency_new_copy(), key_state_list_begin(), key_state_list_get_begin(), key_state_list_get_next(), key_state_list_new_copy(), key_state_list_next(), key_state_new_copy(), policy_get_policy_keys(), policy_key_list_begin(), policy_key_list_get_next(), policy_key_list_new_copy(), policy_key_list_next(), policy_key_new_copy(), policy_list_begin(), policy_list_get_next(), policy_list_new_copy(), policy_list_next(), policy_new_copy(), policy_retrieve_zone_list(), test_class_db_object(), test_list_begin(), test_list_next(), zone_db_get_key_dependencies(), zone_db_get_keys(), zone_db_get_policy(), zone_db_new_copy(), zone_list_db_begin(), zone_list_db_get_next(), zone_list_db_new_copy(), and zone_list_db_next().

## db_object_count()

int db_object_count | ( | const db_object_t * | object,
|  | const db_join_list_t * | join_list,
|  | const db_clause_list_t * | clause_list,
|  | size_t * | count )

Count objects from the database. Return the count in count.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | join_list | a db_join_list_t pointer.
  [in] | clause_list | a db_clause_list_t pointer.
  [out] | count | a size_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 481 of file db_object.c.

References db_connection_count(), and DB_ERROR_UNKNOWN.

Referenced by hsm_key_count(), key_data_count(), test_class_db_object(), test_count_by_id(), test_count_by_name(), and zone_db_count().

## db_object_create()

int db_object_create | ( | const db_object_t * | object,
|  | const db_object_field_list_t * | object_field_list,
|  | const db_value_set_t * | value_set )

Create an object in the database. The object_field_list describes the fields that should be set in the object and the value_set has the values for each field.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | object_field_list | a db_object_field_list_t pointer.
  [in] | value_set | a db_value_set_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 401 of file db_object.c.

References db_connection_create(), and DB_ERROR_UNKNOWN.

Referenced by hsm_key_create(), key_data_create(), key_dependency_create(), key_state_create(), policy_create(), policy_key_create(), test2_create(), test_class_db_object(), test_create(), and zone_db_create().

## db_object_delete()

int db_object_delete | ( | const db_object_t * | object,
|  | const db_clause_list_t * | clause_list )

Delete an object or objects from the database.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | clause_list | a db_clause_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 464 of file db_object.c.

References db_connection_delete(), and DB_ERROR_UNKNOWN.

Referenced by hsm_key_factory_delete_key(), key_data_delete(), key_dependency_delete(), key_state_delete(), policy_delete(), policy_key_delete(), test2_delete(), test_class_db_object(), test_delete(), and zone_db_delete().

## db_object_field_copy()

int db_object_field_copy | ( | db_object_field_t * | object_field,
|  | const db_object_field_t * | from_object_field )

Copy the content of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.
  [in] | from_object_field | a db_object_field_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 76 of file db_object.c.

References DB_ERROR_UNKNOWN, DB_OK, db_object_field::enum_set, db_object_field::name, and db_object_field::type.

Referenced by db_object_field_new_copy().

## db_object_field_free()

void db_object_field_free | ( | db_object_field_t * | object_field | ) |

Delete a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.

Definition at line 69 of file db_object.c.

Referenced by clean_suite_classes(), db_object_field_list_free(), db_object_field_new_copy(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_list_add()

int db_object_field_list_add | ( | db_object_field_list_t * | object_field_list,
|  | db_object_field_t * | object_field )

Add a database object field to a database object field list, this will takes over the ownership of the object field.

Parameters

  [in] | object_field_list | a db_object_field_list_t pointer.
  [in] | object_field | a db_object_field_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 254 of file db_object.c.

References DB_ERROR_UNKNOWN, db_object_field_not_empty(), and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), db_object_field_list_copy(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_db_object_field_list(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_list_begin()

const db_object_field_t * db_object_field_list_begin | ( | const db_object_field_list_t * | object_field_list | ) |

Return the first database object field in a database object field list.

Parameters

  [in] | object_field_list | a db_object_field_list_t pointer.

Returns
  a db_object_field_t pointer or NULL on error or if the list is empty.

Definition at line 284 of file db_object.c.

Referenced by test_class_db_object_field_list().

## db_object_field_list_copy()

int db_object_field_list_copy | ( | db_object_field_list_t * | object_field_list,
|  | const db_object_field_list_t * | from_object_field_list )

Copy the content of a database object field list.

Parameters

  [in] | object_field_list | a db_object_field_list_t pointer.
  [in] | from_object_field_list | a db_object_field_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 216 of file db_object.c.

References db_object_field_list::begin, DB_ERROR_UNKNOWN, db_object_field_list_add(), db_object_field_new_copy(), and DB_OK.

Referenced by db_object_field_list_new_copy().

## db_object_field_list_free()

void db_object_field_list_free | ( | db_object_field_list_t * | object_field_list | ) |

Delete a object field list and all object fields within the list.

Parameters

  [in] | object_field_list | a db_object_field_list_t pointer.

Definition at line 199 of file db_object.c.

References db_object_field_free().

Referenced by clean_suite_classes(), db_object_field_list_new_copy(), db_object_free(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_end(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_list_new()

db_object_field_list_t * db_object_field_list_new | ( | void |  | ) |

Create a new object field list.

Returns
  a db_object_field_list_t pointer or NULL on error.

Definition at line 174 of file db_object.c.

Referenced by __test2_new_object(), __test_new_object(), db_object_field_list_new_copy(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_db_object_field_list(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_list_new_copy()

db_object_field_list_t * db_object_field_list_new_copy | ( | const db_object_field_list_t * | from_object_field_list | ) |

Create a new object field list that is a copy of another.

Parameters

  [in] | from_object_field_list | a db_object_field_list_t pointer.

Returns
  a db_object_field_list_t pointer or NULL on error.

Definition at line 182 of file db_object.c.

References db_object_field_list_copy(), db_object_field_list_free(), and db_object_field_list_new().

## db_object_field_list_size()

size_t db_object_field_list_size | ( | const db_object_field_list_t * | object_field_list | ) |

Return the size of a object field list.

Parameters

  [in] | object_field_list | a db_object_field_list_t pointer.

Returns
  a size_t, may be zero on error.

Definition at line 292 of file db_object.c.

## db_object_field_name()

const char * db_object_field_name | ( | const db_object_field_t * | object_field | ) |

Get the name of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.

Returns
  a character pointer or NULL on error or if no field name has been set.

Definition at line 94 of file db_object.c.

Referenced by test_class_db_object_field().

## db_object_field_new()

db_object_field_t * db_object_field_new | ( | void |  | ) |

Create a database object field.

Returns
  a db_object_field_t pointer or NULL on error.

Definition at line 40 of file db_object.c.

References DB_TYPE_EMPTY.

Referenced by __test2_new_object(), __test_new_object(), db_object_field_new_copy(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_db_object_field(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_new_copy()

db_object_field_t * db_object_field_new_copy | ( | const db_object_field_t * | from_object_field | ) |

Create a database object field that is a copy of another.

Parameters

  [in] | from_object_field | a db_object_field_t pointer.

Returns
  a db_object_field_t pointer or NULL on error.

Definition at line 52 of file db_object.c.

References db_object_field_copy(), db_object_field_free(), and db_object_field_new().

Referenced by db_object_field_list_copy().

## db_object_field_next()

const db_object_field_t * db_object_field_next | ( | const db_object_field_t * | object_field | ) |

Get the next object field connected in a database object field list.

Parameters

  [in] | object_field | a db_object_field_t pointer.

Returns
  a db_object_field_t pointer or NULL on error or if there are no more object fields in the list.

Definition at line 162 of file db_object.c.

References db_object_field::next.

Referenced by test_class_db_object_field_list().

## db_object_field_not_empty()

int db_object_field_not_empty | ( | const db_object_field_t * | object_field | ) |

Check if the object field is not empty.

Parameters

  [in] | object_field | a db_object_field_t pointer.

Returns
  DB_ERROR_* if empty, otherwise DB_OK.

Definition at line 146 of file db_object.c.

References DB_ERROR_UNKNOWN, DB_OK, DB_TYPE_EMPTY, and DB_TYPE_ENUM.

Referenced by db_object_field_list_add(), and test_class_db_object_field().

## db_object_field_set_enum_set()

int db_object_field_set_enum_set | ( | db_object_field_t * | object_field,
|  | const db_enum_t * | enum_set )

Set the enumerate set of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.
  [in] | enum_set | a NULL terminated db_enum_t list.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 134 of file db_object.c.

References DB_ERROR_UNKNOWN, DB_OK, and DB_TYPE_ENUM.

Referenced by hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), and test_class_db_object_field().

## db_object_field_set_name()

int db_object_field_set_name | ( | db_object_field_t * | object_field,
|  | const char * | name )

Set the name of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.
  [in] | name | a character pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 110 of file db_object.c.

References DB_ERROR_UNKNOWN, and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_db_object_field(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_set_type()

int db_object_field_set_type | ( | db_object_field_t * | object_field,
|  | db_type_t | type )

Set the type of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.
  [in] | type | a db_type_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 122 of file db_object.c.

References DB_ERROR_UNKNOWN, DB_OK, and DB_TYPE_EMPTY.

Referenced by __test2_new_object(), __test_new_object(), hsm_key_create(), hsm_key_update(), key_data_create(), key_data_update(), key_dependency_create(), key_state_create(), key_state_update(), policy_create(), policy_key_create(), policy_update(), test2_create(), test2_update(), test_class_db_object_field(), test_create(), test_update(), zone_db_create(), and zone_db_update().

## db_object_field_type()

db_type_t db_object_field_type | ( | const db_object_field_t * | object_field | ) |

Get the type of a database object field.

Parameters

  [in] | object_field | a db_object_field_t pointer.

Returns
  a db_type_t.

Definition at line 102 of file db_object.c.

References DB_TYPE_EMPTY.

Referenced by test_class_db_object_field().

## db_object_free()

void db_object_free | ( | db_object_t * | object | ) |

Delete a database object and the object field list and backend meta data list if set.

Parameters

  [in] | object | a db_object_t pointer.

Definition at line 311 of file db_object.c.

References db_object_field_list_free().

Referenced by clean_suite_classes(), database_version_free(), database_version_list_free(), hsm_key_free(), hsm_key_list_free(), key_data_free(), key_data_list_free(), key_dependency_free(), key_dependency_list_free(), key_state_free(), key_state_list_free(), policy_free(), policy_key_free(), policy_key_list_free(), policy_list_free(), test2_free(), test_class_db_object(), test_free(), test_list_free(), zone_db_free(), and zone_list_db_free().

## db_object_new()

db_object_t * db_object_new | ( | void |  | ) |

Create a new database object.

Returns
  a db_object_t pointer or NULL on error.

Definition at line 304 of file db_object.c.

Referenced by __test2_new_object(), __test_new_object(), and test_class_db_object().

## db_object_object_field_list()

const db_object_field_list_t * db_object_object_field_list | ( | const db_object_t * | object | ) |

Get the object field list of a database object.

Parameters

  [in] | object | a db_object_t pointer.

Returns
  a db_object_field_list_t pointer or NULL on error or if no object field list has been set.

Definition at line 334 of file db_object.c.

Referenced by test_class_db_object().

## db_object_read()

db_result_list_t * db_object_read | ( | const db_object_t * | object,
|  | const db_join_list_t * | join_list,
|  | const db_clause_list_t * | clause_list )

Read an object or objects from the database.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | join_list | a db_join_list_t pointer.
  [in] | clause_list | a db_clause_list_t pointer.

Returns
  a db_result_list_t pointer or NULL on error or if no objects where read.

Definition at line 424 of file db_object.c.

References db_connection_read().

Referenced by database_version_list_get(), hsm_key_get_by_id(), hsm_key_get_by_locator(), hsm_key_list_get_by_clauses(), hsm_key_list_get_by_policy_id(), key_data_get_by_hsm_key_id(), key_data_get_by_id(), key_data_list_get(), key_data_list_get_by_clauses(), key_data_list_get_by_zone_id(), key_dependency_get_by_id(), key_dependency_list_get_by_clauses(), key_dependency_list_get_by_zone_id(), key_state_get_by_id(), key_state_list_get_by_clauses(), key_state_list_get_by_key_data_id(), policy_get_by_id(), policy_get_by_name(), policy_key_get_by_id(), policy_key_get_by_policyid_and_role(), policy_key_list_get_by_clauses(), policy_key_list_get_by_policy_id(), policy_list_get(), policy_list_get_by_clauses(), test2_get_by_id(), test2_get_by_name(), test_class_db_object(), test_get_by_id(), test_get_by_name(), test_list_get(), zone_db_get_by_id(), zone_db_get_by_name(), zone_list_db_get(), zone_list_db_get_by_clauses(), and zone_list_db_get_by_policy_id().

## db_object_set_connection()

int db_object_set_connection | ( | db_object_t * | object,
|  | const db_connection_t * | connection )

Set the database connection of a database object.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | connection | a db_connection_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 341 of file db_object.c.

References DB_ERROR_UNKNOWN, and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), and test_class_db_object().

## db_object_set_object_field_list()

int db_object_set_object_field_list | ( | db_object_t * | object,
|  | db_object_field_list_t * | object_field_list )

Set the object field list of a database object, this takes over the ownership of the object field list.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | object_field_list | a db_object_field_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 386 of file db_object.c.

References DB_ERROR_UNKNOWN, and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), and test_class_db_object().

## db_object_set_primary_key_name()

int db_object_set_primary_key_name | ( | db_object_t * | object,
|  | const char * | primary_key_name )

Set the primary key name of a database object.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | primary_key_name | a character pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 371 of file db_object.c.

References DB_ERROR_UNKNOWN, and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), and test_class_db_object().

## db_object_set_table()

int db_object_set_table | ( | db_object_t * | object,
|  | const char * | table )

Set the table name of a database object.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | table | a character pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 356 of file db_object.c.

References DB_ERROR_UNKNOWN, and DB_OK.

Referenced by __test2_new_object(), __test_new_object(), and test_class_db_object().

## db_object_table()

const char * db_object_table | ( | const db_object_t * | object | ) |

Get the table name of a database object.

Parameters

  [in] | object | a db_object_t pointer.

Returns
  a character pointer or NULL on error or if no table name has been set.

Definition at line 327 of file db_object.c.

Referenced by test_class_db_object().

## db_object_update()

int db_object_update | ( | const db_object_t * | object,
|  | const db_object_field_list_t * | object_field_list,
|  | const db_value_set_t * | value_set,
|  | const db_clause_list_t * | clause_list )

Update an object or objects in the database.

Parameters

  [in] | object | a db_object_t pointer.
  [in] | object_field_list | a db_object_field_list_t pointer.
  [in] | value_set | a db_value_set_t pointer.
  [in] | clause_list | a db_clause_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 441 of file db_object.c.

References db_connection_update(), and DB_ERROR_UNKNOWN.

Referenced by hsm_key_update(), key_data_update(), key_state_update(), policy_update(), test2_update(), test_class_db_object(), test_update(), and zone_db_update().