db_backend.c File Reference
`#include "config.h"`
`#include "db_backend.h"`
`#include "db_backend_mysql.h"`
`#include "db_error.h"`
`#include "database_version.h"`
`#include "hsm_key.h"`
`#include <stdlib.h>`
`#include <string.h>`

Go to the source code of this file.

## Functions

db_backend_handle_t * | db_backend_handle_new (void)
void | db_backend_handle_free (db_backend_handle_t *backend_handle)
int | db_backend_handle_initialize (const db_backend_handle_t *backend_handle)
int | db_backend_handle_connect (const db_backend_handle_t *backend_handle, const db_configuration_list_t *configuration_list)
int | db_backend_handle_create (const db_backend_handle_t *backend_handle, 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_backend_handle_read (const db_backend_handle_t *backend_handle, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
int | db_backend_handle_update (const db_backend_handle_t *backend_handle, 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_backend_handle_delete (const db_backend_handle_t *backend_handle, const db_object_t *object, const db_clause_list_t *clause_list)
int | db_backend_handle_count (const db_backend_handle_t *backend_handle, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)
int | db_backend_handle_set_initialize (db_backend_handle_t *backend_handle, db_backend_handle_initialize_t initialize_function)
int | db_backend_handle_set_shutdown (db_backend_handle_t *backend_handle, db_backend_handle_shutdown_t shutdown_function)
int | db_backend_handle_set_connect (db_backend_handle_t *backend_handle, db_backend_handle_connect_t connect_function)
int | db_backend_handle_set_disconnect (db_backend_handle_t *backend_handle, db_backend_handle_disconnect_t disconnect_function)
int | db_backend_handle_set_create (db_backend_handle_t *backend_handle, db_backend_handle_create_t create_function)
int | db_backend_handle_set_read (db_backend_handle_t *backend_handle, db_backend_handle_read_t read_function)
int | db_backend_handle_set_update (db_backend_handle_t *backend_handle, db_backend_handle_update_t update_function)
int | db_backend_handle_set_delete (db_backend_handle_t *backend_handle, db_backend_handle_delete_t delete_function)
int | db_backend_handle_set_count (db_backend_handle_t *backend_handle, db_backend_handle_count_t count_function)
int | db_backend_handle_set_free (db_backend_handle_t *backend_handle, db_backend_handle_free_t free_function)
int | db_backend_handle_set_transaction_begin (db_backend_handle_t *backend_handle, db_backend_handle_transaction_begin_t transaction_begin_function)
int | db_backend_handle_set_transaction_commit (db_backend_handle_t *backend_handle, db_backend_handle_transaction_commit_t transaction_commit_function)
int | db_backend_handle_set_transaction_rollback (db_backend_handle_t *backend_handle, db_backend_handle_transaction_rollback_t transaction_rollback_function)
int | db_backend_handle_set_data (db_backend_handle_t *backend_handle, void *data)
db_backend_t * | db_backend_new (void)
void | db_backend_free (db_backend_t *backend)
int | db_backend_set_name (db_backend_t *backend, const char *name)
int | db_backend_set_handle (db_backend_t *backend, db_backend_handle_t *handle)
int | db_backend_initialize (const db_backend_t *backend)
int | db_backend_connect (const db_backend_t *backend, const db_configuration_list_t *configuration_list)
int | db_backend_create (const db_backend_t *backend, 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_backend_read (const db_backend_t *backend, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
int | db_backend_update (const db_backend_t *backend, 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_backend_delete (const db_backend_t *backend, const db_object_t *object, const db_clause_list_t *clause_list)
int | db_backend_count (const db_backend_t *backend, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)
db_backend_t * | db_backend_factory_get_backend (const char *name)

## Function Documentation

## db_backend_connect()

int db_backend_connect | ( | const db_backend_t * | backend,
|  | const db_configuration_list_t * | configuration_list
| ) |  |

Connect to the database of a database backend, the connection specific configuration is given by `configuration_list`.

Parameters

  [in] | backend | a db_backend_t pointer.
  [in] | configuration_list | a db_configuration_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 371 of file db_backend.c.

Referenced by test_class_db_backend().

## db_backend_count()

int db_backend_count | ( | const db_backend_t * | backend,
|  | 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] | backend | a db_backend_t pointer.
  [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 453 of file db_backend.c.

## db_backend_create()

int db_backend_create | ( | const db_backend_t * | backend,
|  | 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` refer to the database object begin created, 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] | backend | a db_backend_t pointer.
  [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 385 of file db_backend.c.

## db_backend_delete()

int db_backend_delete | ( | const db_backend_t * | backend,
|  | const db_object_t * | object,
|  | const db_clause_list_t * | clause_list
| ) |  |

Delete an object or objects from the database.

Parameters

  [in] | backend | a db_backend_t pointer.
  [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 439 of file db_backend.c.

## db_backend_factory_get_backend()

db_backend_t* db_backend_factory_get_backend | ( | const char * | name | ) |

Get a new database backend by the name supplied in `name`.

Parameters

  [in] | name | a character pointer.

Returns
  a db_backend_t pointer or NULL on error or if the database backend does not exist.

Definition at line 472 of file db_backend.c.

## db_backend_free()

void db_backend_free | ( | db_backend_t * | backend | ) |

Delete a database backend.

Parameters

  [in] | backend | a db_backend_t pointer.

Definition at line 318 of file db_backend.c.

Referenced by clean_suite_classes(), and test_class_end().

## db_backend_handle_connect()

int db_backend_handle_connect | ( | const db_backend_handle_t * | backend_handle,
|  | const db_configuration_list_t * | configuration_list
| ) |  |

Connect to the database of a database backend, the connection specific configuration is given by `configuration_list`.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | configuration_list | a db_configuration_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 79 of file db_backend.c.

## db_backend_handle_count()

int db_backend_handle_count | ( | const db_backend_handle_t * | backend_handle,
|  | 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] | backend_handle | a db_backend_handle_t pointer.
  [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 161 of file db_backend.c.

## db_backend_handle_create()

int db_backend_handle_create | ( | const db_backend_handle_t * | backend_handle,
|  | 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` refer to the database object begin created, 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] | backend_handle | a db_backend_handle_t pointer.
  [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 93 of file db_backend.c.

## db_backend_handle_delete()

int db_backend_handle_delete | ( | const db_backend_handle_t * | backend_handle,
|  | const db_object_t * | object,
|  | const db_clause_list_t * | clause_list
| ) |  |

Delete an object or objects from the database.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [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 147 of file db_backend.c.

## db_backend_handle_free()

void db_backend_handle_free | ( | db_backend_handle_t * | backend_handle | ) |

Delete a database backend handle, disconnecting the backend and freeing the backend specific data.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.

Definition at line 56 of file db_backend.c.

Referenced by clean_suite_classes().

## db_backend_handle_initialize()

int db_backend_handle_initialize | ( | const db_backend_handle_t * | backend_handle | ) |

Initiate the backend of a database backend.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 68 of file db_backend.c.

## db_backend_handle_new()

db_backend_handle_t* db_backend_handle_new | ( | void |  | ) |

Create a new database backend handle.

Returns
  a db_backend_handle_t pointer or NULL on error.

Definition at line 49 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_read()

db_result_list_t* db_backend_handle_read | ( | const db_backend_handle_t * | backend_handle,
|  | 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] | backend_handle | a db_backend_handle_t pointer.
  [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 113 of file db_backend.c.

## db_backend_handle_set_connect()

int db_backend_handle_set_connect | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_connect_t | connect_function
| ) |  |

Set the connect function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | connect_function | a db_backend_handle_connect_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 196 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_count()

int db_backend_handle_set_count | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_count_t | count_function
| ) |  |

Set the count function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | count_function | a db_backend_handle_count_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 250 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_create()

int db_backend_handle_set_create | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_create_t | create_function
| ) |  |

Set the create function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | create_function | a db_backend_handle_create_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 214 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_data()

int db_backend_handle_set_data | ( | db_backend_handle_t * | backend_handle,
|  | void * | data
| ) |  |

Set the backend specific data of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | data | a void pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 295 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_delete()

int db_backend_handle_set_delete | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_delete_t | delete_function
| ) |  |

Set the delete function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | delete_function | a db_backend_handle_delete_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 241 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_disconnect()

int db_backend_handle_set_disconnect | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_disconnect_t | disconnect_function
| ) |  |

Set the disconnect function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | disconnect_function | a db_backend_handle_disconnect_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 205 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_free()

int db_backend_handle_set_free | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_free_t | free_function
| ) |  |

Set the free function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | free_function | a db_backend_handle_free_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 259 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_initialize()

int db_backend_handle_set_initialize | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_initialize_t | initialize_function
| ) |  |

Set the initialize function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | initialize_function | a db_backend_handle_initialize_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 178 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_read()

int db_backend_handle_set_read | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_read_t | read_function
| ) |  |

Set the read function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | read_function | a db_backend_handle_read_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 223 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_shutdown()

int db_backend_handle_set_shutdown | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_shutdown_t | shutdown_function
| ) |  |

Set the shutdown function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | shutdown_function | a db_backend_handle_shutdown_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 187 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_transaction_begin()

int db_backend_handle_set_transaction_begin | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_transaction_begin_t | transaction_begin_function
| ) |  |

Set the transaction begin function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | transaction_begin_function | a db_backend_handle_transaction_begin_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 268 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_transaction_commit()

int db_backend_handle_set_transaction_commit | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_transaction_commit_t | transaction_commit_function
| ) |  |

Set the transaction commit function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | transaction_commit_function | a db_backend_handle_transaction_commit_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 277 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_transaction_rollback()

int db_backend_handle_set_transaction_rollback | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_transaction_rollback_t | transaction_rollback_function
| ) |  |

Set the transaction rollback function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | transaction_rollback_function | a db_backend_handle_transaction_rollback_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 286 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_set_update()

int db_backend_handle_set_update | ( | db_backend_handle_t * | backend_handle,
|  | db_backend_handle_update_t | update_function
| ) |  |

Set the update function of a database backend handle.

Parameters

  [in] | backend_handle | a db_backend_handle_t pointer.
  [in] | update_function | a db_backend_handle_update_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 232 of file db_backend.c.

Referenced by test_class_db_backend_handle().

## db_backend_handle_update()

int db_backend_handle_update | ( | const db_backend_handle_t * | backend_handle,
|  | 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] | backend_handle | a db_backend_handle_t pointer.
  [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 127 of file db_backend.c.

## db_backend_initialize()

int db_backend_initialize | ( | const db_backend_t * | backend | ) |

Initiate the backend of a database backend.

Parameters

  [in] | backend | a db_backend_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 360 of file db_backend.c.

Referenced by test_class_db_backend().

## db_backend_new()

db_backend_t* db_backend_new | ( | void |  | ) |

Create a new database backend.

Returns
  a db_backend_t pointer or NULL on error.

Definition at line 311 of file db_backend.c.

Referenced by test_class_db_backend().

## db_backend_read()

db_result_list_t* db_backend_read | ( | const db_backend_t * | backend,
|  | 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] | backend | a db_backend_t pointer.
  [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 405 of file db_backend.c.

## db_backend_set_handle()

int db_backend_set_handle | ( | db_backend_t * | backend,
|  | db_backend_handle_t * | handle
| ) |  |

Det the database backend handle of a database backend, this takes over the ownership of the database backend handle.

Parameters

  [in] | backend | a db_backend_t pointer.
  [in] | handle | a db_backend_handle_t.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 348 of file db_backend.c.

Referenced by test_class_db_backend().

## db_backend_set_name()

int db_backend_set_name | ( | db_backend_t * | backend,
|  | const char * | name
| ) |  |

Set the name of a database backend.

Parameters

  [in] | backend | a db_backend_t pointer.
  [in] | name | a character pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 330 of file db_backend.c.

Referenced by test_class_db_backend().

## db_backend_update()

int db_backend_update | ( | const db_backend_t * | backend,
|  | 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] | backend | a db_backend_t pointer.
  [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 419 of file db_backend.c.