table_column_exists

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Sajaki
Registered User
Posts: 1390
Joined: Mon Mar 02, 2009 1:41 pm
Location: Amsterdam
Contact:

table_column_exists

Post by Sajaki »

hi,

in Umil we used to have a handy way of checking if a column exists.

https://wiki.phpbb.com/Umil.table_column_exists

does this exist for extension migrations ?
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: table_column_exists

Post by david63 »

Why would you want it? If you are creating an extension then you would normally be adding your own column and if you need a column that another extension has created (very dangerous practice) then you check if the extension is installed.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: table_column_exists

Post by canonknipser »

In addition to david: if you need a column added by a specific phpBB core version or a specific extension version, use the depends_on function in your migration and check for the migration which added that column
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
Sajaki
Registered User
Posts: 1390
Joined: Mon Mar 02, 2009 1:41 pm
Location: Amsterdam
Contact:

Re: table_column_exists

Post by Sajaki »

david63 wrote: Sun Jun 17, 2018 11:01 am Why would you want it?
because reasons.
Sajaki wrote: Sun Jun 17, 2018 10:32 am hi,

in Umil we used to have a handy way of checking if a column exists.

https://wiki.phpbb.com/Umil.table_column_exists

does this exist for extension migrations ?

Code: Select all

 if ($this->db_tools->sql_column_exists($this->table_prefix . 'users', 'extracolumn'))
{
// code here 
}
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: table_column_exists

Post by david63 »

Sajaki wrote: Sun Jun 17, 2018 12:38 pm because reasons.
Obviously, but if you can tell what those reasons are we will be in a better position to help you. If you don't want to give your reasons and have help, then fine - but you will be on your own.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: table_column_exists

Post by canonknipser »

There are some migrations in the core, which use the function sql_column_exists for specific conversion cases, eg. phpBB3/phpbb/db/migration/data/v310/passwords_convert_p1.php

It was just a simple file search in the migrations folder ...
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: table_column_exists

Post by 3Di »

Sajaki wrote: Sun Jun 17, 2018 12:38 pm
Sajaki wrote: Sun Jun 17, 2018 10:32 am hi,

in Umil we used to have a handy way of checking if a column exists.

https://wiki.phpbb.com/Umil.table_column_exists

does this exist for extension migrations ?

Code: Select all

 if ($this->db_tools->sql_column_exists($this->table_prefix . 'users', 'extracolumn'))
{
// code here 
}
https://github.com/phpBB-Studio/DateTop ... ma.php#L18

Edit: wrong link.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Extension Writers Discussion”