Fossil

Check-in [83c6781670]
Login

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

Overview
Comment:Add the ability to index files.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | search-using-fts4
Files: files | file ages | folders
SHA1: 83c67816701851c5765abf9ed4f74ceeddfac6be
User & Date: drh 2014-12-17 18:28:45.248
Context
2014-12-17
18:51
Much faster implementation of the ftsearch_content() function for file content. check-in: bbcce76f26 user: drh tags: search-using-fts4
18:28
Add the ability to index files. check-in: 83c6781670 user: drh tags: search-using-fts4
16:27
Remove the code that implemented legacy "fossil search" command. FTS4 will be used moving forward. check-in: 389c70a56a user: drh tags: search-using-fts4
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/blob.c.
199
200
201
202
203
204
205








206
207
208
209
210
211
212
/*
** Reset a blob to be an empty container.
*/
void blob_reset(Blob *pBlob){
  blob_is_init(pBlob);
  pBlob->xRealloc(pBlob, 0);
}










/*
** Return true if the blob has been zeroed - in other words if it contains
** no malloced memory.  This only works reliably if the blob has been
** initialized - it can return a false negative on an uninitialized blob.
*/







>
>
>
>
>
>
>
>







199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
** Reset a blob to be an empty container.
*/
void blob_reset(Blob *pBlob){
  blob_is_init(pBlob);
  pBlob->xRealloc(pBlob, 0);
}

/*
** Return true if the result of blob_str() is a string that can be
** freed using fossil_free.
*/
int blob_is_malloced(Blob *pBlob){
  return pBlob && pBlob->aData && pBlob->xRealloc==blobReallocMalloc;
}


/*
** Return true if the blob has been zeroed - in other words if it contains
** no malloced memory.  This only works reliably if the blob has been
** initialized - it can return a false negative on an uninitialized blob.
*/
Changes to src/db.c.
836
837
838
839
840
841
842

843
844
845
846
847
848
849
    db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
    0, 0
  );
  if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
  re_add_sql_func(db);
  foci_register(db);
  ftsearch_add_sql_func(db);

  sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
  return db;
}


/*
** Detaches the zLabel database.







>







836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
    db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
    0, 0
  );
  if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
  re_add_sql_func(db);
  foci_register(db);
  ftsearch_add_sql_func(db);
  add_content_sql_commands(db);
  sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
  return db;
}


/*
** Detaches the zLabel database.
Changes to src/ftsearch.c.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76












77
78
79
80
81
82
83
84
85
86
87
88
89
90
91




92
93
94
95
96
97
98
99
100
101
102
103
104






105
106
107
108
109
110
111
  int id;
  if( zDocId==0 ){
    if( zDocType[0]==0 || zDocType[1]==0 ) return 0;
    zDocId = zDocType + 2;
  }
  id = atoi(zDocId);
  switch( zDocType[0] ){
    case 'c': {    /* A check-in comment. zDocId is the UUID */
      zRes = db_text(0,
        "SELECT coalesce(ecomment,comment) || char(10) ||"
        "       'user: ' || coalesce(euser,user) || char(10) ||"
        "       'branch: ' || coalesce((SELECT value FROM tagxref"
                                     "   WHERE tagid=%d AND tagtype>0"
                                     "     AND rid=%d),'trunk')"
        "  FROM event"
        " WHERE event.objid=%d"
        "   AND event.type GLOB 'c*'",
        TAG_BRANCH, id, id);
      break;












    }
    default: {
      /* No-op */
    }
  }
  return zRes;
}

/* Return a human-readable description for the document described by
** the arguments.  The returned text is in the Wiki format and contains
** links to the document in question.
**
** See ftsearch_content() for further information
*/
char *ftsearch_description(const char *zDocType, const char *zDocId){




  char *zRes = 0;  /* The result to be returned */
  int id;
  if( zDocId==0 ){
    if( zDocType[0]==0 || zDocType[1]==0 ) return 0;
    zDocId = zDocType + 2;
  }
  id = atoi(zDocId);
  switch( zDocType[0] ){
    case 'c': {    /* A check-in comment. zDocId is the UUID */
      char *zUuid = db_text("","SELECT uuid FROM blob WHERE rid=%d", id);
      zRes = mprintf("Check-in [%S]", zUuid);
      fossil_free(zUuid);
      break;






    }
    default: {
      /* No-op */
    }
  }
  return zRes;
}







|











>
>
>
>
>
>
>
>
>
>
>
>









