Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Change table engine for MySQL databases, issue #41 #989

Closed
wants to merge 4 commits into from

2 participants

Shmavon Andrey Andreev
Shmavon

Small functions to allow developers choose table engines. Work with
MySQL and MySQLi drivers (all other ignore it).

The functions are tested, but I will be glad if you perform some more tests on them.
Documentation was "vandalised" by me, hope this will help. :)

Shmavon MunGell Change table engine for MySQL database, issue #41
Small functions to allow developers choose table engines. Works with
MySQL and MySQLi drivers (other ignore it).
67151d0
Andrey Andreev
Owner

Why not just add logic for it in _create_table() and _alter_table()?

Shmavon

It is in _create_table().

_alter_table() function does a bit different tasks (related to content).

There is _rename_table() function, which also uses ALTER TABLE statement and is allocated into separate function.
Thus, I decided to separate table engine definition also.

system/database/drivers/mysqli/mysqli_forge.php
((4 lines not shown))
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set engine of a table
+ *
+ * Generates a platform-specific query so engine of that a table can be changed
+ *
+ * @access private
+ * @param string the table name
+ * @param string the table engine
+ * @return string
+ */
+ function _set_table_engine($table_name, $engine)
+ {
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' ENGINE '.$engine;
Andrey Andreev Owner
narfbg added a note

_protect_identifiers() is supposed to be a protected method, but currently it's public because all the drivers use it for DB forge. There's a protect_identifiers() method (no underscore) that I believe exist solely for this purpose - can we use that instead, please? :)

Also, on a side note - you can directly return that string. There's no point in assigning it and then returning a variable.

Shmavon
MunGell added a note

I used the same coding style as in all other functions in this file. Of course, I can return string directly without additional variable. :) By the way, it might be resonable to do the same with _rename_table() function.

To be honest, protect_identifiers() as well as _protect_identifiers() defined as private ( *@access private ) in annotations and underscored version of the function widely used in the file. So, should I write my functions in different way?

Andrey Andreev Owner
narfbg added a note

Well, they are described as private(and those descriptions are often not correct), but since there's no real definition, the default is public. Those descriptions are currently being removed from all over the place and each of my pending pull requests remove them and put actual definitions instead.

Usually, methods that are prefixed by an underscore are supposed to be private or protected, but protected should be used so that the classes can be easily extendable.

Btw, the mysql driver version that you have has been updated a few hours ago and you should merge the changes first. You'll see that it's a bit different in there. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Andrey Andreev
Owner

@MunGell

Yes, but almost all databases support renaming tables (and some of them have different syntax, not using ALTER TABLE), while this is a MySQL only feature.
We shouldn't pollute the base classes with methods and properties that are not relevant for at least a few of the drivers. And while you can't avoid adding another parameter to create_table(), you can simply use the $fields parameter in _alter_table() and add an if ($alter_type === 'ENGINE') inside it.

Shmavon

@narfbg good point, thanks.

Shmavon

@narfbg your code was merged, some changes done. Take a look ;)

Andrey Andreev
Owner

Um, while manually copying changes technically should work ... it's not the proper way to do that and makes it really hard to review. See this URL for some info on how to do it correctly: http://help.github.com/fork-a-repo/ :)

Shmavon

All copyings have been done particularly in accordance with that manual. :)
I just manually solved a couple of conflicts. Sorry about that.

Andrey Andreev
Owner

This is way too old and didn't have the proper approach anyway. #2776 is way better.

Andrey Andreev narfbg closed this
Andrey Andreev narfbg referenced this pull request from a commit
Andrey Andreev narfbg Add support for optional table attributes to CI_DB_forge::create_table()
Supersedes PRs #989, #2776
Related issue: #41
27f798b
Andrey Andreev
Owner

Anybody who wants this feature, please test the above commit from the feature/dbforge_table_attributes branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 27, 2012
  1. Shmavon

    Change table engine for MySQL database, issue #41

    MunGell authored
    Small functions to allow developers choose table engines. Works with
    MySQL and MySQLi drivers (other ignore it).
  2. Shmavon
  3. Shmavon

    MySQL driver was changed in accordance with suggestions

    MunGell authored
    Waiting for new version of MySQLi driver to change it also.
  4. Shmavon

    MySQLi driver was changed in accordance with suggestions

    MunGell authored
    Now it is ready for tests and possibly for merge.
Something went wrong with that request. Please try again.