Index: /trunk/glueforge/templates/psdb/cleanup.tt
===================================================================
--- /trunk/glueforge/templates/psdb/cleanup.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/cleanup.tt	(revision 5960)
@@ -1,3 +1,3 @@
-void [% table.namespace %]Cleanup(psDB *dbh)
+void [% pkg_namespace %]Cleanup(psDB *dbh)
 {
     psDBCleanup(dbh);
Index: /trunk/glueforge/templates/psdb/cleanup_h.tt
===================================================================
--- /trunk/glueforge/templates/psdb/cleanup_h.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/cleanup_h.tt	(revision 5960)
@@ -2,5 +2,5 @@
  */
 
-void [% table.namespace %]Cleanup(
+void [% pkg_namespace %]Cleanup(
     psDB            *dbh                ///< Database handle
 );
Index: /trunk/glueforge/templates/psdb/code.tt
===================================================================
--- /trunk/glueforge/templates/psdb/code.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/code.tt	(revision 5960)
@@ -7,8 +7,8 @@
 #define MAX_STRING_LENGTH 1024
 
+[% INCLUDE init.tt %]
+[% INCLUDE cleanup.tt %]
 [% FOREACH table = tables -%]
 [% INCLUDE alloc.tt %]
-[% INCLUDE init.tt %]
-[% INCLUDE cleanup.tt %]
 [% INCLUDE createtable.tt %]
 [% INCLUDE droptable.tt %]
Index: /trunk/glueforge/templates/psdb/header.tt
===================================================================
--- /trunk/glueforge/templates/psdb/header.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/header.tt	(revision 5960)
@@ -11,9 +11,9 @@
 /// @{
 
+[% INCLUDE init_h.tt %]
+[% INCLUDE cleanup_h.tt %]
 [% FOREACH table = tables -%]
 [% INCLUDE object_h.tt %]
 [% INCLUDE alloc_h.tt %]
-[% INCLUDE init_h.tt %]
-[% INCLUDE cleanup_h.tt %]
 [% INCLUDE createtable_h.tt %]
 [% INCLUDE droptable_h.tt %]
Index: /trunk/glueforge/templates/psdb/init.tt
===================================================================
--- /trunk/glueforge/templates/psdb/init.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/init.tt	(revision 5960)
@@ -1,3 +1,3 @@
-psDB *[% table.namespace %]Init(const char *host, const char *user, const char *passwd, const char *dbname)
+psDB *[% pkg_namespace %]Init(const char *host, const char *user, const char *passwd, const char *dbname)
 {
     return psDBInit(host, user, passwd, dbname);
Index: /trunk/glueforge/templates/psdb/init_h.tt
===================================================================
--- /trunk/glueforge/templates/psdb/init_h.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/init_h.tt	(revision 5960)
@@ -5,5 +5,5 @@
  */
 
-psDB *[% table.namespace %]Init(
+psDB *[% pkg_namespace %]Init(
     const char      *host,              ///< Database server hostname
     const char      *user,              ///< Database username
Index: /trunk/glueforge/templates/psdb/pop.tt
===================================================================
--- /trunk/glueforge/templates/psdb/pop.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/pop.tt	(revision 5960)
@@ -20,4 +20,10 @@
 
     rowSet = psDBSelectRows(dbh, [% table.namespace FILTER upper %]_TABLE_NAME, NULL, 1);
+    if (!rowSet) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", [% table.namespace FILTER upper %]_INDEX_NAME);
+        psFree(row);
+        return NULL;
+    }
+
     row = psArrayGet(rowSet, 0);
     // FIXME: psArrayGet should increment the ref count
Index: /trunk/glueforge/templates/psdb/popfits.tt
===================================================================
--- /trunk/glueforge/templates/psdb/popfits.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/popfits.tt	(revision 5960)
@@ -3,5 +3,5 @@
     char            query[MAX_STRING_LENGTH];
 
-    if (!fooSelectRowsFits(dbh, fits, NULL, limit)) {
+    if (![% table.namespace %]SelectRowsFits(dbh, fits, NULL, limit)) {
         psError(PS_ERR_UNKNOWN, true, "database error or table is empty");
         return false;
Index: /trunk/glueforge/templates/psdb/top_makefile_am.tt
===================================================================
--- /trunk/glueforge/templates/psdb/top_makefile_am.tt	(revision 5959)
+++ /trunk/glueforge/templates/psdb/top_makefile_am.tt	(revision 5960)
@@ -11,13 +11,15 @@
 [% IF NOT loop.last -%]
     $(top_builddir)/docs/man/man3/[% table.object_name %].3 \
-[% ELSE -%]
+[%- ELSE -%]
     $(top_builddir)/docs/man/man3/[% table.object_name %].3 
 [% END -%]
 [% END %]
 
+docs/man/man3/[% pkg_name %].3
 [%- FOREACH table = tables -%]
-docs/man/man3/[% pkg_name %].3 docs/man/man3/[% table.object_name %].3:
+ docs/man/man3/[% table.object_name %].3
+[%- IF loop.last %]:[% END -%]
+[%- END %]
 	$(DOXYGEN)
-[%- END %]
 
 clean-local:
