Ejemplo n.º 1
0
bool Myth::TestDBSettings( const QString &sHostName,
                           const QString &sUserName,
                           const QString &sPassword,
                           const QString &sDBName,
                           int   dbPort)
{
    bool bResult = false;

    QString db("mythconverg");
    int port = 3306;

    if (!sDBName.isEmpty())
        db = sDBName;

    if (dbPort != 0)
        port = dbPort;

    bResult = TestDatabase(sHostName, sUserName, sPassword, db, port);

    return bResult;
}
Ejemplo n.º 2
0
BOOL CheckDataBaseExist()//返回1,则表示数据库已存在;返回0,则表示不存在并创建
{
	convert_char(_T("\\ResidentFlash\\Config\\RFIDData.db"));

	int res = sqlite3_open(send_data, &pDB);
	if(res)
	{
		AfxMessageBox(_T("打开数据库错误"));
		return FALSE;
	}

	char* errMsg;
	CString strTemp;
	char temp_data[1024]={'\0'};
	//Create bus_depart table
	if(!TableExist(_T("bus_depart"))){
		strTemp = "create table bus_depart (bus_run_ID CHAR(30) NOT NULL PRIMARY KEY, bus_ID CHAR(10), driver_ID CHAR(10), teacher_ID CHAR(10), road_ID CHAR(10), student_number INTEGER, remark VARCHAR(255))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
	#ifdef DEBUG_YFH
			AfxMessageBox(_T("创建表1错误"));
	#endif
		}
	}else{
		//AfxMessageBox(_T("表1已经存在!"));
	}

	//Create bus_stu table
	if(!TableExist(_T("bus_stu"))){
		strTemp = "create table bus_stu (bus_run_ID CHAR(20) NOT NULL, student_ID CHAR(10) NOT NULL, up_station_ID CHAR(10), up_time TIME, down_station_ID CHAR(10), down_time TIME, remark VARCHAR(255),  PRIMARY KEY(bus_run_ID, student_ID))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
	#ifdef DEBUG_YFH
			AfxMessageBox(_T("创建表2错误"));
	#endif
		}
	}else{
		//AfxMessageBox(_T("表2已经存在!"));
	}

	//create schoolbus table
	if(!TableExist(_T("schoolbus"))){
		strTemp = "create table schoolbus (ID INTEGER PRIMARY KEY AUTOINCREMENT, StudentName VARCHAR(16),ParentPhoneNum VARCHAR(16),UpBusTime VARCHAR(10),IsUpMessageSended VARCHAR(10),DownBusTime VARCHAR(10),IsDownMessageSended VARCHAR(10),BusCode VARCHAR(10))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
			AfxMessageBox(_T("创建表3错误"));
		}
	}else{
		//AfxMessageBox(_T("表3已经存在!"));
	}

	//AfxMessageBox(_T("现在开始测试数据库!"));
	TestDatabase();

	return TRUE;
}