~ubuntu-branches/ubuntu/hardy/steam/hardy

« back to all changes in this revision

Viewing changes to tools/dbcopy

  • Committer: Bazaar Package Importer
  • Author(s): Alain Schroeder
  • Date: 2006-11-21 16:03:12 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061121160312-nf96y6nihzsyd2uv
Tags: 2.2.31-3
Add patch to prevent inconsistent data after shutdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!../steam
 
2
 
 
3
void main(int argc, array argv)
 
4
{
 
5
  string db = "mysql://steam:steam@localhost/steam";
 
6
  if ( sizeof(argv) != 4 ) {
 
7
    werror("Usage is dbcopy mysql-handle from-oid to-oid\n");
 
8
    return;
 
9
  }
 
10
  db = argv[1];
 
11
  werror("Database is %O\n", db);
 
12
  object handle = Sql.Sql(db);
 
13
  werror("Copying " + argv[2] + " to " + argv[3]+"\n");
 
14
  copy_object((int)argv[2], (int)argv[3], handle);
 
15
 
 
16
}
 
17
 
 
18
static void copy_object(int fromid, int toid, Sql.Sql handle)
 
19
{
 
20
  mixed row, res, err;
 
21
        
 
22
  werror("Inserting Class ... ");
 
23
  mapping cresult = handle->query("select * from ob_class where ob_id="+fromid)[0];
 
24
  handle->query("delete from ob_class where ob_id=" + toid);
 
25
  handle->query("insert into ob_class values('" + toid + "'," + handle->quote(cresult->ob_class)+")");
 
26
  werror(" done\n");
 
27
 
 
28
 
 
29
  handle->big_query("delete from ob_data where ob_id='"+ toid+"'");
 
30
  res = handle->big_query("select ob_id, ob_ident, ob_attr, ob_data from ob_data where ob_id='"+fromid+"'");
 
31
  
 
32
 
 
33
  if ( !res ) {
 
34
    werror("no result !");
 
35
    return;
 
36
  }
 
37
  while ( row = res->fetch_row() ) {
 
38
    if ( arrayp(row) ) {
 
39
      werror("COPY: %O\n", row);
 
40
      string q = sprintf("insert into ob_data values (%d, '%s', '%s', '%s')",
 
41
                         toid, row[1], row[2], handle->quote(row[3]));
 
42
      string c = sprintf("delete from ob_data where ob_id='%d' and ob_ident='%s' \
 
43
                          and ob_attr='%s'", (int)toid, row[1], row[2]);
 
44
      err = catch {
 
45
        handle->query(c);
 
46
        handle->query(q);
 
47
      };
 
48
      if ( err != 0 ) {
 
49
        werror("Error: %O\n", err);
 
50
      }
 
51
    }
 
52
  }
 
53
}