ermetadb.h File Reference

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

Go to the source code of this file.

Defines

#define ERMETADB_GLOBAL_DATABASE_FILE   "global.db"
#define ERMETADB_LOCAL_DATABASE_FILE   "metadata.db"

Typedefs

typedef typedefG_BEGIN_DECLS
struct erMetadb_t
erMetadb

Functions

erMetadb ermetadb_global_open (const gchar *folder, gboolean readonly)
 opens a global metadata database
erMetadb ermetadb_local_open (const gchar *folder, gboolean create)
 opens a local metadata database
erMetadb ermetadb_local_open_custom (const gchar *folder, const gchar *filename)
 opens a local metadata database with specified name
const gchar * ermetadb_get_dir (erMetadb thiz)
 returns path where database was openened
void ermetadb_close (erMetadb thiz)
 Close and free a metadata database.
int ermetadb_global_create_database (const gchar *folder)
 Create a new global metadata database, overwriting the existing database if present.
int ermetadb_local_create_database (const gchar *folder, const gchar *filename)
int ermetadb_begin_transaction (erMetadb thiz)
 Start a database transaction Only a single transaction is allowed, as seen from the application.
int ermetadb_begin_transaction_readonly (erMetadb thiz)
 Start a read-only database transaction Only a single transaction is allowed, as seen from the application.
int ermetadb_end_transaction (erMetadb thiz)
 Commit or rollback a database transaction Only a single transaction is allowed, as seen from the application. Library decides whether to commit or to rollback the changes. Basically when any query during this transaction has failed, the entire transaction is rolled back, otherwise the transaction is committed. Superfluous calls to ermetadb_end_transaction are ignored.
int ermetadb_global_add_folder (erMetadb thiz, const gchar *filepath, const gchar *foldername, const gint64 time_modified)
 Add a folder to the metadata database.
int ermetadb_global_remove_folder (erMetadb thiz, const gchar *filepath, const gchar *filename)
 Remove a folder from the metadata database.
int ermetadb_global_add_file (erMetadb thiz, const gchar *filepath, const gchar *filename, const gint64 size, const gint64 time_modified, const gchar *title, const gchar *author, const gchar *tag)
 Add a file to the metadata database.
int ermetadb_global_rename_file (erMetadb thiz, const gchar *filepath, const gchar *filename, const gchar *new_filename, const gchar *new_title)
 Renames a file to another name.
int ermetadb_global_remove_file (erMetadb thiz, const gchar *filepath, const gchar *filename)
 Remove a document from the global AND local database.
int ermetadb_global_get_file (erMetadb thiz, const gchar *filepath, const gchar *filename, const metadata_table *names_tbl, metadata_table **values_tbl)
 Get selected file_metadata fields for a file or folder.
int ermetadb_global_change_file (erMetadb thiz, const gchar *filepath, const gchar *filename, const metadata_table *values_tbl)
 Set selected file_metadata fields for a file or folder.
int ermetadb_global_remove_entry (erMetadb thiz, gint64 file_id, const gchar *filepath, const gchar *filename, gboolean is_dir)
 Remove a file/folder from the global AND local database.
int ermetadb_global_update_size (erMetadb thiz, gint64 file_id, gint64 last_modified, gint64 filesize)
 Updates size and last modified fields of entry.
int ermetadb_global_update_title (erMetadb thiz, gint64 file_id, const gchar *title, const gchar *author)
 Updates title and author fields of entry.
int ermetadb_global_select_all (erMetadb thiz, metadata_table **values_tbl)
 Returns the contents of the file_metadata table.
int ermetadb_global_select_files (erMetadb thiz, const gchar *sort_key, gboolean sort_is_ascending, const metadata_table *names_tbl, metadata_table **values_tbl, const gchar *tag_filter)
 Get selected file_metadata fields for a group of files/folders sorted on (1) specified metadata field and (2) filename ascending This function mainly exists for content browser assistance.
int ermetadb_global_select_recent (erMetadb thiz, const gchar *sort_key, int num_items, const metadata_table *names_tbl, metadata_table **values_tbl)
int ermetadb_global_select_subdir (erMetadb thiz, const gchar *sort_key, gboolean sort_is_ascending, const metadata_table *names_tbl, metadata_table **values_tbl, const gchar *path_filter)
int ermetadb_global_select_search (erMetadb thiz, const gchar *sort_key, gboolean sort_is_ascending, const metadata_table *names_tbl, metadata_table **values_tbl, const gchar *search_filter)
int ermetadb_local_remove_application_data (erMetadb thiz, const gchar *filename, const metadata_table *names_tbl)
 Remove selected application_data fields for a file or folder.
int ermetadb_local_set_application_data (erMetadb thiz, const gchar *filename, const metadata_table *values_tbl)
 Set selected application_data fields for a file or folder.
int ermetadb_local_get_application_data (erMetadb thiz, const gchar *filename, const metadata_table *names_tbl, metadata_table **values_tbl)
 Get selected application_data fields for a file or folder.
int ermetadb_local_remove_annotation (erMetadb thiz, const gint64 annotation_id)
 Remove selected annotation.
int ermetadb_local_create_annotation (erMetadb thiz, const gchar *filename, gint64 *annotation_id, const gchar *annotation_type, const gchar *layer, const gint64 file_position, const gchar *title, const gchar *start_anchor, const gchar *end_anchor, const gchar *data_blob, const guint data_len)
 Set selected annotation fields for a file or folder.
int ermetadb_local_set_annotation (erMetadb thiz, const gint64 annotation_id, const gchar *annotation_type, const gchar *layer, const gint64 file_position, const gchar *title, const gchar *start_anchor, const gchar *end_anchor, const gchar *data_blob, const guint data_len)
 Set selected annotation fields for a file or folder.
int ermetadb_local_get_annotations (erMetadb thiz, const gint64 *annotation_id_list, long annotation_id_num, metadata_table **values_tbl)
 Get details of the specified list of annotations.
int ermetadb_local_select_annotations (erMetadb thiz, const gchar *filename, const gchar *annotation_type, const gchar *layer, const gint64 file_position_min, const gint64 file_position_max, metadata_table **values_tbl)
 Get basic annotation fields within the specified range for a file or folder Basic annotation fields are the following columns from table annotations: annotation_id, annotation_type, layer, file_position, start_anchor, end_anchor Results are sorted on (1) file_position and (2) annotation_type and (3) layer Application must select from result the annotations it is really interested in, then call ermetadb_local_get_annotations() for the details of these. This avoids retrieving blob data for annotations that are not used by the application. Note that the library can select on file_position only, which is a pretty course selection, while the application can select on start_anchor and end_anchor, which is much more accurate.

Define Documentation

#define ERMETADB_GLOBAL_DATABASE_FILE   "global.db"
#define ERMETADB_LOCAL_DATABASE_FILE   "metadata.db"

Definition at line 56 of file ermetadb.h.

Referenced by ermetadb_local_create_database(), ermetadb_local_open(), and read_directory().


Typedef Documentation

typedef typedefG_BEGIN_DECLS struct erMetadb_t* erMetadb

File Name : ermetadb.h

Description: eReader metadata database object Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 49 of file ermetadb.h.


Function Documentation

int ermetadb_begin_transaction ( erMetadb  thiz  ) 

Start a database transaction Only a single transaction is allowed, as seen from the application.

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

Name : ermetadb_begin_transaction

Parameters:
[in] thiz - erMetadb object on which to start a transaction
Returns:
ER_OK or error

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

Definition at line 998 of file ermetadb.c.

References ER_FORBIDDEN, LOGPRINTF, and sql3_begin_transaction().

