コード例 #1
0
void Database::dbDelete(bean_key key, C& bean)
{
	try{
		dbExecQuery(key.con,"ROLLBACK TRANSACTION;");
	}catch(...){}
	dbExecQuery(key.con,"BEGIN TRANSACTION;");

		ChildKiller ck;
		ck.killChildren(key,bean);
		dbDeleteRows(key.con, Database::getClassName<C>(), HIBERLITE_PRIMARY_KEY_COLUMN, key.id);

	dbExecQuery(key.con,"COMMIT TRANSACTION;");
}
コード例 #2
0
void Database::dbUpdate(bean_key key, C& bean)
{
	try{
		dbExecQuery(key.con,"ROLLBACK TRANSACTION;");
	}catch(...){}
	dbExecQuery(key.con,"BEGIN TRANSACTION;");

		ChildKiller ck;
		ck.killChildren(key,bean);
		BeanUpdater u;
		u.update(key, bean);

	dbExecQuery(key.con,"COMMIT TRANSACTION;");
}
コード例 #3
0
ファイル: Database.cpp プロジェクト: phambryan/hiberlite
void Database::dropModel()
{
	if(!mx)
		throw std::logic_error("register bean classes first");
	Model mdl=mx->getModel();
	for(Model::iterator it=mdl.begin();it!=mdl.end();it++){
		Table& t=it->second;
		std::string query="DROP TABLE IF EXISTS "+t.name+";";
		dbExecQuery(query);
	}
}
コード例 #4
0
ファイル: Database.cpp プロジェクト: berinhardt/hiberlite
void Database::createModel()
{
	if(!mx)
		throw std::logic_error("register bean classes first");
	Model mdl=mx->getModel();
	for(Model::iterator it=mdl.begin();it!=mdl.end();it++){
		Table& t=it->second;
		std::string query="CREATE TABLE IF NOT EXISTS "+t.name+" (";
		bool needComma=false;
		for(std::map<std::string,Column>::iterator c=t.columns.begin();c!=t.columns.end();c++){
			if(needComma)
				query+=", ";
			needComma=true;
			Column& col=c->second;
			query += col.name + " " + col.storage_type;
			if(col.name==HIBERLITE_PRIMARY_KEY_COLUMN)
				query+=" PRIMARY KEY AUTOINCREMENT";
			
		}
		query +=");";
		HIBERLITE_HL_DBG_DO(std::cout << "query " << query << std::endl;)
		dbExecQuery(query);
	}
コード例 #5
0
void Database::dbDeleteRows(shared_connection con, std::string table, std::string column, C value )
{
	std::string query="DELETE FROM "+table
					+ " WHERE "+column+"="+Transformer::toSQLiteValue(value)+";";
	dbExecQuery(con,query);
}