* On 29 May 2009, Roger Oberholtzer wrote: 
> 
> On Fri, 2009-05-29 at 08:50 -0500, David Champion wrote:
> > * On 29 May 2009, Roger Oberholtzer wrote: 
> > > 
> > > 2. Convert all the text to [wiki:TestProcedureTicket104] This is
> > > probably the most straight forward. But, as the subject suggests, I
> > > wonder if there is a way to do this to all tickets with this variable in
> > > a single script. It would make my life much easier. Otherwise I have a
> > > marathon editing session.
> > 
> > If I understand correctly, you can do this in a single SQL statement
> > on your database:
> > 
> > UPDATE ticket_custom
> >   SET value = '[wiki:' || value || ']'
> >   WHERE name = 'customVariable';
> > 
> > You might want to do this on a copy of the database as a trial run.
> 
> This seems right. Two questions: (1) 'customVariable' is the name of my
> variable, like 'tc_ten', right? (2) I an using the sqlite database
> (IIRC). Where would I execute this command?

Correct.  I use sqlite as well.  Here's what I would do (assuming a
Unix-ish environment) as the user who owns the trac installation:

At your shell prompt (sh$):
sh$ cd /path/to/trac/env
sh$ cd db
sh$ echo .dump | sqlite3 trac.db >trac.dump
sh$ sqlite3 trac.db
SQLite version 3.2.2
Enter ".help" for instructions
sqlite> BEGIN TRANSACTION;
sqlite> SELECT ticket, value FROM ticket_custom where name = 'tc_ten';

You should see a table of ticket numbers with their custom 'tc_ten' values
if 'tc_ten' is the name of your custom field.

sqlite> UPDATE ticket_custom
   ...> SET value = '[wiki:' || value || ']'
   ...> WHERE name = 'tc_ten';

sqlite> SELECT ticket, value FROM ticket_custom where name = 'tc_ten';

This is the same query as above, to confirm that changes were made correctly.

sqlite> COMMIT;

'COMMIT' saves the changes.  Use 'ROLLBACK;' instead if the UPDATE was
incorrect.

Using the BEGIN TRANSACTION/COMMIT/ROLLBACK lets you revert changes at
the database level if the UPDATE was wrong, so to that extent the backup
copy of your database isn't strictly necessary.  I would do it anyway:
perhaps you make the changes you wanted to make, but once you view
the tickets in Trac it turns out that it doesn't address your problem
ideally.  Rolling back at this point is simpler if you can just reload
the database:

sh$ mv trac.db trac.db.bad
sh$ echo '.load trac.dump' | sqlite3 trac.db

-- 
 -D.    [email protected]    NSIT    University of Chicago

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to