Ok I have confused myself once again The subscribethread table has one column (subscribethreadid) that is auto increment, according to this website https://www.vbulletin.com/docs/html/...ards_sql_query I'm not supposed to include that field in an insert query.
I have tried the following queries which result in different errors.
Code:
$db->query_write("
INSERT INTO ".TABLE_PREFIX."unsub_subscribethread
SELECT userid,
threadid,
emailupdate,
folderid,
canview
FROM ".TABLE_PREFIX."subscribethread
WHERE userid = '$id'
AND emailupdate IN (1, 2, 3)");
error
Quote:
Database error in vBulletin 4.1.12:
Invalid SQL:
INSERT INTO unsub_subscribethread
SELECT userid,
threadid,
emailupdate,
folderid,
canview
FROM subscribethread
WHERE userid = ''
AND emailupdate IN (1, 2, 3);
MySQL Error : Column count doesn't match value count at row 1
Error Number : 1136
Request Date : Sunday, August 19th 2012 @ 08:18:50 PM
Error Date : Sunday, August 19th 2012 @ 08:18:50 PM
Script : http://localhost/vb4112/misc.php
Referrer : http://localhost/vb4112/misc.php?do=unsubscribe
IP Address : 127.0.0.1
Username : zombie
Classname : vB_Database
MySQL Version : 5.1.36-community-log
I don't understand how to use VALUES in this case (because the values can't be hard coded IE 5 for userid etc etc), everything I've tried results in syntax errors. So what would I put after VALUES?
Code:
$db->query("
INSERT INTO ".TABLE_PREFIX."unsub_subscribethread
VALUES What goes here?
SELECT (userid, threadid, emailupdate, folderid, canview)
FROM ".TABLE_PREFIX."subscribethread
WHERE userid = '$id'
AND emailupdate IN (1, 2, 3)");
So I went with the SELECT * to insert everything from subscribethreads.
Code:
$db->query_write("
INSERT INTO ".TABLE_PREFIX."unsub_subscribethread
SELECT *
FROM ".TABLE_PREFIX."subscribethread
WHERE userid = '$id'
AND emailupdate IN (1, 2, 3)");
error
None but it doesn't populate unsub_subscribethread, is it because of the auto increment column in subscribethread?
According to this website http://www.w3schools.com/sql/sql_select_into.asp I should be using SELECT INTO to copy subscribethread to unsub_subscribethread (vs INSERT INTO) at least that's how I understand it so I tried;
Code:
$db->query_write("
SELECT userid,
threadid,
emailupdate,
folderid,
canview
INTO ".TABLE_PREFIX."unsub_subscribethread
FROM ".TABLE_PREFIX."subscribethread
WHERE userid = '$id'
AND emailupdate IN (1, 2, 3)");
error
Quote:
Database error in vBulletin 4.1.12:
Invalid SQL:
SELECT userid,
threadid,
emailupdate,
folderid,
canview
INTO unsub_subscribethread
FROM subscribethread
WHERE userid = ''
AND emailupdate IN (1, 2, 3);
MySQL Error : Undeclared variable: unsub_subscribethread
Error Number : 1327
Request Date : Sunday, August 19th 2012 @ 08:28:26 PM
Error Date : Sunday, August 19th 2012 @ 08:28:26 PM
Script : http://localhost/vb4112/misc.php
Referrer : http://localhost/vb4112/misc.php?do=unsubscribe
IP Address : 127.0.0.1
Username : zombie
Classname : vB_Database
MySQL Version : 5.1.36-community-log
Now I can only guess that this is caused by me creating the table unsub_subscreibethread in the "<installcode>" at the start of the plugin (code is below for reference). If I understand what SELECT INTO is supposed to do, it's creating the table "unsub_subscribethread" on the fly? So this wouldn't work because it would try to create the table each time the script is run?
Code:
$db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."unsub_subscribethread LIKE ".TABLE_PREFIX."subscribethread");