Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 08-19-2012, 07:34 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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");
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10615 seconds
  • Memory Usage 3,688KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (34)bbcode_code
  • (2)bbcode_php
  • (14)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (41)post_thanks_box
  • (2)post_thanks_box_bit
  • (41)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (41)post_thanks_postbit_info
  • (41)postbit
  • (1)postbit_attachment
  • (41)postbit_onlinestatus
  • (41)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete