A good number of my consulting clients use the
very useful and powerful survey tool
Limesurvey. Unfortunately, since
version 1.92+, it seems impossible to reimport deactivated responses
tables into new response tables if the survey was modified. I'm sure
this doesn't matter for long form surveys and mainly static surveys, but
some of my clients use this platform as a dynamic form engine. In that
case, forms can and will change over the duration of a project.

To resolve this problem and enable the importation of old responses
tables, I've written a quick Python script. It uses, but that library
should be installed by default on most Linux boxes. The script also
requires a MySQL database backend but it should be easily adaptable to
other database engines.

Before running the script, four variables must be configured:

[sourcecode language="python"]

dbaddr='127.0.0.1' #localhost

dbuser='username' #user name used to access the limesurvey tables

dbpass='password' #password used to access the limesurvey tables

dbdb='limesurveyDB' #limesurvey's database name

[/sourcecode]

After configuring these settings, you should be able to launch the
script. Launching the script with the --help switch will print out the
usage help:

python importOldAnswers.py --help
usage: importOldAnswers.py [-h] [--list SID] [--copy TABLENAME SID]
Import old results in current answer table
optional arguments:
-h, --help show this help message and exit
--list SID list old result table for a given SID
--copy TABLENAME SID copy old table to a new result table

Using the script with the --list SID argument will list all the old
result tables for a given survey id (SID):

From there, you can choose an old result source table to import into an
existing response table:

python importOldAnswers.py --copy lime_old_survey_15946_20130304201731 15946
Copying table lime_old_survey_15946_20130304201731 to lime_survey_15946
Retrieve headers
Number of columns in source table: 228
Number of columns in target table: 229
Number of columns in merged table: 228
Number of answers in source table: 2
Done copying

Now for the caveats: the script will not convert from a data type to
another, it will not truncate data and it will not do any form of sanity
check before inserting data. Never use on a production database, always
work with a copy. If you find a bug, please let me know. I've released
the code with a GPL license, but if that causes a problem let me know.
If you know me in real life and you find that script useful, you can
always buy me a beer! :-)

You can download the code
here, or copy and
paste the following listing: