Have sqlite3_wal_checkpoint() populate the database handle error message and error code (as returned by sqlite3_errmsg() and sqlite3_errcode()).

FossilOrigin-Name: ff234cf574c7ae384ab1ebc79b2171ef0541bc91
diff --git a/src/main.c b/src/main.c
index f6a343e..2767878 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1254,12 +1254,14 @@
   }
   if( iDb<0 ){
     rc = SQLITE_ERROR;
+    sqlite3Error(db, SQLITE_ERROR, "unknown database: %s", zDb);
   }else{
     rc = sqlite3Checkpoint(db, iDb);
+    sqlite3Error(db, rc, 0);
   }
   sqlite3_mutex_leave(db->mutex);
 
-  return rc;
+  return sqlite3ApiExit(db, rc);
 }
 
 /*
diff --git a/src/test1.c b/src/test1.c
index b5fda95..0a886e9 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -4868,6 +4868,35 @@
 }
 #endif
 
+/*
+** tclcmd:  sqlite3_wal_checkpoint db ?NAME?
+*/
+static int test_wal_checkpoint(
+  ClientData clientData, /* Unused */
+  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
+  int objc,              /* Number of arguments */
+  Tcl_Obj *CONST objv[]  /* Command arguments */
+){
+  char *zDb = 0;
+  sqlite3 *db;
+  int rc;
+
+  if( objc!=3 && objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "DB ?NAME?");
+    return TCL_ERROR;
+  }
+
+  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
+    return TCL_ERROR;
+  }
+  if( objc==3 ){
+    zDb = Tcl_GetString(objv[2]);
+  }
+  rc = sqlite3_wal_checkpoint(db, zDb);
+  Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
+  return TCL_OK;
+}
+
 
 /*
 **     tcl_objproc COMMANDNAME ARGS...
@@ -5089,6 +5118,7 @@
 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
      { "sqlite3_unlock_notify", test_unlock_notify, 0  },
 #endif
+     { "sqlite3_wal_checkpoint", test_wal_checkpoint, 0  },
   };
   static int bitmask_size = sizeof(Bitmask)*8;
   int i;