/** * Returns the file_id for the specified file. * @param database is the structure that contains everything that is * related to the database (it's connexion for instance). * @param meta is the file's metadata that we want to insert into the * cache. * @returns a file_row_t structure filed with values returned by the * database. */ static file_row_t *get_file_id(db_t *database, meta_data_t *meta) { file_row_t *row = NULL; char *error_message = NULL; gchar *sql_command = NULL; int db_result = 0; row = new_file_row_t(); sql_command = g_strdup_printf("SELECT file_id from files WHERE inode=%" G_GUINT64_FORMAT " AND name='%s' AND type=%d AND uid=%d AND gid=%d AND ctime=%" G_GUINT64_FORMAT " AND mtime=%" G_GUINT64_FORMAT " AND mode=%d AND size=%" G_GUINT64_FORMAT ";", meta->inode, meta->name, meta->file_type, meta->uid, meta->gid, meta->ctime, meta->mtime, meta->mode, meta->size); db_result = sqlite3_exec(database->db, sql_command, get_file_callback, row, &error_message); free_variable(sql_command); if (db_result == SQLITE_OK) { return row; } else { print_db_error(database->db, _("(%d) Error while searching into the table 'files': %s\n"), db_result, error_message); return NULL; /* to avoid a compilation warning as we exited with failure in print_db_error */ } }
/** * Returns the file_id for the specified file. * @param database is the structure that contains everything that is * related to the database (it's connexion for instance). * @param meta is the file's metadata that we want to insert into the * cache. * @returns a file_row_t structure filed with values returned by the * database. */ static file_row_t *get_file_id(db_t *database, meta_data_t *meta) { file_row_t *row = NULL; sqlite3_stmt *stmt = NULL; gint result = 0; if (database != NULL && database->stmts != NULL && database->db != NULL) { row = new_file_row_t(); stmt = database->stmts->get_file_id_stmt; bind_values_to_get_file_id(database->db, stmt, meta); result = sqlite3_step(stmt); while (result == SQLITE_ROW) { row->nb_row = row->nb_row + 1; result = sqlite3_step(stmt); } print_on_db_error(database->db, result, "get_file_id"); sqlite3_reset(stmt); } return row; }