|
<



|
>
>
>
>








|




>
>
>
>
>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  int id;
  if( zDocId==0 ){
    if( zDocType[0]==0 || zDocType[1]==0 ) return 0;
    zDocId = zDocType + 2;
  }
  id = atoi(zDocId);
  switch( zDocType[0] ){
    case 'c': {    /* A check-in comment. zDocId is the RID */
      zRes = db_text(0,
        "SELECT coalesce(ecomment,comment) || char(10) ||"
        "       'user: ' || coalesce(euser,user) || char(10) ||"
        "       'branch: ' || coalesce((SELECT value FROM tagxref"
                                     "   WHERE tagid=%d AND tagtype>0"
                                     "     AND rid=%d),'trunk')"
        "  FROM event"
        " WHERE event.objid=%d"
        "   AND event.type GLOB 'c*'",
        TAG_BRANCH, id, id);
      break;
    }
    case 'f': {   /* A file with zDocId as the filename.fnid */
      zRes = db_text(0,
        "SELECT content(mlink.fid)"
        "  FROM filename, mlink, event"
        " WHERE filename.fnid=%d"
        "   AND mlink.fnid=filename.fnid"
        "   AND event.objid=mlink.mid"
        " ORDER BY event.mtime DESC LIMIT 1",
        id
      );
      break;
    }
    default: {
      /* No-op */
    }
  }
  return zRes;
}

