OnDuplicateKeyUpdate behaving strangely - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnDuplicateKeyUpdate behaving strangely (
/showthread.php?tid=622225)
OnDuplicateKeyUpdate behaving strangely -
TwinkiDaBoss - 20.11.2016
Alright so I am trying to do some queries with on duplicate key update but seems that i've either set up my DB wrongly or my query, its been a long day so I'm just sitting around bashing my head trying to figure out
PS: No errors inside the mysql log. Query gets executed correctly, altho it doesnt insert anything and I have an empty table sitting.
Query
pawn Код:
"INSERT INTO commands (`command_name`,`command_power`,`author`,`patch`) VALUES ('%e',%i,'%e','%e') ON DUPLICATE KEY UPDATE `command_name`='%e'",cmd_name, power, author, patch,cmd_name
PHP код:
CREATE TABLE `commands` (
`ID` int(10) NOT NULL,
`command_name` varchar(128) NOT NULL,
`command_power` int(10) NOT NULL,
`author` varchar(64) NOT NULL,
`patch` varchar(128) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `commands`
--
ALTER TABLE `commands`
ADD PRIMARY KEY (`ID`),
ADD UNIQUE KEY `command_name` (`command_name`);
Tldr, problem? It doesnt insert anything eventho according to MySQL log its executed correctly.
Re: OnDuplicateKeyUpdate behaving strangely -
Vince - 20.11.2016
You don't seem to have a default value, nor an auto_increment on the ID column. So that query will return an error. Also the query itself won't have any effect if the key exists because it will change command_name to what it already is. Are you trying to update the
other values? If so then you must list those values, not the key itself.
Re: OnDuplicateKeyUpdate behaving strangely -
TwinkiDaBoss - 20.11.2016
Well the thing is I even set the AI on the ID and set the default for the command_name altho its still saying that the query was executed normaly but nothing actually happens with a query.
Dont mind the execution time, running on full debug
Quote:
[04:03:24] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 39.570 milliseconds
[04:03:24] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
|
And this is the new structure
PHP код:
CREATE TABLE `commands` (
`ID` int(11) NOT NULL,
`command_name` varchar(128) NOT NULL DEFAULT 'NONE',
`command_power` int(10) NOT NULL,
`author` varchar(64) NOT NULL,
`patch` varchar(128) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `commands`
--
ALTER TABLE `commands`
ADD PRIMARY KEY (`ID`),
ADD UNIQUE KEY `command_name` (`command_name`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `commands`
--
ALTER TABLE `commands`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Re: OnDuplicateKeyUpdate behaving strangely -
TwinkiDaBoss - 20.11.2016
Anyone?
Bump