コード例 #1
0
ファイル: db_input.c プロジェクト: avsm/openbsd-xen-sys
void
db_delete_line(void)
{
	db_delete(db_le - db_lc, DEL_FWD);
	db_delete(db_lc - db_lbuf_start, DEL_BWD);
	db_le = db_lc = db_lbuf_start;
}
コード例 #2
0
ファイル: msilo.c プロジェクト: miettal/armadillo420_standard
/**
 * - cleaning up the messages that got reply
 * - delete expired messages from database
 */
void m_clean_silo(unsigned int ticks, void *param)
{
	msg_list_el mle = NULL, p;
	db_key_t db_keys[MAX_DEL_KEYS];
	db_val_t db_vals[MAX_DEL_KEYS];
	db_op_t  db_ops[1] = { OP_LEQ };
	int n;
	
	DBG("MSILO:clean_silo: cleaning stored messages - %d\n", ticks);
	
	msg_list_check(ml);
	mle = p = msg_list_reset(ml);
	n = 0;
	while(p)
	{
		if(p->flag & MS_MSG_DONE)
		{
			db_keys[n] = DB_KEY_MID;
			db_vals[n].type = DB_INT;
			db_vals[n].nul = 0;
			db_vals[n].val.int_val = p->msgid;
			DBG("MSILO:clean_silo: cleaning sent message [%d]\n", p->msgid);
			n++;
			if(n==MAX_DEL_KEYS)
			{
				if (db_delete(db_con, db_keys, NULL, db_vals, n) < 0) 
					DBG("MSILO:clean_silo: error cleaning %d messages.\n",n);
				n = 0;
			}
		}
		p = p->next;
	}
	if(n>0)
	{
		if (db_delete(db_con, db_keys, NULL, db_vals, n) < 0) 
			DBG("MSILO:clean_silo: error cleaning %d messages\n", n);
		n = 0;
	}

	msg_list_el_free_all(mle);
	
	// cleaning expired messages
	if(ticks%(check_time*clean_period)<check_time)
	{
		DBG("MSILO:clean_silo: cleaning expired messages\n");
		db_keys[0] = DB_KEY_EXP_TIME;
		db_vals[0].type = DB_INT;
		db_vals[0].nul = 0;
		db_vals[0].val.int_val = (int)time(NULL);
		if (db_delete(db_con, db_keys, db_ops, db_vals, 1) < 0) 
			DBG("MSILO:clean_silo: ERROR cleaning expired messages\n");
	}
}
コード例 #3
0
ファイル: database.c プロジェクト: athersec/robo_a
void db_save(const char* const name, uint8_t* data, uint32_t data_len)
{
	if(false == db_init_done)
		return;

	if(0 != db_find(name))
		db_delete(name);

	uint32_t i, j;
	uint8_t name_len = strlen(name);

	i = db_index;

	for(j = 0; j < name_len; j++) {
		db_buf[i + j] = name[j];
	}
	db_buf[i + j] = '=';

	i = i + j + 1;
	for(j = 0; j < DATA_MSG_LEN; j++) {
		db_buf[i + j] = (uint8_t)(data_len >> (j << 3));
	}

	i = i + j;
	for(j = 0; j < data_len; j++) {
		db_buf[i + j] = data[j];
	}
	db_buf[i + j] = '\n';

	db_index = i + j + 1;
	return;
}
コード例 #4
0
static INT32 contact_provider_delete(ContentProvider* thiz,ContentProviderDestination dest, DatabaseWhereClause* filter)
{

    ContactProvider* sub_provider =(ContactProvider*) thiz->priv_data;
    const CHAR* table = NULL;
    INT32 db_ret=DB_OK;

    DatabaseHandle* db_handle = contact_base_provider_obtain_db_handle();

    return_val_if_fail(sub_provider&&db_handle, DB_ERROR);

    switch (dest)
    {
    case CONTACT_PROVIDER_DESTINATION_CONTACTS:
        table = CONTACT_ME_CONTACTS_TABLE_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_SIM:
        table = CONTACT_SIM_TABLE_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_GROUP:
        table = CONTACT_ME_GROUP_TABLE_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_EXTENSION_NUMBER:
        table = CONTACT_EXTENSION_TABLE_NUMBER_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_EXTENSION_OTHER:
        table = CONTACT_EXTENSION_TABLE_OTHER_NAME;
        break;
    }
    db_ret = db_delete(db_handle ,table,filter);
    contact_base_provider_release_db_handle();
    return db_ret;

}
コード例 #5
0
INT32 sms_update_all_cache_name_in_threads(DatabaseHandle* db_handle)
{
    INT32 result = DB_ERROR;
    Cursor* cursor = NULL;
    INT64 thread_id = -1;
    CHAR* address = NULL;
    DatabaseWhereClause* clause = NULL;
    return_val_if_fail(cursor,DB_OK);
    clause= db_where_clause_create("ID NOT IN (SELECT DISTINCT thread_id FROM sms_tb)",0);
    result=db_delete(db_handle, SMS_THREADS_TABLE_NAME,clause);
    db_clause_destroy( clause);

    cursor = db_raw_query(db_handle, "SELECT thread_id,address FROM threads_tb");
    do
    {
        if (!cursor_get_int(cursor, 0, &thread_id))
            break;
        address= (CHAR*)cursor_get_string( cursor, 1);
        if (address)
            result=sms_update_cache_name_of_thread(db_handle, thread_id,address);

    }while (cursor_move_to_next(cursor)&&result==DB_OK);

    cursor_destroy(cursor);



    return result;
}
コード例 #6
0
ファイル: memoryInC.c プロジェクト: plhughes/CS333-SQL
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;
}
コード例 #7
0
ファイル: main.c プロジェクト: CyberGrandChallenge/samples
void buy()
{
    char name[200];
    key k;
    result res;

    read_until(STDIN, name, 200, '\n');
    k.data.count = strlen(name) + 1;
    k.data.data = (opaque *)name;

    res = db_lookup(k);
    if (res.status == SUCCESS)
    {
        item_details *d = (item_details *)res.rec.data->data.data;
        if (d->count < 1)
        {
            printf("Not enought items\n");
        }
        else
        {
            d->count--;
            if (d->count == 0)
                db_delete(k);
            else
                db_insert(*res.rec.data);
        }
    }
    else
    {
        printf("Item not found\n");
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: turinglife/npp-ustc
/*****************************************************************
Function Name: main
Description: This is a main function
Parameter:  

@argc: argument count
@argv: argument vector

Author: SA12226114(Xin Zhu), SA12226139(Dan Shu)
Date: 2012-11-27
******************************************************************/
int main(int argc, char *argv[])
{
    void *db = NULL;
    char cmdline[CMDLINE_LEN], cmd[CMD_LEN], key[KEY_LEN], value[VALUE_LEN];
    
    /* display menu */
    util_menu();

    while(1)
    {
        /* format command line */
        util_format(cmdline, cmd, key, value);
        
        if(strncmp(cmd, "open", sizeof("open")) == 0)                   /* create database */
        {
            db_create(&db, key);
        }
        else if(strncmp(cmd, "set", sizeof("set")) == 0)                /* store records */
        {
            db_write(db, key, value);
        }
        else if(strncmp(cmd, "get", sizeof("get")) == 0)                /* retrieve records */
        {
            db_read(db, key);
        }
        else if(strncmp(cmd, "remove", sizeof("remove")) == 0)          /* remove a record */
        {
            db_remove(db, key);
        }
        else if(strncmp(cmd, "ls", sizeof("ls")) == 0)                  /* dump all records in database */
        {
            db_queryallrecords(db);
        }
        else if(strncmp(cmd, "close", sizeof("close")) == 0)            /* close the database */
        {
            db_close(&db);
        }
        else if(strncmp(cmd, "delete", sizeof("delete")) == 0)          /* delete the object */
        {
            db_delete(&db);
        }
        else if(strncmp(cmd, "help", sizeof("help")) == 0)              /* display menu info */
        {
            util_menu();
        }
        else if(strncmp(cmd, "quit", sizeof("quit")) == 0)              /* quit system */
        {
            return;
        }
            
    }

    return 0;
}
コード例 #9
0
ファイル: api.c プロジェクト: AgamAgarwal/minix
/*
 * api_dline --
 *	Delete a line.
 *
 * PUBLIC: int api_dline __P((SCR *, db_recno_t));
 */
int
api_dline(SCR *sp, db_recno_t lno)
{
	if (db_delete(sp, lno))
		return 1;
	/* change current line if deleted line is that one
	 * or one berfore that
	 */
	if (sp->lno >= lno && sp->lno > 1)
		sp->lno--;
	return 0;
}
コード例 #10
0
ファイル: db_recovery.c プロジェクト: IceAssassin/fastdht
static int recover_cmd_del(BinLogRecord *pRecord)
{
	int group_id;
	char full_key[FDHT_MAX_FULL_KEY_LEN];
	int full_key_len;
	char *p;  //tmp var

	CHECK_GROUP_ID(pRecord, group_id)
	FDHT_PACK_FULL_KEY(pRecord->key_info, full_key, full_key_len, p)

	return db_delete(g_db_list[group_id], full_key, full_key_len);
}
コード例 #11
0
ファイル: m_broadcast.c プロジェクト: hengzhang/NEU_MSN
void setBroadcasts(char *lbcast,char *bcasts)
{
    gchar *p;
    gchar **parray,**q;
    db_delete(broadcastList);
    appendBroadcastList(lbcast);
    q = parray = g_strsplit(bcasts,",",BROADCASTLEN);
    //将ip加入到广播列表中
    for(p = *q; p; p = *(++q))
        appendBroadcastList(p);
    g_strfreev(parray);
}
コード例 #12
0
INT32 sms_update_thread(DatabaseHandle* db_handle, INT64 thread_id)
{
    INT32 result = DB_ERROR;
    DatabaseWhereClause* clause = NULL;
    CHAR* sql_str = NULL;

    if (thread_id < 0)
    {
        return DB_ERROR;//sms_update_all_threads(db_handle);
    }

    // Delete the row for this thread in the threads table and canonical table if
    // there are no more messages attached to it in either
    // the sms or pdu tables.
    clause = db_where_clause_create("ID = ? AND ID NOT IN (SELECT DISTINCT thread_id FROM sms_tb)",1);

    db_clause_put_int(clause,0,thread_id);

    result = db_delete(db_handle,SMS_THREADS_TABLE_NAME,clause);
    if (result  == DB_OK && db_last_changes(db_handle) > 0 )
    {

        db_clause_destroy(clause);
        // If this deleted the thread id, we have no more work to do.
        return DB_OK;
    }
    db_clause_destroy(clause);


    sql_str = TG_CALLOC_V2(200);
    return_val_if_fail(sql_str, DB_NOMEM);

    //UPDATE message count
    sprintf(sql_str,"UPDATE threads_tb SET message_count =(SELECT COUNT(sms_tb.ID) FROM sms_tb  WHERE thread_id = %ld AND sms_tb.type != 3)",thread_id);
    result = db_execSQL(db_handle, sql_str);

    //update date,maybe no need the sms type in where clause
    sprintf(sql_str,"UPDATE threads_tb SET date =(SELECT date FROM sms_tb  WHERE thread_id = %ld AND sms_tb.type != 3 ORDER BY date DESC LIMIT 1;)",thread_id);
    result = db_execSQL(db_handle, sql_str);

    //update unread count
    sprintf(sql_str,"UPDATE threads_tb SET unread_count =(SELECT COUNT(sms_tb.read) FROM sms_tb  WHERE thread_id = %ld AND read =0)",thread_id);
    result = db_execSQL(db_handle, sql_str);

    //update fail count  //todo,maybe no need this feature

    //update name
    //name = _sms_query_name_from_contacts();

    TG_FREE(sql_str);
    return result;
}
コード例 #13
0
ファイル: ul_db.c プロジェクト: mattvv/kamailio
int ul_db_delete(str * table, str * first, str * second,
                 db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n) {
	ul_db_handle_t * handle;
	if(!db_write){
		LM_ERR("not allowed in read only mode, abort.\n");
		return -1;
	}
	if((handle = get_handle(&mdb.read.dbf, mdb.read.dbh, first, second))  == NULL) {
		LM_ERR("could not retrieve db handle.\n");
		return -1;
	}
	return db_delete(handle, table, _k, _o, _v, _n);
}
コード例 #14
0
ファイル: apteryxd.c プロジェクト: jmcollis/apteryx
static void
apteryx__prune (Apteryx__Server_Service *service,
                const Apteryx__Prune *prune,
                Apteryx__OKResult_Closure closure, void *closure_data)
{
    Apteryx__OKResult result = APTERYX__OKRESULT__INIT;
    result.result = 0;
    GList *paths = NULL, *iter;
    (void) service;

    /* Check parameters */
    if (prune == NULL || prune->path == NULL)
    {
        ERROR ("PRUNE: Invalid parameters.\n");
        result.result = -EINVAL;
        closure (&result, closure_data);
        INC_COUNTER (counters.prune_invalid);
        return;
    }
    INC_COUNTER (counters.prune);

    DEBUG ("PRUNE: %s\n", prune->path);

    /* Proxy first */
    if (proxy_prune (prune->path))
    {
        /* Return result */
        closure (&result, closure_data);
        return;
    }

    /* Collect the list of deleted paths for notification */
    paths = g_list_prepend(paths, g_strdup(prune->path));
    _search_paths (&paths, prune->path);

    /* Prune from database */
    db_delete (prune->path, UINT64_MAX);

    /* Return result */
    closure (&result, closure_data);

    /* Call watchers for each pruned path */
    for (iter = paths; iter; iter = g_list_next (iter))
    {
        notify_watchers ((const char *)iter->data);
    }

    g_list_free_full (paths, g_free);
    return;
}
コード例 #15
0
int db_delete_urecord(urecord_t* _r)
{
	char b[256];
	db_key_t keys[2];
	db_val_t vals[2];
	char* dom;

	keys[0] = user_col;
	keys[1] = domain_col;
	vals[0].type = DB_STR;
	vals[0].nul = 0;
	vals[0].val.str_val.s = _r->aor.s;
	vals[0].val.str_val.len = _r->aor.len;

	if (use_domain) {
		dom = q_memchr(_r->aor.s, '@', _r->aor.len);
		if (!dom) {
			LOG(L_ERR, "db_delete_urecord(): You forgot to set modparam(\"registrar\", \"use_domain\", 1) in ser.cfg!\n");
			vals[0].val.str_val.len = _r->aor.len;
			
			vals[1].type = DB_STR;
			vals[1].nul = 0;
			vals[1].val.str_val.s = _r->aor.s;
			vals[1].val.str_val.len = 0;
		} else {
			vals[0].val.str_val.len = dom - _r->aor.s;
			
			vals[1].type = DB_STR;
			vals[1].nul = 0;
			vals[1].val.str_val.s = dom + 1;
			vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
		}
	}

	     /* FIXME */
	memcpy(b, _r->domain->s, _r->domain->len);
	b[_r->domain->len] = '\0';
	db_use_table(db, b);

	if (db_delete(db, keys, 0, vals, (use_domain) ? (2) : (1)) < 0) {
		LOG(L_ERR, "db_delete_urecord(): Error while deleting from database\n");
		return -1;
	}

	return 0;
}
コード例 #16
0
/* delete from database the entiry record for a given user - if a user has no
 * script, he will be removed complitly from db; users without script are not
 * allowed into db ;-)
 * Returns:  1 - success
 *          -1 - error
 */
int rmv_from_db(db_con_t *db_con, char *usr)
{
	db_key_t   keys[] = {"user"};
	db_val_t   vals[1];

	/* username */
	vals[0].type = DB_STRING;
	vals[0].nul  = 0;
	vals[0].val.string_val = usr;

	if (db_delete(db_con, keys, NULL, vals, 1) < 0) {
		LOG(L_ERR,"ERROR:cpl-c:rmv_from_db: error when deleting script for "
			"user \"%s\"\n",usr);
		return -1;
	}

	return 1;
}
コード例 #17
0
ファイル: server.c プロジェクト: vitalik296/CoursesRepo
void server_answer(http_request_t req, socket_t * clientSocket,db_t * db)
{
    if(!strncmp(req.uri,"/db/editw/",10))
    {
            edit_row(req,clientSocket, db);
    }
    else
    if(!strncmp(req.uri,"/db/edit/",9))
    {
        edit(req,clientSocket, db);
    }
    else
    if(strpbrk(req.uri,"0123456789"))
    {
        if(!strcmp(req.method,"GET"))
        get_row(req,clientSocket, db);
        else
        if(!strcmp(req.method,"DELETE"))
        db_delete(req,db);
    }
    else
    if(!strncmp(req.uri,"/db/paste/",10))
    {
        if(!strcmp(req.method,"GET"))
        post_new_row_get(req,clientSocket);
        else
            if(!strcmp(req.method,"POST"))
            post_new_row_post(req,clientSocket,db);
    }
    else
    if (!strcmp(req.uri, "/db"))
        {
            start_page(clientSocket,db);
        }
    else
        if(!strncmp(req.uri,"/db/",4))
    {
        get_bd(req,clientSocket,db);
    }

}
コード例 #18
0
/*
 * Delete contact from the database
 */
int db_delete_ucontact(ucontact_t* _c)
{
	char b[256];
	char* dom;
	db_key_t keys[3];
	db_val_t vals[3];

	keys[0] = user_col;
	keys[1] = contact_col;
	keys[2] = domain_col;

	vals[0].type = DB_STR;
	vals[0].nul = 0;
	vals[0].val.str_val = *_c->aor;

	vals[1].type = DB_STR;
	vals[1].nul = 0;
	vals[1].val.str_val = _c->c;

	if (use_domain) {
		dom = q_memchr(_c->aor->s, '@', _c->aor->len);
		vals[0].val.str_val.len = dom - _c->aor->s;

		vals[2].type = DB_STR;
		vals[2].nul = 0;
		vals[2].val.str_val.s = dom + 1;
		vals[2].val.str_val.len = _c->aor->s + _c->aor->len - dom - 1;
	}

	     /* FIXME */
	memcpy(b, _c->domain->s, _c->domain->len);
	b[_c->domain->len] = '\0';
	db_use_table(db, b);

	if (db_delete(db, keys, 0, vals, (use_domain) ? (3) : (2)) < 0) {
		LOG(L_ERR, "db_del_ucontact(): Error while deleting from database\n");
		return -1;
	}

	return 0;
}
コード例 #19
0
ファイル: color.c プロジェクト: kanzure/brlcad
/**
 * Used to release database resources occupied by a material record.
 */
void
color_zaprec(struct ged *gedp, struct mater *mp)
{
    struct directory dir;

    /* we get here only if database is NOT read-only */
    if (mp->mt_daddr == MATER_NO_ADDR)
	return;

    dir.d_magic = RT_DIR_MAGIC;
    RT_DIR_SET_NAMEP(&dir, "color_zaprec");
    dir.d_len = 1;
    dir.d_addr = mp->mt_daddr;
    dir.d_flags = 0;

    if (db_delete(gedp->ged_wdbp->dbip, &dir) != 0) {
	bu_vls_printf(gedp->ged_result_str, "Database delete error, aborting");
	return;
    }
    mp->mt_daddr = MATER_NO_ADDR;
}
コード例 #20
0
int process_del_list(str* _d)
{
	struct del_itm* p;
	char b[256];
	db_key_t keys[2];
	db_val_t vals[2];

	keys[0] = user_col;
	keys[1] = contact_col;
	
	if (del_root) {
	     /* FIXME */
		memcpy(b, _d->s, _d->len);
		b[_d->len] = '\0';
		db_use_table(db, b);
	
		VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
		VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
	}

	while(del_root) {
		p = del_root;
		del_root = del_root->next;

		VAL_STR(vals).len = p->user_len;
		VAL_STR(vals).s = p->tail;
		
		VAL_STR(vals + 1).len = p->cont_len;
		VAL_STR(vals + 1).s = p->tail + p->user_len;

		if (db_delete(db, keys, 0, vals, 2) < 0) {
			LOG(L_ERR, "process_del_list(): Error while deleting from database\n");
			return -1;
		}

		pkg_free(p);
	}

	return 0;
}
コード例 #21
0
ファイル: server.c プロジェクト: vitalik296/CoursesRepo
void server_DELETE_id(http_request_t req,socket_t * clientSocket,list_t* list,db_t* self)
{
    char buf[1000]="";
    int id;

    if(strpbrk(req.uri,"-0123456789"))
    {
        id=atoi(strpbrk(req.uri,"-0123456789"));
        Freelanser_free(list_pop_index(list,id));
        db_delete(req,self);
    }
    else
    {
        socket_write_string(clientSocket,"<body>Wrong id<br>"
                            "<a href=\"/Freelancer/\">To Freelancers</a></body>");
        return;
    }



    socket_write_string(clientSocket, "<body>Delete success<br>"
                        "<a href=\"/Freelancer/\">To Freelancers</a></body>");
}
コード例 #22
0
ファイル: test001.c プロジェクト: rryqszq4/lainDB
int main(int argc, char* argv[]){
	DBHANDLE	db;
	char *tmp_val;

	if ((db = db_open("data/db1", O_RDWR | O_CREAT | O_TRUNC, FILE_MODE)) == NULL)
		err_sys("db_open error");

	//printf("%p\n", db);
	
	if (db_store(db, "key_1", "value_1", DB_INSERT) != 0)
		err_quit("db_store error for key_1");
	
	if (db_store(db, "key_2", "value_2", DB_INSERT) != 0)
		err_quit("db_store error for key_2");
	if (db_store(db, "key_3", "value_3", DB_INSERT) != 0)
		err_quit("db_store error for key_3");

	tmp_val = db_fetch(db,"key_1");
	
	printf("%s\n",tmp_val);
	
	if (db_delete(db, "key_1") != 0){
		err_quit("db_delete error");
	}

	if (db_store(db, "key_2", "value_2_2", DB_REPLACE) != 0)
		err_quit("db_store error for key_1");

	tmp_val = db_fetch(db,"key_2");
	
	printf("%s\n",tmp_val);
	
	db_close(db);

	exit(0);
}
コード例 #23
0
HIDDEN void
killtree_callback(struct db_i *dbip, struct directory *dp, void *ptr)
{
    struct killtree_data *gktdp = (struct killtree_data *)ptr;
    int ref_exists = 0;

    if (dbip == DBI_NULL)
	return;

    /* don't bother checking for references if the -f or -a flags are
     * presented to force a full kill and all references respectively.
     */
    if (!gktdp->force && !gktdp->killrefs)
	ref_exists = find_reference(dbip, gktdp->top, dp->d_namep);

    /* if a reference exists outside of the subtree we're killing, we
     * don't kill this object or it'll create invalid reference
     * elsewhere in the database.  do nothing.
     */
    if (ref_exists)
	return;

    if (gktdp->print) {
	if (!gktdp->killrefs)
	    bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep);
	else {
	    if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) {
		gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av");
		gktdp->av_capacity += AV_STEP;
	    }
	    gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep);
	    gktdp->av[gktdp->ac] = (char *)0;

	    bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep);
	}
    } else {
	_dl_eraseAllNamesFromDisplay(gktdp->gedp->ged_gdp->gd_headDisplay, gktdp->gedp->ged_wdbp->dbip, gktdp->gedp->ged_free_vlist_callback, dp->d_namep, 0, gktdp->gedp->freesolid);

	bu_vls_printf(gktdp->gedp->ged_result_str, "KILL %s:  %s\n",
		      (dp->d_flags & RT_DIR_COMB) ? "COMB" : "Solid",
		      dp->d_namep);

	if (!gktdp->killrefs) {
	    if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) {
		bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep);
	    }
	} else {
	    if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) {
		gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av");
		gktdp->av_capacity += AV_STEP;
	    }
	    gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep);
	    gktdp->av[gktdp->ac] = (char *)0;

	    if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) {
		bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep);

		/* Remove from list */
		bu_free((void *)gktdp->av[--gktdp->ac], "killtree_callback");
		gktdp->av[gktdp->ac] = (char *)0;
	    }
	}
    }
}
コード例 #24
0
ファイル: db_input.c プロジェクト: juanfra684/DragonFlyBSD
/* returns TRUE at end-of-line */
int
db_inputchar(int c)
{
    static int escstate;

    if (escstate == 1) {
        /* ESC seen, look for [ or O */
        if (c == '[' || c == 'O')
            escstate++;
        else
            escstate = 0; /* re-init state machine */
        return (0);
    } else if (escstate == 2) {
        escstate = 0;
        /*
         * If a valid cursor key has been found, translate
         * into an emacs-style control key, and fall through.
         * Otherwise, drop off.
         */
        switch (c) {
        case 'A':	/* up */
            c = CTRL('p');
            break;
        case 'B':	/* down */
            c = CTRL('n');
            break;
        case 'C':	/* right */
            c = CTRL('f');
            break;
        case 'D':	/* left */
            c = CTRL('b');
            break;
        default:
            return (0);
        }
    }

    switch (c) {
    case CTRL('['):
        escstate = 1;
        break;
    case CTRL('b'):
        /* back up one character */
        if (db_lc > db_lbuf_start) {
            cnputc(BACKUP);
            db_lc--;
        }
        break;
    case CTRL('f'):
        /* forward one character */
        if (db_lc < db_le) {
            cnputc(*db_lc);
            db_lc++;
        }
        break;
    case CTRL('a'):
        /* beginning of line */
        while (db_lc > db_lbuf_start) {
            cnputc(BACKUP);
            db_lc--;
        }
        break;
    case CTRL('e'):
        /* end of line */
        while (db_lc < db_le) {
            cnputc(*db_lc);
            db_lc++;
        }
        break;
    case CTRL('h'):
    case 0177:
        /* erase previous character */
        if (db_lc > db_lbuf_start)
            db_delete(1, DEL_BWD);
        break;
    case CTRL('d'):
        /* erase next character */
        if (db_lc < db_le)
            db_delete(1, DEL_FWD);
        break;
    case CTRL('u'):
        /* kill entire line: */
        /* at first, delete to beginning of line */
        if (db_lc > db_lbuf_start)
            db_delete(db_lc - db_lbuf_start, DEL_BWD);
    /* FALLTHROUGH */
    case CTRL('k'):
        /* delete to end of line */
        if (db_lc < db_le)
            db_delete(db_le - db_lc, DEL_FWD);
        break;
    case CTRL('t'):
        /* twiddle last 2 characters */
        if (db_lc >= db_lbuf_start + 2) {
            c = db_lc[-2];
            db_lc[-2] = db_lc[-1];
            db_lc[-1] = c;
            cnputc(BACKUP);
            cnputc(BACKUP);
            cnputc(db_lc[-2]);
            cnputc(db_lc[-1]);
        }
        break;
    case CTRL('r'):
        db_putstring("^R\n", 3);
redraw:
        if (db_le > db_lbuf_start) {
            db_putstring(db_lbuf_start, db_le - db_lbuf_start);
            db_putnchars(BACKUP, db_le - db_lc);
        }
        break;
    case CTRL('p'):
        /* Make previous history line the active one. */
        if (db_lhistcur >= 0) {
            bcopy(db_lhistory + db_lhistcur * db_lhistlsize,
                  db_lbuf_start, db_lhistlsize);
            db_lhistcur--;
            goto hist_redraw;
        }
        break;
    case CTRL('n'):
        /* Make next history line the active one. */
        if (db_lhistcur < db_lhistidx - 1) {
            db_lhistcur += 2;
            bcopy(db_lhistory + db_lhistcur * db_lhistlsize,
                  db_lbuf_start, db_lhistlsize);
        } else {
            /*
             * ^N through tail of history, reset the
             * buffer to zero length.
             */
            *db_lbuf_start = '\0';
            db_lhistcur = db_lhistidx;
        }

hist_redraw:
        db_putnchars(BACKUP, db_le - db_lbuf_start);
        db_putnchars(BLANK, db_le - db_lbuf_start);
        db_putnchars(BACKUP, db_le - db_lbuf_start);
        db_le = index(db_lbuf_start, '\0');
        if (db_le[-1] == '\r' || db_le[-1] == '\n')
            *--db_le = '\0';
        db_lc = db_le;
        goto redraw;

    case -1:
        /*
         * eek! the console returned eof.
         * probably that means we HAVE no console.. we should try bail
         * XXX
         */
        return (0);
    case '\n':
    case '\r':
        *db_le++ = c;
        return (1);
    default:
        if (db_le == db_lbuf_end) {
            cnputc('\007');
        }
        else if (c >= ' ' && c <= '~') {
            char *p;

            for (p = db_le; p > db_lc; p--)
                *p = *(p-1);
            *db_lc++ = c;
            db_le++;
            cnputc(c);
            db_putstring(db_lc, db_le - db_lc);
            db_putnchars(BACKUP, db_le - db_lc);
        }
        break;
    }
    return (0);
}
コード例 #25
0
ファイル: delete.c プロジェクト: Alkzndr/freebsd
/*
 * del --
 *	Delete a range of text.
 *
 * PUBLIC: int del __P((SCR *, MARK *, MARK *, int));
 */
int
del(
	SCR *sp,
	MARK *fm,
	MARK *tm,
	int lmode)
{
	recno_t lno;
	size_t blen, len, nlen, tlen;
	CHAR_T *bp, *p;
	int eof, rval;

	bp = NULL;

	/* Case 1 -- delete in line mode. */
	if (lmode) {
		for (lno = tm->lno; lno >= fm->lno; --lno) {
			if (db_delete(sp, lno))
				return (1);
			++sp->rptlines[L_DELETED];
			if (lno % INTERRUPT_CHECK == 0 && INTERRUPTED(sp))
				break;
		}
		goto done;
	}

	/*
	 * Case 2 -- delete to EOF.  This is a special case because it's
	 * easier to pick it off than try and find it in the other cases.
 	 */
	if (db_last(sp, &lno))
		return (1);
	if (tm->lno >= lno) {
		if (tm->lno == lno) {
			if (db_get(sp, lno, DBG_FATAL, &p, &len))
				return (1);
			eof = tm->cno != ENTIRE_LINE && tm->cno >= len ? 1 : 0;
		} else
			eof = 1;
		if (eof) {
			for (lno = tm->lno; lno > fm->lno; --lno) {
				if (db_delete(sp, lno))
					return (1);
				++sp->rptlines[L_DELETED];
				if (lno %
				    INTERRUPT_CHECK == 0 && INTERRUPTED(sp))
					break;
			}
			if (db_get(sp, fm->lno, DBG_FATAL, &p, &len))
				return (1);
			GET_SPACE_RETW(sp, bp, blen, fm->cno);
			MEMCPY(bp, p, fm->cno);
			if (db_set(sp, fm->lno, bp, fm->cno))
				return (1);
			goto done;
		}
	}

	/* Case 3 -- delete within a single line. */
	if (tm->lno == fm->lno) {
		if (db_get(sp, fm->lno, DBG_FATAL, &p, &len))
			return (1);
		GET_SPACE_RETW(sp, bp, blen, len);
		if (fm->cno != 0)
			MEMCPY(bp, p, fm->cno);
		MEMCPY(bp + fm->cno, p + (tm->cno + 1), 
			len - (tm->cno + 1));
		if (db_set(sp, fm->lno,
		    bp, len - ((tm->cno - fm->cno) + 1)))
			goto err;
		goto done;
	}

	/*
	 * Case 4 -- delete over multiple lines.
	 *
	 * Copy the start partial line into place.
	 */
	if ((tlen = fm->cno) != 0) {
		if (db_get(sp, fm->lno, DBG_FATAL, &p, NULL))
			return (1);
		GET_SPACE_RETW(sp, bp, blen, tlen + 256);
		MEMCPY(bp, p, tlen);
	}

	/* Copy the end partial line into place. */
	if (db_get(sp, tm->lno, DBG_FATAL, &p, &len))
		goto err;
	if (len != 0 && tm->cno != len - 1) {
		/*
		 * XXX
		 * We can overflow memory here, if the total length is greater
		 * than SIZE_T_MAX.  The only portable way I've found to test
		 * is depending on the overflow being less than the value.
		 */
		nlen = (len - (tm->cno + 1)) + tlen;
		if (tlen > nlen) {
			msgq(sp, M_ERR, "002|Line length overflow");
			goto err;
		}
		if (tlen == 0) {
			GET_SPACE_RETW(sp, bp, blen, nlen);
		} else
			ADD_SPACE_RETW(sp, bp, blen, nlen);

		MEMCPY(bp + tlen, p + (tm->cno + 1), len - (tm->cno + 1));
		tlen += len - (tm->cno + 1);
	}

	/* Set the current line. */
	if (db_set(sp, fm->lno, bp, tlen))
		goto err;

	/* Delete the last and intermediate lines. */
	for (lno = tm->lno; lno > fm->lno; --lno) {
		if (db_delete(sp, lno))
			goto err;
		++sp->rptlines[L_DELETED];
		if (lno % INTERRUPT_CHECK == 0 && INTERRUPTED(sp))
			break;
	}

done:	rval = 0;
	if (0)
err:		rval = 1;
	if (bp != NULL)
		FREE_SPACEW(sp, bp, blen);
	return (rval);
}
コード例 #26
0
ファイル: t00049.c プロジェクト: alandohf/poonzref
int main(int argc, char* argv[]) 
{ 
    sqlite3 * db; 
    int i; 
    COLUMN column[10]; 
    pTable_name = table_name; 
    strcpy(pTable_name, "test_table"); 
 
    ret = sqlite3_open("student.db", &db); 
    if(ret != SQLITE_OK) 
    { 
        perror("slqite3_open"); 
        exit(1); 
    } 
 
    while(choice != 0) 
    { 
	printf("please input your choise:\n"); 
	printf("-------------------------------------\n"); 
	printf("|0.exit|1.create|2.show|3.insert|4.update|5.delete|6.empty|7.drop|\n"); 
	printf("-------------------------------------\n"); 
        scanf("%d", &choice); 
        
        switch(choice) 
        { 
            case 0: 
	printf("you choise leave, y or n?\n"); 
                    setbuf(stdin, NULL); 
                    scanf("%c", &c); 
                    setbuf(stdin, NULL); 
                    if(c == 'y') 
                    { 
                        if(test_flag == 0) 
                        { 
	db_drop(db, "test_table", &test_flag, &create_flag); 
                        } 
                        
                        printf("goodbye!\n"); 
 
                        sqlite3_close(db); 
 
                        return 0; 
                    } 
                    else 
                    { 
                        choice = -1; 
                    } 
 
                    break; 
                    
            case 1: 
		printf("we will create a table for you, please input the name of your table:\n"); 
		scanf("%s",pTable_name); 
		printf("please input the number of column:\n"); 
		scanf("%d", &column_num); 
		printf("please input column_name column_type:\n"); 
 
		for(i = 0; i < column_num; i++)
		  scanf("%s %s", column[i].column_name, column[i].column_type);                        
		 
		db_create(db, table_name, column_num, column, &create_flag); 
				    break; 
            case 2: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_show(db, table_name); 
				    break; 
                   
            case 3: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_insert(db, table_name, column_num, column, &test_flag, &create_flag); 
				    break; 
            case 4: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_update(db, table_name, column_num, column, &test_flag, &create_flag); 
				    break; 
            case 5: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_delete(db, table_name); 
                    break; 
            case 6: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_empty(db, table_name); 
                    break; 
            case 7: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_drop(db, table_name, &test_flag, &create_flag); 
                    break; 
            default: 
                    printf("your choice is not exist!\n"); 
                    break; 
    
        } 
        
    } 
 
	sqlite3_close(db); 
    return 0; 
} 
コード例 #27
0
ファイル: ex_move.c プロジェクト: ajinkya93/OpenBSD
/*
 * ex_move -- :[line [,line]] mo[ve] line
 *	Move selected lines.
 *
 * PUBLIC: int ex_move(SCR *, EXCMD *);
 */
int
ex_move(SCR *sp, EXCMD *cmdp)
{
	LMARK *lmp;
	MARK fm1, fm2;
	recno_t cnt, diff, fl, tl, mfl, mtl;
	size_t blen, len;
	int mark_reset;
	char *bp, *p;

	NEEDFILE(sp, cmdp);

	/*
	 * It's not possible to move things into the area that's being
	 * moved.
	 */
	fm1 = cmdp->addr1;
	fm2 = cmdp->addr2;
	if (cmdp->lineno >= fm1.lno && cmdp->lineno <= fm2.lno) {
		msgq(sp, M_ERR, "Destination line is inside move range");
		return (1);
	}

	/*
	 * Log the positions of any marks in the to-be-deleted lines.  This
	 * has to work with the logging code.  What happens is that we log
	 * the old mark positions, make the changes, then log the new mark
	 * positions.  Then the marks end up in the right positions no matter
	 * which way the log is traversed.
	 *
	 * XXX
	 * Reset the MARK_USERSET flag so that the log can undo the mark.
	 * This isn't very clean, and should probably be fixed.
	 */
	fl = fm1.lno;
	tl = cmdp->lineno;

	/* Log the old positions of the marks. */
	mark_reset = 0;
	LIST_FOREACH(lmp, &sp->ep->marks, q)
		if (lmp->name != ABSMARK1 &&
		    lmp->lno >= fl && lmp->lno <= tl) {
			mark_reset = 1;
			F_CLR(lmp, MARK_USERSET);
			(void)log_mark(sp, lmp);
		}

	/* Get memory for the copy. */
	GET_SPACE_RET(sp, bp, blen, 256);

	/* Move the lines. */
	diff = (fm2.lno - fm1.lno) + 1;
	if (tl > fl) {				/* Destination > source. */
		mfl = tl - diff;
		mtl = tl;
		for (cnt = diff; cnt--;) {
			if (db_get(sp, fl, DBG_FATAL, &p, &len))
				return (1);
			BINC_RET(sp, bp, blen, len);
			memcpy(bp, p, len);
			if (db_append(sp, 1, tl, bp, len))
				return (1);
			if (mark_reset)
				LIST_FOREACH(lmp, &sp->ep->marks, q)
					if (lmp->name != ABSMARK1 &&
					    lmp->lno == fl)
						lmp->lno = tl + 1;
			if (db_delete(sp, fl))
				return (1);
		}
	} else {				/* Destination < source. */
コード例 #28
0
ファイル: main.cpp プロジェクト: Bediko/DBS2
int main(int argc,const char *argv[]){
  ifstream file;
  string arg;
  //if(!test())
    //exit(0);
  if(argc==1){
    printf("Usage:\n");
    printf("\t\tdbimp  [options] <infile>\n");
    printf("Options\n");
    printf("\t\t-del delete table contents before import\n");
    printf("\t\t-u  database user\n");
    printf("\t\t-p  password\n");
    printf("\t\t-h  database host\n");
    printf("\t\t-d  database name\n");
    exit(1);
  }


  for(int i=1;i<argc-1;i+=2){
    arg=argv[i];
    if(arg.compare("-del")==0){
      deletedb=true;
      i--;
    }
    else if(arg.compare("-u")==0){
      user=argv[i+1];
    }
    else if(arg.compare("-p")==0){
      password=argv[i+1];
    }
    else if(arg.compare("-h")==0){
      host=argv[i+1];
    }
    else if(arg.compare("-d")==0){
      dbname=argv[i+1];
    }
    else{
        printf("Usage:\n");
        printf("\t\tdbimp  [options] <infile>\n");
        printf("Options\n");
        printf("\t\t-del delete table contents before import\n");
        printf("\t\t-u  database user\n");
        printf("\t\t-p  password\n");
        printf("\t\t-h  database host\n");
        printf("\t\t-d  database name\n");
        exit(1);
    }
  }
  arg=argv[argc-1];
  file.open(arg.c_str(), ifstream::in);
  if(!file){
    printf("Usage:\n");
    printf("\t\tdbimp  [options] <infile>\n");
    printf("Options\n");
    printf("\t\t-del delete table contents before import\n");
    printf("\t\t-u  database user\n");
    printf("\t\t-p  password\n");
    printf("\t\t-h  database host\n");
    printf("\t\t-d  database name\n");
    exit(1);
  }
  db_login(user,password,host,dbname);
  string vorname,nachname,geburt,mtnr,line,token;
  vector <string> tupel;
  int count=0,imported=0;


  while(getline(file,line)){
    tupel.clear();
    while (line.find(";", 0) != string::npos)
      { 
        size_t  pos = line.find(";", 0); //store the position of the delimiter
        token = line.substr(0, pos);          //get the token
        line.erase(0, pos + 1);                 //erase it from the source 
        tupel.push_back(token);                //and put it into the array
      }

      tupel.push_back(line);           //the last token is all alone 
    
    if(tupel[0].compare("")==0||tupel[1].compare("")==0||tupel[2].compare("")==0||tupel[3].compare("")==0){
      printf("Import Data incorrect, no undefined fields allowed\n");
      exit(1);
      
    }
    count++;
    if(deletedb){
      db_delete();
      deletedb=false;
    }
    if(db_insert(tupel[3],tupel[0],tupel[1],tupel[2])==0){
      imported++;
    }
  }
  printf("Data read: %i\nData imported:%i\n",count,imported);
}
コード例 #29
0
ファイル: pdt.c プロジェクト: miettal/armadillo420_standard
/*
 
	Fifo command example:
 
	":get_domaincode:[response_file]\n
	 domain_name\n
	 authorization_to_register_domains\n
	 \n
 	"
 
 */
int get_domainprefix(FILE *stream, char *response_file)
{
	db_key_t db_keys[NR_KEYS];
	db_val_t db_vals[NR_KEYS];
	db_op_t  db_ops[NR_KEYS] = {OP_EQ, OP_EQ};

	code_t code;
	dc_t* cell; 
	
	char domain_name[256];
	str sdomain;

	char authorization[10];
	str sauth;
	int authorized=0;
		
	/* read a line -the domain name parameter- from the fifo */
	sdomain.s = domain_name;
	if(!read_line(sdomain.s, 255, stream, &sdomain.len) || sdomain.len==0)	
	{
		LOG(L_ERR, "PDT: get_domaincode: could not read from fifo\n");
		fifo_reply(response_file, "400 |get_domaincode: could not " 
						"read from fifo\n");
		return 1;
	}
	domain_name[sdomain.len] = '\0';

	/* read a line -the authorization to register new domains- from the fifo */
	sauth.s = authorization;
	if(!read_line(sauth.s, 3, stream, &sauth.len) || sauth.len==0)
	{	
		LOG(L_ERR, "PDT: get_domaincode: could not read from fifo\n");
		fifo_reply(response_file, "400 |get_domaincode: could not "
						"read from fifo\n");
		return 1;
	}

	/* see what kind of user we have */
	authorized = sauth.s[0]-'0';

	lock_get(&l);

	/* search the domain in the hashtable */
	cell = get_code_from_hash(hash->dhash, hash->hash_size, domain_name);
	
	/* the domain is registered */
	if(cell)
	{

		lock_release(&l);
			
		/* domain already in the database */	
		fifo_reply(response_file, "201 |Domain name= %.*s"
				"Domain code= %d%d\n",
				sdomain.len, sdomain.s, cell->code, code_terminator);
		return 0;
		
	}
	
	/* domain not registered yet */
	/* user not authorized to register new domains */	
	if(!authorized)
	{
		lock_release(&l);
		fifo_reply(response_file, "203 |Domain name not registered yet\n");
		return 0;
	}

	code = *next_code;
	*next_code = apply_correction(code+1);
		

	/* prepare for insertion into database */
	db_keys[0] = DB_KEY_CODE;
	db_keys[1] = DB_KEY_NAME;

	db_vals[0].type = DB_INT;
	db_vals[0].nul = 0;
	db_vals[0].val.int_val = code;

	db_vals[1].type = DB_STR;
	db_vals[1].nul = 0;
	db_vals[1].val.str_val.s = sdomain.s;
	db_vals[1].val.str_val.len = sdomain.len;
	DBG("%d %.*s\n", code, sdomain.len, sdomain.s);
			
	/* insert a new domain into database */
	if(db_insert(db_con, db_keys, db_vals, NR_KEYS)<0)
	{
		/* next available code is still code */
		*next_code = code;
		lock_release(&l);
		LOG(L_ERR, "PDT: get_domaincode: error storing a"
				" new domain\n");
		fifo_reply(response_file, "204 |Cannot register the new domain in a"
					" consistent way\n");
		return -1;
	}
	
	/* insert the new domain into hashtables, too */
	cell = new_cell(sdomain.s, code);
	if(add_to_double_hash(hash, cell)<0)
		goto error;		

	lock_release(&l);

	/* user authorized to register new domains */
	fifo_reply(response_file, "202 |Domain name= %.*s"
		"	New domain code=  %d%d\n",
		sdomain.len, sdomain.s, code, code_terminator);

	return 0;

	
error:
	/* next available code is still code */
	*next_code = code;
	/* delete from database */
	if(db_delete(db_con, db_keys, db_ops, db_vals, NR_KEYS)<0)
		LOG(L_ERR,"PDT: get_domaincode: database/share-memory are inconsistent\n");
	lock_release(&l);
	
	return -1;
}
コード例 #30
0
ファイル: aglib.c プロジェクト: gitpan/DB-Appgen
int		ag_db_delete(unsigned dbh)
{ return db_delete(h2p(dbh));
}