3
void main(int argc, array argv)
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");
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);
18
static void copy_object(int fromid, int toid, Sql.Sql handle)
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)+")");
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+"'");
34
werror("no result !");
37
while ( row = res->fetch_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]);
49
werror("Error: %O\n", err);