#include "InfoTextDao.h" #include InfoTextDao::InfoTextDao(SQLite::Database* pdb) :BaseDao(pdb) { } InfoTextDao::~InfoTextDao() { } void InfoTextDao::CreateTable() { if (m_pDB->tableExists(InfoText::TABLE_NAME))return; char buffer[1024]; memset(buffer, '\0', sizeof(buffer)); string createsql = "CREATE TABLE %s(%s INTEGER PRIMARY KEY AUTOINCREMENT,%s VARCHAR(50) UNIQUE,%s VARCHAR(500))"; sprintf_s(buffer, sizeof(buffer), createsql.c_str(), InfoText::TABLE_NAME.c_str(), InfoText::FIELD_ID.c_str(), InfoText::FIELD_TEXT_CODE.c_str(), InfoText::FIELD_DEFAULT_TEXT.c_str() ); m_pDB->exec(buffer); vector insertSql; size_t i = 0; SQLite::Transaction transaction(*m_pDB); try { InfoText::Generate(insertSql); for (i; i < insertSql.size(); ++i) { m_pDB->exec(insertSql[i]); } } catch (SQLite::Exception&) { char buffer[1024]; sprintf_s(buffer, sizeof(buffer), "%zd\n",i); OutputDebugStringA(buffer); OutputDebugStringA(insertSql[i].c_str()); OutputDebugStringA("\n"); } transaction.commit(); } void InfoTextDao::Find(map& textmap) { char buffer[2048]; string strsql = "SELECT %s,%s FROM %s"; sprintf_s(buffer, sizeof(buffer), strsql.c_str(), InfoText::FIELD_TEXT_CODE.c_str(), InfoText::FIELD_DEFAULT_TEXT.c_str(), InfoText::TABLE_NAME.c_str()); SQLite::Statement query(*m_pDB, buffer); while (query.executeStep()) { textmap[query.getColumn(InfoText::FIELD_TEXT_CODE.c_str()).getString()] = query.getColumn(InfoText::FIELD_DEFAULT_TEXT.c_str()).getString(); } }