/* Return a human-readable description for the document described by
** the arguments.

**
** See ftsearch_content() for further information
*/
char *ftsearch_description(
  const char *zDocType,
  const char *zDocId,
  int bLink                   /* Provide hyperlink in text if true */
){
  char *zRes = 0;  /* The result to be returned */
  int id;
  if( zDocId==0 ){
    if( zDocType[0]==0 || zDocType[1]==0 ) return 0;
    zDocId = zDocType + 2;
  }
  id = atoi(zDocId);
  switch( zDocType[0] ){
    case 'c': {    /* A check-in comment. zDocId is the RID */
      char *zUuid = db_text("","SELECT uuid FROM blob WHERE rid=%d", id);
      zRes = mprintf("Check-in [%S]", zUuid);
      fossil_free(zUuid);
      break;
    }
    case 'f': {    /* A file.  zDocId is the FNID */
      char *zName = db_text("","SELECT name FROM filename WHERE fnid=%d",id);
      zRes = mprintf("File %s", zName);
      fossil_free(zName);
      break;
    }
    default: {
      /* No-op */
    }
  }
  return zRes;
}
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  char *zContent = 0;
  char *zDesc = 0;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc!=3 ) usage("DOCUMENTCODE");
  if( strlen(g.argv[2])>3 ){
    zContent = ftsearch_content(g.argv[2],0);
    zDesc = ftsearch_description(g.argv[2],0);
  }
  if( zDesc ){
    fossil_print("Description: %s\n", zDesc);
    fossil_free(zDesc);
  }
  if( zContent ){
    fossil_print(







|







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  char *zContent = 0;
  char *zDesc = 0;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc!=3 ) usage("DOCUMENTCODE");
  if( strlen(g.argv[2])>3 ){
    zContent = ftsearch_content(g.argv[2],0);
    zDesc = ftsearch_description(g.argv[2],0,0);
  }
  if( zDesc ){
    fossil_print("Description: %s\n", zDesc);
    fossil_free(zDesc);
  }
  if( zContent ){
    fossil_print(
208
209
210
211
212
213
214

215
216






217
218
219
220
221
222
223
  db_end_transaction(0);
}

/*
** Completely rebuild the ftsearch indexes from scratch
*/
void ftsearch_rebuild_all(void){

  db_begin_transaction();
  ftsearch_disable_all();







  /* The FTSSEARCHXREF table provides a mapping between the integer
  ** document-ids in FTS4 to the "document codes" that describe a 
  ** referenced object 
  */
  db_multi_exec(
    "CREATE TABLE %s.ftsearchxref(\n"







>


>
>
>
>
>
>







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  db_end_transaction(0);
}

/*
** Completely rebuild the ftsearch indexes from scratch
*/
void ftsearch_rebuild_all(void){
  const char *zEnables;
  db_begin_transaction();
  ftsearch_disable_all();
  zEnables = db_get("ftsearch-index-type", "cdeftw");

  /* If none of the search categories are enabled, then do not
  ** bother constructing the search tables
  */
  if( sqlite3_strglob("*[cdeftw]*", zEnables) ) return;

  /* The FTSSEARCHXREF table provides a mapping between the integer
  ** document-ids in FTS4 to the "document codes" that describe a 
  ** referenced object 
  */
  db_multi_exec(
    "CREATE TABLE %s.ftsearchxref(\n"
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
















255
256
257
258
259
260
261
  /* This is the FTS4 table used for searching */
  db_multi_exec(
    "CREATE VIRTUAL TABLE %s.ftsearch"
    " USING fts4(content='ftsearchbody',body);",
    db_name("repository")
  );


  /* Populate the FTSEARCHXREF table with references to all check-in
  ** comments currently in the event table
  */
  db_multi_exec(
    "INSERT INTO ftsearchxref(ftsid,mtime)"
    "  SELECT 'c-' || objid, mtime FROM event"
    "   WHERE type='ci';"
  );

















  /* Index every document mentioned in the FTSEARCHXREF table */
  db_multi_exec(
    "INSERT INTO ftsearch(docid,body)"
    "  SELECT docid, ftsearch_content(ftsid) FROM ftsearchxref;"
  );
  db_end_transaction(0);







>
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  /* This is the FTS4 table used for searching */
  db_multi_exec(
    "CREATE VIRTUAL TABLE %s.ftsearch"
    " USING fts4(content='ftsearchbody',body);",
    db_name("repository")
  );

  if( strchr(zEnables, 'c')!=0 ){
    /* Populate the FTSEARCHXREF table with references to all check-in
    ** comments currently in the event table
    */
    db_multi_exec(
      "INSERT INTO ftsearchxref(ftsid,mtime)"
      "  SELECT 'c-' || objid, mtime FROM event"
      "   WHERE type='ci';"
    );
  }

  if( strchr(zEnables, 'f')!=0 ){
    /* Populate the FTSEARCHXREF table with references to all files
    */
    db_multi_exec(
      "INSERT INTO ftsearchxref(ftsid,mtime)"
      "  SELECT 'f-' || filename.fnid, max(event.mtime)"
      "    FROM filename, mlink, event"
      "   WHERE mlink.fnid=filename.fnid"
      "     AND event.objid=mlink.mid"
      "     AND %s"
      "   GROUP BY 1",
      glob_expr("filename.name", db_get("search-file-glob","*"))
    );
  }

  /* Index every document mentioned in the FTSEARCHXREF table */
  db_multi_exec(
    "INSERT INTO ftsearch(docid,body)"
    "  SELECT docid, ftsearch_content(ftsid) FROM ftsearchxref;"
  );
  db_end_transaction(0);
270
271
272
273
274
275
276
277












278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307



308
309
310
311
312
313
314
** The "search" command locates resources that contain the given web-search
** style PATTERN.  This only works if the repository has be configured to
** enable searching.
**
** The "search-config" is used to setup the search feature of the repository.
** Subcommands are:
**
**   fossil search-config setting ?NAME? ?VALUE?












**
**      Set or query a search setting.  NAMES are:
**         file-glob             Comma-separated list of GLOBs for file search
**         ticket-expr           SQL expression to render TICKET content
**         ticketchng-expr       SQL expression to render TICKETCHNG content
**         index-type            Zero or more characters from [cdeftw]
**
**      The index-type determines what resources are indexed and available for
**      searching.  If the index-type is an empty string, the search is
**      complete disabled.  These are the valid index-types:
**         c: check-in comments
**         d: check-in difference marks
**         e: event text
**         f: file text (subject to the file-glob)
**         t: ticket text (requires ticket-expr and ticketchng-expr)
**         w: wiki pages
**
**      It is necessary to run "fossil search-config rebuild" after making
**      setting changes in order to reconstruct the search index
**
**   fossil search-config rebuild
**   fossil search-config optimize
**
**      Completely rebuild the search index, or optimize the search index.
**
**   fossil search-config reset
**
**      Disable search and remove the search indexes from the repository.
*/
void ftsearch_cmd(void){



  const char *zSubCmd;
  int nSubCmd;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc<3 ) usage("search PATTERN");
  zSubCmd = g.argv[2];
  nSubCmd = (int)strlen(zSubCmd);







|
>
>
>
>
>
>
>
>
>
>
>
>




















|
<

|
<
<
<
<


>
>
>







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

356
357




358
359
360
361
362
363
364
365
366
367
368
369
** The "search" command locates resources that contain the given web-search
** style PATTERN.  This only works if the repository has be configured to
** enable searching.
**
** The "search-config" is used to setup the search feature of the repository.
** Subcommands are:
**
**   fossil search-config doclist
**
**      List all the documents currently indexed
**
**   fossil search-config rebuild
**
**      Completely rebuild the search index.
**
**   fossil search-config reset
**
**      Disable search and remove the search indexes from the repository.
**
**   fossil search-config setting NAME ?VALUE?
**
**      Set or query a search setting.  NAMES are:
**         file-glob             Comma-separated list of GLOBs for file search
**         ticket-expr           SQL expression to render TICKET content
**         ticketchng-expr       SQL expression to render TICKETCHNG content
**         index-type            Zero or more characters from [cdeftw]
**
**      The index-type determines what resources are indexed and available for
**      searching.  If the index-type is an empty string, the search is
**      complete disabled.  These are the valid index-types:
**         c: check-in comments
**         d: check-in difference marks
**         e: event text
**         f: file text (subject to the file-glob)
**         t: ticket text (requires ticket-expr and ticketchng-expr)
**         w: wiki pages
**
**      It is necessary to run "fossil search-config rebuild" after making
**      setting changes in order to reconstruct the search index
**
**   fossil search-config status

**
**      Report on the status of the search configuration.




*/
void ftsearch_cmd(void){
  static const char *azSettings[] = {
     "file-glob", "index-type", "ticket-expr", "ticketchng-expr"
  };
  const char *zSubCmd;
  int nSubCmd;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc<3 ) usage("search PATTERN");
  zSubCmd = g.argv[2];
  nSubCmd = (int)strlen(zSubCmd);
326
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349










350


351
352
353
354



























355









356









357
358
#endif
    if( !db_table_exists("repository","ftsearch") ){
      fossil_fatal("search is disabled - see \"fossil help search\""
                   " for more information");
    }
    db_prepare(&q, "SELECT "
      "       snippet(ftsearch,%Q,%Q,'...'),"
      "       ftsearchxref.ftsid"

      "  FROM ftsearch, ftsearchxref"
      " WHERE ftsearch.body MATCH %Q"
      "   AND ftsearchxref.docid=ftsearch.docid"
      " ORDER BY ftsearchxref.mtime DESC;",
      zMark1, zMark2, zSubCmd);
    while( db_step(&q)==SQLITE_ROW ){
      const char *zSnippet = db_column_text(&q,0);
      char *zDesc = ftsearch_description(db_column_text(&q,1),0);

      if( i++ > 0 ){
        fossil_print("----------------------------------------------------\n");
      }
      fossil_print("%s\n%s\n", zDesc, zSnippet);
      fossil_free(zDesc);
    }
    db_finalize(&q);
  }else if( strncmp(zSubCmd, "settings", nSubCmd)==0 ){













  }else if( strncmp(zSubCmd, "rebuild", nSubCmd)==0 ){
    ftsearch_rebuild_all();
  }else if( strncmp(zSubCmd, "reset", nSubCmd)==0 ){
    ftsearch_disable_all();



























  }else if( strncmp(zSubCmd, "optimize", nSubCmd)==0 ){









  }









  db_end_transaction(0);
}







|
>



|



|
>



|



|
>
>
>
>
>
>
>
>
>
>
|
>
>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#endif
    if( !db_table_exists("repository","ftsearch") ){
      fossil_fatal("search is disabled - see \"fossil help search\""
                   " for more information");
    }
    db_prepare(&q, "SELECT "
      "       snippet(ftsearch,%Q,%Q,'...'),"
      "       ftsearchxref.ftsid,"
      "       date(ftsearchxref.mtime)"
      "  FROM ftsearch, ftsearchxref"
      " WHERE ftsearch.body MATCH %Q"
      "   AND ftsearchxref.docid=ftsearch.docid"
      " ORDER BY ftsearchxref.mtime DESC LIMIT 50;",
      zMark1, zMark2, zSubCmd);
    while( db_step(&q)==SQLITE_ROW ){
      const char *zSnippet = db_column_text(&q,0);
      char *zDesc = ftsearch_description(db_column_text(&q,1),0,0);
      const char *zDate = db_column_text(&q,2);
      if( i++ > 0 ){
        fossil_print("----------------------------------------------------\n");
      }
      fossil_print("%s (%s)\n%s\n", zDesc, zDate, zSnippet);
      fossil_free(zDesc);
    }
    db_finalize(&q);
  }else if( strncmp(zSubCmd, "doclist", nSubCmd)==0 ){
    if( db_table_exists("repository","ftsearch") ){
      Stmt q;
      db_prepare(&q, "SELECT ftsid, date(mtime) FROM ftsearchxref"
                     " ORDER BY mtime DESC");
      while( db_step(&q)==SQLITE_ROW ){
        const char *zDate = db_column_text(&q,1);
        const char *zFtsid = db_column_text(&q,0);
        char *zDesc = ftsearch_description(zFtsid,0,0);
        fossil_print("%s (%s)\n", zDesc, zDate);
        fossil_free(zDesc);
      }
      db_finalize(&q);
    }
  }else if( strncmp(zSubCmd, "rebuild", nSubCmd)==0 ){
    ftsearch_rebuild_all();
  }else if( strncmp(zSubCmd, "reset", nSubCmd)==0 ){
    ftsearch_disable_all();
  }else if( strncmp(zSubCmd, "settings", nSubCmd)==0 ){
    const char *zName = g.argv[3];
    const char *zValue = g.argc>=5 ? g.argv[4] : 0;
    char *zFullname;
    int i;
    if( g.argc<4 ) usage("setting NAME ?VALUE?");
    for(i=0; i<count(azSettings); i++){
      if( strcmp(zName, azSettings[i])==0 ) break;
    }
    if( i>=count(azSettings) ){
      Blob x;
      blob_init(&x,0,0);
      for(i=0; i<count(azSettings); i++) blob_appendf(&x," %s", azSettings[i]);
      fossil_fatal("unknown setting \"%s\" - should be one of:%s",
          zName, blob_str(&x));
    }
    zFullname = mprintf("search-%s", zName);
    if( zValue==0 ){
      zValue = db_get(zFullname, 0);
    }else{
      db_set(zFullname, zValue, 0);
    }
    if( zValue==0 ){
      fossil_print("%s is not defined\n", zName);
    }else{
      fossil_print("%s: %s\n", zName, zValue);
    }
  }else if( strncmp(zSubCmd, "status", nSubCmd)==0 ){
    int i;
    fossil_print("search settings:\n");
    for(i=0; i<count(azSettings); i++){
      char *zFullname = mprintf("search-%s", azSettings[i]);
      char *zValue = db_get(zFullname, 0);
      if( zValue==0 ){
        fossil_print("  %s is undefined\n", azSettings[i]);
      }else{
        fossil_print("  %s: %s\n", azSettings[i], zValue);
      }
      fossil_free(zFullname);
    }
    if( db_table_exists("repository","ftsearchxref") ){
      int n = db_int(0, "SELECT count(*) FROM ftsearchxref");
      fossil_print("search is enabled with %d documents indexed\n", n);
    }else{
      fossil_print("search is disabled\n");
    }
  }
  db_end_transaction(0);
}
Changes to src/sqlcmd.c.
38
39
40
41
42
43
44



45
46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61
  int argc,
  sqlite3_value **argv
){
  int rid;
  Blob cx;
  const char *zName;
  assert( argc==1 );



  zName = (const char*)sqlite3_value_text(argv[0]);
  if( zName==0 ) return;
  g.db = sqlite3_context_db_handle(context);
  g.repositoryOpen = 1;
  rid = name_to_rid(zName);

  if( rid==0 ) return;
  if( content_get(rid, &cx) ){
    sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx),
                                 SQLITE_TRANSIENT);
    blob_reset(&cx);
  }
}

/*
** Implementation of the "compress(X)" SQL function.  The input X is
** compressed using zLib and the output is returned.
*/







>
>
>
|
|
|
|
|
>



|
<







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
  int argc,
  sqlite3_value **argv
){
  int rid;
  Blob cx;
  const char *zName;
  assert( argc==1 );
  if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
    rid = sqlite3_value_int(argv[0]);
  }else{
    zName = (const char*)sqlite3_value_text(argv[0]);
    if( zName==0 ) return;
    g.db = sqlite3_context_db_handle(context);
    g.repositoryOpen = 1;
    rid = name_to_rid(zName);
  }
  if( rid==0 ) return;
  if( content_get(rid, &cx) ){
    sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx),
                       blob_is_malloced(&cx) ? fossil_free : SQLITE_TRANSIENT);

  }
}

/*
** Implementation of the "compress(X)" SQL function.  The input X is
** compressed using zLib and the output is returned.
*/