[Ajuda] Maneira eficaz de melhorar esse cуdigo
#1

Eu estou tendo dъvidas de como posso melhorar a minha callback de salvamento de contas. Estava cogitando utilizar o mйtodo strcat mas acho muito arriscado. Alguйm teria como me dar um conselho sobre como eu posso melhorar esse cуdigo?

Код:
	new query[128];
	format(query, sizeof(query), "UPDATE `accounts` SET `admin` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAdmin], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `admintemp` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAdminTemp], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `helper` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHelper], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `vip` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pVIP], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `expire` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pExpire], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `level` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pLevel], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `exp` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pExp], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `money` = '%i' WHERE `name` = '%q'", GetPlayerMoneyEx(playerid), PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `bank` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pBank], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `ouros` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pOuros], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `moedasazuis` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMA], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `sex` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSex], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `age` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAge], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `skin` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSkin], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `ban` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pBan], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `cellphone` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCellphone], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `phonebook` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pPhoneBook], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `job` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pJob], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `connecttime` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pConnectTime], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `contracttime` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pContractTime], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `headvalue` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHeadValue], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `headvaluet` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHeadValueT], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `family` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pFamily], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `member` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMember], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `leader` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pLeader], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `rank` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pRank], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `spawn` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSpawn], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `kills` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pKills], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `deaths` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pDeaths], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `doenca` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pDoenca], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `hospital` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHospital], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `hospitaltime` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHospTime], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `canhospital` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCanHospital], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `jailed` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pJailed], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `jailtime` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pJailTime], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `crimes` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCrimes], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `wantedlevel` = '%i' WHERE `name` = '%q'", WantedPoints[playerid], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `carlic` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCarLic], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `flylic` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pFlyLic], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `boatlic` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pBoatLic], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `ammulic` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAmmuLic], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `registered` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pReg], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `married` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMarried], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `marriedto` = '%q' WHERE `name` = '%q'", APlayerData[playerid][pMarriedTo], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `ajustado` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAjustado], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `hajustado` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHAjustado], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `mutedchat` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMutedChat], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `muted` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMuted], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `giftbox` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pGiftBox], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `payday` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pPayDay], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `lottonr` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pLottoNr], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `upgrade` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pUpgrade], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `adminfuncao` = '%q' WHERE `name` = '%q'", APlayerData[playerid][pFuncao], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `lastlogin` = '%q' WHERE `name` = '%q'", APlayerData[playerid][pLastLogin], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `orgvip` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pOrgVIP], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `agendado` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pAgendado], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `adminagendou` = '%q' WHERE `name` = '%q'", APlayerData[playerid][pAdminAgendou], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `motivoagendou` = '%q' WHERE `name` = '%q'", APlayerData[playerid][pMotivoAgendou], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `tempoagendado` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pTempoAgendado], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `warns` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pWarns], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `health` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSHealth], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `armour` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSArmour], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `drugperk` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pDrugPerk], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `maconha` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMaconha], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `cocaina` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCocaina], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `crack` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCrack], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `materiais` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMateriais], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `housekey` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHouseKey], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `housecarkey` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pHouseCarKey], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `bizzkey` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pBizzKey], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `fazkey` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pFazKey], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `fome` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pFome], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `sede` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSede], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `lawskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pLawSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `detskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pDetSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `mechskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pMechSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `boxskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pBoxSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `sexskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSexSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `drogasskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pDrogasSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `newsskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pNewsSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `carskill` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCarSkill], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `capacete` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pCapacete], PlayerName(playerid));
	db_query(Connect, query);

	format(query, sizeof(query), "UPDATE `accounts` SET `sino` = '%i' WHERE `name` = '%q'", APlayerData[playerid][pSino], PlayerName(playerid));
	db_query(Connect, query);
Reply
#2

Coloque uns 15 itens em cada query que com certeza absoluta vai ficar mais rбpido do que isso ai.

@EDIT

Toda vez que vocк vai salvar alguma conta, seu sistema tem que criar uma nova variбvel query, formatar ela e entгo executa-la.

Com mais itens, ela cria a variбvel, formata e executa menos vezes.
Pelos meus cбlculos, vocк tem uns 60 itens ali.
Faзa umas 3 querys com 20 itens cada.

OBS: Aumente o tamanho da query para 1500, 2000...
Reply
#3

Tem como me dar uma ajuda aн por favor? Eu to me embolando todo aqui pra poder organizar de 20 em 20 colunas.
Reply
#4

POWWWWWWWWWW, que spam de queries... Sua DB vai ter um ataque de esgotamento

UPDATE TABELA_MOTHER_FUCKER SET CAMPO1 = 1, CAMPO2 = 1, CAMPO3 = 1 WHERE FODASE = 1

Coloca tudo numa assim

aconselho tb a usar metodos threaded para essas operaзхes

Normalmente, inserts sao coisas que vc nгo necessita esperar resposta (Normalmente ne.... sei la o que vc fez)
Entгo, joga essa query para outro thread, e foi...
o codigo continua executando independentemente se esse fdp deu certo ou nao
Reply
#5

Nгo entendo sua dificuldade de organizaзгo...

(Fiz somente uma parte)

Код:
new query[550];
format(query, sizeof(query), "\
	UPDATE `accounts` SET\
		`admin` = '%i',\
		`admintemp` = '%i',\
		`helper` = '%i',\
		`vip` = '%i',\
		`expire` = '%i',\
		`level` = '%i',\
		`exp` = '%i',\
		`money` = '%i',\
		`bank` = '%i',\
		`ouros` = '%i',\
		`moedasazuis` = '%i',\
		`sex` = '%i',\
		`age` = '%i',\
		`skin` = '%i',\
		`ban` = '%i',\
		`cellphone` = '%i',\
		`phonebook` = '%i',\
		`job` = '%i',\
		WHERE `name` = '%q'", 
APlayerData[playerid][pAdmin], APlayerData[playerid][pAdminTemp], APlayerData[playerid][pHelper], APlayerData[playerid][pVIP],
APlayerData[playerid][pExpire], APlayerData[playerid][pLevel], APlayerData[playerid][pExp], GetPlayerMoneyEx(playerid), APlayerData[playerid][pBank], 
APlayerData[playerid][pOuros], APlayerData[playerid][pMA], APlayerData[playerid][pSex], APlayerData[playerid][pAge], APlayerData[playerid][pSkin], 
APlayerData[playerid][pBan], APlayerData[playerid][pCellphone], APlayerData[playerid][pPhoneBook],  APlayerData[playerid][pJob], PlayerName(playerid))
Reply
#6

Tipo, o problema й que criando isso numa format ele dб input too long. Eu fiz em strcat e agora tб mais de boa. Obrigado pela ajuda aн.
Reply
#7

Quote:
Originally Posted by pWesley
Посмотреть сообщение
Tipo, o problema й que criando isso numa format ele dб input too long. Eu fiz em strcat e agora tб mais de boa. Obrigado pela ajuda aн.
Usou o compilador do zeex?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)