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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2012, 02:59 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query syntax error help

I'm attempting to copy the subscribethread table to a new table called unsub_subscribethread. Once the table is created I need to copy the data from subscribethread to unsub_subscribethread. I'm still a novice with sql but what I have looks right to me, but both queries give a syntax error

Code:
$db->query_write("CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX . "unsub_subscribethread LIKE subscribethread");
Code:
$db->query_write("INSERT " . " unsub_sunscribethread SELECT * FROM subscribethread ");
Reply With Quote
  #2  
Old 08-05-2012, 08:06 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your query should be:
$db->query_write("CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX . "unsub_subscribethread LIKE" .TABLE_PREFIX."subscribethread");
Reply With Quote
  #3  
Old 08-05-2012, 10:51 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're using a table prefix, the second query also needs TABLE_PREFIX in there (twice, once for each table name).
Reply With Quote
  #4  
Old 08-05-2012, 08:47 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah thanks guys I didn't know I needed TABLE_PREFIX again, assumed it was taken care of the first time

--------------- Added [DATE]1344207241[/DATE] at [TIME]1344207241[/TIME] ---------------

Quick question, does it matter if the . has a space before and after TABLE_PREFIX?

Reason I ask is Simon's query has them without spaces in the 2nd part of the query.
Reply With Quote
  #5  
Old 08-06-2012, 06:38 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There's a space before but not after, this is because you want things similar to this
LIKE mytableprefix_subscribethread
otherwise it would look like this and fail
LIKE mytableprefix_ subscribethread
or this
LIKEmytableprefix_subscribethread
Reply With Quote
  #6  
Old 08-06-2012, 09:14 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still don't understand why it's different in the creating part. In the creating portion of the query it's dot space table_prefix space dot space quotation. Why isn't it dot table_prefix dot quotation?

The online tutorials (at least the ones I have checked) don't even use the same punctuations. In some they use the comma and in others they use the period. Some say you don't need the semi-colon, others say you do. Some use quotation marks around text while others use single quotation marks. How the hell do you know which one is right?
Reply With Quote
  #7  
Old 08-06-2012, 10:47 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i think you're getting confused because vbulletin has done it's trick of adding a space after x amount of characters, here it is in quotes
Quote:
$db->query_write("CREATE TABLE IF NOT EXISTS " . TABLE_PREFIX ."unsub_subscribethread LIKE " .TABLE_PREFIX."subscribethread");
so after TABLE_PREFIX. the quotation should be butt up against it because you ar etrying to get mytableprefix_ unsub_subscribethread if there was a space it would look like mytableprefix_ unsub_subscribethread and would create a table that would be called SPACEunsub_subscribethread (the word space wouldn't be there just a blank space )

So, in a nutshell the one in the quote in this post is correct if you dont wnt to introduce any other anomalies.
Reply With Quote
  #8  
Old 08-06-2012, 02:39 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
I still don't understand why it's different in the creating part. In the creating portion of the query it's dot space table_prefix space dot space quotation. Why isn't it dot table_prefix dot quotation?
What you're doing is building a string representing the sql for the query, so there's a lot of different ways that could be done. In the examples above it's being done by using the "string concatenation" operator (the dot) to put together multiple strings. The spaces that appear outside of quotes are optional, so that, for instance:

Code:
"The table prefix is " . TABLE_PREFIX . " for sql queries"

and

"The table prefix is ".TABLE_PREFIX." for sql queries"
Result in the same string, because the extra spaces are outside of the string "literals" so they're optional.

Quote:
The online tutorials (at least the ones I have checked) don't even use the same punctuations. In some they use the comma and in others they use the period. Some say you don't need the semi-colon, others say you do. Some use quotation marks around text while others use single quotation marks. How the hell do you know which one is right?
I don't know about the comma thing - in php, a dot is used to concatenate strings and a comma doesn't work. (Unless you're talking about the SQL and not the php, in that case we'd have to see examples to explain it).

As for the semicolon, that's used to end an sql query but it isn't needed when doing queries using the vb functions. One string has to equal exactly one query, so there's no need for an end character.

In php you can use either single or double quotes. There are some differences (you should look at the php docs if you're interested), but in a lot of cases either one will work. If you're talking about use of quotes in the sql query itself, they are optional in some cases and in some cases they need to be back ticks (which can be confused with single quotes). Most likely the only thing you have to worry about (as far as valid sql) is putting single quotes around literal strings.

Having said all that, a couple of the queries posted above *are* missing a space - there needs to be a space before inserting the table prefix but not after, as Simon explained, but the query above is missing a space after LIKE.

I hope this helps - I'm afraid it might just be more confusing.
Reply With Quote
  #9  
Old 08-06-2012, 03:15 PM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
....Having said all that, a couple of the queries posted above *are* missing a space - there needs to be a space before inserting the table prefix but not after, as Simon explained, but the query above is missing a space after LIKE.

I hope this helps - I'm afraid it might just be more confusing.
ooops, fixed
Reply With Quote
  #10  
Old 08-06-2012, 08:54 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Having said all that, a couple of the queries posted above *are* missing a space - there needs to be a space before inserting the table prefix but not after, as Simon explained, but the query above is missing a space after LIKE.

I hope this helps - I'm afraid it might just be more confusing.
Ok so can I just not use the spaces like so;

Code:
$db->query_write("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."unsub_subscribethread LIKE ".TABLE_PREFIX."subscribethread");
Or do I have to have a space before the first TABLE_PREFIX like so;

Code:
$db->query_write("CREATE TABLE IF NOT EXISTS " .TABLE_PREFIX."unsub_subscribethread LIKE ".TABLE_PREFIX."subscribethread");
It's the mixed use of spaces and non spaces that doesn't make sense (at least to me at this point )
Reply With Quote
Reply


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 07:46 PM.


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.05605 seconds
  • Memory Usage 2,268KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (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_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • 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
  • 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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete