GnuCash
5.6-150-g038405b370+
|
The PriceDB is intended to be a database of price quotes, or more specifically, a database of GNCPrices. More...
Files | |
file | gnc-pricedb.h |
a simple price database for gnucash | |
Typedefs | |
typedef gboolean(* | GncPriceForeachFunc) (GNCPrice *p, gpointer user_data) |
Functions | |
GNCPriceDB * | gnc_pricedb_get_db (QofBook *book) |
Return the pricedb associated with the book. More... | |
GNCPriceDB * | gnc_collection_get_pricedb (QofCollection *col) |
Return the pricedb via the Book's collection. More... | |
void | gnc_pricedb_destroy (GNCPriceDB *db) |
Destroy the given pricedb and unref all of the prices it contains. More... | |
void | gnc_pricedb_begin_edit (GNCPriceDB *) |
Begin an edit. More... | |
void | gnc_pricedb_commit_edit (GNCPriceDB *) |
Commit an edit. More... | |
void | gnc_pricedb_set_bulk_update (GNCPriceDB *db, gboolean bulk_update) |
Set flag to indicate whether duplication checks should be performed. More... | |
gboolean | gnc_pricedb_add_price (GNCPriceDB *db, GNCPrice *p) |
Add a price to the pricedb. More... | |
gboolean | gnc_pricedb_remove_price (GNCPriceDB *db, GNCPrice *p) |
Remove a price from the pricedb and unref the price. More... | |
gboolean | gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list, GDate *fiscal_end_date, time64 cutoff, PriceRemoveSourceFlags source, PriceRemoveKeepOptions keep) |
Remove and unref prices older than a certain time. More... | |
GNCPrice * | gnc_pricedb_lookup_latest (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency) |
Find the most recent price between the two commodities. More... | |
PriceList * | gnc_pricedb_lookup_latest_any_currency (GNCPriceDB *db, const gnc_commodity *commodity) |
Find the most recent price between a commodity and all other commodities. More... | |
gboolean | gnc_pricedb_has_prices (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency) |
Report whether the pricedb contains prices for one commodity in another. More... | |
PriceList * | gnc_pricedb_get_prices (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency) |
Return all the prices for a given commodity in another. More... | |
GNCPrice * | gnc_pricedb_lookup_day_t64 (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency, time64 t) |
Return the price between the two commodities on the indicated day. More... | |
GNCPrice * | gnc_pricedb_lookup_nearest_in_time64 (GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t) |
Return the price between the two commoditiesz nearest to the given time. More... | |
PriceList * | gnc_pricedb_lookup_nearest_in_time_any_currency_t64 (GNCPriceDB *db, const gnc_commodity *c, time64 t) |
Return the price nearest in time to that given between the given commodity and every other. More... | |
GNCPrice * | gnc_pricedb_lookup_nearest_before_t64 (GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t) |
Return the nearest price between the given commodities before the given time. More... | |
PriceList * | gnc_pricedb_lookup_nearest_before_any_currency_t64 (GNCPriceDB *db, const gnc_commodity *c, time64 t) |
Return the nearest price between the given commodity and any other before the given time. More... | |
gnc_numeric | gnc_pricedb_get_nearest_before_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t) |
Retrieve the price one currency to another using the price nearest to before the given time. More... | |
gnc_numeric | gnc_pricedb_get_nearest_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t) |
Retrieve the price one currency to another using the price nearest to the given time. More... | |
gnc_numeric | gnc_pricedb_get_latest_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency) |
Retrieve the price one currency to another using the latest price. More... | |
gnc_numeric | gnc_pricedb_convert_balance_latest_price (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency) |
Convert a balance from one currency to another using the most recent price between the two. More... | |
gnc_numeric | gnc_pricedb_convert_balance_nearest_price_t64 (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t) |
Convert a balance from one currency to another using the price nearest to the given time. More... | |
gnc_numeric | gnc_pricedb_convert_balance_nearest_before_price_t64 (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t) |
Convert a balance from one currency to another using the price nearest to before the given time. More... | |
gboolean | gnc_pricedb_foreach_price (GNCPriceDB *db, GncPriceForeachFunc f, gpointer user_data, gboolean stable_order) |
Call a GncPriceForeachFunction once for each price in db, until the function returns FALSE. More... | |
int | gnc_pricedb_num_prices (GNCPriceDB *db, const gnc_commodity *c) |
Get the number of prices, in any currency, for a given commodity. More... | |
GNCPrice * | gnc_pricedb_nth_price (GNCPriceDB *db, const gnc_commodity *c, const int n) |
Get the nth price for the given commodity in reverse date order. More... | |
void | gnc_pricedb_nth_price_reset_cache (GNCPriceDB *db) |
guint | gnc_pricedb_get_num_prices (GNCPriceDB *db) |
Return the number of prices in the database. More... | |
gboolean | gnc_pricedb_equal (GNCPriceDB *db1, GNCPriceDB *db2) |
Test equality of two pricedbs. More... | |
Internal/Debugging | |
void | gnc_pricedb_print_contents (GNCPriceDB *db, FILE *f) |
This simple function can be useful for debugging the pricedb code. | |
The PriceDB is intended to be a database of price quotes, or more specifically, a database of GNCPrices.
Whenever a you store a price in the pricedb, the pricedb adds its own reference to the price, so you can safely unref that price after inserting it into the DB if you're finished with it otherwise.
For the time being, it is still a fairly simple database supporting only fairly simple queries. It is expected that new queries will be added as needed, and that there is some advantage to delaying complex queries for now in the hope that we get a real DB implementation before they're really needed.
Every QofBook contains a GNCPriceDB, accessible via gnc_pricedb_get_db.
Similarly, when the pricedb returns a price to you, either singly, or in a price list, the price will have had a ref added for you, so you only need to unref the price(s) when you're finished with it/them.
GNCPriceDB* gnc_collection_get_pricedb | ( | QofCollection * | col | ) |
Return the pricedb via the Book's collection.
col | The QofCollection holding the pricedb |
Definition at line 902 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_add_price | ( | GNCPriceDB * | db, |
GNCPrice * | p | ||
) |
Add a price to the pricedb.
You may drop your reference to the price (i.e. call unref) after this succeeds, whenever you're finished with the price.
db | The pricedb |
p | The GNCPrice to add. |
Definition at line 1110 of file gnc-pricedb.cpp.
void gnc_pricedb_begin_edit | ( | GNCPriceDB * | ) |
void gnc_pricedb_commit_edit | ( | GNCPriceDB * | ) |
Commit an edit.
Definition at line 438 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_convert_balance_latest_price | ( | GNCPriceDB * | pdb, |
gnc_numeric | balance, | ||
const gnc_commodity * | balance_currency, | ||
const gnc_commodity * | new_currency | ||
) |
Convert a balance from one currency to another using the most recent price between the two.
pdb | The pricedb |
balance | The balance to be converted |
balance_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
Definition at line 2558 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_convert_balance_nearest_before_price_t64 | ( | GNCPriceDB * | pdb, |
gnc_numeric | balance, | ||
const gnc_commodity * | balance_currency, | ||
const gnc_commodity * | new_currency, | ||
time64 | t | ||
) |
Convert a balance from one currency to another using the price nearest to before the given time.
pdb | The pricedb |
balance | The balance to be converted |
balance_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
t | The time in which the last price before it should be used. |
Definition at line 2579 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_convert_balance_nearest_price_t64 | ( | GNCPriceDB * | pdb, |
gnc_numeric | balance, | ||
const gnc_commodity * | balance_currency, | ||
const gnc_commodity * | new_currency, | ||
time64 | t | ||
) |
Convert a balance from one currency to another using the price nearest to the given time.
pdb | The pricedb |
balance | The balance to be converted |
balance_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
t | The time nearest to which price should be used. |
Definition at line 2568 of file gnc-pricedb.cpp.
void gnc_pricedb_destroy | ( | GNCPriceDB * | db | ) |
Destroy the given pricedb and unref all of the prices it contains.
This may not deallocate all of those prices. Other code may still be holding references to them.
db | The pricedb to destroy. |
Definition at line 865 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_equal | ( | GNCPriceDB * | db1, |
GNCPriceDB * | db2 | ||
) |
Test equality of two pricedbs.
For XML Backend Testing
Definition at line 984 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_foreach_price | ( | GNCPriceDB * | db, |
GncPriceForeachFunc | f, | ||
gpointer | user_data, | ||
gboolean | stable_order | ||
) |
Call a GncPriceForeachFunction once for each price in db, until the function returns FALSE.
If stable_order is not FALSE, make sure the ordering of the traversal is stable (i.e. the same order every time given the same db contents – stable traversals may be less efficient).
db | The pricedb |
f | The function to call |
user_data | A data to pass to each invocation of f |
stable_order | Ensure that the traversal is performed in the same order each time. |
Definition at line 2732 of file gnc-pricedb.cpp.
GNCPriceDB* gnc_pricedb_get_db | ( | QofBook * | book | ) |
Return the pricedb associated with the book.
book | The QofBook holding the pricedb |
Definition at line 909 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_get_latest_price | ( | GNCPriceDB * | pdb, |
const gnc_commodity * | orig_currency, | ||
const gnc_commodity * | new_currency | ||
) |
Retrieve the price one currency to another using the latest price.
pdb | The pricedb |
orig_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
Definition at line 2523 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_get_nearest_before_price | ( | GNCPriceDB * | pdb, |
const gnc_commodity * | orig_currency, | ||
const gnc_commodity * | new_currency, | ||
const time64 | t | ||
) |
Retrieve the price one currency to another using the price nearest to before the given time.
pdb | The pricedb |
orig_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
t | The time to be used for for comparison |
Definition at line 2505 of file gnc-pricedb.cpp.
gnc_numeric gnc_pricedb_get_nearest_price | ( | GNCPriceDB * | pdb, |
const gnc_commodity * | orig_currency, | ||
const gnc_commodity * | new_currency, | ||
const time64 | t | ||
) |
Retrieve the price one currency to another using the price nearest to the given time.
pdb | The pricedb |
orig_currency | The commodity in which the balance is currently expressed |
new_currency | The commodity to which the balance should be converted |
t | The time in which the nearest price should be used. |
Definition at line 2514 of file gnc-pricedb.cpp.
guint gnc_pricedb_get_num_prices | ( | GNCPriceDB * | db | ) |
Return the number of prices in the database.
For XML Backend Testing
Definition at line 931 of file gnc-pricedb.cpp.
PriceList* gnc_pricedb_get_prices | ( | GNCPriceDB * | db, |
const gnc_commodity * | commodity, | ||
const gnc_commodity * | currency | ||
) |
Return all the prices for a given commodity in another.
Does not retrieve reverse prices, i.e. prices of the second commodity in the first.
db | The pricedb from which to retrieve prices. |
commodity | The commodity for which prices should be retrieved. |
currency | The commodity in which prices should be quoted. If NULL, all prices in any commodity are included. |
Definition at line 2049 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_has_prices | ( | GNCPriceDB * | db, |
const gnc_commodity * | commodity, | ||
const gnc_commodity * | currency | ||
) |
Report whether the pricedb contains prices for one commodity in another.
Does not check the reverse direction.
db | The pricedb to check |
commodity | The commodity to check for the existence of prices |
currency | The commodity in which prices are sought. If NULL reports all commodities. |
Definition at line 2010 of file gnc-pricedb.cpp.
GNCPrice* gnc_pricedb_lookup_day_t64 | ( | GNCPriceDB * | db, |
const gnc_commodity * | commodity, | ||
const gnc_commodity * | currency, | ||
time64 | t | ||
) |
Return the price between the two commodities on the indicated day.
Note that the notion of day might be distorted by changes in timezone.
The returned GNCPrice may be in either direction so check to ensure that its value is correctly applied.
db | The pricedb |
commodity | The first commodity |
currency | The second commodity |
t | A time. The price returned will be in the same day as this time according to the local timezone. |
Definition at line 2173 of file gnc-pricedb.cpp.
GNCPrice* gnc_pricedb_lookup_latest | ( | GNCPriceDB * | db, |
const gnc_commodity * | commodity, | ||
const gnc_commodity * | currency | ||
) |
Find the most recent price between the two commodities.
The returned GNCPrice may be in either direction so check to ensure that its value is correctly applied.
db | The pricedb |
commodity | The first commodity |
currency | The second commodity |
Definition at line 1733 of file gnc-pricedb.cpp.
PriceList* gnc_pricedb_lookup_latest_any_currency | ( | GNCPriceDB * | db, |
const gnc_commodity * | commodity | ||
) |
Find the most recent price between a commodity and all other commodities.
The returned GNCPrices may be in either direction so check to ensure that their values are correctly applied.
db | The pricedb |
commodity | The commodity for which to obtain prices |
Definition at line 1957 of file gnc-pricedb.cpp.
PriceList* gnc_pricedb_lookup_nearest_before_any_currency_t64 | ( | GNCPriceDB * | db, |
const gnc_commodity * | c, | ||
time64 | t | ||
) |
Return the nearest price between the given commodity and any other before the given time.
The returned GNCPrice may be in either direction so check to ensure that its value is correctly applied.
db | The pricedb |
c | The commodity |
t | The time before which to find prices |
Definition at line 1985 of file gnc-pricedb.cpp.
GNCPrice* gnc_pricedb_lookup_nearest_before_t64 | ( | GNCPriceDB * | db, |
const gnc_commodity * | c, | ||
const gnc_commodity * | currency, | ||
time64 | t | ||
) |
Return the nearest price between the given commodities before the given time.
The returned GNCPrice may be in either direction so check to ensure that its value is correctly applied.
db | The pricedb |
c | The first commodity |
currency | The second commodity |
t | The time before which to find the price |
Definition at line 2307 of file gnc-pricedb.cpp.
GNCPrice* gnc_pricedb_lookup_nearest_in_time64 | ( | GNCPriceDB * | db, |
const gnc_commodity * | c, | ||
const gnc_commodity * | currency, | ||
time64 | t | ||
) |
Return the price between the two commoditiesz nearest to the given time.
The returned GNCPrice may be in either direction so check to ensure that its value is correctly applied.
db | The pricedb |
c | The first commodity |
currency | The second commodity |
t | The time nearest to which the returned price should be. |
Definition at line 2292 of file gnc-pricedb.cpp.
PriceList* gnc_pricedb_lookup_nearest_in_time_any_currency_t64 | ( | GNCPriceDB * | db, |
const gnc_commodity * | c, | ||
time64 | t | ||
) |
Return the price nearest in time to that given between the given commodity and every other.
The returned GNCPrices may be in either direction so check to ensure that their values are correctly applied.
db,The | pricedb |
c,The | commodity for which prices should be obtained. |
t,The | time nearest to which the prices should be obtained. |
Definition at line 1965 of file gnc-pricedb.cpp.
GNCPrice* gnc_pricedb_nth_price | ( | GNCPriceDB * | db, |
const gnc_commodity * | c, | ||
const int | n | ||
) |
Get the nth price for the given commodity in reverse date order.
db | The pricedb |
c | The commodity whose nth price is needed |
n | Zero based index of the price wanted |
Definition at line 2121 of file gnc-pricedb.cpp.
int gnc_pricedb_num_prices | ( | GNCPriceDB * | db, |
const gnc_commodity * | c | ||
) |
Get the number of prices, in any currency, for a given commodity.
db | The pricedb |
c | The commodity |
Definition at line 2074 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_remove_old_prices | ( | GNCPriceDB * | db, |
GList * | comm_list, | ||
GDate * | fiscal_end_date, | ||
time64 | cutoff, | ||
PriceRemoveSourceFlags | source, | ||
PriceRemoveKeepOptions | keep | ||
) |
Remove and unref prices older than a certain time.
db | The pricedb |
comm_list | A list of commodities |
fiscal_end_date | the end date of the current accounting period |
cutoff | The time before which prices should be deleted. |
source | Whether Finance::Quote, user or all prices should be deleted. |
keep | Whether scaled, monthly, weekly or no prices should be left. |
Definition at line 1547 of file gnc-pricedb.cpp.
gboolean gnc_pricedb_remove_price | ( | GNCPriceDB * | db, |
GNCPrice * | p | ||
) |
Remove a price from the pricedb and unref the price.
db | The Pricedb |
p | The price to remove. |
Definition at line 1217 of file gnc-pricedb.cpp.
void gnc_pricedb_set_bulk_update | ( | GNCPriceDB * | db, |
gboolean | bulk_update | ||
) |
Set flag to indicate whether duplication checks should be performed.
Normally used at load time to speed up loading the pricedb.
db | The pricedb |
bulk_update | TRUE to disable duplication checks, FALSE to enable them. |
Definition at line 881 of file gnc-pricedb.cpp.