Diff
Not logged in

Differences From:

File src/tkt.c part of check-in [a5e4e1ba96] - More work on ticketing. This is a non-working incremental check-in. by drh on 2007-11-24 23:59:47. [view]

To:

File src/tkt.c part of check-in [f394d84560] - Update SQLite to the latest build from CVS. Add in the FTS3 extension, though it is not yet being used. Additional work toward tickets. by drh on 2007-11-25 16:13:52. [view]

@@ -58,8 +58,9 @@
 ** all the values there to zero.
 */
 static void getAllTicketFields(void){
   Stmt q;
+  int i;
   if( nField>0 ) return;
   db_prepare(&q, "PRAGMA table_info(ticket)");
   while( db_step(&q)==SQLITE_ROW ){
     const char *zField = db_column_text(&q, 1);
@@ -75,10 +76,13 @@
   }
   db_finalize(&q);
   qsort(azField, nField, sizeof(azField[0]), nameCmpr);
   azAppend = &azField[nField];
-  memset(azAppend, 0, sizeof(azAppend[0])*nField*2);
+  memset(azAppend, 0, sizeof(azAppend[0])*nField);
   azValue = &azAppend[nField];
+  for(i=0; i<nField; i++){
+    azValue[i] = "";
+  }
 }
 
 /*
 ** Return the index into azField[] of the given field name.
@@ -214,9 +218,9 @@
       db_multi_exec("CREATE TEMP TABLE _pending_ticket(uuid TEXT UNIQUE)");
       db_commit_hook(ticket_rebuild_at_commit, 1);
       isInit = 1;
     }
-    db_multi_exec("INSERT OR IGNORE INTO _pending_ticket"
+    db_multi_exec("INSERT OR IGNORE INTO _pending_ticket "
                   "VALUES(%Q)", p->zTicketUuid);
   }
   blob_reset(&sql);
 }
@@ -316,66 +320,8 @@
   SbS_Render(pInterp, zScript);
   style_footer();
 }
 
-/*
-** Subscript command:   submit_new_ticket
-**
-** If the variable named LABEL exists, then submit a new ticket
-** based on the values of other defined variables.
-*/
-static int submitNewCmd(struct Subscript *p, void *pNotify){
-  const char *zLabel;
-  int nLabel, size;
-  if( SbS_RequireStack(p, 1, "submit_new_ticket") ) return 1;
-  zLabel = SbS_StackValue(p, 0, &nLabel);
-  if( SbS_Fetch(p, zLabel, nLabel, &size)!=0 ){
-    char *zDate, *zUuid;
-    int i;
-    int rid;
-    Blob tktchng, cksum;
-
-    blob_zero(&tktchng);
-    zDate = db_text(0, "SELECT datetime('now')");
-    zDate[10] = 'T';
-    blob_appendf(&tktchng, "D %s\n", zDate);
-    free(zDate);
-    for(i=0; i<nField; i++){
-      const char *zValue;
-      int nValue;
-      zValue = SbS_Fetch(p, azField[i], -1, &nValue);
-      if( zValue ){
-        while( nValue>0 && isspace(zValue[nValue-1]) ){ nValue--; }
-        blob_appendf(&tktchng, "J %s %z\n",
-           azField[i], fossilize(zValue,nValue));
-      }
-    }
-    zUuid = db_text(0, "SELECT lower(hex(randomblob(20)))");
-    blob_appendf(&tktchng, "K %s\n", zUuid);
-    (*(char**)pNotify) = zUuid;
-    blob_appendf(&tktchng, "U %F\n", g.zLogin ? g.zLogin : "");
-    md5sum_blob(&tktchng, &cksum);
-    blob_appendf(&tktchng, "Z %b\n", &cksum);
-
-#if 0
-    @ <hr><pre>
-    @ %h(blob_str(&tktchng))
-    @ </pre><hr>
-    blob_zero(&tktchng)
-    SbS_Pop(p, 1);
-    return SBS_OK;
-#endif
-
-    rid = content_put(&tktchng, 0, 0);
-    if( rid==0 ){
-      fossil_panic("trouble committing ticket: %s", g.zErrMsg);
-    }
-    manifest_crosslink(rid, &tktchng);
-    return SBS_RETURN;
-  }
-  SbS_Pop(p, 1);
-  return SBS_OK;
-}
 
 
 /*
 ** Subscript command:   STRING FIELD append_field
@@ -442,9 +388,9 @@
         }
       }
     }
   }
-  if( *(char**)pUuid==0 ){
+  if( *(char**)pUuid ){
     zUuid = db_text(0,
        "SELECT tkt_uuid FROM ticket WHERE tkt_uuid GLOB '%s*'", P("name")
     );
   }else{
@@ -455,16 +401,16 @@
   blob_appendf(&tktchng, "U %F\n", g.zLogin ? g.zLogin : "");
   md5sum_blob(&tktchng, &cksum);
   blob_appendf(&tktchng, "Z %b\n", &cksum);
 
-#if 1
-  @ <hr><pre>
-  @ %h(blob_str(&tktchng))
-  @ </pre><hr>
-  blob_zero(&tktchng);
-  SbS_Pop(p, 1);
-  return SBS_OK;
-#endif
+  if( strncmp(g.zPath,"debug_",6)==0 ){
+    @ <hr><pre>
+    @ %h(blob_str(&tktchng))
+    @ </pre><hr>
+    blob_zero(&tktchng);
+    SbS_Pop(p, 1);
+    return SBS_OK;
+  }
 
   rid = content_put(&tktchng, 0, 0);
   if( rid==0 ){
     fossil_panic("trouble committing ticket: %s", g.zErrMsg);
@@ -475,8 +421,9 @@
 
 
 /*
 ** WEBPAGE: tktnew
+** WEBPAGE: debug_tktnew
 */
 void tktnew_page(void){
   char *zScript;
   int nScript;
@@ -487,14 +434,14 @@
   style_header("New Ticket");
   ticket_init();
   getAllTicketFields();
   initializeVariablesFromCGI();
-  @ <form method="POST" action="%s(g.zBaseURL)/tktnew">
+  @ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
   zScript = (char*)SbS_Fetch(pInterp, "tktnew_template", -1, &nScript);
   zScript = mprintf("%.*s", nScript, zScript);
   SbS_Store(pInterp, "login", g.zLogin, 0);
   SbS_Store(pInterp, "date", db_text(0, "SELECT datetime('now')"), 2);
-  SbS_AddVerb(pInterp, "submit_ticket", submitNewCmd, (void*)&zNewUuid);
+  SbS_AddVerb(pInterp, "submit_ticket", submitTicketCmd, (void*)&zNewUuid);
   if( SbS_Render(pInterp, zScript)==SBS_RETURN && zNewUuid ){
     cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zNewUuid));
     return;
   }
