changeset 618:3b1fdba9a95c

tj: Implement initial 'delete' command functionality.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 Feb 2021 13:37:35 +0200
parents ce7a666991e3
children cccf72482667
files tj.tcl
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tj.tcl	Wed Feb 10 13:36:56 2021 +0200
+++ b/tj.tcl	Wed Feb 10 13:37:35 2021 +0200
@@ -403,7 +403,26 @@
 
   } elseif {[tj_cmd_match "delete" $rcmd]} {
     # !tj delete <id>
-    tj_msg $upublic $unick $uchan "help_delete"
+    if {![utl_arg_get $rarglist rindex uid 0]} {
+      tj_msg $upublic $unick $uchan "help_delete"
+      return 1
+    }
+
+    set usql "SELECT COUNT(*) FROM tj WHERE uuser='[utl_escape $uhand]' AND uid LIKE '[utl_escape $uid]'"
+    if {[catch {set nitems [tj_dbh onecolumn $usql]} uerrmsg]} {
+      tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg]
+      tj_log "$uerrmsg on SQL:\n$usql"
+      return 1
+    }
+
+    set usql "DELETE FROM tj WHERE uuser='[utl_escape $uhand]' AND uid LIKE '[utl_escape $uid]'"
+    if {[catch {set ndone [tj_dbh onecolumn $usql]} uerrmsg]} {
+      tj_msg $upublic $unick $uchan "err_sql" [list $uerrmsg]
+      tj_log "$uerrmsg on SQL:\n$usql"
+      return 1
+    }
+
+    tj_msg $upublic $unick $uchan "items_deleted" [list $uid $nitems]
   } elseif {[tj_cmd_match "show" $rcmd]} {
     # !tj show [#id] <name>
     # Check for #id prefix