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

Go to the source code of this file.

## Functions

db_connection_t * | db_connection_new (void)
void | db_connection_free (db_connection_t *connection)
int | db_connection_set_configuration_list (db_connection_t *connection, const db_configuration_list_t *configuration_list)
int | db_connection_setup (db_connection_t *connection)
int | db_connection_connect (const db_connection_t *connection)
int | db_connection_create (const db_connection_t *connection, 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_connection_read (const db_connection_t *connection, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
int | db_connection_update (const db_connection_t *connection, 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_connection_delete (const db_connection_t *connection, const db_object_t *object, const db_clause_list_t *clause_list)
int | db_connection_count (const db_connection_t *connection, 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_connection_connect()

int db_connection_connect | ( | const db_connection_t * | connection | ) |

Connect to the database.

Parameters

  [in] | connection | a db_connection_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 88 of file db_connection.c.

References db_connection::backend, db_connection::configuration_list, db_backend_connect(), and DB_ERROR_UNKNOWN.

Referenced by get_database_connection(), test_class_db_connection(), and test_initialization_connection().

## db_connection_count()

int db_connection_count | ( | const db_connection_t * | connection,
|  | 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] | connection | a db_connection_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 170 of file db_connection.c.

References db_connection::backend, db_backend_count(), and DB_ERROR_UNKNOWN.

Referenced by db_object_count(), and test_class_db_connection().

## db_connection_create()

int db_connection_create | ( | const db_connection_t * | connection,
|  | 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] | connection | a db_connection_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 102 of file db_connection.c.

References db_connection::backend, db_backend_create(), and DB_ERROR_UNKNOWN.

Referenced by db_object_create(), and test_class_db_connection().

## db_connection_delete()

int db_connection_delete | ( | const db_connection_t * | connection,
|  | const db_object_t * | object,
|  | const db_clause_list_t * | clause_list
| ) |  |

Delete an object or objects from the database.

Parameters

  [in] | connection | a db_connection_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 156 of file db_connection.c.

References db_connection::backend, db_backend_delete(), and DB_ERROR_UNKNOWN.

Referenced by db_object_delete(), and test_class_db_connection().

## db_connection_free()

void db_connection_free | ( | db_connection_t * | connection | ) |

Delete a database connection and the database backend within.

Parameters

  [in] | connection | a db_connection_t pointer.

Definition at line 45 of file db_connection.c.

References db_connection::backend, and db_backend_free().

Referenced by autostart(), clean_suite_classes(), clean_suite_database_operations(), clean_suite_initialization(), enforce_task_flush_all(), engine_setup(), engine_stop_workers(), get_database_connection(), and test_class_end().

## db_connection_new()

db_connection_t * db_connection_new | ( | void |  | ) |

Create a new database connection.

Returns
  a db_connection_t pointer or NULL on error.

Definition at line 38 of file db_connection.c.

Referenced by get_database_connection(), test_class_db_connection(), and test_initialization_connection().

## db_connection_read()

db_result_list_t * db_connection_read | ( | const db_connection_t * | connection,
|  | 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] | connection | a db_connection_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 122 of file db_connection.c.

References db_connection::backend, and db_backend_read().

Referenced by db_object_read(), and test_class_db_connection().

## db_connection_set_configuration_list()

int db_connection_set_configuration_list | ( | db_connection_t * | connection,
|  | const db_configuration_list_t * | configuration_list
| ) |  |

Set the database configuration list for a database connection.

Parameters

  [in] | connection | a db_connection_t pointer.
  [in] | configuration_list | a db_configuration_list_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 54 of file db_connection.c.

References db_connection::configuration_list, DB_ERROR_UNKNOWN, and DB_OK.

Referenced by get_database_connection(), test_class_db_connection(), and test_initialization_connection().

## db_connection_setup()

int db_connection_setup | ( | db_connection_t * | connection | ) |

Setup the database connection, this verifies the information in the database configuration list and allocated a database backend.

Parameters

  [in] | connection | a db_connection_t pointer.

Returns
  DB_ERROR_* on failure, otherwise DB_OK.

Definition at line 66 of file db_connection.c.

References db_connection::backend, db_connection::configuration_list, db_backend_factory_get_backend(), db_configuration_list_find(), db_configuration_value(), DB_ERROR_UNKNOWN, and DB_OK.

Referenced by get_database_connection(), test_class_db_connection(), and test_initialization_connection().

## db_connection_update()

int db_connection_update | ( | const db_connection_t * | connection,
|  | 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] | connection | a db_connection_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 136 of file db_connection.c.

References db_connection::backend, db_backend_update(), and DB_ERROR_UNKNOWN.

Referenced by db_object_update(), and test_class_db_connection().