Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 03 Jan 2009, 20:43
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Installation Tables and Columns Help...

Okay, lets say I have a mod... and in version1, I have the following install code... (the code is an example, I know its not functioning, but thats got nothing to do with my problem)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Then I create a version2, with an extra column... so I made my install code this...


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Now I am making a version 3... and there is yet another column to add... I tried the following code, but I got an error when it hit the ADD COLUMN column3 code... because column3 already exists.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I tried looking for a possible IF NOT EXIST condition for altering tables to add columns, but it looks like you cant do it. I know I could just delete the add column3 query, and it would work great for people who are updating from version2 to version3. But that line would still be required if people were upgrading from version1. So is there a proper way for me to handle this problem?
Reply With Quote
  #2  
Old 03 Jan 2009, 21:55
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
You could run a query to retrieve the columns in "table" and then control the flow of logic from there.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Former vBulletin.org Staff Member

Please feel free to re-use any of the code in any of my projects submitted to vB.org, so long as original attribution is retained.
Reply With Quote
  #3  
Old 03 Jan 2009, 22:52
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Hmm... how would that code be written exactly? What would be the code to construct $columns?
Reply With Quote
  #4  
Old 03 Jan 2009, 23:22
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

You'd need to loop through $columns and take out the "field" key.
__________________
Former vBulletin.org Staff Member

Please feel free to re-use any of the code in any of my projects submitted to vB.org, so long as original attribution is retained.
Reply With Quote
  #5  
Old 04 Jan 2009, 04:31
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Huh? I'm confused? What would I need to loop? Wouldn't this be enough?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Thanks for the help BTW.
Reply With Quote
  #6  
Old 04 Jan 2009, 04:45
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
If you look at what $columns contains, you'll see it is a two-dimensional array. You need to loop through it after your query to extract the relevant information; in this case - the field names.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then you can run the in_array check.
__________________
Former vBulletin.org Staff Member

Please feel free to re-use any of the code in any of my projects submitted to vB.org, so long as original attribution is retained.
Reply With Quote
  #7  
Old 04 Jan 2009, 05:02
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Real name: Hanson
There is a reason why you are allowed to create multiple install codes in products. In the version 1 install code, use the first query. In the version 2 code, create a query using ALTER and add another column. In the version 3 install code, create another query.

On a new installation of the modification, vBulletin will run the install codes in order of version.
__________________
Former vBulletin.org Staff Member

View My Modifications
29 Releases and Counting... Latest Modification: dmActivityStream - vBookie Integration (4.x)

Please do not PM me to ask for support - please use the relevant thread or forum.
Reply With Quote
  #8  
Old 04 Jan 2009, 09:20
Jaxel Jaxel is offline
 
Join Date: Sep 2005
So this this shoudl work? the table name is video... and the column is timelength...


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I will use the install code stuff in future iterations...

Last edited by Jaxel; 04 Jan 2009 at 09:39.
Reply With Quote
  #9  
Old 04 Jan 2009, 10:01
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Real name: Hanson
Why not use the install code functionality now?
__________________
Former vBulletin.org Staff Member

View My Modifications
29 Releases and Counting... Latest Modification: dmActivityStream - vBookie Integration (4.x)

Please do not PM me to ask for support - please use the relevant thread or forum.
Reply With Quote
  #10  
Old 04 Jan 2009, 14:26
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Because what if someone is upgrading from Version 1 to Version 3... They wont get the changes in Version 2, because its not in the new install code. If I put the new install code in Version 3; then it gets the redundancy error.

Anyway, the code worked, thanks Kirk!
Reply With Quote
  #11  
Old 04 Jan 2009, 17:20
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Don't forget to take table prefixes into account in your SHOW COLUMNS query.
__________________
Former vBulletin.org Staff Member

Please feel free to re-use any of the code in any of my projects submitted to vB.org, so long as original attribution is retained.
Reply With Quote
  #12  
Old 05 Jan 2009, 02:11
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Originally Posted by Kirk Y View Post
Don't forget to take table prefixes into account in your SHOW COLUMNS query.
Oh shit... thanks for the heads up!

$vidcolumns = $db->query_read("SHOW COLUMNS FROM " . TABLE_PREFIX . "video");
$videocolumns = array();
while ($vidcolumn = $db->fetch_array($vidcolumns))
{
$videocolumns[] = $vidcolumn['Field'];
}
if (!in_array('timelength', $videocolumns))
{
echo('<li>Altering Table <strong>' . TABLE_PREFIX . 'video</strong> ... ');
$db->query_write("ALTER TABLE video ADD timelength int(10) unsigned NOT NULL");
}
Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Miscellaneous Hacks Custom Field Columns: Display Custom Fields in Two Columns on Memberlist Search calorie vBulletin 3.7 Add-ons 5 05 Aug 2008 09:50



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 10:05.

Layout Options | Width: Wide Color: