123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- // testsqlite3.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "testsqlite3.h"
- // #ifdef _DEBUG
- // #define new DEBUG_NEW
- // #endif
- #include <io.h>
- #include "..\\SQLite3\\sqlite3.h"
- #pragma comment(lib, "SQLite3.lib")
- #include "StringProcess.h"
- #include "DataImpl.h"
- #include "TaskInfoMessage.pb.h"
- // 唯一的应用程序对象
- CWinApp theApp;
- using namespace std;
- static int callback(void *NotUsed, int argc, char **argv, char **azColName)
- {
- int i;
- for(i=0; i<argc; i++)
- {
- printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
- }
- printf("\n");
- return 0;
- }
- #define CHECK_RC(rc,szInfo,szErrMsg,db) if(rc!=SQLITE_OK) \
- {printf("%s error!\n",szInfo);\
- printf("%s\n",szErrMsg); \
- sqlite3_free(szErrMsg); \
- sqlite3_close(db); \
- system("pause");\
- return 0;}
- int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
- {
- int nRetCode = 0;
- // 初始化 MFC 并在失败时显示错误
- if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
- {
- // TODO: 更改错误代码以符合您的需要
- _tprintf(_T("错误: MFC 初始化失败\n"));
- nRetCode = 1;
- }
- else
- {
- #if 0
- // TODO: 在此处为应用程序的行为编写代码。
- sqlite3 *db;
- char *dbPath="F:\\输出文件\\服务端\\test.db";
- char *szErrMsg = 0;
- char szpath[MAX_PATH] = {0};
- std::string ss= "F:\\输出文件\\服务端\\test.db";
- if ( StringProcess::ascii_to_utf8(dbPath, szpath) == 0)
- return 0;
- StringProcess::GB2312ToUTF_8(ss, dbPath, strlen(dbPath));
- sprintf(szpath, _T("%s"), ss.c_str());
- if ( -1 == _access(dbPath, 0 ) )
- {
- int rc= sqlite3_open(szpath, &db);
- CHECK_RC(rc,"open database",szErrMsg,db);
- char *szSql="create table UserInfo(ID int primary key , UserName char, PassWord char);";
- rc=sqlite3_exec(db,szSql,0,0,&szErrMsg);
- CHECK_RC(rc,"create table",szErrMsg,db);
- rc=sqlite3_exec(db,"insert into UserInfo(ID,UserName,PassWord) values(1,'kfqcome','123456')",0,0,&szErrMsg);
- CHECK_RC(rc,"insert info",szErrMsg,db);
- rc=sqlite3_exec(db,"insert into UserInfo(ID,UserName,PassWord) values(2,'miss wang','654321')",0,0,&szErrMsg);
- CHECK_RC(rc,"insert info",szErrMsg,db);
- szSql="select * from UserInfo";
- rc = sqlite3_exec(db,szSql, callback, 0, &szErrMsg);
- CHECK_RC(rc,"query values",szErrMsg,db);
- sqlite3_close(db);
- }
- else
- {
- int rc= sqlite3_open(szpath, &db);
- CHECK_RC(rc,"open database",szErrMsg,db);
- char *szSql="select * from UserInfo";
- rc = sqlite3_exec(db,szSql, callback, 0, &szErrMsg);
- CHECK_RC(rc,"query values",szErrMsg,db);
- sqlite3_close(db);
- }
- #endif
- #if 0
- CHAR *pszError = NULL;
- sqlite3 *pObj = NULL;
- // 打开;
- INT nResult = sqlite3_open("sms.db", &pObj);
- if ( SQLITE_OK != nResult )
- return -1;
- // 创建;
- #define _CREATE_TABLE_ "CREATE TABLE UserInfo (Autoid INTEGER NOT NULL,Account TEXT(16) NOT NULL,Password TEXT(16) NOT NULL,PRIMARY KEY (Autoid ASC),CONSTRAINT IU_UserInfo UNIQUE (Account));"
- //nResult = sqlite3_exec(pObj, _CREATE_TABLE_, NULL, NULL, &pszError);
- if ( SQLITE_OK != nResult )
- {
- printf("%s\n", pszError);
- }
- // 插入;
- CStringA strInsert = "";
- nResult = sqlite3_exec(pObj, "insert into UserInfo(Autoid, Account, Password) values (2, 'aaaa', '123456')", NULL, NULL, &pszError);
- if ( SQLITE_OK != nResult )
- {
- printf("%s\n", pszError);
- }
- // 查询;
- INT nRow = 0;
- INT nCol = 0;
- CHAR **pazResult = NULL;
- nResult = sqlite3_get_table(pObj, "select * from UserInfo", &pazResult, &nRow, &nCol, &pszError);
- if ( SQLITE_OK != nResult )
- {
- printf("%s\n", pszError);
- }
- else
- {
- // 解析表数据;
- std::vector<string> vValues;
- for ( int i = 1; i <= nRow; i++ )
- {
- for(int j = 0; j<nCol; j++)
- {
- #ifdef _UNICODE
- WCHAR wszValue[256] = {0};
- StringProcess::ascii_to_unicode(pazResult[i*nCol + j], wszValue);
- vValues.push_back(wszValue);
- #else
- vValues.push_back(pazResult[i*nCol + j]);
- #endif
- }
- }
- // 释放;
- sqlite3_free_table(pazResult);
- }
- #endif
- #if 1
- if (CDataImpl::GetInstance()->Open())
- {
- if (0)
- {// 插入数据;
- satdDatabase::complieServer tagServer;
- tagServer.set_server("192.168.1.1");
- tagServer.set_user("home");
- tagServer.set_password("password99999");
- CDataImpl::GetInstance()->InsertComplieServer(tagServer);
- // 查询数据;
- satdDatabase::listServer list;
- int nRow = CDataImpl::GetInstance()->QueryComplieServer(list);
- for (int i = 0; i < list.servers_size(); i++)
- {
- satdDatabase::complieServer ser = list.servers(i);
- OutputDebugString(ser.server().c_str()); OutputDebugString("\n");
- OutputDebugString(ser.user().c_str()); OutputDebugString("\n");
- OutputDebugString(ser.password().c_str()); OutputDebugString("\n");
- }
- }
- if (0)
- {
- satdDatabase::model tagModel;
- tagModel.set_name("set_name");
- tagModel.set_softsuffix("set_softsuffix");
-
- satdDatabase::listEndFlag* pflags = tagModel.mutable_flags();
- pflags->add_terminator("end1");
- pflags->add_terminator("end2");
- pflags->add_terminator("end3");
- pflags->add_terminator("end4");
- pflags->add_terminator("end5");
-
- satdDatabase::modelContent *pMc = tagModel.mutable_content();
- pMc->set_complietime("set_complietime");
- pMc->set_projectmodel("set_projectmodel");
- pMc->set_productname("set_productname");
- pMc->set_svndir("set_svndir");
- pMc->set_command("set_command");
- pMc->set_projectname("set_projectname");
- pMc->set_projectsn("set_projectsn");
- pMc->set_softver("set_softver");
- pMc->set_svnver("set_svnver");
- pMc->set_projectid("set_projectid");
- pMc->set_zone("set_zone");
- pMc->set_uistyle("set_uistyle");
- pMc->set_compliefiledir("set_compliefiledir");
- pMc->set_username("set_username");
- pMc->set_time("set_time");
- CDataImpl::GetInstance()->InsertAutoComplieModel(tagModel);
- // 查询;
- satdDatabase::listModel models;
- CDataImpl::GetInstance()->QueryAutoComplieModel(models);
- for ( int i = 0; i < models.models_size(); i++ )
- {
- satdDatabase::model md = models.models(i);
- OutputDebugString(md.name().c_str()); OutputDebugString("\n");
- OutputDebugString(md.softsuffix().c_str()); OutputDebugString("\n");
-
- pflags = md.mutable_flags();
- for ( int j = 0; j < md.mutable_flags()->terminator_size(); j++)
- {
- OutputDebugString(pflags->terminator(j).c_str()); OutputDebugString("\n");
- }
- pMc = md.mutable_content();
- OutputDebugString(pMc->compliefiledir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectmodel().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->productname().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->svndir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->command().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectname().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectsn().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->softver().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectid().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->zone().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->uistyle().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->compliefiledir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->username().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->time().c_str()); OutputDebugString("\n");
- }
- }
- if (0)
- {
- satdDatabase::model tagModel;
- tagModel.set_name("set_name");
- tagModel.set_softsuffix("set_softsuffix__dddddd");
- satdDatabase::listEndFlag* pflags = tagModel.mutable_flags();
- pflags->add_terminator("end111");
- pflags->add_terminator("end222");
- pflags->add_terminator("end333");
- pflags->add_terminator("end444");
- pflags->add_terminator("end555");
- satdDatabase::modelContent *pMc = tagModel.mutable_content();
- pMc->set_complietime("set_complietimedddd");
- pMc->set_projectmodel("set_projectmodelddd");
- pMc->set_productname("set_productnameddd");
- pMc->set_svndir("set_svndidddr");
- pMc->set_command("set_commadddnd");
- pMc->set_projectname("set_projectnameddd");
- pMc->set_projectsn("set_projectsnddd");
- pMc->set_softver("set_softverddd");
- pMc->set_svnver("set_svnverddd");
- pMc->set_projectid("set_projectidddd");
- pMc->set_zone("set_zoneddd");
- pMc->set_uistyle("set_uistyleddd");
- pMc->set_compliefiledir("set_compliefiledirddd");
- pMc->set_username("set_username");
- pMc->set_time("set_time");
- CDataImpl::GetInstance()->UpdateAutoCompliteModel(tagModel);
- // 查询;
- satdDatabase::listModel models;
- CDataImpl::GetInstance()->QueryAutoComplieModel(models);
- for (int i = 0; i < models.models_size(); i++)
- {
- satdDatabase::model md = models.models(i);
- OutputDebugString(md.name().c_str()); OutputDebugString("\n");
- OutputDebugString(md.softsuffix().c_str()); OutputDebugString("\n");
- pflags = md.mutable_flags();
- for (int j = 0; j < md.mutable_flags()->terminator_size(); j++)
- {
- OutputDebugString(pflags->terminator(j).c_str()); OutputDebugString("\n");
- }
- pMc = md.mutable_content();
- OutputDebugString(pMc->compliefiledir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectmodel().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->productname().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->svndir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->command().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectname().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectsn().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->softver().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->projectid().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->zone().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->uistyle().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->compliefiledir().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->username().c_str()); OutputDebugString("\n");
- OutputDebugString(pMc->time().c_str()); OutputDebugString("\n");
- }
- }
- if (1)
- {
- CDataImpl::GetInstance()->ExecteSQL("delete from model where name = 'set_name'");
- }
- }
- #endif
- //getchar();
- system("pause");
- }
- return nRetCode;
- }
|