Skip to content

adding Sub_part info to mySQLi db import/export code#8615

Closed
pollen8 wants to merge 2 commits intojoomla:stagingfrom
pollen8:db-import-export-keylengths
Closed

adding Sub_part info to mySQLi db import/export code#8615
pollen8 wants to merge 2 commits intojoomla:stagingfrom
pollen8:db-import-export-keylengths

Conversation

@pollen8
Copy link
Contributor

@pollen8 pollen8 commented Dec 8, 2015

Allows for export and import of keys with length values

To test:

Run this sql query to create a test table

CREATE TABLE `dbkeytest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
   `fileupload` text,
  PRIMARY KEY (`id`),
  KEY `fb_join_fileupload_INDEX` (`fileupload`(10)) )

In index.php after:

$app = JFactory::getApplication('site');

add:

jimport('joomla.filesystem.file');
$res =  (string) JFactory::getDbo()->getExporter()->from('dbkeytest');
JFile::write(JPATH_SITE . '/tmp/dbkeytest.xml', $res);
echo $res; exit;

refresh your site and you should see a white page, view the page source and you should see.


<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <database name="">
  <table_structure name="dbkeytest">
   <field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" />
   <field Field="fileupload" Type="text" Null="YES" Key="MUL" Extra="" />
   <key Table="dbkeytest" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="id" Collation="A" Sub_part ="" Null="" Index_type="BTREE" Comment="" />
   <key Table="dbkeytest" Non_unique="1" Key_name="fb_join_fileupload_INDEX" Seq_in_index="1" Column_name="fileupload" Collation="A" Sub_part ="10" Null="YES" Index_type="BTREE" Comment="" />
  </table_structure>
 </database>
</mysqldump>

An xml file should also have been saved in /tmp/dbkeytest.xml.

Note that Sub_part ="10" has been added to the key 'fb_join_fileupload_INDEX'

The importer will also work IF you have this PR merged in as well
https://issues.joomla.org/tracker/joomla-cms/7378

To test:

Drop the table dbkeytest

Replace the test code you added to index.php with:

JFactory::getDbo()->getImporter()->from(file_get_contents(JPATH_SITE . '/tmp/dbkeytest.xml'))
		->asXml()->mergeStructure();
exit;

Refresh the browser and you should see that the db table dbkeytest has been re-created in the database and that the key 'fb_join_fileupload_INDEX' has the sub_part applied. ie if you run:

show create table dbkeytest;

the results should be

CREATE TABLE `dbkeytest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fileupload` text,
  PRIMARY KEY (`id`),
  KEY `fb_join_fileupload_INDEX` (`fileupload`(10))
) ENGINE=InnoDB DEFAULT CHARSET=utf8

@wilsonge
Copy link
Contributor

wilsonge commented Dec 8, 2015

Out of interest is this the same behaviour as when you do a xml export in mysql? Which is what these database dumps seem to be based on?

Also can you merge into/rebase on staging in your PR so the unit tests run please?

@cheesegrits
Copy link
Contributor

I have tested this item ✅ successfully on 43e8acb

Output without patch has no Sub_part ...

<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <database name="">
  <table_structure name="dbkeytest">
   <field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" />
   <field Field="fileupload" Type="text" Null="YES" Key="MUL" Extra="" />
   <key Table="dbkeytest" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="id" Collation="A" Sub_part ="" Null="" Index_type="BTREE" Comment="" />
   <key Table="dbkeytest" Non_unique="1" Key_name="fb_join_fileupload_INDEX" Seq_in_index="1" Column_name="fileupload" Collation="A" Null="YES" Index_type="BTREE" Comment="" />
  </table_structure>
 </database>
</mysqldump>

Output with patch is correct ...

<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <database name="">
  <table_structure name="dbkeytest">
   <field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" />
   <field Field="fileupload" Type="text" Null="YES" Key="MUL" Extra="" />
   <key Table="dbkeytest" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="id" Collation="A" Sub_part ="" Null="" Index_type="BTREE" Comment="" />
   <key Table="dbkeytest" Non_unique="1" Key_name="fb_join_fileupload_INDEX" Seq_in_index="1" Column_name="fileupload" Collation="A" Sub_part ="10" Null="YES" Index_type="BTREE" Comment="" />
  </table_structure>
 </database>
</mysqldump>

Couldn't apply PR 7378 automagically (patch tool says it conflicts, which it doesn't really), but after adding the xmlToCreate() function from that PR by hand, the import test worked, with a structure of:

CREATE TABLE `dbkeytest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fileupload` text,
  PRIMARY KEY (`id`),
  KEY `fb_join_fileupload_INDEX` (`fileupload`(10))
) ENGINE=InnoDB DEFAULT CHARSET=utf8

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @cheesegrits


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@pollen8
Copy link
Contributor Author

pollen8 commented Dec 11, 2015

Out of interest is this the same behaviour as when you do a xml export in mysql?

Yes that's the SQL generated by Navicat when I export the table.

I believe I have updated the PR to staging - please let me know if I haven't its not something I have had a lot of experience with and could well have moofed it!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@Eighke
Copy link
Contributor

Eighke commented May 16, 2016

@pollen8 Don't forget PDO importer / exporter. For some reason it doesn't extends mysqli.

@mertozer94
Copy link

I have tested this item 🔴 unsuccessfully on 0c9c7cb

I created the test table with the query and then i added the code but i get this error :
Fatal error: Method JDatabaseExporterMysqli::__toString() must not throw an exception in C:\xampp\htdocs\joomla\index.php on line 0


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@Curtista
Copy link

Curtista commented Aug 2, 2016

I have tested this item ✅ successfully on 0c9c7cb

I followed the test steps which where given to test this patch and I have pretty much the same result that cheesegrits gets.

@icampus


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@brianteeman
Copy link
Contributor

@pollen8

Can you please

Also can you merge into/rebase on staging in your PR so the unit tests run please?

Without that this will never b considered to be merged into core


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@toxic2302
Copy link

I have tested this item ✅ successfully on 0c9c7cb

With your test instructions, my output looks like cheesegrits and Curtista's output. I can export and import the dbkeyset table.

My output at the end of this instructions:

CREATE TABLE `dbkeytest` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `fileupload` text,
 PRIMARY KEY (`id`),
 KEY `fb_join_fileupload_INDEX` (`fileupload`(10))
) ENGINE=InnoDB DEFAULT CHARSET=utf8

@icampus


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8615.

@alikon
Copy link
Contributor

alikon commented Sep 26, 2016

can someone double check this pr with the #__menu table ?

i've got 'Index column size too large. The maximum column size is 767 bytes.

foreach ($columns as $column)
{
$kColumns[] = (string) $column['Column_name'];
$kColumns[] = (string) $column['Column_name'] . $kLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$kLength = (string) $column['Sub_part'];
$kLength = $kLength == '' ? '' : '(' . $kLength . ')';

@alikon
Copy link
Contributor

alikon commented Sep 26, 2016

@pollen8 did you have time to fix conflitcs ?

@ghost
Copy link

ghost commented May 5, 2017

as there is no fix for Conflicts for long Time should this be closed?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/8615.

@brianteeman
Copy link
Contributor

@pollen8 please update this PR otherwise it will have to be closed in a few weeks

@brianteeman
Copy link
Contributor

@franz-wohlkoenig in the past in cases like this I would mark it as information required and then after a few weeks if it wasnt updated I would close it with a message something like "This has been closed due to lack of response to the requests above - it can always be reopened in the future if it is updated"


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/8615.

@ghost
Copy link

ghost commented May 5, 2017

Thanks for Information, will do, @brianteeman

@alikon
Copy link
Contributor

alikon commented May 5, 2017

i've reworked this in #14272

@mbabker
Copy link
Contributor

mbabker commented May 21, 2017

Closing in favor of the updated #14272

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.