/home/dcp1990/prog/fakedbfs/libfakedbfs/sqlite.c File Reference

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <sqlite3.h>
#include <fakedbfs/fdbfsconfig.h>
#include <fakedbfs/fakedbfs.h>
#include <fakedbfs/db.h>
#include <fakedbfs/debug.h>

Functions

int fdbfs_db_busy_handler (void *data, int prior)
 Handle busy conditions in the sqlite database. (internal).
int fdbfs_db_open (fdbfs_t *f)
 Open the database and initialise sqlite.
int fdbfs_db_close (fdbfs_t *f)
 Close the database.
int fdbfs_db_table_exists (fdbfs_t *f, const char *tname)
 Check if a table exists in the database.
int fdbfs_db_cat_exists (fdbfs_t *f, const char *cat)
 Check if a catalogue exists in the database.
int fdbfs_db_create_table (fdbfs_t *f, const char *tname, const char *tspec)
 Create a table.
const char * fdbfs_db_gettype (enum DataType t)
 Get the database-specific typename for an DataType enum.
int fdbfs_db_add_column (fdbfs_t *f, const char *tname, const char *cname, coltype_t datatype)
 Add a column to a table.
int fdbfs_db_del_column (fdbfs_t *f, const char *tname, const char *cname)
 Delete a column from a table.
int fdbfs_db_add_to_enum_list_table (fdbfs_t *f, const char *name, const char *tname, const char *specf)
 Add an entry to the enum_list table.
int fdbfs_db_cat_getcfdname (fdbfs_t *f, const char *catname, char **tcfd)
 Get CFD name of table. (without cfd_ prefix).
int fdbfs_db_cfd_update_refcount (fdbfs_t *f, const char *name, int add, unsigned int val)
 Update refcount of CFD table entry.
int fdbfs_db_add_to_cfd_list_table (fdbfs_t *f, const char *name, const char *alias, const char *tablename, const char *specfile)
 Add entry to catalogue field definition list table.
int fdbfs_db_add_to_cat_list_table (fdbfs_t *f, const char *name, const char *alias, const char *tablename, const char *fieldtable)
 Add an entry to the cat_list table.
int fdbfs_db_add_to_field_desc (fdbfs_t *f, const char *tablename, const char *name, const char *alias, enum DataType type, const char *typen)
 Add to the field description table for a catalogue.
int fdbfs_db_delete (fdbfs_t *f, const char *from, const char *wherecol, const char *wherecmp, const char *whereval)
 Delete row from table in database.
int fdbfs_db_drop_table (fdbfs_t *f, const char *tablename)
 Drops a table from the database.
int fdbfs_db_add_enum_elem (fdbfs_t *f, const char *tname, const char *name, const char *fmtname, unsigned int value, enum DataType dtype, const char *subelements)
 Add an element to an enumeration description table.
int fdbfs_db_bind_field (fdbfs_t *f, int *count, enum DataType type, void *value, size_t len, sqlite3_stmt *stmt)
 Bind a field to a statement.
int fdbfs_db_get_lastupdate (fdbfs_t *f, const char *cat, const char *filename)
 Get the lastupdate time from a catalogue.
int fdbfs_db_mib_add (fdbfs_t *f, const char *mib, enum DataType type, union Data data)
 Adds a MIB to the configuration table.
int fdbfs_db_mib_update (fdbfs_t *f, const char *mib, enum DataType type, union Data data)
 Updates a MIB in the configuration table.

Function Documentation

int fdbfs_db_add_column fdbfs_t f,
const char *  tname,
const char *  cname,
coltype_t  datatype
 

Add a column to a table.

fdbfs_db_add_column adds a column to a table. This isn't exactly production-ready. It requires that the version of SQLite support the "ALTER TABLE ADD COLUMN" command.

Parameters:
f The instance of fakedbfs.
tname The name of the table to operate on.
cname The name of the new column.
datatype The datatype of the column.
Returns:
0 on error, non-zero on success.

int fdbfs_db_add_enum_elem fdbfs_t f,
const char *  tname,
const char *  name,
const char *  fmtname,
unsigned int  value,
enum DataType  dtype,
const char *  subelements
 

Add an element to an enumeration description table.

fdbfs_add_enum_elem() adds a row to an enum descripton table.

Parameters:
f The instance of fakedbfs.
tname The name of the enum description table.
name The name of the new element.
fmtname The friendly alias of the new element.
value The integer value of the new element.
dtype The datatype of the new element, if other.
subelements The subelements for this element.
Returns:
0 on error.

int fdbfs_db_add_to_cat_list_table fdbfs_t f,
const char *  name,
const char *  alias,
const char *  tablename,
const char *  fieldtable
 

Add an entry to the cat_list table.

fdbfs_db_add_to_cat_list_table() adds an entry to the cat list table.

Parameters:
f The instance of fakedbfs.
name The name of the catalogue.
alias The friendly alias of the catalogue.
tablename The table that the catalogue is defined in.
fieldtable The field description table for this catalogue.
specf The name of the filename the catalogue was originally defined in.
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_add_to_cfd_list_table fdbfs_t f,
const char *  name,
const char *  alias,
const char *  tablename,
const char *  specfile
 

Add entry to catalogue field definition list table.

Parameters:
f Instance of fakedbfs to operate on.
name Name of new CFD.
alias Alias of new CFD.
tablename Table where this CFD resides.
specfile Specfile in which this CFD originated.
Returns:
0 on error.

int fdbfs_db_add_to_enum_list_table fdbfs_t f,
const char *  name,
const char *  tname,
const char *  specf
 

Add an entry to the enum_list table.

fdbfs_db_add_to_enum_list_table() adds an entry to the enum list table.

Parameters:
f The instance of fakedbfs.
name The name of the enum.
tname The table that the enum is defined in.
specf The name of the filename the enum was originally defined in.
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_add_to_field_desc fdbfs_t f,
const char *  tablename,
const char *  name,
const char *  alias,
enum DataType  type,
const char *  typen
 

Add to the field description table for a catalogue.

fdbfs_db_add_to_field_desc() adds an entry to the field description table for a catalogue.

Parameters:
f The instance of fakedbfs.
tablename The name of the field description table.
name The name of the field.
alias The friendly alias of the field.
type The datatype of the field.
typen The name of the enum, if applicable (NULL otherwise).
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_bind_field fdbfs_t f,
int *  count,
enum DataType  type,
void *  value,
size_t  len,
sqlite3_stmt *  stmt
 

Bind a field to a statement.

fdbfs_db_bind_field() binds data to an SQLite statement. The field counter is increased on each call.

Parameters:
f The instance of fakedbfs.
[in,out] count A pointer to an integer specifying the index of the current field. This will be increased by one.
type The datatype of the field to bind.
value A pointer to the data to bind; the type of data is derived from the type parameter.
len For BLOB data, the length of data to bind. strlen() is used on strings, so this is not necessary for strings.
stmt The sqlite statement to operate on.
Returns:
0 on error.

int fdbfs_db_busy_handler void *  data,
int  prior
 

Handle busy conditions in the sqlite database. (internal).

int fdbfs_db_cat_exists fdbfs_t f,
const char *  cat
 

Check if a catalogue exists in the database.

fdbfs_db_cat_exists() looks at the cat_list table to see if a catalogue exists.

Parameters:
f The instance of fakedbfs on which to operate.
cat The catalogue name to check for.
Returns:
Non-zero on existence, zero on error or no existence.

int fdbfs_db_cat_getcfdname fdbfs_t f,
const char *  catname,
char **  tcfd
 

Get CFD name of table. (without cfd_ prefix).

Parameters:
f Instance of fakedbfs.
catname Name of catalogue.
[out] tcfd Pointer to char* that will be set to cfdname (must be freed)
Returns:
0 on error, 1 otherwise.

int fdbfs_db_cfd_update_refcount fdbfs_t f,
const char *  name,
int  add,
unsigned int  val
 

Update refcount of CFD table entry.

Parameters:
f Instance of fakedbfs to operate on.
name Name of CFD.
add True if adding, false if subtracting.
val Value to add to refcount.
Returns:
0 on error.

int fdbfs_db_close fdbfs_t f  ) 
 

Close the database.

fdbfs_db_close() closes the database.

Parameters:
f The instance of fakedbfs on which to operate.
Returns:
Non-zero on success, zero on error.

int fdbfs_db_create_table fdbfs_t f,
const char *  tname,
const char *  tspec
 

Create a table.

fdbfs_db_create_table() creates a table of the specified name and specification.

Parameters:
f The instance of fakedbfs.
tname The name of the new table.
tspec The database-specific specification of the new table.
Returns:
0 on error, 1 on success.

int fdbfs_db_del_column fdbfs_t f,
const char *  tname,
const char *  cname
 

Delete a column from a table.

fdbfs_db_del_column() deletes a column from a table if the database driver supports it. SQLite doesn't, so for now this does nothing.

Parameters:
f The instance of fakedbfs.
tname The table from which to remove the column.
cname The column to remove.
Returns:
0 on error, 1 otherwise.

int fdbfs_db_delete fdbfs_t f,
const char *  from,
const char *  wherecol,
const char *  wherecmp,
const char *  whereval
 

Delete row from table in database.

fdbfs_db_delete() deletes rows from a table based on certain conditions.

Parameters:
f The instance of fakedbfs.
from The table to operate on.
wherecol The column to check.
wherecmp The comparison operator. (==, etc)
whereval The value to check for.
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_drop_table fdbfs_t f,
const char *  tablename
 

Drops a table from the database.

fdbfs_db_drop_table() drops the named table from the database.

Parameters:
f The instance of fakedbfs.
tablename The name of the table to drop.
Returns:
0 on error, non-zero on success.

int fdbfs_db_get_lastupdate fdbfs_t f,
const char *  cat,
const char *  filename
 

Get the lastupdate time from a catalogue.

fdbfs_db_get_lastupdate() gets the lastupdate time for a certain file in a catalogue.

Parameters:
f The instance of fakedbfs.
cat The catalogue to operate on.
filename The filename to query.
Return values:
-2 No match for this file.
-1 Error.
Returns:
The time of last updating on the specified file.

const char* fdbfs_db_gettype enum DataType  t  ) 
 

Get the database-specific typename for an DataType enum.

fdbfs_db_gettype() returns the database-specific type string for a specified DataType enum.

Parameters:
t The type to retrieve.
Returns:
A string containing the database-specific type.

int fdbfs_db_mib_add fdbfs_t f,
const char *  mib,
enum DataType  type,
union Data  data
 

Adds a MIB to the configuration table.

This is used by the configuration subsystem.

Parameters:
f The instance of fakedbfs.
mib The mib to add.
type The datatype of this MIB.
data The value of this MIB.
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_mib_update fdbfs_t f,
const char *  mib,
enum DataType  type,
union Data  data
 

Updates a MIB in the configuration table.

This is used by the configuration subsystem.

Parameters:
f The instance of fakedbfs.
mib The mib to update.
type The datatype of this MIB.
data The value of this MIB.
Returns:
0 on error, non-zero otherwise.

int fdbfs_db_open fdbfs_t f  ) 
 

Open the database and initialise sqlite.

fdbfs_db_open() opens our database and sets certain sqlite paramaters.

Parameters:
f The instance of fakedbfs on which to operate.
Returns:
Non-zero on success, zero on error.

int fdbfs_db_table_exists fdbfs_t f,
const char *  tname
 

Check if a table exists in the database.

fdbfs_db_table_exists() looks at the sqlite_master table to see if a table exists.

Parameters:
f The instance of fakedbfs on which to operate.
tname The tablename to check for.
Returns:
Non-zero on existence, zero on error or no existence.


Generated on Wed Apr 19 16:26:23 2006 for fakedbfs by  doxygen 1.4.6