Differences From:
File
src/tkt.c
part of check-in
[39aa870f8f]
- Work toward a new mechanism for configuring the ticket subsystem
and rendering ticket entry, editing, and viewing screens. Nothing
works, but it is all commented out so the code code compile.
by
drh on
2007-10-14 00:29:14.
[view]
To:
File
src/tkt.c
part of check-in
[8f423ad438]
- Fix a bug in wiki rendering that caused an extra paragraph end tag
following a hyperlink.
by
drh on
2007-10-21 11:11:02.
[view]
@@ -53,8 +53,17 @@
*/
static int nField = 0;
static Blob fieldList;
static char **azField = 0;
+static char **azValue = 0;
+static unsigned char *aChanged = 0;
+
+/*
+** Compare two entries in azField for sorting purposes
+*/
+static int nameCmpr(void *a, void *b){
+ return strcmp((char*)a, (char*)b);
+}
/*
** Subscript command: LIST setfields
**
@@ -71,17 +80,81 @@
blob_appendf(&fieldList, zFieldList, nFieldList);
while( blob_token(&fieldList, &field) ){
nField++;
}
- azField = malloc( sizeof(azField[0])*nField );
- blob_rewind(&fieldList);
- i = 0;
- while( blob_token(&fieldList, &field) ){
- azField[i] = blob_terminate(&field);
+ azField = malloc( sizeof(azField[0])*nField*2 + nField );
+ if( azField ){
+ azValue = &azField[nField];
+ aChanged = (unsigned char*)&azValue[nField];
+ blob_rewind(&fieldList);
+ i = 0;
+ while( blob_token(&fieldList, &field) ){
+ azField[i] = blob_terminate(&field);
+ azValue[i] = 0;
+ aChanged[i] = 0;
+ }
}
+ qsort(azField, nField, sizeof(azField[0]), nameCmpr);
}
SbS_Pop(p, 1);
return 0;
+}
+
+/*
+** Find the text of the field whose name is the Nth element down
+** on the Subscript stack. 0 means the top of the stack.
+**
+** First check for a value for this field as passed in via
+** CGI parameter. If not found, then use the value from the
+** database.
+*/
+static const char *field_value(int N){
+ const char *zFName;
+ int nFName;
+ char *zName;
+ int i;
+ const char *zValue;
+
+ zFName = SbS_StackValue(pInterp, N, &nFName);
+ if( zField==0 ){
+ return 0;
+ }
+ zName = mprintf("%.*s", nFName, zFName);
+ zValue = P(zName);
+ if( zValue==0 ){
+ for(i=0; i<nField; i++){
+ if( strcmp(azField[i], zName)==0 ){
+ zValue = azValue[i];
+ break;
+ }
+ }
+ }
+ free(zName);
+ return zValue;
+}
+
+/*
+** Fill in the azValue[] array with the contents of the ticket
+** table for the entry determined by the "name" CGI parameter.
+*/
+static void fetchOriginalValues(void){
+ Blob sql;
+ Stmt q;
+ int i;
+ char *zSep = "SELECT ";
+ blob_zero(&sql);
+ for(i=0; i<nField; i++){
+ blob_appendf(&sql, "%s%s", zSep, azField[i]);
+ zSep = ", ";
+ }
+ blob_appendf(" FROM ticket WHERE uuid=%Q", PD("name",""));
+ db_prepare(&q, "%b", &sql);
+ if( db_step(&q)==SQLITE_ROW ){
+ for(i=0; i<nField; i++){
+ azValue[i] = db_column_malloc(&q, i);
+ }
+ }
+ db_finalize(&q);
}
/*
** Subscript command: INTEGER not INTEGER