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 hsm_key_list_new_copy(), hsm_key_new_copy(), key_data_cache_hsm_key(), key_data_get_hsm_key(), key_data_get_zone(), key_data_list_new_copy(), key_data_new_copy(), key_dependency_get_from_key_data(), key_dependency_list_new_copy(), key_dependency_new_copy(), key_state_list_new_copy(), key_state_new_copy(), policy_get_policy_keys(), policy_key_list_new_copy(), policy_key_new_copy(), policy_list_new_copy(), policy_new_copy(), zone_db_get_key_dependencies(), zone_db_get_keys(), zone_db_get_policy(), zone_db_new_copy(), and zone_list_db_new_copy().

## 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.

## 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.

## 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.

## 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.

## 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_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.

## 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.

## 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.

## 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.

Referenced by clean_suite_classes(), db_object_free(), and test_class_end().

## 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.

## 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.

## 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.

Referenced by test_class_db_object_field().

## 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.

## 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.

## 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.

Referenced by 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.

Referenced by 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.

Referenced by test_class_db_object_field().

## 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.

Referenced by test_class_db_object_field().

## 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.

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(), and db_object::object_field_list.

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_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.

## 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.

## 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.

Referenced by database_version_list_get(), key_data_list_get(), policy_list_get(), test_list_get(), and zone_list_db_get().

## 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.

## 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.

## 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, DB_OK, and db_object::primary_key_name.

## 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, DB_OK, and db_object::table.

## 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.

## 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.