Esempio n. 1
0
SqlRow DataBase::category_select(int id)
{
    std::string query = "SELECT * FROM categories WHERE id=";

    query += IntToStdString(id);

    SqlResult r = executeSql(query);

    if ( r.empty() ) {
        return SqlRow();
    }

    return r[0];
}
Esempio n. 2
0
void DataBase::category_delete(int id)
{
    std::vector<int> categories;

    recurse_category(id, &categories);
    categories.push_back(id);

    std::vector<int>::iterator it;

    std::string cids = "(";
    for ( it = categories.begin(); it < categories.end(); it++ ) {
        if ( it != categories.begin() ) {
            cids += ",";
        }
        cids += IntToStdString(*it);
    }
    cids += ")";

    SqlResult   qr   = question_select_where("category IN " + cids);
    std::string qids = "(";

    SqlResult::iterator rit;
    for ( rit = qr.begin(); rit < qr.end(); rit++ ) {
        SqlRow q = *rit;
        if ( rit != qr.begin() ) {
            qids += ",";
        }
        qids += q["id"];
    }

    qids += ")";

    std::string
        query = "DELETE FROM categories WHERE id IN " + cids;
    executeSql( query.c_str() );

    query = "DELETE FROM answers WHERE question IN " + qids;
    executeSql( query.c_str() );

    query = "DELETE FROM questions WHERE id IN " + qids;
    executeSql( query.c_str() );
}
Esempio n. 3
0
bool SqlCommand::Execute(SqlResult& sqlResult) {
    if (m_stmt == nullptr) {
        m_sqlConnection.SetLastError("SqlResult Execute Error << stmt has not been parepared");
        return false;
    }

    const auto ret = mysql_stmt_execute(m_stmt);
    if (ret != 0) {
        AcquireErrorInfo();
        return false;
    }

    sqlResult.Reset(&m_sqlConnection, m_stmt);
    return true;
}
Esempio n. 4
0
CCSprite* WordPuzzleLayer::getImageWithIndex(CCArray* wordIdxArray, int index)
{
	CCString* idxString = (CCString*)wordIdxArray->objectAtIndex(index);
	// 태호씨 워드스키마를 DBController로 대체
	DBController* wordSchema = DBController::sharedDB();
	char buf[100];
	sprintf(buf, "WHERE words.idx=%s", idxString->m_sString.c_str());
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)    
	wordSchema->queryWithWhereStatementDBWordsSchema(buf);
	if (wordSchema->fetchDBWordsSchema()) 
#else
        wordSchema->queryWithWhereStatement(buf);
	if (wordSchema->fetch()) 
#endif
	{
		// handle data from database record
	
		SqlQuery query( *DBController::sharedDB()->getDB() );
		
		std::ostringstream strStream;
		CCString *ccStr = (CCString*)wordIdxArray->objectAtIndex(index);
		strStream << "SELECT soundName,imageName FROM words WHERE words.idx=" <<  ccStr->toStdString();
		SqlResult r = query( strStream.str() );
		
		if (r.empty()) 
			return NULL;
		
		
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)
		soundPath = "sound/voice/" + r.fetch();
#else
		soundPath = "voice/" + r.fetch();
#endif
		
		
		string imageName = r.fetch();
		
		//프레임 애니메이션 생성 코드
		CCAnimation *ani = CCAnimation::animation();
		char buf[200];
		int count = 0;
		
		// picturecard/ani/a/abacus_ca_img00.png 형식으로 넘어온다. 뒤에 6글자 잘라서 번호 다시 붙여사용
		// 이미지가 존재할 경우에만 화면에 추가
		if ( imageName.length() != 0 && imageName != " ")
		{
			// DB에는 파일명만저장, 경로 붙여줄것
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)
			imageName = __CONFIG_IMAGE_PATH_ANIMATION_ "350/" + imageName.substr(0,1) +"/" + imageName;
#else
			imageName = "ani/350/" + imageName.substr(0,1) +"/" + imageName;
#endif
			imageName = imageName.substr(0, imageName.length()-6);
		}
		
		while (1) 
		{
			sprintf(buf,"%s%02d.png",imageName.c_str(),count);
			// 첫프레임 대표스프라이트는 직접 add
			if (count == 0) 
			{
				sprImage = CCSprite::spriteWithFile(buf);
				if (sprImage) 
				{
					sprImage->setAnchorPoint(imageAnchor);	
					sprImage->setScale(imageOriginalScale);
					sprImage->setPosition(imagePosition);
				}
			}
			
			// 아이폰의 경우 bundle에 접근하면 되고
			// 안드로이드는 zip으로 패키징된 apk에 접근해야한다
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
			if( LCUtil::isFileExistAtBundle(buf) )
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)	
				if( CCFileUtils::isFileExistInAPK(buf) )
#endif 
				{
					CCSprite *sprFrame = CCSprite::spriteWithFile(buf);
					ani->addFrame(CCSpriteFrame::frameWithTexture(sprFrame->getTexture(),sprFrame->getTextureRect()));
					count++;
				}
				else
					break;
		}
		// 프레임이 한장 이상일경우에만 애니 실행
		if (count > 1) 
		{
			ani->setDelay(0.25);
			aniAction = CCAnimate::actionWithAnimation(ani, true);
			aniAction->retain();
		}
		else 
		{
			aniAction = NULL;
		}	
		
		return sprImage;
	}
	return NULL;
}