Using Flexigrid with MySQL field carriage returns

Problem
You want to use flexigrid with a MySQL fields that contains carriage returns. As the flexigrid uses json it doesn’t work with carriage returns, and displays an empty page, instead of an error page.

Solution
In the page_name.json.erb file in the fields that has carriage returns make sure that you use to_json method as in the example below:

‘<%=fg_escape event.comments.to_json -%>‘,

Mandriva – Rails 2.3.2 – mysql gem – ‘ERROR: Error installing mysql’

Problem
You are trying to install the mysql gem in Mandriva, but it fails with error messages:

ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension...
checking for mysql_query() in -lmysclient... no ....

Solution
After searching in google, with solutions about providing different options (– –with-mysql-config, ..etc), even trying different combinations for providing the client library path, the configuration file, or the header file path, was still faced with the same error installing the mysql gem.
As the Mandriva installation was quite new, it turns out to be a couple of missing packages.
So try:

urpmi gcc
urpmi make

and run:

gem install mysql

again.

It should work out ok install the gem and output:

Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed

Comparing data from two big MySQL tables

Problem
You have two big tables in MySQL (>640K records), that maybe differ in the number of fields, but you want to make sure that the data in the common fields in both tables are the same.

Solution

  1. Use mysql to export the data from the first table in a csv file, selecting only the common fields.
    We use the /tmp folder on the server to make sure we have the right permissions to create the file:

    mysql>SELECT common_field1, common_field2, ... 
    INTO OUTFILE '/tmp/first_table.txt'
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    FROM table1;
  2. If the tables are in different databases remember to switch db:
    use seconddb;

    Export the second table in the second file:

    mysql>SELECT common_field1, common_field2, ... 
    INTO OUTFILE '/tmp/second_table.txt'
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    FROM table2;
  3. now use the diff. You can use any of the following options:
    • diff -q first_table.txt second_table.txt
    • diff first_table.txt second_table.txt > diff.txt

Converting Paradox tables to MySQL sql in Linux

Problem
You want to convert some legacy tables created in Paradox (.db, .px) to another format so you can use it in MySQL.

Solution
Download the px tools from here.

Follow the instructions, in the INSTALL file after you untar the file.
You should have to do the usual three step linux installation:

configure
make
sudo make install

Afterwards to make sure that the .db file is a paradox file run:

pxinfo -f  path/to/paradox/db/file.db

The program should read the header and report back with something along the lines:

File-Version: Paradox 7.x
Filetype: indexed .DB
....

To export each Paradox db file to an sql statement run the following:

pxsqldump -d mysql -f path/to/paradox/file.db > path/to/mysql/exported/file.sql

File column plugin with ActiveScaffold upload branch

When using the file_column plugin in the active_scaffold upload branch, the documentation in the file_column doesn’t make it clear what we have to change to make it work.

In the example below the model is number and the file_column is intro.

1. In models/number.rb add:

file_column :intro

2. in controllers/numbers_controller.rb, make sure we have:

config.create.multipart = true
config.update.multipart = true

3. in helpers/numbers_helper.rb add:

def intro_form_column(record, input name)
  file_column_field 'record', :intro
end

def intro_column(record)
  record.intro ? link_to(File.basename(record.intro),
    url_for_file_column(record,'intro'), :popup => true) : "-"
end

4. in views/numbers/_intro_form_column.rhtml add:


  <%= file_column_field  'record', 'intro' %>