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.)
*/
}
-/* 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';
}