@@ -505,16 +452,16 @@
 
 
 /*
 ** WEBPAGE: tktedit
+** WEBPAGE: debug_tktedit
 */
 void tktedit_page(void){
   char *zScript;
   int nScript;
   int nName;
   const char *zName;
   int nRec;
-  char *zUuid = 0;
 
   login_check_credentials();
   if( !g.okApndTkt && !g.okWrTkt ){ login_needed(); return; }
   style_header("Edit Ticket");
@@ -540,19 +487,19 @@
   ticket_init();
   getAllTicketFields();
   initializeVariablesFromCGI();
   initializeVariablesFromDb();
-  @ <form method="POST" action="%s(g.zBaseURL)/tktedit">
+  @ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
   @ <input type="hidden" name="name" value="%s(zName)">
   zScript = (char*)SbS_Fetch(pInterp, "tktedit_template", -1, &nScript);
   zScript = mprintf("%.*s", nScript, zScript);
   SbS_Store(pInterp, "login", g.zLogin, 0);
   SbS_Store(pInterp, "date", db_text(0, "SELECT datetime('now')"), 2);
   SbS_AddVerb(pInterp, "append_field", appendRemarkCmd, 0);
-  SbS_AddVerb(pInterp, "submit_ticket", submitTicketCmd, (void*)&zUuid);
-  if( SbS_Render(pInterp, zScript)==SBS_RETURN && zUuid ){
-    cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zUuid));
+  SbS_AddVerb(pInterp, "submit_ticket", submitTicketCmd, (void*)&zName);
+  if( SbS_Render(pInterp, zScript)==SBS_RETURN && zName ){
+    cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zName));
     return;
   }
   @ </form>
   style_footer();
 }