Fossil

Check-in [5b131851]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:removed old rptshowJson().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json-multitag-test | json
Files: files | file ages | folders
SHA1:5b131851006f6d9e28a3642b9bf1b76345b030db
User & Date: json-demo 2011-11-04 20:44:06
Context
2011-11-04
20:46
Added missing #ifdefs for json mode. check-in: d92aad29 user: json-demo tags: json-multitag-test, json
20:44
removed old rptshowJson(). check-in: 5b131851 user: json-demo tags: json-multitag-test, json
20:37
Added configure option --enable-json to enable json features. They are disabled by default. check-in: 525816e6 user: json-demo tags: json-multitag-test, json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/report.c.

1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
  sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
  report_unrestrict_sql();
  if( zFilter ){
    free(zSql);
  }
}


void rptshowJson( 
    const char *zRep,
    char const * zLimit,
    const char *zFilter,
    char indention
){
  Stmt q;
  char *zSql;
  char const *zTitle;
  char const *zOwner;
  char *zClrKey;
  char *zErr1 = 0;
  int count = 0;
  int rn;
  int rc;
  cson_value * zJVal = NULL;

  if (!zRep || !strcmp(zRep,zFullTicketRptRn) || !strcmp(zRep,zFullTicketRptTitle) ){
    zTitle = zFullTicketRptTitle;
    zSql = mprintf("SELECT * FROM ticket");
    zOwner = g.zLogin;
    zClrKey = "";
  }else{
    rn = atoi(zRep);
    if( rn ){
      db_prepare(&q,
       "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
    }else{
      db_prepare(&q,
       "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE title=%Q", zRep);
    }
    if( db_step(&q)!=SQLITE_ROW ){
      db_finalize(&q);
      rpt_list_reports();
      fossil_fatal("unkown report format(%s)!",zRep);
    }
    zTitle = db_column_malloc(&q, 0)/*leak!*/;
    zSql = db_column_malloc(&q, 1);
    zOwner = db_column_malloc(&q, 2)/*leak!*/;
    zClrKey = db_column_malloc(&q, 3);
    db_finalize(&q);
  }
  if( zFilter ){
    char * old = zSql;
    zSql = mprintf("SELECT * FROM (%s) WHERE %s%s%s",old,zFilter,
             (zLimit?" LIMIT ":""), (zLimit?zLimit:""));
    free(old);
  }else if( zLimit ){
    char * old = zSql;
    zSql = mprintf("%s LIMIT %s",old, zLimit);
    free(old);
  }
  count = 0;
  /*fprintf(stderr,"SQL=[%s]\n",zSql);*/
  sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
  rc = cson_sqlite3_sql_to_json(g.db, &zJVal, zSql, 1);
  if( 0 == rc ){
      cson_output_opt outOpt = cson_output_opt_empty;
      outOpt.addNewline = 1;
      outOpt.indentation = indention;
      rc = cson_output_FILE( zJVal, stdout, &outOpt );
  } else{
    fossil_fatal("sql-to-json failed with code %d (%s)!", rc,
                 cson_rc_string(rc));
  }
  sqlite3_set_authorizer(g.db, 0, 0);
  cson_value_free(zJVal);
  free(zSql);
  free(zClrKey);
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
1138
1139
1140
1141
1142
1143
1144







































































  sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
  report_unrestrict_sql();
  if( zFilter ){
    free(zSql);
  }
}