⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbobject.c

📁 bonddb 是一个源于PostgreSQL封装包的对象。它是一个由C/C++编写的快速数据提取层应用软件
💻 C
📖 第 1 页 / 共 2 页
字号:
	obj->mapobject = NULL;	obj->field = NULL;	obj->birth = NULL;	obj->cache = NULL;	obj->currentcache = NULL;	obj->id = NULL;	obj->numcache = 0;	/* Just to keep the proper authorities happy */	db_bureaucrat_add(obj);	return obj;	}/** * db_obj_free: * * Lets do some cleanup. always a good idea you know. * * Returns: non-zero on failure */gintdb_obj_free(Object * obj)	{	if (obj == NULL)		return 1;	db_obj_clear(obj);	if (db_bureaucrat_deleteinstance_byobject(obj) != 0)		{		errormsg("You are attempting a double free here. Instance id %d. I have to abort.", obj->objectinstance);		g_assert(NULL);		return -1;		}	/* to see if everything is ok with the object */#ifdef _SELFTEST	db_obj_test(obj);#endif	/* Clean up record */	if (obj->res != NULL)		{		if (obj->freeresult == TRUE)			db_dbclear(obj->res);		obj->res = NULL;		}	if (obj->query != NULL)		mem_free(obj->query);	if (obj->name != NULL)		mem_free(obj->name);	db_freemapobject(obj);	memset(obj, 0, sizeof(Object));	mem_free(obj);	obj = NULL;	return 0;	}/** * db_obj_clear: * * Frees up an object nearly, As in blanks it out so that its a fresh empty object, ready to be used again. *//* blanks an object out, not freeing it but making it quivilant to a new blank record */gintdb_obj_clear(Object * obj)	{	g_assert(obj);	db_toliet_flushobject(obj);	if (obj->res != NULL)		{		if (obj->freeresult == TRUE)			db_dbclear(obj->res);		obj->res = NULL;		}	if (obj->query != NULL)		mem_free(obj->query);	if (obj->mapobject != NULL)		db_freemapobject(obj);	db_filter_freeapplied(obj);	db_birth_free(obj->birth);	db_cache_cleanup(obj);	db_field_freeall(obj);	obj->query = NULL;	obj->newrecord = TRUE;	obj->freeresult = FALSE;	obj->changed = FALSE;	obj->unknownid = TRUE;	obj->filtered = FALSE;	obj->field = NULL;	obj->row = -1;	obj->num = 0;	obj->id = NULL;	obj->numfield = 0;	obj->mapobject = NULL;	obj->cache = NULL;	obj->currentcache = NULL;	obj->birth = NULL;	return 0;	}/** * db_obj_applydefaults: * @obj: Database object to apply defaults to. * * This will apply a bunch of default and start up values to an object.  The object will be recorded * as not changed so it wont save back the changes unless you change something yourself. This is handy * if you want to create a object with a bunch of values but not save it until you really need to.  * The birth is also used to correctly allocate values for reference variables, ie make sure specific * ids are set. This function is called by db_clear_obj.   * * Returns: non-zero on error */gintdb_obj_applydefaults(Object * obj)	{	return db_default_populateobject(obj);	}/** * db_obj_handle_empty_recordset: * @obj: Database object with a empty recordset * * If you fail to load any items (ie no items in the database) this function can be used to create * a blank record  * * Returns: non-zero on failure */gintdb_obj_handle_empty_recordset(Object * obj)	{	gint retval = 0;	g_assert(obj);	if (db_isrecordset(obj) == TRUE)		{		warningmsg("Object isn't %s empty.", obj->name);		return -1;		}	obj->num = 0;	obj->newrecord = FALSE;	/* Remeber to move to postion zero when calling this function */	/* Populate it in with field names. */	/* this code is commented out so that it has a empty record set with 0 items */	retval -= db_field_populate(obj);	/* retval -= db_moveto(obj, 0);	   retval -= db_obj_applydefaults(obj); */ 	return retval;	}/** * db_obj_handle_new_recordset: * @obj: Database class object to make a new record * * Assuming your starting a record set and you want one blank item * to begin with.  Default values are added.  A db_moveto(obj,0) * is called to realign the object correctly. */gintdb_obj_handle_new_recordset(Object * obj)	{	gint retval = 0;	g_assert(obj);	if (db_isrecordset(obj) == TRUE)		{		warningmsg("Object isn't %s empty.", obj->name);		return -1;		}	obj->num = 1;	obj->newrecord = TRUE;	/* Remeber to move to postion zero when calling this function */	/* Populate it in with field names. */	retval -= db_field_populate(obj);	retval -= db_moveto(obj, 0);	retval -= db_obj_applydefaults(obj);	return retval;	}/** * db_obj_dodelete: * @obj: database object * * This function is used primarly by db_deleteobject().   * Yes i know these functions are similar, this is a lower level one supposedly.   * * Returns: non-zero on error */gintdb_obj_dodelete(Object * obj)	{	DbRecordSet *res;	gint newpos;	gchar *query, *idsql;	g_assert(obj);	if (obj->id == NULL)		return -1;	if (db_id_isnewrecord(obj->id) == FALSE)		{		/* Get me an sql statement */		idsql = db_id_createsql(obj, obj->id);		query = mem_strdup_printf("DELETE FROM %s WHERE %s", obj->name, idsql);		mem_free(idsql);		/* run that sql statement */		res = db_dbexec(globaldbconn, query);		/* Tidy up */		if (db_checkpgresult(res) != 0)			{			errormsg("error in deleting Object*");			db_dbclear(res);			mem_free(query);			return -1;			}		mem_free(query);		db_dbclear(res);		}	/* Delete item from the cache */	/*	message("DELETEING CACHE, it was %d",obj->numrow); */	db_filter_deletedrow(obj, obj->row);	db_cache_delete(obj);	/*	message("DELETEING CACHE, its now %d",obj->numrow); */	/* Move everything along and tidy up */	/* Francis: Replace back debug: line with next following if-else block if it cause any problems. If Francis's logic	   is correct, if it was indicating the last row and it was deleted, then it moves the one before. Otherwise just	   stay there. */	/* debug: newpos = obj->row - 1; */	if (obj->row == obj->num - 1)		{		newpos = obj->row - 1;		}	else		{		newpos = obj->row;		}	if (newpos < 0)		newpos = 0;	obj->num--;	if (obj->row < 0)		obj->row = 0;	if (obj->num <= 0)		{		db_obj_clear(obj);		db_obj_handle_empty_recordset(obj);		}	else		db_moveto(obj, newpos);	return 0;	}#ifdef _OBSOLETE/** * db_obj_setcacheandid: * @obj: database object * * OBSOLETE * This function will make sure, if your doing a read that a object id exists in the idindex * entry. And if your doing a write, or just created a new record etc that a cache exists and * the id's exist properly. This is an internal function that is used by api calls to make * sure things are done right in one place.  This assumes you have moved the obj->row before * calling this function.  This is important, else weird things will happen. * * Returns: non-zero on failure. */gintdb_obj_setcacheandid(Object * obj)	{	DbCache *cache;	g_assert(obj);	/* get an id for it */	obj->id = db_id_remeber(obj);	g_assert(obj->id);	if (db_id_isnewrecord(obj->id) == TRUE)		{		if (db_toliet_isincache(obj) == NULL)			{			/* Update cache to record this one exists */			cache = db_toliet_addtocache(obj);			g_assert(cache);			/* cache->id = obj->id; cache->state = OBJ_NEW; */			/* make sure the idindex record is upto date with the new record. */			db_id_updatecache(obj);			}		}	else		{		if ((cache = db_toliet_isincache(obj)) != NULL)			{			if (cache->state == OBJ_NEW)				cache->state = OBJ_READ;			}		}	return 0;	}#endifgintdb_obj_debug(Object * obj)	{	debug_output("Num rows: %d Current Row: %d Unfiltered Num %d", obj->num, obj->row, db_numrecord(obj));	db_cache_debug(obj);	return 0;	}/** * db_obj_refresh: * * Rerun any queries on @obj because we think things have changed in the backend sql * database and you need to take a fresh perspective on life. oh no i mean the data souce. */gintdb_obj_refresh(Object * obj)	{	g_assert(obj);	g_assert(obj->query);	db_toliet_flushall();	if (db_isrecordset(obj) == TRUE)		{		if (obj->freeresult == TRUE)			db_dbclear(obj->res);		obj->res = NULL;		}	/* run query */	debugmsg("%s", obj->query);	obj->res = db_dbexec(globaldbconn, obj->query);	/* check results */	if (db_checkpgresult(obj->res) != 0)		{		errormsg("error in loading object");		obj->res = NULL;		return -1;		}	/* get the number of objects */	if ((obj->num = db_dbnumrows(obj->res)) <= 0)		{		warningmsg("No records found for refresh %s", obj->query);		db_obj_clear(obj);		return -1;		}	if (db_isappend(obj) == TRUE)		obj->num++;	if (obj->row >= obj->num)		obj->row = obj->num - 1;	db_moveto(obj, obj->row);	return 0;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -