## Database

Database — Database related functions

## Stability Level

Unstable, unless otherwise indicated

## Functions

FontManagerDatabase * | font_manager_database_new ()
void | font_manager_database_open ()
void | font_manager_database_close ()
void | font_manager_database_begin_transaction ()
void | font_manager_database_commit_transaction ()
void | font_manager_database_execute_query ()
void | font_manager_database_end_query ()
sqlite3_stmt * | font_manager_database_get_cursor ()
void | font_manager_database_vacuum ()
void | font_manager_database_initialize ()
JsonObject * | font_manager_database_get_object ()
void | font_manager_update_database ()
gboolean | font_manager_update_database_finish ()
void | font_manager_get_matching_families_and_fonts ()

## Types and Values

#define | FONT_MANAGER_CURRENT_DATABASE_VERSION
#define | FONT_MANAGER_TYPE_DATABASE
| FontManagerDatabase

## Object Hierarchy

        GObject
        ╰── FontManagerDatabase

## Includes

    #include <font-manager-database.h>

## Description

Database class and related functions.

## Functions

### font_manager_database_new ()

    FontManagerDatabase *
    font_manager_database_new (void);

#### Returns

FontManagerDatabase.

[transfer full]

### font_manager_database_open ()

    void
    font_manager_database_open (FontManagerDatabase *self,
                                GError **error);

Open database.

Note: It is not necessary to call this function in normal usage. The methods provided by this class will open the database if needed.

#### Parameters

self | FontManagerDatabase |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_close ()

    void
    font_manager_database_close (FontManagerDatabase *self,
                                 GError **error);

Close database. It is not necessary to call this function in normal usage.

#### Parameters

self | FontManagerDatabase |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_begin_transaction ()

    void
    font_manager_database_begin_transaction
                                   (FontManagerDatabase *self,
                                    GError **error);

Begin a transaction, this should be paired with `font_manager_database_commit_transaction()`.

#### Parameters

self | FontManagerDatabase |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_commit_transaction ()

    void
    font_manager_database_commit_transaction
                                   (FontManagerDatabase *self,
                                    GError **error);

End a transaction. It is an error to call this function without having previously called `font_manager_database_begin_transaction()`.

#### Parameters

self | FontManagerDatabase |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_execute_query ()

    void
    font_manager_database_execute_query (FontManagerDatabase *self,
                                         const gchar *sql,
                                         GError **error);

Calls to this function must be paired with a call to font_manager_database_end_query

#### Parameters

self | FontManagerDatabase |
sql | Valid SQL query |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_end_query ()

    void
    font_manager_database_end_query (FontManagerDatabase *self);

Finalize the prepared statement created by a previous call to font_manager_database_execute_query

#### Parameters

self | fontManagerDatabase |

### font_manager_database_get_cursor ()

    sqlite3_stmt *
    font_manager_database_get_cursor (FontManagerDatabase *self);

[skip]

#### Parameters

self | FontManagerDatabase |

#### Returns

sqlite3_stmt or `NULL`.

[transfer none][nullable]

### font_manager_database_vacuum ()

    void
    font_manager_database_vacuum (FontManagerDatabase *self,
                                  GError **error);

Run sqlite3 VACUUM command on currently selected database.

#### Parameters

self | FontManagerDatabase |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_initialize ()

    void
    font_manager_database_initialize (FontManagerDatabase *self,
                                      GError **error);

Ensures database is at latest schema version. Creates required tables if needed.

#### Parameters

self | FontManagerDatabase instance |
error | GError or `NULL` to ignore errors. | [nullable]

### font_manager_database_get_object ()

    JsonObject *
    font_manager_database_get_object (FontManagerDatabase *self,
                                      const gchar *sql,
                                      GError **error);

#### Parameters

self | FontManagerDatabase |
sql | SQL query |
error | GError or `NULL` to ignore errors |

#### Returns

JsonObject representation of first result, `NULL` if there were no results or there was an error.

[transfer full][nullable]

### font_manager_update_database ()

    void
    font_manager_update_database (FontManagerDatabase *db,
                                  JsonArray *available_fonts,
                                  FontManagerProgressCallback progress,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data);

Update application database as needed.

#### Parameters

db | FontManagerDatabase instance |
available_fonts | JsonArray returned by font_manager_sort_json_listing |
progress | FontManagerProgressCallback. | [scope call][nullable]
cancellable | GCancellable or `NULL`. | [nullable]
callback | GAsyncReadyCallback or `NULL`. | [nullable][scope async]
user_data | user data passed to callback or `NULL`. | [nullable]

### font_manager_update_database_finish ()

    gboolean
    font_manager_update_database_finish (GAsyncResult *result,
                                         GError **error);

#### Parameters

result | GAsyncResult |
error | GError or `NULL` to ignore errors. | [nullable]

#### Returns

`TRUE` on success

### font_manager_get_matching_families_and_fonts ()

    void
    font_manager_get_matching_families_and_fonts
                                   (FontManagerDatabase *db,
                                    FontManagerStringSet *families,
                                    FontManagerStringSet *fonts,
                                    const gchar *sql,
                                    GError **error);

Query MUST return two result columns. The first containing the family name and the second containing the font description.

#### Parameters

db | FontManagerDatabase |
families | FontManagerStringSet |
fonts | FontManagerStringSet |
sql | SQL query to execute |
error | GError or `NULL` to ignore errors |

## Types and Values

### FONT_MANAGER_CURRENT_DATABASE_VERSION

    #define FONT_MANAGER_CURRENT_DATABASE_VERSION 3

### FONT_MANAGER_TYPE_DATABASE

    #define FONT_MANAGER_TYPE_DATABASE font_manager_database_get_type()

### FontManagerDatabase

    typedef struct _FontManagerDatabase FontManagerDatabase;