MySQL help

Mkm hi.
Got table of server scanner.
QuoteCREATE TABLE IF NOT EXISTS `clq_server_info` (
`IDX` int(10) unsigned NOT NULL AUTO_INCREMENT,
`NAME` varchar(100) DEFAULT NULL,
`RAWNAME` varchar(64) DEFAULT NULL,
`IP` varchar(32) DEFAULT NULL,
`SCANNER` enum('','quake3') DEFAULT 'quake3',
`PRIORITY` char(1) DEFAULT 'N',
`PRIO_MODIFIER` float NOT NULL DEFAULT '1',
`LASTSCAN` int(10) NOT NULL DEFAULT '0',
`LASTRESPONSE` int(10) NOT NULL DEFAULT '0',
`NEXTSCAN` int(10) NOT NULL DEFAULT '0',
`STATUS` char(1) DEFAULT 'U',
`SEQCOUNT` int(11) NOT NULL DEFAULT '0',
`FULLTIME` int(10) unsigned NOT NULL DEFAULT '0',
`FULLSCORE` int(10) unsigned NOT NULL DEFAULT '0',
`FULLPLAYERS` int(10) unsigned NOT NULL DEFAULT '0',
`TEMPTIME` int(10) unsigned NOT NULL DEFAULT '0',
`TEMPPLAYERS` int(11) NOT NULL DEFAULT '0',
`GAMEIDX` mediumint(8) unsigned NOT NULL DEFAULT '1',
`GAMEID` varchar(8) DEFAULT 'unknown',
`PROTOCOL` mediumint(9) NOT NULL DEFAULT '-1',
`MODNAME` varchar(16) DEFAULT 'unknown',
`MODVERSION` varchar(32) DEFAULT NULL,
`GAMETYPE` enum('','obj','sw','cpgn','lms','ctf','mv') DEFAULT NULL,
`GAMESTATUS` enum('','warmup','process','review') DEFAULT NULL,
`MAPNAME` varchar(32) DEFAULT '-',
`MAPIDX` mediumint(8) unsigned NOT NULL DEFAULT '0',
`MAPLASTCHANGE` int(10) unsigned NOT NULL DEFAULT '0',
`MAPTIMELEFT` smallint(5) unsigned NOT NULL DEFAULT '0',
`NEXTMAP` varchar(32) DEFAULT NULL,
`MAXSLOTS` mediumint(8) unsigned NOT NULL DEFAULT '0',
`CURRSLOTS` mediumint(8) unsigned NOT NULL DEFAULT '0',
`INVSLOTS` smallint(5) unsigned NOT NULL DEFAULT '0',
`PRIVSLOTS` mediumint(8) unsigned NOT NULL DEFAULT '0',
`FLAGS` set('pb','ff','ll','pw','al','mu','bt','hw','os','lf','ps','voice','tv','bot','pure','adm','patched','slac','stream') DEFAULT NULL,
`OS` enum('','windows','linux','mac') DEFAULT NULL,
`PROTECTION` set('','pb','etpro','cd','slac') DEFAULT NULL,
`TYPE` enum('','tv') DEFAULT NULL,
`RATINGSTATUS` enum('auto','on','off') DEFAULT 'auto',
`RATINGMSG` tinyint(3) unsigned NOT NULL DEFAULT '0',
`ENABLED` enum('yes','') DEFAULT 'yes',
`COUNTRY` char(2) DEFAULT NULL,
`REGION` char(1) DEFAULT NULL,
`INFOSTRING` varchar(80) DEFAULT NULL,
`URL` varchar(128) DEFAULT NULL,
`MESSAGES` varchar(100) DEFAULT NULL,
`CMDLINE` varchar(255) DEFAULT NULL,
`SLOWN` enum('','yes') DEFAULT NULL,
`SLBONUS` float unsigned NOT NULL DEFAULT '1',
`PROCTIME` float(8,5) NOT NULL DEFAULT '-1.00000',
`FULLPROCTIME` float(8,5) NOT NULL DEFAULT '0.00000',
`TIMEUP` int(10) unsigned NOT NULL DEFAULT '0',
`TIMEDOWN` int(10) unsigned NOT NULL DEFAULT '0',
`CLANIDX` mediumint(8) unsigned NOT NULL DEFAULT '0',
`SKILL_EFF` bigint(20) unsigned NOT NULL DEFAULT '0',
`SKILL_TIME` int(10) unsigned NOT NULL DEFAULT '0',
`POPULARITY` float NOT NULL DEFAULT '0',
`RANK` mediumint(8) unsigned NOT NULL DEFAULT '0',
`AVGRATING` float NOT NULL DEFAULT '0',
`RATINGTIME` float NOT NULL DEFAULT '3600',
`FAULTS` int(10) unsigned NOT NULL DEFAULT '0',
`GAMES` mediumint(8) unsigned NOT NULL DEFAULT '1',
`ISDEBUG` enum('','yes') DEFAULT NULL,
`SPECRANK` int(11) NOT NULL DEFAULT '0',
`MOJO` int(11) NOT NULL DEFAULT '0',
`MOJOMSG` varchar(255) NOT NULL DEFAULT '""',
PRIMARY KEY (`IDX`),
UNIQUE KEY `UIP` (`IP`),
KEY `INEXTSCAN` (`NEXTSCAN`),
KEY `IRAWNAME` (`RAWNAME`(5)),
KEY `POPULARITY` (`POPULARITY`),
KEY `SLOWN` (`SLOWN`),
KEY `CLANIDX` (`CLANIDX`),
KEY `RANK` (`RANK`),
KEY `flagsindex` (`FLAGS`),
KEY `enabledindex` (`ENABLED`),
KEY `GameIDIndex` (`GAMEIDX`),
KEY `mapnameindex` (`MAPNAME`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=710962 ;

Now theres data inside.
The problem is about that,the data keeps coming and coming.
So if theres same IP with same name.
It keeps adding every time adding new lines,instead updaiting them.
THe problem is about theres new IPs coming,they will be scanned,but you cant UPDATE a data what doesn't excists.
Its hard to explain it.But are/is there any PHP functions what check if theres info about this text in MySQL if yes it updates if not it inserts??
Comments
11
there are many way to do this, the easiest way is using INSERT ON DUPLICATE KEY UPDATE or REPLACE INTO (pretty simple, one query), other way would be creating trigger event (if you need to do some checks which are not related to primary/unique keys).
But remember, for first method you need have MySQL 5.0+ so be sure before you implement this.
Well thanks for reminding the MySQL functions.
Istead triggers I ill use debugging statements.
So basicly if user requests a page,the following line will be excuted.
Quote
$this->SqlUpdates['GAMETYPE'] = '\''.DB_escape($this->GetIsoVariable('sv_gametype')).'\'';

Attenting to SL code
Quote
if (!DB_execsql('UPDATE '.$tblprefix.'server_session_players SET DOUBLETIME=DOUBLETIME+'.intval($Player->PlayTime).' WHERE SESIDX='.$this->SessionIdx.' AND PLIDX='.$Player->Idx))
DB_execsql('INSERT INTO '.$tblprefix.'server_session_players SET SESIDX='.$this->SessionIdx.', PLIDX='.$Player->Idx.', JOINTIME='.$Player->JoinTime.', DOUBLETIME='.$Player->PlayTime);

Theres this one.
Didn't notice this one before.
But yeah,seems to work.
Parent
there are many way how you can do it, from simple ones to complex ones, if you need to save as much of processing/time per query as you can, you would go for DB only way to do it (since its possible). But you have enough resources and dont really care that much for any bit of a performance boost, simple ones can be better if you are not that much into advanced query building.

btw, in assumption that SESIDX and PLIDX are unique keys, you could try this:

QuoteDB_execsql("INSERT INTO ".$tblprefix."server_session_players SET SESIDX=".$this->SessionIdx.", PLIDX=".$Player->Idx.", JOINTIME=".$Player->JoinTime.", DOUBLETIME=".$Player->PlayTime." ON DUPLICATE KEY UPDATE DOUBLETIME=DOUBLETIME+".intval($Player->PlayTime).")


hope I didnt do any typo :)
Parent
Heh:D
Dun worry about the performence.
The trackercore has impressive framework.
Proofed.I got 1700 servers scanned and the kept scanned every 30second and this way for 6 days and only it used only 8% of memory =)
tbh..it makes forcescan to all servers in 10 seconds.
Then the system gets 30seconds to sleep and again repeats all this.
Parent
in php itself you gotta do like

If (select blabla from table where uniqueID = ?)
update;
else
insert;


what also helps is to set the keys to be unique in your DB, but then you'll just get an error if it tries to insert it, it wont update i think.

What comment #1 says about MySQL options i dont know much about but it seems interesting if its possible to catch such exceptions with trigger events :)
well, I admit your method would by far the simplest one but I guess this is perfect example of what should be treated on DB side exclusively (checking if row exists and then decide whether do an update or insert would take much more processing and time compared to single statement, especialy for big tables).
Parent
alter table? insert into? no idea.
i have databases for two weeks now, and its annoying as fuck x]
im so glad i didnt pick IT for uni X)
Back to top