Angband
Functions | Variables
db.c File Reference

SQLite3 database storage functions. More...

#include <sqlite3.h>
#include <time.h>
#include <sys/stat.h>
#include "angband.h"
#include "init.h"

Functions

static bool stats_make_output_dir (void)
 Utility functions.
bool stats_db_open (void)
 

Interface functions


bool stats_db_close (void)
 Call stats_close_db to close the database connection and free module variables.
int stats_db_exec (char *sql_str)
 Evaluate a sqlite3 SQL statement on the previously opened database.
int stats_db_stmt_prep (sqlite3_stmt **sql_stmt, char *sql_str)
 Prepare a sqlite3 SQL statement for evaluation.
int stats_db_bind_ints (sqlite3_stmt *sql_stmt, int num_cols, int offset,...)
 Utility function for binding many ints at once.
int stats_db_bind_rv (sqlite3_stmt *sql_stmt, int col, random_value rv)
 Utility function for binding a random_value to a parameter as TEXT.

Variables

static sqlite3 * db
 Module state variables.
static char * ANGBAND_DIR_STATS
static char * db_filename

Detailed Description

SQLite3 database storage functions.

Copyright (c) 2011 Robert Au myshk.nosp@m.in+a.nosp@m.ngban.nosp@m.d@du.nosp@m.rak.n.nosp@m.et

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

int stats_db_bind_ints ( sqlite3_stmt *  sql_stmt,
int  num_cols,
int  offset,
  ... 
)

Utility function for binding many ints at once.

The offset argument should be the number of columns to skip before starting to bind. Arguments after num_cols should be a series of ints to be bound to parameters in sql_stmt, in order.

References value.

int stats_db_bind_rv ( sqlite3_stmt *  sql_stmt,
int  col,
random_value  rv 
)

Utility function for binding a random_value to a parameter as TEXT.

Note optimization for storing values without randomness.

References random::base, random::dice, random::m_bonus, random::sides, and strnfmt().

bool stats_db_close ( void  )

Call stats_close_db to close the database connection and free module variables.

References ANGBAND_DIR_STATS, db, db_filename, and mem_free().

int stats_db_exec ( char *  sql_str)

Evaluate a sqlite3 SQL statement on the previously opened database.

The argument sql_str should contain the SQL statement, encoded as UTF-8. The return value is zero on success or a sqlite3 error code on failure. This function is a wrapper around sqlite3_exec and is for statements that don't expect output. Use stats_db_stmt_prep(), sqlite3_bind_*(), and sqlite3_step() for more complex statements.

References db.

bool stats_db_open ( void  )


Interface functions

Call stats_db_open first to create the database file and set up a database connection. Returns true on success, false on failure.

References ANGBAND_DIR_STATS, db, db_filename, file_exists(), mem_alloc(), path_build(), PATH_SEP, size, stats_make_output_dir(), strnfmt(), and object::time.

int stats_db_stmt_prep ( sqlite3_stmt **  sql_stmt,
char *  sql_str 
)

Prepare a sqlite3 SQL statement for evaluation.

sql_stmt should be a non-NULL, unallocated pointer. The sqlite3 library will allocate memory appropriately. The caller should later delete this statement with sqlite3_finalize(). sql_str should contain the SQL statement, encoded as UTF-8. The function returns 0 on success or a sqlite3 error code on failure.

References db.

static bool stats_make_output_dir ( void  )
static

Utility functions.

References ANGBAND_DIR_STATS, ANGBAND_DIR_USER, dir_create(), mem_alloc(), path_build(), PATH_SEP, and size.

Referenced by stats_db_open().

Variable Documentation

char* ANGBAND_DIR_STATS
static
sqlite3* db
static
char* db_filename
static

Referenced by stats_db_close(), and stats_db_open().