Exemple #1
0
string UserService::SelectSignle(string u_id){
	DBConn db;
	string sql=SELECT_SINGLE_USER_SQL+Utils::AddSingleQuoteMark(u_id);
	string res=db.Query_single_mysql(sql);
	db.Close_mysql();
	return res;
}
Exemple #2
0
void LoginDialog::ok()
{
	DBConn* conn = DBService::getInstance()->getConnection();
	if (!conn->isConnected())
	{
		QMessageBox::critical(NULL, "Ошибка БД", "Нет подключения к БД");
		reject();
	}

	QString sql =
			QString("SELECT count(*) FROM users WHERE user_name = \'%1\' AND password = \'%2\'")
			.arg(name->text(), passwd->text());
	QSqlQuery q = conn->executeQuery(sql);
	bool res = false;
	if (q.isActive() && q.next())
	{
		res = q.value(0).toInt() > 0;
	}

	if (res == false)
	{
		QMessageBox::warning(NULL, "Предупреждение", "Неверный пароль");
	}
	else
	{
		accept();
	}
}
/* 查询所有管理员*/
string AdminService::selectAllAdmin(){
	DBConn db;
	string res = db.Query_all_mysql(SELECT_ALL_ADMIN_SQL, "Admin");
cout<<"AdminService::selectAllAdmin(), res="<<res<<endl;
    db.Close_mysql();
    return res;
}
string FacilityService::SelectSignle(string id) {
    string sql = "select * from facility where facility_id="
                 + Utils::AddSingleQuoteMark(id);
    DBConn db;
    string res = db.Query_single_mysql(sql);
    return res;
}
int MeetroomService::SelectMeetroomExist(string mr_id){
	DBConn db;
	string sql=SELECT_MR_ID_SQL+Utils::AddSingleQuoteMark(mr_id);
	string res=db.Query_mysql(sql);
	if(res.empty()==true){
		return 0;
	}
	return -1;
}
Exemple #6
0
string UserService::SelectAll(){
	DBConn db;
	string res=db.Query_all_mysql(SELECT_ALL_USER_SQL,"Users");
cout<<"i'm return back from Db.query_all_sql,result="<<res<<endl;
	db.Close_mysql();
cout<<"i'm in the UserService SelectAll:res="<<endl;
	return res;

}
//为会议室添加设备 成功
int FacilityService::UpdateForRoom(string id,string mr_id) {
    string sql = "update facility set meetroom_id = '"  + mr_id + "' where facility_id = " + Utils::AddSingleQuoteMark(id);
    DBConn db;
    if (db.Execute_mysql(sql) == 0) {
        db.Close_mysql();
        return 330;
    } else
        db.Close_mysql();
    return 331;
}
/*按id查询单个管理员*/
string AdminService::selectSingleAdmin(string a_id){
cout<<"AdminService::slelectSingleAdmin  ---------i'm here"<<endl;
	DBConn db;
	string sql = SELECT_SINGLE_ADMIN_SQL+Utils::AddSingleQuoteMark(a_id);
cout<<"select single sql= "<<sql<<endl;
	string res = db.Query_single_mysql(sql);
cout<<"AdminService::selectSingleAdmin(), res="<<res<<endl;
	db.Close_mysql();
	return res;
}
void DBConnQueryWorker::doJob(DBConnQueryJobPtr job) {
  string &sql = job->m_sql;
  Util::replaceAll(sql, "INDEX", lexical_cast<string>(job->m_index).c_str());

  if (!job->m_server) {
    job->m_affected = -1;
    job->m_error.code = -1;
    job->m_error.msg = "(server info missing)";
    return;
  }

  try {
    DBConn conn;
    int count = 0;
  retry:
    try {
      count++;
      conn.open(job->m_server, job->m_connectTimeout, job->m_readTimeout);
    } catch (DatabaseException &e) {
      if (job->m_retryQueryOnFail &&
          count <= job->m_maxRetryQueryOnFail) {
        goto retry;
      } else {
        throw;
      }
    }

    if (job->m_dsResult) {
      DBDataSet ds;
      job->m_affected = conn.execute(sql.c_str(), &ds,
                                     job->m_retryQueryOnFail);
      Lock lock(*job->m_dsMutex);
      job->m_dsResult->addDataSet(ds);
    } else {
      job->m_affected = conn.execute(sql.c_str(), nullptr,
                                     job->m_retryQueryOnFail);
    }
  } catch (DatabaseException &e) {
    job->m_affected = -1;
    job->m_error.code = e.m_code;
    job->m_error.msg = e.getMessage();
  } catch (Exception &e) {
    job->m_affected = -1;
    job->m_error.code = -1;
    job->m_error.msg = e.getMessage();
  } catch (std::exception &e) {
    job->m_affected = -1;
    job->m_error.code = -1;
    job->m_error.msg = e.what();
  } catch (...) {
    job->m_affected = -1;
    job->m_error.code = -1;
    job->m_error.msg = "(unknown exception)";
  }
}
Exemple #10
0
int UserService::SelectUserExist(string u_id){
	DBConn db;
	string sql="select u_name from user where u_id='"+u_id+"'";
	string res=db.Query_mysql(sql);
	if(res.empty()==true){
		cout<<"无重复,可插入!"<<endl;
		return 0;
	}
	cout<<"重复,不可插入!"<<endl;
	return -1;
}
Exemple #11
0
/**
 * return 106;//管理删除成功
 * return 107;//管理员删除失败
 */