Referenced by db_start_transaction().

00999 {
01000     LOGPRINTF("entry nesting [%d]", thiz->transaction_nesting);
01001 
01002     g_assert(thiz);
01003     g_assert(thiz->database);
01004     g_return_val_if_fail( thiz->transaction_nesting == 0, ER_FORBIDDEN );
01005 
01006     return sql3_begin_transaction(thiz);
01007 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_begin_transaction_readonly ( erMetadb  thiz  ) 

Start a read-only database transaction Only a single transaction is allowed, as seen from the application.

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

Name : ermetadb_begin_transaction_readonly

Parameters:
[in] thiz - erMetadb object on which to start a transaction
Returns:
ER_OK or error

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

Definition at line 1010 of file ermetadb.c.

References ER_FORBIDDEN, LOGPRINTF, and sql3_begin_transaction_readonly().

01011 {
01012     LOGPRINTF("entry nesting [%d]", thiz->transaction_nesting);
01013 
01014     g_assert(thiz);
01015     g_assert(thiz->database);
01016     g_return_val_if_fail( thiz->transaction_nesting == 0, ER_FORBIDDEN );
01017 
01018     return sql3_begin_transaction_readonly(thiz);
01019 }

Here is the call graph for this function:

void ermetadb_close ( erMetadb  thiz  ) 

Close and free a metadata database.

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

Name : ermetadb_close

Parameters:
[in] thiz - erMetadb object or NULL
Returns:
ER_OK or error code

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

Definition at line 851 of file ermetadb.c.

References ER_FAIL, ERRORPRINTF, LOGPRINTF, and sql3_commit_or_rollback().

Referenced by add_file_to_metadata(), add_folder_to_metadata(), close_database(), convert_database_05_06(), database_open(), db_close(), delete_local_metadata(), erscribble_doc_free_without_database(), erscribble_doc_new(), erscribble_doc_open(), meta_file_close(), meta_file_open(), and read_directory().

00852 {
00853     LOGPRINTF("entry");
00854 
00855     if (thiz == NULL) return;
00856 
00857     if (thiz->database) {   // close database if open
00858         // abort transaction, if any
00859         if (thiz->transaction_nesting != 0)
00860         {
00861             thiz->transaction_nesting = 1;
00862             sql3_commit_or_rollback(thiz, ER_FAIL);
00863         }
00864 
00865         // close database
00866         int rc = sqlite3_close(thiz->database);
00867         if (rc != SQLITE_OK)
00868         {
00869             ERRORPRINTF("sqlite close error [%d] [%s]", rc, sqlite3_errmsg(thiz->database));
00870         }
00871         thiz->database = NULL;
00872     }
00873     g_free(thiz->directory);
00874     g_free(thiz);
00875 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_end_transaction ( erMetadb  thiz  ) 

Commit or rollback a database transaction Only a single transaction is allowed, as seen from the application. Library decides whether to commit or to rollback the changes. Basically when any query during this transaction has failed, the entire transaction is rolled back, otherwise the transaction is committed. Superfluous calls to ermetadb_end_transaction are ignored.

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

Name : ermetadb_end_transaction

Parameters:
[in] thiz - erMetadb object on which to end a transaction
Returns:
ER_OK or error or 'err' value when this is not ER_OK

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

Definition at line 1022 of file ermetadb.c.

References ER_OK, LOGPRINTF, sql3_commit_or_rollback(), and WARNPRINTF.

Referenced by db_end_transaction().

01023 {
01024     LOGPRINTF("entry nesting [%d]", thiz->transaction_nesting);
01025 
01026     g_assert(thiz);
01027     g_assert(thiz->database);
01028 
01029     if (thiz->transaction_nesting != 1)
01030     {
01031         // nesting level unbalanced: force rollback
01032         WARNPRINTF("entry with transaction_nesting [%d]", thiz->transaction_nesting);
01033         thiz->transaction_nesting = 1;
01034         thiz->do_force_rollback   = TRUE;
01035     }
01036 
01037     return sql3_commit_or_rollback(thiz, ER_OK);
01038 }

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar* ermetadb_get_dir ( erMetadb  thiz  ) 

returns path where database was openened

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

Name : ermetadb_get_dir

Parameters:
[in] thiz - erMetadb object
Returns:
path. Does not have to be freed

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

Definition at line 845 of file ermetadb.c.

Referenced by open_global_database().

00846 {
00847     return thiz->directory;
00848 }

Here is the caller graph for this function:

int ermetadb_global_add_file ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename,
const gint64  size,
const gint64  time_modified,
const gchar *  title,
const gchar *  author,
const gchar *  tag 
)

Add a file to the metadata database.

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

Name : ermetadb_global_add_file

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path of the file
[in] filename - filename of the file
[in] size - size of file
[in] time_modified - folder modification date/time as seconds since epoch
[in] title - title of file or NULL
[in] author - author of file or NULL
[in] tag - tag of file or NULL
Returns:
ER_OK or error code

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

Definition at line 264 of file ermetadb_file.c.

References add_filename(), and LOGPRINTF.

Referenced by add_file_to_metadata(), create_shortcut_item(), and db_add_entry().

00272 {
00273     LOGPRINTF("folder [%s]  file [%s]", filepath, filename);
00274 
00275     return add_filename(thiz, filepath, filename, FALSE, size, time_modified, title, author, tag);
00276 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_add_folder ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  foldername,
const gint64  time_modified 
)

Add a folder to the metadata database.

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

Name : ermetadb_global_add_folder

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path of the document
[in] foldername - filename of the folder
[in] time_modified - folder modification date/time as seconds since epoch
Returns:
ER_OK or error code

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

Definition at line 253 of file ermetadb_file.c.

References add_filename(), and LOGPRINTF.

Referenced by add_folder_to_metadata(), and db_add_entry().

00257 {
00258     LOGPRINTF("folder [%s]  file [%s]", filepath, foldername);
00259 
00260     return add_filename(thiz, filepath, foldername, TRUE, 0, time_modified, NULL, NULL, NULL);
00261 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_change_file ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename,
const metadata_table values_tbl 
)

Set selected file_metadata fields for a file or folder.

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

Name : ermetadb_global_change_file

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path for the document or folder
[in] filename - filename of the document or folder
[in] values_tbl - metadata_table holding metadata names and values a single row only, because data is for one file or folder
Returns:
ER_OK or error code

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

Definition at line 553 of file ermetadb_file.c.

References LOGPRINTF, and set_file_metadata_impl().

Referenced by db_query_update_lastread(), and save_file_metadata().

00557 {
00558     LOGPRINTF("folder [%s]  file [%s]", filepath, filename);
00559 
00560     return set_file_metadata_impl( thiz, filepath, filename, values_tbl );
00561 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_create_database ( const gchar *  folder  ) 

Create a new global metadata database, overwriting the existing database if present.

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

Name : ermetadb_global_create_database

Parameters:
[in] folder - directory in which the database file must be located
Returns:
ER_OK or error code

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

Definition at line 959 of file ermetadb.c.

References create_database(), ERMETADB_GLOBAL_DATABASE_FILE, and LOGPRINTF.

Referenced by create_db().

00960 {
00961     LOGPRINTF("folder [%s]", folder);
00962 
00963     g_assert(folder && folder[0]);
00964 
00965     return create_database(ERMETADB_GLOBAL_DATABASE_FILE, folder, ERMETADB_GLOBAL_DATABASE_FILE);
00966 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_get_file ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename,
const metadata_table names_tbl,
metadata_table **  values_tbl 
)

Get selected file_metadata fields for a file or folder.

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

Name : ermetadb_global_get_file

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path for the document or folder
[in] filename - filename of the document or folder
[in] names_tbl - metadata_table holding metadata names or NULL to get all metadata columns
[out] values_tbl - metadata_table holding metadata names and values a single row only, because data is for one file or folder or NULL on error Caller must use metadata_table_free() to release this table.
Returns:
ER_OK or error code

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

Definition at line 634 of file ermetadb_file.c.

References CHECK_GLOBAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ermetadb_private_get_global_column_names(), ERRORPRINTF, get_column_names(), get_global_id(), ISDIR_DONT_CARE, LOGPRINTF, metadata_table_n_rows, name, sql3_begin_transaction_readonly(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by db_query_get_metadata(), and load_file_metadata().

00639 {
00640     LOGPRINTF("folder [%s]  file [%s]", filepath, filename);
00641 
00642     CHECK_GLOBAL
00643     g_assert(filename && filename[0]);
00644     g_assert(filepath && filepath[0]);
00645     g_return_val_if_fail( (metadata_table_n_rows(names_tbl) == 0), ER_INVALID_PARAMETER );
00646     g_return_val_if_fail( (values_tbl && *values_tbl == NULL    ), ER_INVALID_PARAMETER );
00647 
00648     gint64 file_id = get_global_id(thiz, filename, filepath, ISDIR_DONT_CARE);
00649     if (file_id < 0) return ER_NOT_FOUND;
00650 
00651     int ret = sql3_begin_transaction_readonly(thiz);
00652     if (ret != ER_OK) return ret;
00653 
00654     GString *columns = NULL;
00655     // build column names for sql query
00656     if (names_tbl)
00657     {
00658         columns = get_column_names(names_tbl);
00659     }
00660     else
00661     {
00662         columns = g_string_new("");
00663         const char* const *name;
00664         // get all known columns
00665         for ( name = ermetadb_private_get_global_column_names("file_metadata") ; *name ; name++ )
00666         {
00667             if (   strcmp(*name, "file_id"        ) != 0
00668                 && strcmp(*name, "filename"       ) != 0
00669                 && strcmp(*name, "directory_path" ) != 0
00670                 && strcmp(*name, "file_type"      ) != 0 )
00671             {
00672                 if (columns->len > 0)
00673                 {
00674                     g_string_append( columns, ", "  );
00675                 }
00676                 g_string_append( columns, *name );
00677             }
00678         }
00679         for ( name = ermetadb_private_get_global_column_names("thumbnails") ; *name ; name++ )
00680         {
00681             if ( strcmp(*name, "file_id") != 0 )
00682             {
00683                 if (columns->len > 0)
00684                 {
00685                     g_string_append( columns, ", "  );
00686                 }
00687                 g_string_append( columns, *name );
00688             }
00689         }
00690     }
00691 
00692     // build query
00693     GString *sql = g_string_new("");
00694     g_string_printf( sql, "SELECT %s FROM file_metadata AS m"
00695                           " LEFT JOIN thumbnails AS t"
00696                           " ON m.file_id = t.file_id"
00697                           " WHERE m.file_id=%lld",
00698                      columns->str,
00699                      file_id      );
00700     g_string_free(columns, TRUE);
00701 
00702     // execute query
00703     metadata_table *result = NULL;
00704     if (ret == ER_OK)
00705     {
00706         int rc = sql3_execute_query(thiz->database, sql->str, NULL, &result);
00707         if (rc != ER_OK)
00708         {
00709             ERRORPRINTF("cannot get metadata, sql [%s]", sql->str);
00710             ret = rc;
00711         }
00712     }
00713     g_string_free(sql, TRUE);
00714 
00715     ret = sql3_commit_or_rollback(thiz, ret);
00716 
00717     *values_tbl = result;
00718     return ret;
00719 }

Here is the call graph for this function:

Here is the caller graph for this function:

erMetadb ermetadb_global_open ( const gchar *  folder,
gboolean  readonly 
)

opens a global metadata database

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

Name : ermetadb_global_open

Parameters:
[in] folder,path of .db file [in] readonly, to open db readonly or not if NOT readonly and db is corrupt/non-existent, a new db will be created
Returns:
Pointer to the newly created object, or NULL

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

Definition at line 824 of file ermetadb.c.

References database_open(), ERMETADB_GLOBAL_DATABASE_FILE, and LOGPRINTF.

Referenced by add_file_to_metadata(), add_folder_to_metadata(), convert_database_05_06(), db_open_global(), open_database(), and open_global_database().

00825 {
00826     LOGPRINTF("folder [%s]", folder);
00827     return database_open(folder, ERMETADB_GLOBAL_DATABASE_FILE, TRUE, readonly, FALSE);
00828 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_remove_entry ( erMetadb  thiz,
gint64  file_id,
const gchar *  filepath,
const gchar *  filename,
gboolean  is_dir 
)

Remove a file/folder from the global AND local database.

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

Name : ermetadb_global_remove_entry

Parameters:
[in] thiz - erMetadb object
[in] file_id - db id of entry
[in] filepath - directory_path for the document
[in] filename - filename of the document
[in] is_dir - whether entry is a dir
Returns:
ER_OK or error code ER_OK when filename with filepath not present in database

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

Definition at line 403 of file ermetadb_file.c.

References CHECK_GLOBAL, delete_entry(), delete_local_metadata(), and LOGPRINTF.

Referenced by db_delete_entry(), and ermetadb_global_remove_file().

00408 {
00409     LOGPRINTF("id [%lld]  folder [%s]  file [%s]", file_id, filepath, filename);
00410 
00411     CHECK_GLOBAL
00412     g_assert(file_id > 0);
00413     g_assert(filepath && filepath[0]);
00414     g_assert(filename && filename[0]);
00415 
00416     int res = delete_entry(thiz, file_id);
00417 
00418     if (!is_dir) { // for a dir, there is no metadata
00419         delete_local_metadata(filepath, filename);
00420     }
00421 
00422     return res;
00423 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_remove_file ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename 
)

Remove a document from the global AND local database.

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

Name : ermetadb_global_remove_file

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path for the document
[in] filename - filename of the document
Returns:
ER_OK or error code ER_OK when filename with filepath not present in database

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

Definition at line 372 of file ermetadb_file.c.

References CHECK_GLOBAL, ER_NOT_FOUND, ermetadb_global_remove_entry(), get_global_id(), ISDIR_DOCUMENT, and LOGPRINTF.

Referenced by delete_item_from_db().

00373 {
00374     LOGPRINTF("folder [%s]  file [%s]", filepath, filename);
00375 
00376     CHECK_GLOBAL
00377     g_assert(filepath && filepath[0]);
00378     g_assert(filename && filename[0]);
00379 
00380     gint64 file_id = get_global_id (thiz, filename, filepath, ISDIR_DOCUMENT);
00381     if (file_id == -1) return ER_NOT_FOUND;
00382 
00383     return ermetadb_global_remove_entry(thiz, file_id, filepath, filename, FALSE);
00384 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_remove_folder ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename 
)

Remove a folder from the metadata database.

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

Name : ermetadb_global_remove_folder

NOTE: does NOT remove local metadata. Not a problem, since complete directory is deleted anyway.

Parameters:
[in] thiz - erMetadb object
[in] filepath - path of the folder
[in] filename - filename of the folder
Returns:
ER_OK or error code ER_OK when foldername not present in database

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

Definition at line 341 of file ermetadb_file.c.

References CHECK_GLOBAL, delete_entry(), ER_FAIL, ER_NOT_FOUND, ER_OK, get_global_id(), ISDIR_FOLDER, LOGPRINTF, sql3_begin_transaction(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by delete_item_from_db().

00342 {
00343     LOGPRINTF("folder [%s]  file [%s]", filepath, filename);
00344 
00345     CHECK_GLOBAL
00346     g_assert(filepath && filepath[0]);
00347     g_assert(filename && filename[0]);
00348 
00349     gint64 file_id = get_global_id (thiz, filename, filepath, ISDIR_FOLDER);
00350     if (file_id == -1) return ER_NOT_FOUND;
00351 
00352     // delete all underlying entries with trumbnails (and metadata)
00353     int ret = sql3_begin_transaction(thiz);
00354     if (ret != ER_OK) return ER_FAIL;
00355 
00356     delete_entry(thiz, file_id);
00357 
00358     // Also delete items that are in the directory.
00359     // ASSUMES that directory is really deleted from FS, so local metadb info
00360     // will be deleted automatically
00361     // NOTE: thumbnail data is deleted by database trigger
00362     GString *sql = g_string_new("");
00363     g_string_printf(sql, "DELETE FROM file_metadata WHERE directory_path LIKE '%s/%s%%';", filepath, filename);
00364     ret = sql3_execute_query(thiz->database, sql->str, NULL, NULL);
00365     g_string_free(sql, TRUE);
00366 
00367     ret = sql3_commit_or_rollback(thiz, ret);
00368     return ret;
00369 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_rename_file ( erMetadb  thiz,
const gchar *  filepath,
const gchar *  filename,
const gchar *  new_filename,
const gchar *  new_title 
)

Renames a file to another name.

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

Name : ermetadb_global_rename_file

Parameters:
[in] thiz - erMetadb object
[in] filepath - directory_path for the document
[in] filename - old filename of the document
[in] new_filename - new filename of the document
[in] new_title- new title of the document
Returns:
ER_OK or error code ER_OK when filename with filepath not present in database

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

Definition at line 279 of file ermetadb_file.c.

References CHECK_GLOBAL, LOGPRINTF, sql3_commit_or_rollback(), and sql3_execute_query().

00284 {
00285     LOGPRINTF("folder [%s]  file [%s->%s]", filepath, filename, new_filename);
00286 
00287     CHECK_GLOBAL;
00288     g_assert(filepath && filepath[0]);
00289     g_assert(filename && filename[0]);
00290     g_assert(new_filename && new_filename[0]);
00291     g_assert(new_title && new_title[0]);
00292 
00293     char *sql_path    = sqlite3_mprintf("%Q", filepath);
00294     char *sql_srcfile = sqlite3_mprintf("%Q", filename);
00295     char *sql_dstfile = sqlite3_mprintf("%Q", new_filename);
00296     char *sql_title   = sqlite3_mprintf("%Q", new_title);
00297 
00298     // in case of overwrite: first delete old occurence, case-insensitive!
00299     GString *delq = g_string_new("");
00300     g_string_printf(delq , "DELETE FROM file_metadata "
00301                            " WHERE filename LIKE %s" 
00302                            " AND directory_path = %s",
00303                      sql_dstfile,
00304                      sql_path);
00305     (void) sql3_execute_query(thiz->database, delq->str, NULL, NULL);
00306     g_string_free(delq, TRUE);
00307 
00308     GString *sql = g_string_new("");
00309     g_string_printf( sql, "UPDATE file_metadata SET"
00310                           " filename = %s"
00311                           " , title = %s"
00312                           " WHERE filename = %s"
00313                           " AND directory_path = %s",
00314                      sql_dstfile,
00315                      sql_title,
00316                      sql_srcfile,
00317                      sql_path);
00318     int ret = sql3_execute_query(thiz->database, sql->str, NULL, NULL);
00319 
00320     g_string_free(sql, TRUE);
00321     sqlite3_free( sql_path );
00322     sqlite3_free( sql_srcfile );
00323     sqlite3_free( sql_dstfile );
00324     sqlite3_free( sql_title );
00325 
00326     ret = sql3_commit_or_rollback(thiz, ret);
00327     return ret;
00328 }

Here is the call graph for this function:

int ermetadb_global_select_all ( erMetadb  thiz,
metadata_table **  values_tbl 
)

Returns the contents of the file_metadata table.

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

Name : ermetadb_global_select_all

Parameters:
[in] thiz - erMetadb object
[out] values_tbl - tables with all the results
Returns:
ER_OK or error code

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

Definition at line 722 of file ermetadb_file.c.

References CHECK_GLOBAL, ER_INVALID_PARAMETER, ER_OK, ERRORPRINTF, LOGPRINTF, and sql3_execute_query().

Referenced by db_get_model().

00723 {
00724     LOGPRINTF("entry");
00725 
00726     CHECK_GLOBAL
00727     g_return_val_if_fail( (values_tbl && *values_tbl == NULL), ER_INVALID_PARAMETER );
00728 
00729     const char* sql = "SELECT file_id,"
00730                       " filename,"
00731                       " directory_path,"
00732                       " is_directory,"
00733                       " file_size,"
00734                       " file_time_modified"
00735                       " FROM file_metadata";
00736     metadata_table *result = NULL;
00737     int ret = sql3_execute_query(thiz->database, sql, NULL, &result);
00738     if (ret != ER_OK)
00739     {
00740         ERRORPRINTF("cannot get filenames");
00741     }
00742 
00743     *values_tbl = result;
00744     return ret;
00745 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_select_files ( erMetadb  thiz,
const gchar *  sort_key,
gboolean  sort_is_ascending,
const metadata_table names_tbl,
metadata_table **  values_tbl,
const gchar *  tag_filter 
)

Get selected file_metadata fields for a group of files/folders sorted on (1) specified metadata field and (2) filename ascending This function mainly exists for content browser assistance.

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

Name : ermetadb_global_select_files

Parameters:
[in] thiz - erMetadb object
[in] sort_key - metadata field to sort on or NULL when no sort required (i.e. sort on filename only)
[in] sort_is_ascending - sorting order
[in] start_item - index (0 ..) of the first item from the selection to be returned
[in] num_items - maximum number of items to be returned or -1 for unlimited number of items
[in] names_tbl - metadata_table holding metadata names
[out] values_tbl - metadata_table holding metadata names and values one row per file or folder or NULL on error Caller must use metadata_table_free() to release this table.
[in] tag_filter - tag filter to be used or NULL
Returns:
ER_OK or error code

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

Definition at line 815 of file ermetadb_file.c.

References global_select_common(), and LOGPRINTF.

Referenced by db_query_execute().

00821 {
00822     LOGPRINTF("tag_filter [%s]", tag_filter);
00823 
00824     char extra_sql[128];
00825     extra_sql[0] = 0;
00826     if (tag_filter) sprintf(extra_sql, "WHERE tag = '%s'", tag_filter);
00827     int ret = global_select_common(thiz, 
00828                                    sort_key, 
00829                                    sort_is_ascending, 
00830                                    0,
00831                                    names_tbl,
00832                                    values_tbl,
00833                                    extra_sql);
00834     return ret;
00835 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_select_recent ( erMetadb  thiz,
const gchar *  sort_key,
int  num_items,
const metadata_table names_tbl,
metadata_table **  values_tbl 
)

Definition at line 838 of file ermetadb_file.c.

References global_select_common(), and LOGPRINTF.

Referenced by db_query_execute_recent().

00843 {
00844     LOGPRINTF("entry");
00845 
00846     int ret = global_select_common(thiz, 
00847                                    sort_key, 
00848                                    FALSE, 
00849                                    num_items,
00850                                    names_tbl,
00851                                    values_tbl,
00852                                    "WHERE tag != ''");
00853     return ret;
00854 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_select_search ( erMetadb  thiz,
const gchar *  sort_key,
gboolean  sort_is_ascending,
const metadata_table names_tbl,
metadata_table **  values_tbl,
const gchar *  search_filter 
)

Definition at line 881 of file ermetadb_file.c.

References global_select_common(), and LOGPRINTF.

Referenced by db_query_execute_search_filter().

00887 {
00888     LOGPRINTF("search_filter [%s]", search_filter);
00889 
00890     g_assert(search_filter && search_filter[0]);
00891 
00892     char sql[1024];
00893     sprintf(sql, "WHERE (filename LIKE '%%%s%%' or"
00894                             " title LIKE '%%%s%%' or"
00895                             " author LIKE '%%%s%%') AND tag != ''",
00896                             search_filter, search_filter, search_filter);
00897     int ret = global_select_common(thiz, 
00898                                    sort_key, 
00899                                    sort_is_ascending, 
00900                                    0,
00901                                    names_tbl,
00902                                    values_tbl,
00903                                    sql);
00904     return ret;
00905 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_select_subdir ( erMetadb  thiz,
const gchar *  sort_key,
gboolean  sort_is_ascending,
const metadata_table names_tbl,
metadata_table **  values_tbl,
const gchar *  path_filter 
)

Definition at line 857 of file ermetadb_file.c.

References global_select_common(), and LOGPRINTF.

Referenced by db_query_execute_path_filter().

00863 {
00864     LOGPRINTF("path_filter [%s]", path_filter);
00865 
00866     g_assert(path_filter && path_filter[0]);
00867 
00868     char sql[256];
00869     sprintf(sql, " WHERE directory_path = '%s'", path_filter);
00870     int ret = global_select_common(thiz, 
00871                                    sort_key, 
00872                                    sort_is_ascending, 
00873                                    0,
00874                                    names_tbl,
00875                                    values_tbl,
00876                                    sql);
00877     return ret;
00878 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_update_size ( erMetadb  thiz,
gint64  file_id,
gint64  last_modified,
gint64  filesize 
)

Updates size and last modified fields of entry.

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

Name : ermetadb_global_update_size

Parameters:
[in] thiz - erMetadb object
[in] file_id - db id of entry
[in] last_modified - when file was last modified
[in] filesize - size of file
Returns:
ER_OK or error code

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

Definition at line 564 of file ermetadb_file.c.

References CHECK_GLOBAL, ER_NOT_FOUND, ER_OK, LOGPRINTF, and sql3_execute_query().

Referenced by db_update_entry().

00568 {
00569     LOGPRINTF("id [%lld]", file_id);
00570 
00571     CHECK_GLOBAL
00572     g_assert(file_id > 0);
00573 
00574     char query[255];
00575     snprintf(query, sizeof(query),
00576         "Update file_metadata SET file_size=%lld, file_time_modified=%lld WHERE file_id = %lld;",
00577         filesize, last_modified, file_id);
00578     if (!sql3_execute_query(thiz->database, query, NULL, NULL)) {
00579         return ER_NOT_FOUND;
00580     }
00581     return ER_OK;
00582 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_global_update_title ( erMetadb  thiz,
gint64  file_id,
const gchar *  title,
const gchar *  author 
)

Updates title and author fields of entry.

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

Name : ermetadb_global_update_title

Parameters:
[in] thiz - erMetadb object
[in] file_id - db id of entry
[in] title - title field. cannot be NULL
[in] author - author field. cannot be NULL
Returns:
ER_OK or error code

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

Definition at line 585 of file ermetadb_file.c.

References CHECK_GLOBAL, ER_NOT_FOUND, ER_OK, LOGPRINTF, and sql3_execute_query().

Referenced by db_update_shortcut_entry().

00589 {
00590     LOGPRINTF("id [%lld]", file_id);
00591 
00592     CHECK_GLOBAL
00593     g_assert(file_id > 0);
00594     g_assert(title);
00595     g_assert(author);
00596 
00597     char *sql3_title = sqlite3_mprintf("%Q", title);
00598     char *sql3_author = sqlite3_mprintf("%Q", author);
00599     char query[255];
00600     snprintf(query, sizeof(query),
00601         "Update file_metadata SET title=%s, author=%s WHERE file_id = %lld;",
00602         sql3_title, sql3_author, file_id);
00603     sqlite3_free(sql3_title);
00604     sqlite3_free(sql3_author);
00605 
00606     if (!sql3_execute_query(thiz->database, query, NULL, NULL)) {
00607         return ER_NOT_FOUND;
00608     }
00609     return ER_OK;
00610 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_create_annotation ( erMetadb  thiz,
const gchar *  filename,
gint64 *  annotation_id,
const gchar *  annotation_type,
const gchar *  layer,
const gint64  file_position,
const gchar *  title,
const gchar *  start_anchor,
const gchar *  end_anchor,
const gchar *  data_blob,
const guint  data_len 
)

Set selected annotation fields for a file or folder.

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

Name : ermetadb_local_create_annotation

Parameters:
[in] thiz - erMetadb object
[in] filename - file or folder to which this annotation belongs
[out] annotation_id - unique id of this annotation
[in] annotation_type - specifies what type of annotation this is
[in] layer - specifies what layer this annotation belongs to or empty string when no layer is applicable
[in] file_position - page number (1, 2, ..) for page-oriented docs like pdf, relative position (0 .. 100,000 for 0 .. 100%) for reflowable content
[in] title - specifies a title for this annotation or NULL when no title is applicable
[in] start_anchor - exact begin position of this annotation in the document or NULL when not relevant
[in] end_anchor - exact end position of this annotation in the document or NULL when not relevant
[in] data_blob - data belonging to this annotation as a blob or NULL when no data Note: caller must release this data after the function returns.
[in] data_len - number of bytes in data_blob or zero when no data
Returns:
ER_OK or error code

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

Definition at line 282 of file ermetadb_local.c.

References CHECK_LOCAL, ER_FAIL, ER_OK, ERMETADB_FAIL, ERRORPRINTF, find_or_create_filename(), LOGPRINTF, set_annotation_impl(), sql3_begin_transaction(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by save_page_data().

00293 {
00294     LOGPRINTF("file [%s]", filename);
00295 
00296     CHECK_LOCAL
00297     g_assert(filename && filename[0]);
00298     g_assert(annotation_id);
00299 
00300     gint64 anno_id = -1;
00301 
00302     int ret = sql3_begin_transaction(thiz);
00303     if (ret != ER_OK) return ret;
00304 
00305     gint64 file_id = find_or_create_filename(thiz, filename);
00306     if (file_id < 0) {
00307         ret = ER_FAIL;
00308         goto out;
00309     }
00310 
00311     // create an empty annotation
00312     // build query
00313     GString *sql = g_string_new("");  // SQL statements
00314     g_string_printf( sql, "INSERT INTO annotations"
00315                           " (file_id, annotation_type, layer, file_position)"
00316                           " VALUES (%lld, 'dummy', 'dummy', 0 )",
00317                      file_id );
00318 
00319     // execute query
00320     int rc = sql3_execute_query(thiz->database, sql->str, NULL, NULL);
00321     if (rc != ER_OK)
00322     {
00323         ERRORPRINTF("cannot create annotation, sql [%s]", sql->str);
00324         ret = ERMETADB_FAIL;
00325     }
00326     else
00327     {
00328         // retrieve the new annotation_id
00329         anno_id = sqlite3_last_insert_rowid(thiz->database);
00330     }
00331     g_string_free(sql, TRUE);
00332 
00333     // set annotation fields
00334     if (ret == ER_OK)
00335     {
00336         ret = set_annotation_impl( thiz,
00337                                    anno_id,
00338                                    annotation_type,
00339                                    layer,
00340                                    file_position,
00341                                    title,
00342                                    start_anchor,
00343                                    end_anchor,
00344                                    data_blob,
00345                                    data_len        );
00346     }
00347 out:
00348     ret = sql3_commit_or_rollback(thiz, ret);
00349 
00350     *annotation_id = anno_id;
00351     return ret;
00352 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_create_database ( const gchar *  folder,
const gchar *  filename 
)

Definition at line 969 of file ermetadb.c.

References create_database(), ERMETADB_LOCAL_DATABASE_FILE, and LOGPRINTF.

Referenced by create_db().

00970 {
00971     LOGPRINTF("folder [%s]  file [%s]", folder, filename);
00972 
00973     g_assert(folder && folder[0]);
00974     g_assert(filename && filename[0]);
00975 
00976     return create_database(ERMETADB_LOCAL_DATABASE_FILE, folder, filename);
00977 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_get_annotations ( erMetadb  thiz,
const gint64 *  annotation_id_list,
long  annotation_id_num,
metadata_table **  values_tbl 
)

Get details of the specified list of annotations.

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

Name : ermetadb_local_get_annotations

Parameters:
[in] thiz - erMetadb object
[in] annotation_id_list - unique id's of these annotations
[in] annotation_id_num - number of unique id's in annotation_id_list
[out] values_tbl - metadata_table holding annotation values one row per annotation_id or NULL on error Caller must use metadata_table_free() to release this table.
Returns:
ER_OK or error code

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

Definition at line 391 of file ermetadb_local.c.

References CHECK_LOCAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ERRORPRINTF, get_local_column_names(), LOGPRINTF, name, sql3_begin_transaction_readonly(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by load_page_data().

00395 {
00396     LOGPRINTF("entry");
00397 
00398     CHECK_LOCAL
00399     g_return_val_if_fail(  annotation_id_list                , ER_INVALID_PARAMETER );
00400     g_return_val_if_fail(  annotation_id_num >= 0            , ER_INVALID_PARAMETER );
00401     g_return_val_if_fail( (values_tbl && *values_tbl == NULL), ER_INVALID_PARAMETER );
00402 
00403     // get known column names
00404     GString *columns = g_string_new("");
00405     const char* const *name;
00406     for ( name = get_local_column_names( "annotations" ) ; *name ; name++ )
00407     {
00408         if ( strcmp(*name, "file_id" ) != 0 )
00409         {
00410             if (columns->len != 0) g_string_append( columns, ", "  );
00411             g_string_append( columns, *name );
00412         }
00413     }
00414 
00415     metadata_table *result = NULL;
00416 
00417     int ret = sql3_begin_transaction_readonly(thiz);
00418     if (ret != ER_OK) goto out;
00419 
00420     // build sql
00421     const gint64 *p_anno = annotation_id_list;
00422     GString *sql = g_string_new("");  // SQL query
00423     g_string_printf( sql, "SELECT %s"
00424                           " FROM annotations"
00425                           " WHERE annotation_id IN (%lld",
00426                      columns->str,
00427                      *p_anno      );
00428     p_anno++;
00429     int i;
00430     for ( i = 1 ; i < annotation_id_num ; i++ )
00431     {
00432         g_string_append_printf( sql, ", %lld", *p_anno );
00433         p_anno++;
00434     }
00435     g_string_append( sql, ");" );
00436 
00437     // execute query
00438     int rc = sql3_execute_query(thiz->database, sql->str, NULL, &result);
00439     if (rc != ER_OK)
00440     {
00441         ERRORPRINTF("cannot get metadata, sql [%s]", sql->str);
00442         ret = ER_NOT_FOUND;
00443     }
00444     g_string_free(sql, TRUE);
00445 
00446     // NOTE can turn ok into fail!
00447     ret = sql3_commit_or_rollback(thiz, ret);
00448 out:
00449     g_string_free(columns, TRUE);
00450 
00451     *values_tbl = result;
00452     return ret;
00453 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_get_application_data ( erMetadb  thiz,
const gchar *  filename,
const metadata_table names_tbl,
metadata_table **  values_tbl 
)

Get selected application_data fields for a file or folder.

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

Name : ermetadb_local_get_application_data

Parameters:
[in] thiz - erMetadb object
[in] filename - filename of the document or folder
[in] names_tbl - metadata_table holding application keys a single row only, because keys are for one file or folder
[out] values_tbl - metadata_table holding application keys and values a single row only, because keys/values are for one file or folder or NULL on error Caller must use metadata_table_free() to release this table.
Returns:
ER_OK or error code

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

Definition at line 768 of file ermetadb_local.c.

References CHECK_LOCAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ERMETADB_FAIL, ERRORPRINTF, get_keys(), get_local_id(), LOGPRINTF, metadata_table_free, rotate_keyval_table(), sql3_begin_transaction_readonly(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by load_application_data(), and meta_file_open().

00772 {
00773     LOGPRINTF("file [%s]", filename);
00774 
00775     CHECK_LOCAL
00776     g_assert(filename && filename[0]);
00777     g_return_val_if_fail( names_tbl, ER_INVALID_PARAMETER );
00778     g_return_val_if_fail( (values_tbl && *values_tbl == NULL ), ER_INVALID_PARAMETER );
00779 
00780     gint64 file_id = get_local_id(thiz, filename);
00781     if (file_id < 0) return ER_NOT_FOUND;
00782 
00783     int ret = sql3_begin_transaction_readonly(thiz);
00784     if (ret != ER_OK) return ret;
00785 
00786     // build sql query
00787     GString *keys = get_keys(names_tbl);
00788     GString *sql = g_string_new("");
00789     g_string_printf( sql, "SELECT key, value"
00790                           " FROM application_data"
00791                           " WHERE file_id=%lld"
00792                           "   AND key IN (%s);",
00793                      file_id,
00794                      keys->str );
00795     g_string_free(keys, TRUE);
00796 
00797     // execute query
00798     metadata_table *result = NULL;
00799     int rc = sql3_execute_query(thiz->database, sql->str, NULL, &result);
00800     if (rc != ER_OK)
00801     {
00802         ERRORPRINTF("cannot get application_data, sql [%s]", sql->str);
00803         ret = ERMETADB_FAIL;
00804     }
00805     g_string_free(sql, TRUE);
00806 
00807     // NOTE: ret can become OK here after rollback!
00808     ret = sql3_commit_or_rollback(thiz, ret);
00809 
00810     // rotate result: one row per key-val --> one column per key-val
00811     metadata_table *rotated = NULL;
00812     if (rc == ER_OK && result)
00813     {
00814         rotated = rotate_keyval_table(result);
00815     }
00816     *values_tbl = rotated;
00817 
00818     metadata_table_free(result);
00819     return ret;
00820 }

Here is the call graph for this function:

Here is the caller graph for this function:

erMetadb ermetadb_local_open ( const gchar *  folder,
gboolean  create 
)

opens a local metadata database

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

Name : ermetadb_local_open

Parameters:
[in] folder,path of .db file
[in] create,whether to create one if it doesn't exist or is corrupt
Returns:
Pointer to the newly created object, or NULL

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

Definition at line 831 of file ermetadb.c.

References database_open(), ERMETADB_LOCAL_DATABASE_FILE, and LOGPRINTF.

Referenced by delete_local_metadata(), erscribble_doc_new(), erscribble_doc_open(), meta_file_close(), meta_file_open(), and read_directory().

00832 {
00833     LOGPRINTF("folder [%s]  create [%d]", folder, create);
00834     return database_open(folder, ERMETADB_LOCAL_DATABASE_FILE, FALSE, FALSE, create);
00835 }

Here is the call graph for this function:

Here is the caller graph for this function:

erMetadb ermetadb_local_open_custom ( const gchar *  folder,
const gchar *  filename 
)

opens a local metadata database with specified name

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

Name : ermetadb_local_open_custom

Parameters:
[in] folder,path of .db file
[in] filename,name of .db file
Returns:
Pointer to the newly created object, or NULL

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

Definition at line 838 of file ermetadb.c.

References database_open(), and LOGPRINTF.

00839 {
00840     LOGPRINTF("folder [%s]  file [%s]", folder, filename);
00841     return database_open(folder, filename, FALSE, FALSE, FALSE);
00842 }

Here is the call graph for this function:

int ermetadb_local_remove_annotation ( erMetadb  thiz,
const gint64  annotation_id 
)

Remove selected annotation.

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

Name : ermetadb_local_remove_annotation

Parameters:
[in] thiz - erMetadb object
[in] annotation_id - unique id of this annotation
Returns:
ER_OK or error code

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

Definition at line 141 of file ermetadb_local.c.

References CHECK_LOCAL, ER_OK, ERMETADB_FAIL, ERRORPRINTF, LOGPRINTF, and sql3_execute_query().

Referenced by erscribble_doc_delete_page_impl(), and save_page_data().

00142 {
00143     LOGPRINTF("annotation_id [%lld]", annotation_id);
00144 
00145     CHECK_LOCAL
00146 
00147     char query[255];
00148     sprintf(query, "DELETE FROM annotations WHERE annotation_id = %lld", annotation_id );
00149     int rc = sql3_execute_query(thiz->database, query, NULL, NULL);
00150     if (rc != ER_OK)
00151     {
00152         ERRORPRINTF("cannot delete annotation, sql [%s]", query);
00153         rc = ERMETADB_FAIL;
00154     }
00155     return rc;
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_remove_application_data ( erMetadb  thiz,
const gchar *  filename,
const metadata_table names_tbl 
)

Remove selected application_data fields for a file or folder.

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

Name : ermetadb_local_remove_application_data

Parameters:
[in] thiz - erMetadb object
[in] filename - filename of the document or folder
[in] names_tbl - metadata_table holding application keys a single row only, because keys are for one file or folder
Returns:
ER_OK or error code

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

Definition at line 569 of file ermetadb_local.c.

References CHECK_LOCAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ERMETADB_FAIL, ERRORPRINTF, get_keys(), get_local_id(), LOGPRINTF, metadata_table_n_rows, sql3_begin_transaction(), sql3_commit_or_rollback(), and sql3_execute_query().

00572 {
00573     LOGPRINTF("file [%s]", filename);
00574 
00575     CHECK_LOCAL
00576     g_assert(filename && filename[0]);
00577     g_return_val_if_fail( names_tbl, ER_INVALID_PARAMETER );
00578     g_return_val_if_fail( (metadata_table_n_rows(names_tbl) == 0), ER_INVALID_PARAMETER );
00579 
00580     gint64 file_id = get_local_id(thiz, filename);
00581     if (file_id < 0) return ER_NOT_FOUND;
00582 
00583     // start transaction
00584     int ret = sql3_begin_transaction(thiz);
00585     if (ret != ER_OK) return ret;
00586 
00587     // build sql query
00588     GString *keys = get_keys(names_tbl);
00589     GString *sql = g_string_new("");
00590     g_string_printf( sql, "DELETE FROM application_data"
00591                           " WHERE file_id=%lld"
00592                           "   AND key IN (%s);",
00593                      file_id, keys->str );
00594     g_string_free(keys, TRUE);
00595 
00596     int rc = sql3_execute_query(thiz->database, sql->str, NULL, NULL);
00597     if (rc != ER_OK)
00598     {
00599         ERRORPRINTF("cannot delete application_data, sql [%s]", sql->str);
00600         ret = ERMETADB_FAIL;
00601     }
00602     g_string_free(sql, TRUE);
00603 
00604     ret = sql3_commit_or_rollback(thiz, ret);
00605     return ret;
00606 }

Here is the call graph for this function:

int ermetadb_local_select_annotations ( erMetadb  thiz,
const gchar *  filename,
const gchar *  annotation_type,
const gchar *  layer,
const gint64  file_position_min,
const gint64  file_position_max,
metadata_table **  values_tbl 
)

Get basic annotation fields within the specified range for a file or folder Basic annotation fields are the following columns from table annotations: annotation_id, annotation_type, layer, file_position, start_anchor, end_anchor Results are sorted on (1) file_position and (2) annotation_type and (3) layer Application must select from result the annotations it is really interested in, then call ermetadb_local_get_annotations() for the details of these. This avoids retrieving blob data for annotations that are not used by the application. Note that the library can select on file_position only, which is a pretty course selection, while the application can select on start_anchor and end_anchor, which is much more accurate.

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

Name : ermetadb_local_select_annotations

Parameters:
[in] thiz - erMetadb object
[in] filename - filename of the document or folder
[in] annotation_type - specifies what type of annotation is requested or NULL to select all annotation types
[in] layer - specifies what layer these annotations belong to or empty string to select annotation to which no layer is applicable or NULL to select all layers
[in] file_position_min - minimum value for file_position of selected annotations or -1 when no minimum selection on file_position
[in] file_position_max - maximum value for file_position of selected annotations or -1 when no maximum selection on file_position
[out] values_tbl - metadata_table holding annotation values one row per annotation or NULL on error Caller must use metadata_table_free() to release this table.
Returns:
ER_OK or error code

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

Definition at line 457 of file ermetadb_local.c.

References CHECK_LOCAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ERRORPRINTF, get_local_id(), LOGPRINTF, sql3_begin_transaction_readonly(), sql3_commit_or_rollback(), and sql3_execute_query().

Referenced by load_document_data().

00464 {
00465     LOGPRINTF("file [%s]", filename);
00466 
00467     CHECK_LOCAL
00468     g_assert(filename && filename[0]);
00469     g_return_val_if_fail( (annotation_type == NULL || annotation_type[0] != 0), ER_INVALID_PARAMETER );
00470     g_return_val_if_fail( values_tbl && *values_tbl == NULL, ER_INVALID_PARAMETER );
00471 
00472     // start transaction
00473     int ret = sql3_begin_transaction_readonly(thiz);
00474     if (ret != ER_OK) return ret;
00475 
00476     metadata_table *result = NULL;
00477     
00478     gint64 file_id = get_local_id(thiz, filename);
00479     if (file_id < 0) goto out;
00480 
00481     // build sql
00482     GString *sql = g_string_new("");
00483     g_string_printf( sql, "SELECT annotation_id"
00484                                ", annotation_type"
00485                                ", layer"
00486                                ", file_position"
00487                                ", start_anchor"
00488                                ", end_anchor"
00489                           " FROM annotations"
00490                           " WHERE file_id = %lld",
00491                      file_id );
00492     if (annotation_type)
00493     {
00494         char *str = sqlite3_mprintf("%Q", annotation_type);
00495         g_string_append_printf(sql, " AND annotation_type = %s", str);
00496         sqlite3_free(str);
00497     }
00498     if (layer)
00499     {
00500         char *str = sqlite3_mprintf("%Q", layer);
00501         g_string_append_printf(sql, " AND layer = %s", str);
00502         sqlite3_free(str);
00503     }
00504     if (file_position_min >= 0)
00505     {
00506         g_string_append_printf(sql, " AND file_position >= %lld", file_position_min);
00507     }
00508     if (file_position_max >= 0)
00509     {
00510         g_string_append_printf(sql, " AND file_position <= %lld", file_position_max);
00511     }
00512     g_string_append(sql, "ORDER BY file_position, annotation_type, layer;");
00513 
00514     // execute query
00515     int rc = sql3_execute_query(thiz->database, sql->str, NULL, &result);
00516     if (rc != ER_OK)
00517     {
00518         ERRORPRINTF("cannot get annotations, sql [%s]", sql->str);
00519         ret = ER_NOT_FOUND;
00520     }
00521     g_string_free(sql, TRUE);
00522 
00523 out:
00524     ret = sql3_commit_or_rollback(thiz, ret);
00525 
00526     *values_tbl = result;
00527     return ret;
00528 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_set_annotation ( erMetadb  thiz,
const gint64  annotation_id,
const gchar *  annotation_type,
const gchar *  layer,
const gint64  file_position,
const gchar *  title,
const gchar *  start_anchor,
const gchar *  end_anchor,
const gchar *  data_blob,
const guint  data_len 
)

Set selected annotation fields for a file or folder.

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

Name : ermetadb_local_set_annotation

Parameters:
[in] thiz - erMetadb object
[in] annotation_id - unique id of this annotation
[in] annotation_type - specifies what type of annotation this is
[in] layer - specifies what layer this annotation belongs to or empty string when no layer is applicable
[in] file_position - page number (1, 2, ..) for page-oriented docs like pdf, relative position (0 .. 100,000 for 0 .. 100%) for reflowable content
[in] title - specifies a title for this annotation or NULL when no title is applicable
[in] start_anchor - exact begin position of this annotation in the document or NULL when not relevant
[in] end_anchor - exact end position of this annotation in the document or NULL when not relevant
[in] data_blob - data belonging to this annotation as a blob or NULL when no data Note: caller must release this data after the function returns.
[in] data_len - number of bytes in data_blob or zero when no data
Returns:
ER_OK or error code

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

Definition at line 355 of file ermetadb_local.c.

References CHECK_LOCAL, ER_OK, LOGPRINTF, set_annotation_impl(), sql3_begin_transaction(), and sql3_commit_or_rollback().

Referenced by save_page_data().

00365 {
00366     LOGPRINTF("annotation_id [%lld]", annotation_id);
00367 
00368     CHECK_LOCAL
00369     g_assert(annotation_id);
00370 
00371     int ret = sql3_begin_transaction(thiz);
00372     if (ret != ER_OK) return ret;
00373 
00374     ret = set_annotation_impl( thiz,
00375                                annotation_id,
00376                                annotation_type,
00377                                layer,
00378                                file_position,
00379                                title,
00380                                start_anchor,
00381                                end_anchor,
00382                                data_blob,
00383                                data_len        );
00384 
00385     ret = sql3_commit_or_rollback(thiz, ret);
00386     return ret;
00387 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ermetadb_local_set_application_data ( erMetadb  thiz,
const gchar *  filename,
const metadata_table values_tbl 
)

Set selected application_data fields for a file or folder.

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

Name : ermetadb_local_set_application_data

Parameters:
[in] thiz - erMetadb object
[in] filename - filename of the document or folder
[in] values_tbl - metadata_table holding application keys (column name) and values a single row only, because keys/values are for one file or folder keys with value type METADATA_NULL will be removed from the database
Returns:
ER_OK or error code

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

Definition at line 609 of file ermetadb_local.c.

References CHECK_LOCAL, ER_INVALID_PARAMETER, ER_NOT_FOUND, ER_OK, ERMETADB_FAIL, ERRORPRINTF, find_or_create_filename(), LOGPRINTF, METADATA_NULL, metadata_table_get_cell(), metadata_table_n_columns, metadata_table_n_rows, metadata_cell::name, sql3_begin_transaction(), sql3_commit_or_rollback(), sql3_execute_query(), and metadata_cell::type.

Referenced by meta_file_close(), and save_application_data().

00612 {
00613     LOGPRINTF("file [%s]", filename);
00614 
00615     CHECK_LOCAL
00616     g_assert(filename && filename[0]);
00617     g_return_val_if_fail( values_tbl, ER_INVALID_PARAMETER );
00618     g_return_val_if_fail( (metadata_table_n_rows(values_tbl) == 1), ER_INVALID_PARAMETER );
00619 
00620     gint64 file_id = find_or_create_filename(thiz, filename);
00621     if (file_id < 0) return ER_NOT_FOUND;
00622 
00623     int ret = sql3_begin_transaction(thiz);
00624     if (ret != ER_OK) return ret;
00625 
00626     // build delete and insert statements for sql query
00627     GString *sql_del = NULL;     // SQL delete statement
00628     GString *sql_ins   = NULL;     // SQL insert statements
00629     int n_cols = metadata_table_n_columns(values_tbl);
00630     int col;
00631     for (col = 0 ; col < n_cols ; col++)
00632     {
00633         const metadata_cell*cell = metadata_table_get_cell(values_tbl, col);
00634         if (cell && cell->name && cell->name->str)
00635         {
00636             char* sql3_cellname = sqlite3_mprintf("%Q", cell->name->str);
00637 
00638             if (cell->type == METADATA_NULL)
00639             {
00640                 // add this key to sql delete statement
00641                 if (sql_del == NULL)
00642                 {
00643                     sql_del = g_string_new("");
00644                     g_string_printf( sql_del, "DELETE FROM application_data"
00645                                               " WHERE file_id=%lld"
00646                                               "   AND key IN ( %s",
00647                                      file_id,
00648                                      sql3_cellname );
00649                 }
00650                 else
00651                 {
00652                     g_string_append_printf( sql_del, ", %s", sql3_cellname );
00653                 }
00654             }
00655             else
00656             {
00657                 // add this key to sql_insert statement
00658                 if (sql_ins == NULL)
00659                 {
00660                     sql_ins = g_string_new("");
00661                 }
00662                 g_string_append_printf( sql_ins, "INSERT OR REPLACE INTO application_data"
00663                                                  " (file_id, key, value)"
00664                                                  " VALUES (%lld, %s, ?%d);",
00665                                         file_id,
00666                                         sql3_cellname,
00667                                         col + 1   );
00668             }
00669             sqlite3_free( sql3_cellname );
00670         }
00671     }
00672     if (sql_del) g_string_append( sql_del, " );" );
00673 
00674     // execute delete query
00675     if (sql_del)
00676     {
00677         int rc = sql3_execute_query(thiz->database, sql_del->str, NULL, NULL);
00678         if (rc != ER_OK)
00679         {
00680             ERRORPRINTF("cannot delete application_data, sql [%s]", sql_del->str);
00681             ret = ERMETADB_FAIL;
00682         }
00683     }
00684 
00685     // execute insert query
00686     if (ret == ER_OK && sql_ins)
00687     {
00688         int rc = sql3_execute_query(thiz->database, sql_ins->str, values_tbl, NULL);
00689         if (rc != ER_OK)
00690         {
00691             ERRORPRINTF("cannot insert application_data, sql [%s]", sql_ins->str);
00692             ret = ERMETADB_FAIL;
00693         }
00694     }
00695 
00696     ret = sql3_commit_or_rollback(thiz, ret);
00697 
00698     if (sql_ins) { g_string_free(sql_ins, TRUE); }
00699     if (sql_del) { g_string_free(sql_del, TRUE); }
00700     return ret;
00701 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208