metadata_table.h File Reference

#include <glib.h>
#include "metadata_cell.h"
Include dependency graph for metadata_table.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  metadata_table

Defines

#define metadata_table_n_rows(table)   (table ? (table)->n_rows : 0 )
#define metadata_table_n_columns(table)   (table ? (table)->n_columns : 0 )
#define metadata_table_data(table)   (table ? (table)->cell_data : NULL)
#define metadata_table_cell_index(table, row, column)   (table ? (((row) * (table)->n_columns) + (column)) : 0)
#define metadata_table_free(table)
 Free the memory allocated to a metadata_table and the elements it holds and clear the pointer passed as argument. Function is void when a NULL pointer is passed.
#define metadata_table_dump(thiz)
 Dump content of a metadata_table,.

Functions

metadata_tablemetadata_table_new (void)
 Create a new metadata_table.
void metadata_table_free_impl (metadata_table *thiz)
void metadata_table_dump_impl (const metadata_table *thiz)
int metadata_table_add_column (metadata_table *thiz, const char *name)
 Add a column at the end of the table, only allowed on empty table or table with one row.
int metadata_table_find_column (const metadata_table *thiz, const char *name)
 Find column by its name.
int metadata_table_set_int64 (metadata_table *thiz, const guint idx, const gint64 value)
 Assign an integer value to a specific cell in a sql table.
int metadata_table_set_double (metadata_table *thiz, const guint idx, const double value)
 Assign a floating point value to a specific cell in a sql table.
int metadata_table_set_text (metadata_table *thiz, const guint idx, const char *value)
 Assign a string value to a specific cell in a sql table This may move data already in the table to another memory location.
int metadata_table_set_blob (metadata_table *thiz, const guint idx, gchar *value, const guint len)
 Assign a blob to a specific cell in a sql table BLOB = Binary Large OBject.
const metadata_cellmetadata_table_get_cell (const metadata_table *thiz, const guint idx)
 Report the value of a specific cell in a metadata_table.
GString * metadata_table_get_string (const metadata_table *thiz, const guint idx)
 Report the value of a specific cell in a metadata_table, converted to a UTF-8 text string Not possible for SQLCELL_BLOB types.

Define Documentation

#define metadata_table_cell_index ( table,
row,
column   )     (table ? (((row) * (table)->n_columns) + (column)) : 0)
#define metadata_table_data ( table   )     (table ? (table)->cell_data : NULL)

Definition at line 51 of file metadata_table.h.

#define metadata_table_dump ( thiz   ) 

Dump content of a metadata_table,.

---------------------------------------------------------------------------

Name : metadata_table_dump

Parameters:
thiz - the metadata_table
Returns:
--

--------------------------------------------------------------------------

Definition at line 120 of file metadata_table.h.

Referenced by execute_single_statement(), and sql3_execute_query().

#define metadata_table_free ( table   ) 
Value:
{                                    \
            metadata_table_free_impl(table); \
            (table) = NULL;                  \
        }

Free the memory allocated to a metadata_table and the elements it holds and clear the pointer passed as argument. Function is void when a NULL pointer is passed.

---------------------------------------------------------------------------

Name : metadata_table_free

Parameters:
thiz - the metadata_table to be freed
Returns:
--

--------------------------------------------------------------------------

Definition at line 98 of file metadata_table.h.

Referenced by add_file_ids(), check_database_version(), check_global_database_columns(), check_global_database_tables(), clear_last_read(), convert_database_01_06(), convert_database_05_06(), db_query_create(), db_query_execute(), db_query_execute_path_filter(), db_query_execute_recent(), db_query_execute_search_filter(), db_query_get_metadata(), db_query_update_lastread(), ermetadb_local_get_application_data(), execute_single_statement(), filemodel_quit(), get_global_id(), get_local_id(), load_application_data(), load_dir_from_metadb(), load_document_data(), load_file_metadata(), meta_file_close(), meta_file_open(), open_sql_database(), rotate_keyval_table(), save_application_data(), save_file_metadata(), set_annotation_impl(), sql3_execute_query(), and sql3_execute_statements().

#define metadata_table_n_columns ( table   )     (table ? (table)->n_columns : 0 )
#define metadata_table_n_rows ( table   )     (table ? (table)->n_rows : 0 )

File Name : metadata_table.h

Description: Table with metadata, usually results of a sql query. This type is designed for easy compatibility with sqlite3. Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 49 of file metadata_table.h.

Referenced by add_file_ids(), check_global_database_columns(), check_global_database_tables(), db_get_model(), ermetadb_global_get_file(), ermetadb_local_remove_application_data(), ermetadb_local_set_application_data(), execute_single_statement(), load_dir_from_metadb(), metadata_table_dump_impl(), rotate_keyval_table(), and set_file_metadata_impl().


Function Documentation

int metadata_table_add_column ( metadata_table thiz,
const char *  name 
)

Add a column at the end of the table, only allowed on empty table or table with one row.

---------------------------------------------------------------------------

Name : metadata_table_add_column

Parameters:
thiz - the metadata_table
[in] name - name of the column to be added
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 127 of file metadata_table.c.

References metadata_table::cell_data, ER_INVALID_PARAMETER, ER_OK, LOGPRINTF, metadata_cell_set_name(), metadata_table::n_columns, and metadata_table::n_rows.

Referenced by create_result_table(), db_query_create(), db_query_update_lastread(), load_application_data(), load_file_metadata(), meta_file_close(), meta_file_open(), rotate_keyval_table(), save_application_data(), save_file_metadata(), and set_annotation_impl().

00128 {
00129     LOGPRINTF("entry: thiz [%p] name [%s]", thiz, name);
00130 
00131     g_return_val_if_fail(thiz,                ER_INVALID_PARAMETER);
00132     g_return_val_if_fail(name,                ER_INVALID_PARAMETER);
00133     g_return_val_if_fail((thiz->n_rows <= 1), ER_INVALID_PARAMETER);
00134 
00135     // add column
00136     thiz->n_columns++;
00137     guint n_col = thiz->n_columns;
00138     g_array_set_size(thiz->cell_data, n_col);
00139 
00140     // set name
00141     metadata_cell *cell = &g_array_index(thiz->cell_data, metadata_cell, n_col - 1);
00142     metadata_cell_set_name(cell, name);
00143 
00144     return ER_OK;
00145 }

Here is the call graph for this function:

Here is the caller graph for this function:

void metadata_table_dump_impl ( const metadata_table thiz  ) 

Definition at line 83 of file metadata_table.c.

References LOGPRINTF, metadata_table_cell_index, metadata_table_get_cell(), metadata_table_get_string(), metadata_table_n_columns, metadata_table_n_rows, metadata_cell::name, and QUERYPRINTF.

00084 {
00085     LOGPRINTF("entry: thiz [%p]", thiz);
00086     if (thiz == NULL) return;
00087 
00088     int n_rows = metadata_table_n_rows(thiz);
00089     int n_cols = metadata_table_n_columns(thiz);
00090     GString *dump = g_string_new("");
00091 
00092     // print column names
00093     int col;
00094     for (col = 0; col < n_cols ; col++)
00095     {
00096         const metadata_cell *cell = metadata_table_get_cell(thiz, col);
00097         if (cell->name  &&  cell->name->str)
00098         {
00099             g_string_append(dump, cell->name->str);
00100         }
00101         g_string_append_c(dump, '|');
00102     }
00103     QUERYPRINTF("%s", dump->str);
00104 
00105     // print row values
00106     int row;
00107     for (row = 0 ; row < n_rows ; row++)
00108     {
00109         g_string_set_size(dump, 0);
00110         for (col = 0; col < n_cols ; col++)
00111         {
00112             GString *value = metadata_table_get_string(thiz, metadata_table_cell_index(thiz, row, col));
00113             if (value  &&  value->str)
00114             {
00115                 g_string_append(dump, value->str);
00116                 g_string_free(value, TRUE);
00117             }
00118             g_string_append_c(dump, '|');
00119         }
00120         QUERYPRINTF("%s", dump->str);
00121     }
00122 
00123     g_string_free(dump, TRUE);
00124 }

Here is the call graph for this function:

int metadata_table_find_column ( const metadata_table thiz,
const char *  name 
)

Find column by its name.

---------------------------------------------------------------------------

Name : metadata_table_find_column

Parameters:
thiz - the metadata_table
[in] name - name of the column to be found
Returns:
index of the column (0 ...), or -1 on error

--------------------------------------------------------------------------

Definition at line 148 of file metadata_table.c.

References metadata_table::cell_data, LOGPRINTF, metadata_table::n_columns, and metadata_cell::name.

Referenced by check_global_database_columns(), check_global_database_tables(), get_column_data(), load_application_data(), load_file_metadata(), load_page_data(), load_pages_basic_data(), rotate_keyval_table(), save_application_data(), set_boolean(), and set_double().

00149 {
00150     LOGPRINTF("entry: thiz [%p] name [%s]", thiz, name);
00151     g_assert(thiz);
00152     g_assert(name);
00153 
00154     metadata_cell *cell = &g_array_index(thiz->cell_data, metadata_cell, 0);
00155     unsigned int i;
00156     for (i = 0 ; i < thiz->n_columns; i++, cell++)
00157     {
00158         if (strcmp(name, cell->name->str) == 0)
00159         {
00160             return i;
00161         }
00162     }
00163 
00164     return -1;
00165 }

