Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
|
A SQLiteTool is a datatype that allows access to the data stored within a SQLite instance. More...
#include <sqlite_tool.h>
Public Member Functions | |
const SQLITE_PREFIX char *SQLITE_OP_EQUALS_S | SQLITE_VAL ("=") |
bool | SetSQLiteDatabase (SQLiteTool *tool_p, const char *db_s, int flags) |
Set the database an collection that a SQLite will use. More... | |
bool | SetSQLiteToolTable (SQLiteTool *tool_p, const char *table_s) |
Set the tablethat a SQLite will use. More... | |
SQLiteTool * | AllocateSQLiteTool (const char *db_s, int flags) |
This allocates a SQLiteTool that connects to the SQLite instance specified in the grassroots.config file. More... | |
bool | CloseSQLiteTool (SQLiteTool *tool_p) |
Close the database connection for a given a SQLiteTool. More... | |
void | FreeSQLiteTool (SQLiteTool *tool_p) |
Delete a SQLiteTool and release the connection that it held This calls CloseSqlTool() and then releases the memory. More... | |
char * | InsertOrUpdateSQLiteData (SQLiteTool *tool_p, json_t *values_p, const char *const table_s, const char *const primary_key_s) |
Insert data from a given JSON fragment using a given SQLite. More... | |
bool | RemoveSQLiteRows (SQLiteTool *tool_p, const json_t *selector_json_p, const bool remove_first_match_only_flag) |
Remove some documents from a SQLite collection. More... | |
json_t * | FindMatchingSQLiteDocuments (SQLiteTool *tool_p, LinkedList *where_clauses_p, const char **fields_ss, char **error_ss) |
Find matching documents for a given query. More... | |
json_t * | GetAllSQLiteResultsAsJSON (SQLiteTool *tool_p) |
Get all results from a SQLite database. More... | |
int32 | GetAllSQLiteResultsForKeyValuePair (SQLiteTool *tool_p, json_t **docs_pp, const char *const key_s, const char *const value_s, const char **fields_ss) |
Get all results for a given key-value query. More... | |
json_t * | GetCurrentValuesFromSQLiteToolAsJSON (SQLiteTool *tool_p, const char **fields_ss, const size_t num_fields) |
When iterating over a SQLite's results get the values and increment the current result that the SQLite is pointing at. More... | |
json_t * | GetAllExistingSQLiteResultsAsJSON (SQLiteTool *tool_p) |
Convert all of a SQLiteTool results into JSON array. More... | |
int32 | IsKeyValuePairInDatabase (SQLiteTool *tool_p, const char *database_s, const char *key_s, const char *value_s) |
Check whether a database_s contains any documents with a given key-value pair. More... | |
void | FreeSQLiteToolErrorString (SQLiteTool *tool_p, char *error_s) |
Free an error string that was generated from a given SQLiteTool. More... | |
char * | CreateSQLiteTable (SQLiteTool *tool_p, const char *table_s, LinkedList *columns_p, const bool delete_if_exists_flag) |
Create a table for the given SQLiteTool. More... | |
Data Fields | |
char * | sqlt_table_s |
The name of the table that this SQLiteTool is currently accessing. More... | |
A SQLiteTool is a datatype that allows access to the data stored within a SQLite instance.
const SQLITE_PREFIX char *SQLITE_OP_EQUALS_S SQLITE_VAL | ( | ) |
bool SetSQLiteDatabase | ( | SQLiteTool * | tool_p, |
const char * | db_s, | ||
int | flags | ||
) |
Set the database an collection that a SQLite will use.
tool_p | The SQLite to update. |
db_s | The database to use. |
flags | The flags to use when opening the underlying sqlite database see sqlite3_open_v2() |
true
if the SQLite was updated successfully. false
otherwise. bool SetSQLiteToolTable | ( | SQLiteTool * | tool_p, |
const char * | table_s | ||
) |
Set the tablethat a SQLite will use.
tool_p | The SQLite to update. |
table_s | The table to use. |
true
if the SQLite was updated successfully. false
otherwise. SQLiteTool * AllocateSQLiteTool | ( | const char * | db_s, |
int | flags | ||
) |
This allocates a SQLiteTool that connects to the SQLite instance specified in the grassroots.config file.
db_s | The database to use. |
flags | The flags to use when opening the underlying sqlite database see sqlite3_open_v2() |
NULL
upon error.bool CloseSQLiteTool | ( | SQLiteTool * | tool_p | ) |
Close the database connection for a given a SQLiteTool.
tool_p | The SQLiteTool to close. |
true
if the tool was closed successfully, false
otherwise. void FreeSQLiteTool | ( | SQLiteTool * | tool_p | ) |
Delete a SQLiteTool and release the connection that it held This calls CloseSqlTool() and then releases the memory.
tool_p | The SQLiteTool to free. |
char * InsertOrUpdateSQLiteData | ( | SQLiteTool * | tool_p, |
json_t * | values_p, | ||
const char *const | table_s, | ||
const char *const | primary_key_s | ||
) |
Insert data from a given JSON fragment using a given SQLite.
Insert of update data in a set of matching documents.
tool_p | The SQLite to use. |
values_p | The JSON fragment to insert. |
primary_key_id_s | The key used to get the values from values_p that the matching documents will be updated with. |
NULL
upon error. This value will need to be freed using FreeMemory() to avoid a memory leak.tool_p | The SQLite to update with. |
values_p | The JSON values to add to the documents. |
table_s | The table to add the data to. |
primary_key_s | The primary key for this data. |
NULL
if the updates were successful. bool RemoveSQLiteRows | ( | SQLiteTool * | tool_p, |
const json_t * | selector_json_p, | ||
const bool | remove_first_match_only_flag | ||
) |
Remove some documents from a SQLite collection.
tool_p | The SQLite that will amend the collection. |
selector_json_p | The statement used to choose which documents to remove. |
remove_first_match_only_flag | If this is true then only the first matching document will be removed. If this is false then all matching documents will be removed. |
true
if any matching SQLite documents were removed successfully, false
otherwise. json_t * FindMatchingSQLiteDocuments | ( | SQLiteTool * | tool_p, |
LinkedList * | where_clauses_p, | ||
const char ** | fields_ss, | ||
char ** | error_ss | ||
) |
Find matching documents for a given query.
tool_p | The SQLite that will search the collection. |
where_clauses_p | The LinkedList of SqlClauseNodes specifying the query to run. |
fields_ss | If specified, then just the keys listed in this array along with their associated values will be stored. This array must have NULL as its final element. If this is NULL , then all of the keys and values in the matching documents will be stored. |
error_ss | If an error occurs, this will point to a newly-allocated string describing the error. This needs to be freed using FreeSQLiteToolErrorString(). |
true
if any matching SQLite documents were found successfully, false
otherwise. json_t * GetAllSQLiteResultsAsJSON | ( | SQLiteTool * | tool_p | ) |
Get all results from a SQLite database.
tool_p | The SQLite to get the results with. |
NULL
upon error. int32 GetAllSQLiteResultsForKeyValuePair | ( | SQLiteTool * | tool_p, |
json_t ** | docs_pp, | ||
const char *const | key_s, | ||
const char *const | value_s, | ||
const char ** | fields_ss | ||
) |
Get all results for a given key-value query.
tool_p | The SQLite to get the results with. |
docs_pp | A pointer to a JSON array pointer where the results will be placed. |
key_s | The key of the query. |
value_s | The value of the query. |
fields_ss | If specified, then just the keys listed in this array along with their associated values will be stored. This array must have NULL as its final element. If this is NULL , then all of the keys and values in the matching documents will be stored. |
json_t * GetCurrentValuesFromSQLiteToolAsJSON | ( | SQLiteTool * | tool_p, |
const char ** | fields_ss, | ||
const size_t | num_fields | ||
) |
When iterating over a SQLite's results get the values and increment the current result that the SQLite is pointing at.
tool_p | The SQLite to get the results from. |
fields_ss | If specified, then just the keys listed in this array along with their associated values will be stored. If this is NULL , then all of the keys and values in the matching documents will be stored. |
num_fields | The number of entries in fields_ss. |
NULL
upon error. json_t * GetAllExistingSQLiteResultsAsJSON | ( | SQLiteTool * | tool_p | ) |
Convert all of a SQLiteTool results into JSON array.
tool_p | The SQLiteTool to get the results with. |
NULL
upon error. int32 IsKeyValuePairInDatabase | ( | SQLiteTool * | tool_p, |
const char * | database_s, | ||
const char * | key_s, | ||
const char * | value_s | ||
) |
Check whether a database_s contains any documents with a given key-value pair.
tool_p | The SQLite to check with. |
database_s | The database to check. |
key_s | The key to search for. |
value_s | The value to search for. |
void FreeSQLiteToolErrorString | ( | SQLiteTool * | tool_p, |
char * | error_s | ||
) |
Free an error string that was generated from a given SQLiteTool.
tool_p | The given SQLiteTool. |
error_s | The error string to free. |
char * CreateSQLiteTable | ( | SQLiteTool * | tool_p, |
const char * | table_s, | ||
LinkedList * | columns_p, | ||
const bool | delete_if_exists_flag | ||
) |
Create a table for the given SQLiteTool.
tool_p | The given SQLiteTool. |
table_s | The name of the table to create. |
columns_p | A LinkedList of SQLiteColumnNodes describing the table's columns. |
delete_if_exists_flag | If this is true , then any existing table with the given name will get deleted and then recreated. If this is false then the function will fail and return an error if table already exists. |
NULL
if the table creation was successful. char* sqlt_table_s |
The name of the table that this SQLiteTool is currently accessing.