<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://openconcept.ca" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>MySQL</title>
 <link>http://openconcept.ca/code/mysql</link>
 <description>The taxonomy view with a depth of 0.</description>
 <language>en</language>
<item>
 <title>Create RSS Feeds of Search Results with Views 2</title>
 <link>http://openconcept.ca/blog/varun/create_rss_feeds_for_search_results_with_views_2</link>
 <description>&lt;p&gt;Recently, while working at requirements for a Government client I was tasked with finding a way to create rss feeds for site wide searches. Here, I&#039;ve decided to share this solution with the wider community.&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;RSS Search&quot; src=&quot;/sites/openconcept.ca/files/teaser_rssSearch.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Being able to subscribe to search results with RSS is useful to sites such as &lt;a href=&quot;http://twitter.com&quot;&gt;twitter.com&lt;/a&gt; where there is a large amount of content or frequently updated information. When a user may only be interested in a small sub-set of all this information, it may be useful to offer them an RSS feed. RSS feeds help to make it more convenient for people to stay up to date with changes to content on a website.&lt;/p&gt;
&lt;p&gt;To accomplish this, I&#039;ve used &lt;a href=&quot;http://drupal.org/project/views&quot;&gt;Views 2&lt;/a&gt; to create a new search page for performing a site wide search. In addition to views, the following modules also had to be enabled: PHP input filter, Search, and Views UI. In this example, I&#039;ve used the &lt;a href=&quot;http://drupal.org/project/devel&quot;&gt;devel&lt;/a&gt; generate module to generate a large set of nodes on which to test my search.&lt;/p&gt;
&lt;h3&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Step 1&lt;/span&gt;. Build the page view&lt;/h3&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;RSS Search Page&quot; src=&quot;/sites/openconcept.ca/files/view_page.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The page view will replace the core search module&#039;s search block and page. Begin by creating a new page view. As fields, add &amp;quot;Node: Title&amp;quot; and &amp;quot;Node: Teaser&amp;quot;. As filters, use &amp;quot;Node: Published&amp;quot; and the important one, &amp;quot;Search: Search Terms&amp;quot;. This search filter hooks into the drupal core search and must be &lt;span style=&quot;font-weight: bold;&quot;&gt;exposed&lt;/span&gt; to allow users to enter search terms. I&#039;ve set the path as &#039;search-site&#039;. It is also advisable to turn the pager on(It comes in handy later).&lt;/p&gt;
&lt;p&gt;Add &amp;quot;Search: Score&amp;quot; under sort criteria and ensure it is set to descending.&lt;/p&gt;
&lt;p&gt;Note that search results are only indexed when CRON is run. If you are not seeing any results, please run cron.&lt;/p&gt;
&lt;p&gt;Since we want to direct users to our new search page, the core search block should be disabled.&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;RSS Search Page&quot; src=&quot;/sites/openconcept.ca/files/core_and_searchPage.png&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Step 2&lt;/span&gt;. Build the rss view&lt;/h3&gt;
&lt;p&gt;Next, we add a feed display to the view. Most of the settings will be the same as those of the page view, however, in addition, we must also set &amp;quot;RSS Feed&amp;quot; as the Style and &amp;quot;Node&amp;quot; as the Row Style(under basic settings). I&#039;ve set this path as &#039;search-rss&#039;.&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;The RSS Page&quot; src=&quot;/sites/openconcept.ca/files/view_rss.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Step 3&lt;/span&gt;. The PHP used to tie them together.&lt;/h3&gt;
&lt;p&gt;So at this point we have two pages we can look at, YOURDOMAIN/search-site and YOURDOMAIN/search-rss.&amp;nbsp; Both of their content changes based on text which is passed in through the URL where &amp;quot;keys&amp;quot; is set as some text after the ? in the URL.&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;The RSS Page&quot; src=&quot;/sites/openconcept.ca/files/addrBar.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;To put these two pages together we must create a link from the &#039;search-site&#039; page to the &#039;search-rss&#039; page so that variables that are being passed in through the URL are preserved. To do this I&#039;ve added the following PHP to the header of the views page that was set up.&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;The PHP code&quot; src=&quot;/sites/openconcept.ca/files/view_php.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;geshifilter&quot;&gt;&amp;nbsp;&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $view = views_get_current_view();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $rss_url = &#039;search-rss?keys=&#039;.$view-&amp;gt;exposed_input[&#039;keys&#039;];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $rss_icon = theme_feed_icon( $rss_url , $view-&amp;gt;exposed_input[&#039;keys&#039;]);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; echo &amp;quot;&amp;lt;div&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; echo &amp;quot;&amp;lt;p&amp;gt;Current search yields &amp;quot;.$view-&amp;gt;total_rows .&amp;quot; results. &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;quot; .&amp;quot;&amp;lt;br/&amp;gt;Save your search and get periodic updates &amp;quot;.$rss_icon ; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; echo &#039;&amp;lt;span&amp;gt;&amp;lt;a href=&amp;quot;http://www.whatisrss.com&amp;quot;&amp;gt; &amp;nbsp; [What is this?]&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; echo &amp;quot;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
?&amp;gt; &lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The code simply grabs the current view&#039;s exposed input (&amp;quot;keys&amp;quot;) and creates a link to the rss page. theme_feed_icon() creates that nice orange RSS symbol for me.&lt;/p&gt;
&lt;p&gt;The variable $view-&amp;gt;total_rows is only available when pagination is enabled.&lt;/p&gt;
&lt;p&gt;The result is a new search page for the site that will also give you an rss feed based on the terms that were searched for.&lt;/p&gt;
&lt;p&gt;An export of the view is &lt;a href=&quot;/sites/openconcept.ca/files/site_search_view.txt&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here are two more screenshots:&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;The PHP code&quot; src=&quot;/sites/openconcept.ca/files/searchPage.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img align=&quot;top&quot; alt=&quot;The PHP code&quot; src=&quot;/sites/openconcept.ca/files/eg_rss.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
 <enclosure url="http://openconcept.ca/sites/openconcept.ca/files/site_search_view.txt" length="5659" type="text/plain" />
 <category domain="http://openconcept.ca/taxonomy/term/208">Community</category>
 <category domain="http://openconcept.ca/code/drupal_6x">Drupal 6.x</category>
 <category domain="http://openconcept.ca/code/mysql">MySQL</category>
 <category domain="http://openconcept.ca/code/php">PHP</category>
 <category domain="http://openconcept.ca/topic/rss">RSS</category>
 <category domain="http://openconcept.ca/topic/views">Views</category>
 <pubDate>Mon, 09 Nov 2009 17:07:39 -0500</pubDate>
 <dc:creator>Varun</dc:creator>
 <guid isPermaLink="false">2358 at http://openconcept.ca</guid>
</item>
<item>
 <title>Splitting up Unweildy Database Dumps/Exports</title>
 <link>http://openconcept.ca/blog/ethan/splitting_up_unweildy_database_exports</link>
 <description>&lt;p&gt;I recently found myself in possession of a huge (~1.5GB) MySQL dump that I needed to restore after a system reinstall. When a text file gets this large, it is very difficult to edit or even view, as text editors simply can&#039;t handle the size. Fortunately, I figured out a simple way of separating the single file into separate databases that could be viewed or imported individually. It works because a typical database dump first creates the database, then the tables, then inserts the data into those tables. It does this sequentially, for one database at a time. My solution simply uses the csplit (Standard in GNU/Linux, OS X) and a regular expression searching for lines starting with &quot;CREATE DATABASE&quot;.
&lt;/p&gt;
&lt;div class=&quot;geshifilter&quot;&gt;csplit &lt;span style=&quot;color: #660033;&quot;&gt;-k&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-f&lt;/span&gt; db &lt;span style=&quot;color: #660033;&quot;&gt;-n&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;2&lt;/span&gt; dump.sql &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/^CREATE DATABASE.*$/&#039;&lt;/span&gt; &lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;
The arguments are well documented, but the important one is the regular expression, &#039;/^CREATE DATABASE.*$/&#039;. You&#039;ll see a number of files titled db00, db01, etc. which contain the SQL queries required to restore one complete database.
&lt;/p&gt;&lt;p&gt;
You can then use phpMyAdmin or the mysql command-line to individually import each database. If these prove unsuccessful, a php script named &lt;a href=&quot;http://www.ozerov.de/bigdump.php&quot;&gt;BigDump&lt;/a&gt; might be of use.
&lt;/p&gt;</description>
 <comments>http://openconcept.ca/blog/ethan/splitting_up_unweildy_database_exports#comments</comments>
 <category domain="http://openconcept.ca/topic/csplit">Csplit</category>
 <category domain="http://openconcept.ca/code/mysql">MySQL</category>
 <category domain="http://openconcept.ca/code/shell_script">Shell commands/scripts</category>
 <category domain="http://openconcept.ca/taxonomy/term/205">Support</category>
 <pubDate>Tue, 23 Oct 2007 13:26:11 -0400</pubDate>
 <dc:creator>ethan</dc:creator>
 <guid isPermaLink="false">634 at http://openconcept.ca</guid>
</item>
<item>
 <title>Troubleshooting MySQL Dumps and Imports</title>
 <link>http://openconcept.ca/mysql_dumps_and_imports</link>
 <description>&lt;p&gt;
The various versions of MySQL are more or less compatible with one another, but problems arise pretty regularly, especially when it comes to moving between versions of MySQL. Here are some notes about common MySQL dumping and importing issues, particularly those relevant to Back-End, Drupal, and CiviCRM.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Reserved words&lt;/strong&gt;
&lt;/p&gt;
Reserved words can change from release to release. Problems with reserved words in table and field names (BE has a few) can be solved by adding --quote-names to the mysqldump command:&lt;/p&gt;
&lt;div class=&quot;geshifilter&quot;&gt;mysqldump &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;--opt --all-databases --quote-names -u username -p &amp;amp;gt; dump_file_name&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;
&lt;strong&gt;InnoDB problems&lt;/strong&gt;
&lt;/p&gt;
Problems also arise with older versions of mysqldump when there are InnoDB tables with foreign keys (as in the case of CiviCRM). The problem is that the foreign key must exist and be indexed, which might not yet be the case on an import. The MySQL manual notes that if mysql dump doesn&amp;#39;t include a statement disabling foreign key checking, then it can be done manually from the mysql CLI as follows:&lt;/p&gt;
&lt;div class=&quot;geshifilter&quot;&gt;mysql&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SET&lt;/span&gt; F&lt;span style=&quot;color: #66cc66;&quot;&gt;OR&lt;/span&gt;EIGN_KEY_CHECKS &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; 0;&lt;br /&gt;
mysql&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; SOURCE dump_file_name;&lt;br /&gt;
mysql&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SET&lt;/span&gt; F&lt;span style=&quot;color: #66cc66;&quot;&gt;OR&lt;/span&gt;EIGN_KEY_CHECKS &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;h3&gt;Upgrades&lt;/h3&gt;
&lt;p&gt;The above steps will already help with this, but importing data from an older version of MySQL into a newer requires using some additional tools to make sure the tables are correctly updated to the new specs. The latest versions of MySQL (5.0.19+) offer the mysql_upgrade command that does this. If it&amp;#39;s not available (as was recently the case on MySQL 5.0.18 on SUSE 10.1), run these commands:&lt;/p&gt;
&lt;div class=&quot;geshifilter&quot;&gt;mysqlcheck &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;--check --all-databases --auto-repair&lt;/span&gt;&lt;br /&gt;
mysql_fix_privilege_tables&lt;/div&gt;
&lt;h3&gt;Auto increment&lt;/h3&gt;
&lt;p&gt;Apparently the versions of mysqldump included with MySQL versions 3.23 and 4.0 don&amp;#39;t properly mark autoincrement fields, which can wreak havok with Drupal installs. Fortunately, there is a simple fix for this problem in Drupal here: &lt;a href=&quot;http://drupal.org/node/65665&quot;&gt;http://drupal.org/node/65665&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Another autoincrement problem arises when the value &amp;#39;0&amp;#39; (zero) is inserted into an autoincrement field; by default, MySQL attempts to set this field to &amp;#39;1&amp;#39; (one), which can cause problems if a subsequent statement also tries to insert that value. The workaround for this is to temporarily turn off MySQL&amp;#39;s usual handling of autoinsert fields with the statement SET sql_mode=&amp;#39;NO_AUTO_VALUE_ON_ZERO&amp;#39;.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;I recently combined this with the above fix for foreign key checking as follows:
&lt;/p&gt;
&lt;div class=&quot;geshifilter&quot;&gt;mysql &lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;u root &lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;p &lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;e &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;SET SESSION sql_mode=&#039;NO_AUTO_VALUE_ON_ZERO&#039;; SET FOREIGN_KEY_CHECKS = 0; SOURCE /home/stevem/mysql_all.sql; SET FOREIGN_KEY_CHECKS = 1;&amp;quot;&lt;/span&gt; &lt;/div&gt;
&lt;p&gt;
Passing the SESSION keyword makes it explicit that the sql_mode is set only for this one client connection.&amp;nbsp;
&lt;/p&gt;
</description>
 <comments>http://openconcept.ca/mysql_dumps_and_imports#comments</comments>
 <category domain="http://openconcept.ca/code/mysql">MySQL</category>
 <category domain="http://openconcept.ca/taxonomy/term/205">Support</category>
 <pubDate>Thu, 28 Sep 2006 17:42:46 -0400</pubDate>
 <dc:creator>stevem</dc:creator>
 <guid isPermaLink="false">167 at http://openconcept.ca</guid>
</item>
</channel>
</rss>
