![]() |
|
Data Structures | |
struct | tab_exists_t |
Macros | |
#define | ERRCHECK {Apop_stopif(err, return 1, 0, "%s: %s",query, err); } |
#define | ERRCHECK_NR {Apop_stopif(err, return NULL, 0, "%s: %s",query, err); } |
#define | ERRCHECK_SET_ERROR(outdata) {Apop_stopif(err, if (!(outdata)) (outdata)=apop_data_alloc(); (outdata)->error='q'; sqlite3_free(err); return outdata, 0, "%s: %s",query, err); } |
#define | Fillin(query, fmt) |
Functions | |
int | apop_db_open (char const *filename) |
int | apop_table_exists (char const *name, char remove) |
int | apop_db_close (char vacuum) |
int | apop_query (const char *fmt,...) |
apop_data * | apop_query_to_text (const char *fmt,...) |
apop_data * | apop_query_to_data (const char *fmt,...) |
gsl_matrix * | apop_query_to_matrix (const char *fmt,...) |
gsl_vector * | apop_query_to_vector (const char *fmt,...) |
double | apop_query_to_float (const char *fmt,...) |
apop_data * | apop_query_to_mixed_data (const char *typelist, const char *fmt,...) |
void | qxprintf (char **q, char *format,...) |
int | apop_data_to_db (const apop_data *set, const char *tabname, const char output_append) |
Variables | |
apop_opts_type | apop_opts |
An easy front end to SQLite. Includes a few nice features like a variance, skew, and kurtosis aggregator for SQL.
#define Fillin | ( | query, | |
fmt | |||
) |
int apop_db_close | ( | char | vacuum | ) |
Closes the database on disk. If you opened the database with apop_db_open(NULL)
, then this is basically optional.
vacuum | 'v': vacuum—do clean-up to minimize the size of the database on disk. 'q': Don't bother; just close the database. (default = 'q') |
int apop_db_open | ( | char const * | filename | ) |
If you want to use a database on the hard drive instead of memory, then call this once and only once before using any other database utilities.
If you want a disposable database which you won't use after the program ends, don't bother with this function.
The trade-offs between an on-disk database and an in-memory db are as one would expect: memory is faster, but is destroyed when the program exits. SQLite includes a command line utility (sqlite3
) which let you ask queries of a database on disk, which may be useful for debugging. There are also some graphical front-ends; just ask your favorite search engine for SQLite GUI.
MySQL users: either set the environment variable APOP_DB_ENGINE=mysql or set apop_opts.db_engine
= 'm'.
The Apophenia package assumes you are only using a single SQLite database at a time. You can use the SQL attach
function to load other databases, or see this blog post for further suggestions and sample code.
When you are done doing your database manipulations, be sure to call apop_db_close if writing to disk.
filename | The name of a file on the hard drive on which to store the database. If NULL , then the database will be kept in memory (in which case, the other database functions will call this function for you and you don't need to bother). |
int apop_table_exists | ( | char const * | name, |
char | remove | ||
) |
Check for the existence of a table, and maybe delete it.
Recreating a table which already exists can cause errors, so it is good practice to check for existence first. Also, this is the stylish way to delete a table, since just calling "drop table"
will give you an error if the table doesn't exist.
name | the table name (no default) |
remove | 'd' ==>delete table so it can be recreated in main. 'n' ==>no action. Return result so program can continue. (default) |
apop_opts.stop_on_warn='n'
, returns -1 on errors.apop_opts_type apop_opts |
Here are where the options are initially set. See the apop_opts_type documentation for details.