1/* 2 * Copyright 2001-2004 Brandon Long 3 * All Rights Reserved. 4 * 5 * ClearSilver Templating System 6 * 7 * This code is made available under the terms of the ClearSilver License. 8 * http://www.clearsilver.net/license.hdf 9 * 10 */ 11 12#ifndef __WDB_H_ 13#define __WDB_H_ 1 14 15#include "util/skiplist.h" 16#include "util/dict.h" 17#include "util/ulist.h" 18#include <db.h> 19 20typedef struct _column 21{ 22 char *name; 23 int ondisk_index; /* index# on disk, constant for life of db, 24 must be 1 or higher */ 25 int inmem_index; /* load time specific, needs to be flushed on 26 alter table */ 27 char type; 28} WDBColumn; 29 30typedef struct _row 31{ 32 int table_version; /* random number which maps to the same number 33 of the table defn when loaded to verify they 34 match */ 35 char *key_value; 36 int data_count; 37 void *data[1]; 38} WDBRow; 39 40typedef struct _cursor 41{ 42 int table_version; /* random number which maps to the same number 43 of the table defn when loaded to verify they 44 match */ 45 DBC *db_cursor; 46} WDBCursor; 47 48typedef struct _wdb 49{ 50 char *name; 51 char *key; 52 char *path; 53 dictCtx attrs; 54 dictCtx cols; 55 skipList ondisk; 56 ULIST *cols_l; 57 DB *db; 58 int last_ondisk; 59 int defn_dirty; /* must save defn on destroy */ 60 int table_version; /* random number which maps to the same number 61 of the table defn when loaded/changed to 62 verify they match */ 63} WDB; 64 65 66#define WDB_TYPE_STR 's' 67#define WDB_TYPE_INT 'i' 68 69#define WDBC_FIRST (1<<0) 70#define WDBC_NEXT (1<<1) 71#define WDBC_FIND (1<<2) 72 73#define WDBR_INSERT (1<<0) 74 75NEOERR * wdb_open (WDB **wdb, const char *name, int flags); 76NEOERR * wdb_save (WDB *wdb); 77NEOERR * wdb_update (WDB *wdb, const char *name, const char *key); 78NEOERR * wdb_create (WDB **wdb, const char *path, const char *name, 79 const char *key, ULIST *col_def, int flags); 80void wdb_destroy (WDB **wdb); 81NEOERR * wdb_column_insert (WDB *wdb, int loc, const char *key, char type); 82NEOERR * wdb_column_delete (WDB *wdb, const char *name); 83NEOERR * wdb_column_update (WDB *wdb, const char *oldkey, const char *newkey); 84NEOERR * wdb_column_exchange (WDB *wdb, const char *key1, const char *key2); 85 86/* 87 * function: wdb_keys 88 * description: this function returns the key and column names for the 89 * current database 90 * input: wdb - open database 91 * output: primary_key - pointer to the primary key 92 * data - pointer to a ULIST of the columns. 93 * both of these are allocated structures, you can clear data 94 * with uListDestroy (data, ULIST_FREE) 95 * return: STATUS_OK on no error or egerr.h error 96 */ 97NEOERR * wdb_keys (WDB *wdb, char **primary_key, ULIST **data); 98 99NEOERR * wdb_attr_get (WDB *wdb, const char *key, char **value); 100NEOERR * wdb_attr_set (WDB *wdb, const char *key, const char *value); 101NEOERR * wdb_attr_next (WDB *wdb, char **key, char **value); 102NEOERR * wdbr_lookup (WDB *wdb, const char *key, WDBRow **row); 103NEOERR * wdbr_create (WDB *wdb, const char *key, WDBRow **row); 104NEOERR * wdbr_save (WDB *wdb, WDBRow *row, int flags); 105NEOERR * wdbr_delete (WDB *wdb, const char *key); 106NEOERR * wdbr_destroy (WDB *wdb, WDBRow **row); 107NEOERR * wdbr_get (WDB *wdb, WDBRow *row, const char *key, void **value); 108NEOERR * wdbr_set (WDB *wdb, WDBRow *row, const char *key, void *value); 109NEOERR * wdbr_dump (WDB *wdb, WDBRow *row); 110NEOERR * wdbr_next (WDB *wdb, WDBCursor *cursor, WDBRow **row, int flags); 111NEOERR * wdbr_find (WDB *wdb, WDBCursor *cursor, const char *key, WDBRow **row); 112NEOERR * wdbc_create (WDB *wdb, WDBCursor **cursor); 113NEOERR * wdbc_destroy (WDB *wdb, WDBCursor **cursor); 114 115#endif /* __WDB_H_ */ 116