Diff
Not logged in

Differences From Artifact [a0de858682]:

To Artifact [6bbc910307]:


41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
41
42
43
44
45
46
47

48
49
50
51
52
53
54
55







-
+







  if( zName==0 ) return;
  g.db = sqlite4_context_db_handle(context);
  g.repositoryOpen = 1;
  rid = name_to_rid(zName);
  if( rid==0 ) return;
  if( content_get(rid, &cx) ){
    sqlite4_result_blob(context, blob_buffer(&cx), blob_size(&cx), 
                                 SQLITE_TRANSIENT);
                                 SQLITE4_TRANSIENT);
    blob_reset(&cx);
  }
}

/*
** Implementation of the "compress(X)" SQL function.  The input X is
** compressed using zLib and the output is returned.
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+







  nOut = 13 + nIn + (nIn+999)/1000;
  pOut = sqlite4_malloc(0, nOut+4);
  pOut[0] = nIn>>24 & 0xff;
  pOut[1] = nIn>>16 & 0xff;
  pOut[2] = nIn>>8 & 0xff;
  pOut[3] = nIn & 0xff;
  compress(&pOut[4], &nOut, pIn, nIn);
  sqlite4_result_blob(context, pOut, nOut+4, SQLITE_DYNAMIC);
  sqlite4_result_blob(context, pOut, nOut+4, SQLITE4_DYNAMIC);
}

/*
** Implementation of the "decompress(X)" SQL function.  The argument X
** is a blob which was obtained from compress(Y).  The output will be
** the value Y.
*/
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
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







-
+















-
+

-
+

-
+

-
+








  pIn = sqlite4_value_blob(argv[0]);
  nIn = sqlite4_value_bytes(argv[0]);
  nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
  pOut = sqlite4_malloc(0, nOut+1);
  rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
  if( rc==Z_OK ){
    sqlite4_result_blob(context, pOut, nOut, SQLITE_DYNAMIC);
    sqlite4_result_blob(context, pOut, nOut, SQLITE4_DYNAMIC);
  }else{
    sqlite4_result_error(context, "input is not zlib compressed", -1);
  }
}

/*
** This is the "automatic extensionn" initializer that runs right after
** the connection to the repository database is opened.  Set up the
** database connection to be more useful to the human operator.
*/
static int sqlcmd_autoinit(
  sqlite4 *db,
  const char **pzErrMsg,
  const void *notUsed
){
  sqlite4_create_function(db, "content", 1, SQLITE_ANY, 0,
  sqlite4_create_function(db, "content", 1, SQLITE4_ANY, 0,
                          sqlcmd_content, 0, 0);
  sqlite4_create_function(db, "compress", 1, SQLITE_ANY, 0,
  sqlite4_create_function(db, "compress", 1, SQLITE4_ANY, 0,
                          sqlcmd_compress, 0, 0);
  sqlite4_create_function(db, "decompress", 1, SQLITE_ANY, 0,
  sqlite4_create_function(db, "decompress", 1, SQLITE4_ANY, 0,
                          sqlcmd_decompress, 0, 0);
  return SQLITE_OK;
  return SQLITE4_OK;
}


/*
** COMMAND: sqlite4
**
** Usage: %fossil sqlite4 ?DATABASE? ?OPTIONS?