--- motion-20060109-051002/motion.c	2006-01-09 05:10:03.000000000 +0100
+++ motion-20060109-051002-fix-first-event-mysql/motion.c	2006-01-09 18:52:18.000000000 +0100
@@ -569,6 +569,16 @@ static void motion_init(struct context *
 	}
 #endif /* HAVE_PGSQL */
 
+
+#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL)
+	/* Set the sql mask file according to the SQL config options*/ 
+	
+	cnt->sql_mask = cnt->conf.sql_log_image * (FTYPE_IMAGE + FTYPE_IMAGE_MOTION) +
+			cnt->conf.sql_log_snapshot * FTYPE_IMAGE_SNAPSHOT +
+			cnt->conf.sql_log_mpeg * (FTYPE_MPEG + FTYPE_MPEG_MOTION) +
+			cnt->conf.sql_log_timelapse * FTYPE_MPEG_TIMELAPSE;
+#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) */
+	
 	/* Load the mask file if any */
 	if (cnt->conf.mask_file) {
 		if ((picture = fopen(cnt->conf.mask_file, "r"))) {
