diff --git a/controller/SqliteNetworkController.cpp b/controller/SqliteNetworkController.cpp index b5d949e52..b9c6d269c 100644 --- a/controller/SqliteNetworkController.cpp +++ b/controller/SqliteNetworkController.cpp @@ -184,9 +184,9 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) : ||(sqlite3_prepare_v2(_db,"DELETE FROM IpAssignment WHERE networkId = ? AND nodeId IS NULL AND \"type\" = ?",-1,&_sDeleteLocalRoutes,(const char **)0) != SQLITE_OK) /* Relay */ - ||(sqlite3_prepare_v2(_db,"SELECT nodeId,phyAddress FROM Relay WHERE networkId = ? ORDER BY nodeId ASC",-1,&_sGetRelays,(const char **)0) != SQLITE_OK) + ||(sqlite3_prepare_v2(_db,"SELECT \"address\",\"phyAddress\" FROM Relay WHERE \"networkId\" = ? ORDER BY \"address\" ASC",-1,&_sGetRelays,(const char **)0) != SQLITE_OK) ||(sqlite3_prepare_v2(_db,"DELETE FROM Relay WHERE networkId = ?",-1,&_sDeleteRelaysForNetwork,(const char **)0) != SQLITE_OK) - ||(sqlite3_prepare_v2(_db,"INSERT INTO Relay (networkId,nodeId,phyAddress) VALUES (?,?,?)",-1,&_sCreateRelay,(const char **)0) != SQLITE_OK) + ||(sqlite3_prepare_v2(_db,"INSERT INTO Relay (\"networkId\",\"address\",\"phyAddress\") VALUES (?,?,?)",-1,&_sCreateRelay,(const char **)0) != SQLITE_OK) /* Member */ ||(sqlite3_prepare_v2(_db,"SELECT rowid,authorized,activeBridge FROM Member WHERE networkId = ? AND nodeId = ?",-1,&_sGetMember,(const char **)0) != SQLITE_OK) @@ -205,7 +205,7 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) : /* Config */ ||(sqlite3_prepare_v2(_db,"SELECT \"v\" FROM \"Config\" WHERE \"k\" = ?",-1,&_sGetConfig,(const char **)0) != SQLITE_OK) - ||(sqlite3_prepare_v2(_db,"INSERT OR REPLACE INTO \"Config\" (\"k\",\"v\") VALUES (?,?)",-1,&_sSetConfig,(const char **)0) != SQLITE_OK) + ||(sqlite3_prepare_v2(_db,"INSERT INTO \"Config\" (\"k\",\"v\") VALUES (?,?)",-1,&_sSetConfig,(const char **)0) != SQLITE_OK) ) { //printf("!!! %s\n",sqlite3_errmsg(_db)); @@ -227,7 +227,7 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) : sqlite3_reset(_sSetConfig); sqlite3_bind_text(_sSetConfig,1,"instanceId",10,SQLITE_STATIC); sqlite3_bind_text(_sSetConfig,2,instanceId,32,SQLITE_STATIC); - if (sqlite3_step(_sSetConfig) != SQLITE_OK) { + if (sqlite3_step(_sSetConfig) != SQLITE_DONE) { sqlite3_close(_db); throw std::runtime_error("SqliteNetworkController unable to read or initialize instanceId"); } diff --git a/controller/schema.sql b/controller/schema.sql index c3eec234d..e85785b75 100644 --- a/controller/schema.sql +++ b/controller/schema.sql @@ -67,12 +67,11 @@ CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision CREATE TABLE Relay ( networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE, - nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE, - phyAddress varchar(64) NOT NULL, - PRIMARY KEY (networkId, nodeId) + address char(10) NOT NULL, + phyAddress varchar(64) NOT NULL ); -CREATE INDEX Relay_networkId ON Relay (networkId); +CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address); CREATE TABLE Rule ( networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE, diff --git a/controller/schema.sql.c b/controller/schema.sql.c index 78123db4e..efeb280ce 100644 --- a/controller/schema.sql.c +++ b/controller/schema.sql.c @@ -68,12 +68,11 @@ "\n"\ "CREATE TABLE Relay (\n"\ " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\ -" nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,\n"\ -" phyAddress varchar(64) NOT NULL,\n"\ -" PRIMARY KEY (networkId, nodeId)\n"\ +" address char(10) NOT NULL,\n"\ +" phyAddress varchar(64) NOT NULL\n"\ ");\n"\ "\n"\ -"CREATE INDEX Relay_networkId ON Relay (networkId);\n"\ +"CREATE UNIQUE INDEX Relay_networkId_address ON Relay (networkId,address);\n"\ "\n"\ "CREATE TABLE Rule (\n"\ " networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\