HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


alter_table_field... really an sql question...

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#92048 (In Topic #18476)
Avatar

Community saint

I am working on the 'upgrade' code for the rewards addon, for the next verison will add a table, and also change a table field from text to an integer.

So curious, if you do an alter_table_field, does that wipe out the data in the field completely, or does it try to convert it to the new type and keep it, if it can?

Probably more of an sql question than anything…

Paul
Back to the top
 
Posted
Rating:
#92051
Avatar

No wiping. If converting from a string to a number it might lose representation in the conversion though, for example. I'm not 100% on that – MySQL may complain instead, or it may depend on settings or versions.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#92053
Avatar

Community saint

Ok, thanks.   What I am doing is going from a string to an integer, the string will now be stored in a different table and the integer will be an id reference to a record in that table.

So I can read the table, get all the fields, step through and change the text to the proper id number then alter the table and it will be fine.

Or I can read in, then alter, then do the step through that updates the records with the proper reference id in that altered field.

BTW, is the $upgrade thing in the installation function just sent via what the overall addon is listed as (version is)?

Paul
Back to the top
 
Posted
Rating:
#92054
Avatar

You'd be better off reading the field values, deleting that field, recreating it, then inserting the new values.

That way MySQL doesn't have to do the representation loss itself (what it calls 'truncation'). I think the MySQL strict mode might complain about it.

BTW, is the $upgrade thing in the installation function just sent via what the overall addon is listed as (version is)?

Yes.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#92055
Avatar

Community saint

Allright, thanks.   About the version #, which does it use, the info file in the add-on, or the one stated inside the info() function?

Paul
Back to the top
 
Posted
Rating:
#92057
Avatar

Neither. The point of it is it is the one that used to be in the info function (which was copied to the modules table when the module was last installed/upgraded).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#92059
Avatar

Community saint

Ok… then call me confused.  I made changes, uploaded a new version.   Went to my site and did the install updates to non bundled addons, it did have it selected as one to do, but none of the new code/files are installed at all.

Will go look some more..

Paul
Back to the top
 
Posted
Rating:
#92061
Avatar

Module upgrading is covered in the Code Book, one thing of note is $info['update_require_upgrade']=1; needs setting.

If you'd reimported the addon, I can't say why new files would not have been placed.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#92062
Avatar

Community saint

Figured out the update_required_upgrade thing… all the codebook seems to say is:


Upgrading via the 'install' function

The code in the install function needs to analyse the parameters passed to see if an upgrade is being performed (and from what version) or if a new install is being performed. The code is then structured to act accordingly.
For a new module there is no need to consider how upgrades would happen.


Paul
Back to the top
 
Posted
Rating:
#92073
Avatar

Hmm, very unclear yeah, that was mentioned earlier in the document but not linked. Will fix thx.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: