int main(int argc, char *argv[]) { Database *db; LinkedList *ll; db = db_create("project_seven"); //CREATE DATABASE project_seven; tbl_delete(db, "animals"); //DROP TABLE IF EXISTS animals; func_delete(db, "num_animals"); //DROP FUNCTION IF EXISTS num_animals; tbl_create(db, "animals"); //CREATE TABLE animals /* Capabilities of this function changed to make implementation easier. The purpose of this function is to demonstrate memory management */ func_create(db, "num_animals", num_animals); //CREATE FUNCTION num_animals() /*Creates rows in table*/ ll = ll_create(); ll_append(ll, "Cow"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Cow"); ll = ll_create(); ll_append(ll, "Dog"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Dog"); /*Printing tables, and rows created*/ db_print(db); //SHOW TABLES; tbl_print(db, "animals"); //SELECT * FROM animals; /*Deallocating memory*/ tbl_clear(db, "animals"); //DELETE FROM animals; tbl_print(db, "animals"); //SELECT * FROM animals; /*Allocating so that we can deallocate again*/ ll = ll_create(); ll_append(ll, "Pig"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Pig"); ll = ll_create(); ll_append(ll, "Cat"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Cat"); tbl_print(db, "animals"); //SELECT * FROM animals; /*Deallocating memory*/ tbl_clear(db, "animals"); //TRUNCATE TABLE animals; tbl_print(db, "animals"); //SELECT * FROM animals; tbl_delete(db, "animals"); //DROP TABLE IF EXISTS animals; func_delete(db, "num_animals"); //DROP FUNCTION IF EXISTS num_animals; db_print(db); //SHOW TABLES; db_delete(db); //DROP DATABASE IF EXISTS project_seven; return 0; }
void nnpfs_dnlc_purge_mp(struct mount *mp) { NNPFSDEB(XDEBDNLC, ("nnpfs_dnlc_purge_mp()\n")); tbl_clear (); cache_purgevfs(mp); }
static int tbl_shutdown (void) { size_t i; for (i = 0; i < tables_num; ++i) tbl_clear (&tables[i]); sfree (tables); return 0; } /* tbl_shutdown */
void nnpfs_dnlc_purge (struct vnode *vp) { NNPFSDEB(XDEBDNLC, ("nnpfs_dnlc_purge\n")); if (tbl.dvp == vp || tbl.vp == vp) tbl_clear (); cache_purge(vp); }
static int tbl_config_table (oconfig_item_t *ci) { tbl_t *tbl; int status = 0; size_t i; if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { log_err ("<Table> expects a single string argument."); return 1; } tbl = realloc (tables, (tables_num + 1) * sizeof (*tables)); if (NULL == tbl) { char errbuf[1024]; log_err ("realloc failed: %s.", sstrerror (errno, errbuf, sizeof (errbuf))); return -1; } tables = tbl; ++tables_num; tbl = tables + tables_num - 1; tbl_setup (tbl, ci->values[0].value.string); for (i = 0; i < ((size_t) ci->children_num); ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Separator")) tbl_config_set_s (c->key, &tbl->sep, c); else if (0 == strcasecmp (c->key, "Instance")) tbl_config_set_s (c->key, &tbl->instance, c); else if (0 == strcasecmp (c->key, "Result")) tbl_config_result (tbl, c); else log_warn ("Ignoring unknown config key \"%s\" " "in <Table %s>.", c->key, tbl->file); } if (NULL == tbl->sep) { log_err ("Table \"%s\" does not specify any separator.", tbl->file); status = 1; } else { strunescape (tbl->sep, strlen (tbl->sep) + 1); } if (NULL == tbl->instance) { tbl->instance = sstrdup (tbl->file); replace_special (tbl->instance, strlen (tbl->instance)); } if (NULL == tbl->results) { log_err ("Table \"%s\" does not specify any (valid) results.", tbl->file); status = 1; } if (0 != status) { tbl_clear (tbl); --tables_num; return status; } for (i = 0; i < tbl->results_num; ++i) { tbl_result_t *res = tbl->results + i; size_t j; for (j = 0; j < res->instances_num; ++j) if (res->instances[j] > tbl->max_colnum) tbl->max_colnum = res->instances[j]; for (j = 0; j < res->values_num; ++j) if (res->values[j] > tbl->max_colnum) tbl->max_colnum = res->values[j]; } return 0; } /* tbl_config_table */
static int tbl_config_table(oconfig_item_t *ci) { if (ci->values_num != 1 || ci->values[0].type != OCONFIG_TYPE_STRING) { log_err("<Table> expects a single string argument."); return 1; } tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables)); if (tbl == NULL) { log_err("realloc failed: %s.", STRERRNO); return -1; } tables = tbl; tbl = tables + tables_num; tbl_setup(tbl, ci->values[0].value.string); for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *c = ci->children + i; if (strcasecmp(c->key, "Separator") == 0) cf_util_get_string(c, &tbl->sep); else if (strcasecmp(c->key, "Plugin") == 0) cf_util_get_string(c, &tbl->plugin_name); else if (strcasecmp(c->key, "Instance") == 0) cf_util_get_string(c, &tbl->instance); else if (strcasecmp(c->key, "Result") == 0) tbl_config_result(tbl, c); else log_warn("Ignoring unknown config key \"%s\" " "in <Table %s>.", c->key, tbl->file); } int status = 0; if (tbl->sep == NULL) { log_err("Table \"%s\" does not specify any separator.", tbl->file); status = 1; } else { strunescape(tbl->sep, strlen(tbl->sep) + 1); } if (tbl->instance == NULL) { tbl->instance = sstrdup(tbl->file); replace_special(tbl->instance, strlen(tbl->instance)); } if (tbl->results == NULL) { assert(tbl->results_num == 0); log_err("Table \"%s\" does not specify any (valid) results.", tbl->file); status = 1; } if (status != 0) { tbl_clear(tbl); return status; } for (size_t i = 0; i < tbl->results_num; ++i) { tbl_result_t *res = tbl->results + i; for (size_t j = 0; j < res->instances_num; ++j) if (res->instances[j] > tbl->max_colnum) tbl->max_colnum = res->instances[j]; for (size_t j = 0; j < res->values_num; ++j) if (res->values[j] > tbl->max_colnum) tbl->max_colnum = res->values[j]; } tables_num++; return 0; } /* tbl_config_table */