Patterns in static

Apophenia

Data Structures | Macros | Functions | Variables
apop_db.c File Reference

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_dataapop_query_to_text (const char *fmt,...)
 
apop_dataapop_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_dataapop_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
 

Detailed Description

An easy front end to SQLite. Includes a few nice features like a variance, skew, and kurtosis aggregator for SQL.

Macro Definition Documentation

#define Fillin (   query,
  fmt 
)
Value:
char *query; \
va_list argp; \
va_start(argp, fmt); \
Apop_stopif(vasprintf(&query, fmt, argp)==-1, , 0, "Trouble writing to a string."); \
va_end(argp); \
Apop_notify(2, "%s", query);
#define Apop_stopif(test, onfail, level,...)
Definition: apop.h:1004
#define Apop_notify(verbosity,...)
Definition: apop.h:980

Function Documentation

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.

Parameters
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')
Returns
0 on OK, nonzero on error.
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.

Parameters
filenameThe 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).
Returns
0: everything OK
1: database did not open.
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.

Parameters
namethe 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)
Returns
0 = table does not exist
1 = table was found, and if remove=='d', has been deleted
  • In the SQLite engine, this function considers table views to be tables.
  • If apop_opts.stop_on_warn='n', returns -1 on errors.

Variable Documentation

apop_opts_type apop_opts
Initial value:
=
{ .verbose=1,
.output_delimiter ="\t", .input_delimiters = "|,\t",
.db_name_column = "row_names", .nan_string = "NaN",
.db_engine = '\0', .db_user = "\0",
.db_pass = "\0", .thread_count = 1,
.log_file = NULL,
.rng_seed = 479901, .version = 0.999 }

Here are where the options are initially set. See the apop_opts_type documentation for details.

Autogenerated by doxygen on Sun Oct 26 2014 (Debian 0.999b+ds3-2).