The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Check if table column exists inside XML
I did a quick check if anyone has posted a HOW TO for this, but I didnt find any so I will post how I managed to check if a table column exists inside an XML product file.
You will replace the fields to the ones you are looking for as well as the table names too. The example below will be used in the next version of my vBSupport v0.5 inside the <installcode> Code:
// check for ticket.categoryid field if (!($categoryid = $db->query_first("SHOW COLUMNS FROM " . TABLE_PREFIX . "ticket LIKE 'categoryid'"))) { // alter the table to add the column categoryid $db->query_write("ALTER TABLE " . TABLE_PREFIX . "ticket ADD COLUMN categoryid INT UNSIGNED NOT NULL DEFAULT '0' AFTER ticketid"); } If the field is NOT found, it will run the commands inside the braces. If it already exists, it will not run the code inside the braces. Not sure if there is an easier way to do this, I looked to see if ALTER TABLE ADD COLUMN IF NOT EXISTS was available, but it doesnt seem to be. If someone has an easier way, by all means post it here. The reason I need to verify them is because I dont want the people upgrading to lose all of their tickets/replies by dropping the table and recreating it every time I release an upgrade. -CMX |
#2
|
||||
|
||||
Hmm, I just fire off ALTER TABLE Queries without bothering if it does exist or not.
If it does mySQL will return an Error, but who cares ^.^ You could also use Class vB_Database_Alter_MySQL (probably the preferred and best way). (The Reason I didn't so far is that it wasn't wroking in the Beta Versions, but seems like the Code has been fixed since RC1 ) |
#3
|
|||
|
|||
Ok, thanx.
I was wondering if it found an MySQL error if it would finish the rest of the queries or not? -CMX |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|