Here is the caller graph for this function:

void metadata_table_free_impl ( metadata_table thiz  ) 

Definition at line 65 of file metadata_table.c.

References metadata_table::cell_data, and metadata_cell_clear().

00066 {
00067     if (thiz == NULL) return;
00068     g_return_if_fail(thiz->cell_data);
00069 
00070     // clear all cells
00071     metadata_cell *cell = &g_array_index(thiz->cell_data, metadata_cell, 0);
00072     unsigned int i;
00073     for (i = 0 ; i < thiz->cell_data->len ; i++, cell++)
00074     {
00075         metadata_cell_clear(cell);
00076     }
00077 
00078     g_array_free(thiz->cell_data, TRUE);
00079     g_free(thiz);
00080 }

Here is the call graph for this function:

const metadata_cell* metadata_table_get_cell ( const metadata_table thiz,
const guint  idx 
)

Report the value of a specific cell in a metadata_table.

---------------------------------------------------------------------------

Name : metadata_table_get_cell

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
Returns:
cell value as a metadata_cell -- DO NOT MODIFY or NULL when error

--------------------------------------------------------------------------

Definition at line 310 of file metadata_table.c.

References metadata_table::cell_data, and LOGPRINTF.

Referenced by add_file_ids(), bind_single_statement(), check_database_version(), ermetadb_local_set_application_data(), get_column_data(), get_column_names(), get_global_id(), get_keys(), get_local_id(), load_application_data(), load_file_metadata(), load_page_data(), load_pages_basic_data(), metadata_table_dump_impl(), metadata_table_get_string(), rotate_keyval_table(), and set_file_metadata_impl().

00311 {
00312     LOGPRINTF("entry: thiz [%p] idx [%d]", thiz, idx);
00313     g_return_val_if_fail(thiz,                         NULL);
00314     g_return_val_if_fail(thiz->cell_data,              NULL);
00315 
00316     if (idx < thiz->cell_data->len)
00317     {
00318         // report cell
00319         const metadata_cell *cell = &g_array_index(thiz->cell_data, metadata_cell, idx);
00320         return cell;
00321     }
00322 
00323     return NULL;
00324 }

Here is the caller graph for this function:

GString* metadata_table_get_string ( const metadata_table thiz,
const guint  idx 
)

Report the value of a specific cell in a metadata_table, converted to a UTF-8 text string Not possible for SQLCELL_BLOB types.

---------------------------------------------------------------------------

Name : metadata_table_get_string

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
Returns:
cell value as a zero-terminated GString, or NULL when error caller must release this string using g_string_free(string, TRUE)

--------------------------------------------------------------------------

Definition at line 327 of file metadata_table.c.

References ERRORPRINTF, LOGPRINTF, metadata_cell_get_string(), and metadata_table_get_cell().

Referenced by check_global_database_columns(), check_global_database_tables(), metadata_table_dump_impl(), and rotate_keyval_table().

00328 {
00329     LOGPRINTF("entry: thiz [%p] idx [%d]", thiz, idx);
00330 
00331     const metadata_cell *cell = metadata_table_get_cell(thiz, idx);
00332     if (cell == NULL)
00333     {
00334         ERRORPRINTF("cannot find cell: thiz [%p] idx [%u]", thiz, idx);
00335         return NULL;
00336     }
00337     else
00338     {
00339         return metadata_cell_get_string(cell);
00340     }
00341 }

Here is the call graph for this function:

Here is the caller graph for this function:

metadata_table* metadata_table_new ( void   ) 

Create a new metadata_table.

---------------------------------------------------------------------------

Name : metadata_table_new

Parameters:
-- 
Returns:
Pointer to the newly created table, or NULL

--------------------------------------------------------------------------

Definition at line 49 of file metadata_table.c.

References metadata_table::cell_data, metadata_table::n_columns, and metadata_table::n_rows.

Referenced by create_result_table(), db_query_create(), db_query_update_lastread(), load_application_data(), load_file_metadata(), meta_file_close(), meta_file_open(), rotate_keyval_table(), save_application_data(), save_file_metadata(), and set_annotation_impl().

00050 {
00051     metadata_table *thiz = g_new0(metadata_table, 1);
00052     g_assert(thiz);
00053     thiz->n_rows    = 0;
00054     thiz->n_columns = 0;
00055     thiz->cell_data = g_array_new(TRUE, TRUE, sizeof(metadata_cell));
00056 #if METADATA_NULL != 0x00
00057 # error  METADATA_NULL must have value 0x00
00058 # error    new entries in the metadata_table->cell_data array are initialised to 0x00,
00059 # error    which is assumed to set the metadata_cell.type to METADATA_NULL
00060 #endif
00061     return thiz;
00062 }

Here is the caller graph for this function:

int metadata_table_set_blob ( metadata_table thiz,
const guint  idx,
gchar *  value,
const guint  len 
)

Assign a blob to a specific cell in a sql table BLOB = Binary Large OBject.

---------------------------------------------------------------------------

Name : metadata_table_set_blob

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
[in] value - binary value Note: The value is "swallowed" by the metadata_cell so caller looses ownership and must drop all pointers to it. The metadata_cell will eventually release it with g_free() so caller must have allocated it with g_new() or g_malloc().
[in] len - length of value in bytes
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 271 of file metadata_table.c.

References add_row_if_needed(), ER_INVALID_PARAMETER, LOGPRINTF, metadata_cell_set_blob(), and metadata_table::n_columns.

Referenced by save_file_metadata().

00272 {
00273     LOGPRINTF("entry: thiz [%p] idx [%d] value [%p]", thiz, idx, value);
00274 
00275     g_return_val_if_fail( thiz,                 ER_INVALID_PARAMETER);
00276     g_return_val_if_fail((thiz->n_columns > 0), ER_INVALID_PARAMETER);
00277     g_return_val_if_fail( value,                ER_INVALID_PARAMETER);
00278 
00279     metadata_cell *cell = add_row_if_needed(thiz, idx);
00280     return metadata_cell_set_blob(cell, value, len);
00281 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_table_set_double ( metadata_table thiz,
const guint  idx,
const double  value 
)

Assign a floating point value to a specific cell in a sql table.

---------------------------------------------------------------------------

Name : metadata_table_set_double

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
[in] value - floating point value (double)
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 246 of file metadata_table.c.

References add_row_if_needed(), ER_INVALID_PARAMETER, LOGPRINTF, metadata_cell_set_double(), and metadata_table::n_columns.

Referenced by set_double().

00247 {
00248     LOGPRINTF("entry: thiz [%p] idx [%d] value [%f]", thiz, idx, value);
00249 
00250     g_return_val_if_fail( thiz,                 ER_INVALID_PARAMETER);
00251     g_return_val_if_fail((thiz->n_columns > 0), ER_INVALID_PARAMETER);
00252 
00253     metadata_cell *cell = add_row_if_needed(thiz, idx);
00254     return metadata_cell_set_double(cell, value);
00255 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_table_set_int64 ( metadata_table thiz,
const guint  idx,
const gint64  value 
)

Assign an integer value to a specific cell in a sql table.

---------------------------------------------------------------------------

Name : metadata_table_set_int64

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
[in] value - integer value (gint64)
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 234 of file metadata_table.c.

References add_row_if_needed(), ER_INVALID_PARAMETER, LOGPRINTF, metadata_cell_set_int64(), and metadata_table::n_columns.

Referenced by db_query_update_lastread(), and set_boolean().

00235 {
00236     LOGPRINTF("entry: thiz [%p] idx [%d] value [%lld]", thiz, idx, value);
00237 
00238     g_return_val_if_fail( thiz,                 ER_INVALID_PARAMETER);
00239     g_return_val_if_fail((thiz->n_columns > 0), ER_INVALID_PARAMETER);
00240 
00241     metadata_cell *cell = add_row_if_needed(thiz, idx);
00242     return metadata_cell_set_int64(cell, value);
00243 }

Here is the call graph for this function:

Here is the caller graph for this function:

int metadata_table_set_text ( metadata_table thiz,
const guint  idx,
const char *  value 
)

Assign a string value to a specific cell in a sql table This may move data already in the table to another memory location.

---------------------------------------------------------------------------

Name : metadata_table_set_text

Parameters:
thiz - the metadata_table
[in] idx - cell index (0 ...)
[in] value - string value Note: The value is copied into metadata_cell, so caller keeps ownership and must eventually free it.
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 258 of file metadata_table.c.

References add_row_if_needed(), ER_INVALID_PARAMETER, LOGPRINTF, metadata_cell_set_text(), and metadata_table::n_columns.

Referenced by save_application_data(), and save_file_metadata().

00259 {
00260     LOGPRINTF("entry: thiz [%p] idx [%d] value [%s]", thiz, idx, value);
00261 
00262     g_return_val_if_fail( thiz,                 ER_INVALID_PARAMETER);
00263     g_return_val_if_fail((thiz->n_columns > 0), ER_INVALID_PARAMETER);
00264     g_return_val_if_fail( value,                ER_INVALID_PARAMETER);
00265 
00266     metadata_cell *cell = add_row_if_needed(thiz, idx);
00267     return metadata_cell_set_text(cell, value);
00268 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208