#include "../dbapi2/dbapi2.h"
#include "../core/error.h"
+#include "../core/nsmalloc.h"
#include "trusts.h"
extern DBAPIConn *trustsdb;
if(migration)
return 1;
- cbd = malloc(sizeof(struct callbackdata));
+ cbd = nsmalloc(POOL_TRUSTS, sizeof(struct callbackdata));
if(!cbd)
return 2;
migration = migration_start(tm_group, tm_host, tm_final, cbd);
if(!migration) {
- free(cbd);
+ nsfree(POOL_TRUSTS, cbd);
return 3;
}
} else {
if(!r->success) {
Error("trusts", ERR_ERROR, "A error occured executing the rename table query.");
- errcode = 100;
+ errcode = MIGRATION_LASTERROR;
} else {
Error("trusts", ERR_INFO, "Migration table copying complete.");
}
if(cbd->callback)
cbd->callback(errcode, cbd->tag);
- free(cbd);
+ nsfree(POOL_TRUSTS, cbd);
}
static void tm_final(void *tag, int errcode) {
Error("trusts", ERR_ERROR, "Migration error: %d", errcode);
if(cbd) {
cbd->callback(errcode, cbd->tag);
- free(cbd);
+ nsfree(POOL_TRUSTS, cbd);
}
} else {
+ trusts_closedb(0);
+
Error("trusts", ERR_INFO, "Migration completed, copying tables...");
-/*
- trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
- "BEGIN TRANSACTION; DROP TABLE ?; ALTER TABLE ? RENAME TO ?; DROP TABLE ?; ALTER TABLE ? RENAME TO ?; COMMIT;",
- "TTsTTs", "groups", "migration_groups", "groups", "hosts", "migration_hosts", "hosts");
-*/
-/*
- trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
- "BEGIN TRANSACTION; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; COMMIT;",
- "TTTTTT", "groups", "groups", "migration_groups", "hosts", "hosts", "migration_hosts");
-*/
-/*
- trustsdb->query(trustsdb, cbd?tm_complete:NULL, cbd,
- "DELETE FROM ?; INSERT INTO ? SELECT * FROM ?; DELETE FROM ?; INSERT INTO ? SELECT * FROM ?;",
- "TTTTTT", "groups", "groups", "migration_groups", "hosts", "hosts", "migration_hosts");
-*/
+
trustsdb->squery(trustsdb, "BEGIN TRANSACTION", "");
trustsdb->squery(trustsdb, "DROP TABLE ?", "T", "groups");
trustsdb->squery(trustsdb, "ALTER TABLE ? RENAME TO ?", "Ts", "migration_groups", "groups");