From 695afd0dc2e85ec39d1e48d98b22f9da32499028 Mon Sep 17 00:00:00 2001 From: danw Date: Thu, 3 Jul 1997 07:52:31 +0000 Subject: [PATCH] Check `strings_id' in the numvalues table at startup. A server crash in the right place could leave it pointing to an already-filled part of the table, which makes the server unable to add new strings to the db until it's fixed. (See [687]-[690] in moira-admin.) --- server/qvalidate.pc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/qvalidate.pc b/server/qvalidate.pc index 91f1f12c..3ed00cd0 100644 --- a/server/qvalidate.pc +++ b/server/qvalidate.pc @@ -533,10 +533,25 @@ int readlock_table(vo) */ } -/* Check the database at startup time. NOT! */ +/* Check the database at startup time. */ void sanity_check_database(void) { + EXEC SQL BEGIN DECLARE SECTION; + int oid, id; + EXEC SQL END DECLARE SECTION; + + /* Sometimes a crash can leave strings_id in numvalues in an + incorrect state. Check for that and fix it. */ + + EXEC SQL SELECT value INTO :oid FROM numvalues WHERE name='strings_id'; + + for (id=oid+1; sqlca.sqlcode==0; id++) + EXEC SQL SELECT string_id INTO :id FROM strings + WHERE string_id=:id; + + if (id!=oid+1) + EXEC SQL UPDATE numvalues SET value=:id-1 WHERE name='strings_id'; } -- 2.45.1