If there is no row in the server_settings table, use a default value
authorrich <rich>
Mon, 27 Sep 2004 09:46:00 +0000 (09:46 +0000)
committerrich <rich>
Mon, 27 Sep 2004 09:46:00 +0000 (09:46 +0000)
instead of crashing horribly.

scripts/cocanwiki_server_settings.ml

index cb4212a..e8c7813 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_server_settings.ml,v 1.1 2004/09/23 15:16:21 rich Exp $
+ * $Id: cocanwiki_server_settings.ml,v 1.2 2004/09/27 09:46:00 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,17 +36,21 @@ open Printf
  * opportunity, in a request context, and cache the results.
  *)
 let server_settings_version, server_settings_stats_page =
+  let default = 1, None in
   let settings = ref None in
   let get_settings (dbh : Dbi.connection) =
     let sth = dbh#prepare "select version, stats_page from server_settings" in
     sth#execute [];
     let s =
-      match sth#fetch1 () with
-       | [ `Int version; (`String _ | `Null) as stats_page ] ->
-           let stats_page =
-             match stats_page with `String s -> Some s | `Null -> None in
-           version, stats_page
-       | _ -> assert false in
+      try
+       (match sth#fetch1 () with
+          | [ `Int version; (`String _ | `Null) as stats_page ] ->
+              let stats_page =
+                match stats_page with `String s -> Some s | `Null -> None in
+              version, stats_page
+          | _ -> assert false)
+      with
+         Not_found -> default in
     sth#finish ();
     settings := Some s;
     s