int AdminService::deleteSingleAdmin(string a_id){

	string sql="delete from admin where a_id="+Utils::AddSingleQuoteMark(a_id);
		DBConn db;
		if(db.Execute_mysql(sql)==0){
			db.Close_mysql();
				return 106;
		}else{
			db.Close_mysql();
				return 107;
		}
}
Exemple #12
0
/**
 * return 106;//管理删除成功
 * return 107;//管理员删除失败
 */
int AdminService::deleteAllAdmin(){

	string sql="delete from admin";
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
		return 108;
	}else{
		db.Close_mysql();
		return 109;
	}
}
Exemple #13
0
int MeetroomService::DeleteSignle(string mr_id){
	string sql=DELETE_SINGLE_MR_SQL+Utils::AddSingleQuoteMark(mr_id);
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
			return 410;
	}else{
		db.Close_mysql();
			return 411;
	}

}
Exemple #14
0
int UserService::DeleteSignle(string u_id){
	string sql="delete from user where u_id="+Utils::AddSingleQuoteMark(u_id);
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
			return 400;
	}else{
		db.Close_mysql();
			return 401;
	}

}
Exemple #15
0
/**
 * return 100;//登录成功
 * return 101;//登录失败 :密码错误
 * return 102;//登录失败:ID不存在
 */
int AdminService::LoginSys(string a_id,string a_psd){
	DBConn db;
	string sql="select a_psd from admin where a_id="+Utils::AddSingleQuoteMark(a_id);
	string res=db.Query_mysql(sql);
	if(res.empty()==true){
		return 102;
	}else if(res==a_psd){
		return 100;
	}else{
		return 101;
	}
}
Exemple #16
0
int MeetroomService::Update(Meetroom mr){

	string sql = "update meetroom set meetroom_name='"+ mr.getMeetroomName() + "',meetroom_addr='" + mr.getMeetroomAddr() + "',available_state='"+ mr.getAvailableState() + "',meetroom_size='"+mr.getMeetroomSize()+"' where meetroom_id='"+mr.getMeetroomId()+"'";
	cout<<"update sql:"<<sql<<endl;
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
		return 420;
	}else{
		db.Close_mysql();
		return 421;
	}
}
Exemple #17
0
/*按id查询管理员权限*/
string AdminService::GetAdminPriority(string a_id){
	Json::Value value;
	Json::Reader reader;
	string reVal;
	DBConn db;
	string sql = "select a_priority from admin where a_id='"+a_id+"'";
cout<<"AdminService::GetAdminPriority-----sql="<<sql<<endl;
	if (reader.parse(db.Query_single_mysql(sql),value)) {
		reVal = value["a_priority"].asString();
	}
cout<<"AdminService::GetAdminPriority-----res="<<reVal<<endl;
    return reVal;
}
Exemple #18
0
//删除facility成功600 失败601
int FacilityService::DeleteSignle(string id) {
    string sql = "delete from facility where facility_id="
                 + Utils::AddSingleQuoteMark(id);
    DBConn db;
    if (db.Execute_mysql(sql) == 0) {
        db.Close_mysql();
        return 310;
    } else {
        db.Close_mysql();
        return 311;
    }

}
Exemple #19
0
//更新设备成功 320 失败321
int FacilityService::Update(Facility fac) {
    string sql = "update facility set facility_name='" + fac.getFacilityName()
                 + "',available_state='" + fac.getAvailableState()
                 + "',meetroom_id='" + fac.getMeetroomId() + "',facility_ip='"
                 + fac.getFacilityIp() + "'where facility_id="+Utils::AddSingleQuoteMark(fac.getFacilityId());
    DBConn db;
    if (db.Execute_mysql(sql) == 0) {
        db.Close_mysql();
        return 320;
    } else
        db.Close_mysql();
    return 321;
}
Exemple #20
0
/**
 * return 108;//管理员更新成功
 * return 109;//管理员更新失败
 */
int AdminService::updateAdmin(Admin admin){

	string sql = "update admin set a_name='"+ admin.getName() + "',a_psd='" + admin.getPsd() + "',a_priority='"+ admin.getPriority() +"' where u_id='"+admin.getId()+"'";
cout<<"AdminService::updateAdmin ---- update sql="<<sql<<endl;
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
		return 108;
	}else{

		db.Close_mysql();
		return 109;
	}
}
Exemple #21
0
int UserService::Update(User user){

	string sql = "update user set u_name='"+ user.getName() + "',u_phone='" + user.getPhone() + "',u_department='"+ user.getDepartment() + "',u_gender='"+user.getGender()+"' where u_id='"+user.getId()+"'";
	cout<<"update sql:"<<sql<<endl;
	DBConn db;
	if(db.Execute_mysql(sql)==0){
		db.Close_mysql();
		return 0;
	}else{

		db.Close_mysql();
		return -1;
	}
}
Exemple #22
0
/*检查是否已有此id的admin
 *@return 0:无重复   -1:重复
 *
 * */
int AdminService::SelectAdminExist(string a_id){
	DBConn db;
    string sql = "select a_id from admin where a_id='"+a_id+"'";

cout<<"i'm in the AdminService::SelectAdminExist, sql="<<sql<<endl;

	string res = db.Query_mysql(sql);

cout<<"i'm in the AdminService::SelectAdminExist, res="<<res<<endl;
    if(res.empty()==true){
    	cout<<"无重复,可插入!"<<endl;
    	return 0;
    }
    cout<<"重复,不可插入!"<<endl;
    return -1;
}
Exemple #23
0
int MeetroomService::Add(Meetroom mr){

	int tmp=this->SelectMeetroomExist(mr.getMeetroomId());
	if(tmp==0){
		string sql=ADD_MR_SQL+ mr.getMeetroomId() + "','" +mr.getMeetroomName()+ "','" +mr.getMeetroomAddr() +
						"','"+mr.getAvailableState() +"','"+mr.getMeetroomSize()+ "')";
			DBConn db;
			if(db.Execute_mysql(sql)==0){
				db.Close_mysql();
				return 400; //添加成功
			}
			db.Close_mysql();
			return 402;//添加失败
	}else{
		return 401;//ID重复
	}
}
std::string MessageCallBack::processMysqlRequest(const std::string& db, const std::string& sql)
{
  DBConn* conn = DBConnPool::getDBPoolInstance()->getConn(db);
  if( conn == NULL ) {
    char temp[1024] = {0};
    int s = strlen("error");
    long len = htonl(s);
    memcpy(temp, &len, MSG_HEAD_SIZE);
    memcpy(temp+MSG_HEAD_SIZE, "error", strlen("error"));
    std::string msg(temp, strlen("error")+MSG_HEAD_SIZE);
    return msg;
  }
  std::string s = conn->query(sql);
  DBConnPool::getDBPoolInstance()->releaseConn(conn);

  return addHeader(s);
}
Exemple #25
0
int FacilityService::SelectFacilityExist(string id, string ip) {
    string sql = "select  facility_name from facility where facility_id=" + Utils::AddSingleQuoteMark(id);
    string sql1 = "select  facility_id from facility where facility_ip=" + Utils::AddSingleQuoteMark(ip);

    DBConn db;
    string res_name = db.Query_mysql(sql);
    string res_id = db.Query_mysql(sql1);
    db.Close_mysql();
    if (res_id.empty()) { //查看该IP是否被占用
        if (res_name.empty()) { //查看该ID是否存在
            return 300; //可以添加
        } else {
            return 302; //该ID已存在
        }
    } else {
        return 301; //IP被占用
    }
}
Exemple #26
0
void Package::commitStats(ServerDataPtr server, int runId) const {
  DBConn conn;
  conn.open(server);

  {
    DBQuery q(&conn, "UPDATE hphp_dep");
    q.setField("parent_file = parent");
    q.filterBy("run = %d", runId);
    q.filterBy("kind IN ('PHPInclude', 'PHPTemplate')");
    q.execute();
  }
  {
    DBQuery q(&conn, "UPDATE hphp_run");
    q.setField("committed = 1");
    q.filterBy("id = %d", runId);
    q.execute();
  }
}
Exemple #27
0
/**
 * return 103;//管理员添加成功
 * return 104;//管理员添加失败
 * return 105;//管理员添加失败:ID重复
 */
int AdminService::addAdmin(Admin admin){
	string sql="insert into admin(a_id,a_name,a_psd,a_priority)values('"+admin.getId()+"','"
			+admin.getName()+"','"+admin.getPsd()+"','"+admin.getPriority()+"')";
	string sql1="update admin set a_loginState='0' where a_id='"+admin.getId()+"'";
cout<<"insert admin sql:"<<sql<<endl;
	int tmp = this->SelectAdminExist(admin.getId());
	if(tmp==0){
		DBConn db;
		if(db.Execute_mysql(sql)==0){
			db.Execute_mysql(sql1);           //添加成功一个admin,默认登录状况为未登录把loginState设置为“0”
			db.Close_mysql();
			return 103;      //添加成功
		}
		db.Close_mysql();
		return 104;         //添加失败
	}else{
		return 105;         //添加失败:ID重复
	}
}
Exemple #28
0
int UserService::Add(User user){

	int tmp=this->SelectUserExist(user.getId());
	if(tmp==0){
		string sql="insert into user(u_id,u_name,u_department,u_phone,u_gender)values('"+ user.getId() + "','" +user.getName()+ "','" + user.getDepartment() +
						"','"+user.getPhone() +"','"+user.getGender()+ "')";
			DBConn db;
			if(db.Execute_mysql(sql)==0){
				db.Close_mysql();
				return 200; //添加成功
			}
			db.Close_mysql();
			return 201;//添加失败
	}else{
		return 202;//添加失败:ID重复
	}


}
Exemple #29
0
int FacilityService::Add(Facility fac) {
    string sql =
        "insert into facility(facility_id,facility_name,available_state,meetroom_id,facility_ip)values('"
        + fac.getFacilityId() + "','" + fac.getFacilityName()
        + "','" + fac.getAvailableState() + "','"
        + fac.getMeetroomId() + "','" + fac.getFacilityIp() + "')";
    int check = this->SelectFacilityExist(fac.getFacilityId(),fac.getFacilityIp(), fac.getMeetroomId());
    DBConn db;
    if (check == 300) {
        db.Execute_mysql(sql);
        db.Close_mysql();
        return 300;
    } else if (check == 301) {
        db.Close_mysql();
        return 301;
    } else {
        db.Close_mysql();
        return 302;
    }
}
Exemple #30
0
/**
 * Load from database "config" table that looks like this:
 *
 * CREATE TABLE `config` (
 *   `id` varchar(255) NOT NULL,
 *   `name` varchar(255) NOT NULL,
 *   `value` varchar(255) NOT NULL,
 *   PRIMARY KEY  (`id`,`name`)
 * ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 *
 * Only a subset of options are supported.
 */
void Option::Load(ServerDataPtr server) {
  DBConn conn;
  conn.open(server);

  DBQueryPtr q(new DBQuery(&conn, "SELECT id, name, value FROM config"));
  DBDataSet ds;
  q->execute(ds);

  for (ds.moveFirst(); ds.getRow(); ds.moveNext()) {
    const char *id = ds.getField(0);
    string name = ds.getField(1);
    string value = ds.getField(2);
    boost::algorithm::trim<std::string>(name);
    boost::algorithm::trim<std::string>(value);

    if (strcmp(id, "IncludeRoots") == 0) {
      IncludeRoots[name] = value;
    } else if (strcmp(id, "AutoloadRoots") == 0) {
      AutoloadRoots[name] = value;
    } else if (strcmp(id, "IncludeSearchPaths") == 0) {
      IncludeSearchPaths.push_back(name);
    } else if (strcmp(id, "PackageDirectories") == 0) {
      PackageDirectories.insert(name);
    } else if (strcmp(id, "PackageExcludeDirs") == 0) {
      PackageExcludeDirs.insert(name);
    } else if (strcmp(id, "PackageExcludeFiles") == 0) {
      PackageExcludeFiles.insert(name);
    } else if (strcmp(id, "PackageExcludeStaticFiles") == 0) {
      PackageExcludeStaticFiles.insert(name);
    } else if (strcmp(id, "DynamicFunctionPrefix") == 0) {
      DynamicFunctionPrefixes.push_back(name);
    } else if (strcmp(id, "DynamicFunctionPostfix") == 0) {
      DynamicFunctionPostfixes.push_back(name);
    } else if (strcmp(id, "DynamicMethodPrefix") == 0) {
      DynamicMethodPrefixes.push_back(name);
    } else if (strcmp(id, "DynamicInvokeFunctions") == 0) {
      DynamicInvokeFunctions.insert(name);
    }
  }
}