Fossil

Check-in [5258a43d]
Login

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

Overview
Comment:More reliably work around the problem experienced by the previous commit. Not sure if this is the right long-term solution since we seem to have an architectural problem: at least one of Fossil's custom SQL functions can change the schema (in this case, by creating a temporary table), thereby invalidating a prepared statement while it is running. See the comment in checkin.c for a bit more information. Of course, there are rearrangements that avoid the issue, but it is certainly a trap for the unwary.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | andygoth-changes
Files: files | file ages | folders
SHA1:5258a43d78fd433daa4ed36cae21b1d7e46c4efd
User & Date: andygoth 2016-11-06 20:19:47
Context
2016-11-06
21:28
Remove some excess comments, minor rearrangement check-in: 8b8e7654 user: andygoth tags: andygoth-changes
20:19
More reliably work around the problem experienced by the previous commit. Not sure if this is the right long-term solution since we seem to have an architectural problem: at least one of Fossil's custom SQL functions can change the schema (in this case, by creating a temporary table), thereby invalidating a prepared statement while it is running. See the comment in checkin.c for a bit more information. Of course, there are rearrangements that avoid the issue, but it is certainly a trap for the unwary. check-in: 5258a43d user: andygoth tags: andygoth-changes
07:57
Begin expanding status_report() to support being the backend for the ls command. The work is not yet complete. First we must debug a mysterious abort in SQLite. Test case: run "./fossil changes -differ" with at least one changed file. check-in: 9d5de8d7 user: andygoth tags: andygoth-changes
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/checkin.c.

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
      " SELECT pathname, %s, %s, 0, 0, 0, 0, 0, 0"
      " FROM sfile WHERE pathname NOT IN (%s)%s",
      flags & C_MTIME ? "datetime(mtime, 'unixepoch', toLocal())" : "''",
      flags & C_SIZE  ? "size" : "0",
      fossil_all_reserved_names(0), blob_sql_text(&where));
  }

#if 1
  /* SQLITE BUG WORKAROUND??? */
  /* If I step the query sans the ORDER BY clause, then I can run the full query
   * without incident.  But if I delete this workaround and run the query
   * normally, I get SQLITE_ABORT due to ROLLBACK, which makes no sense. */
  db_prepare(&q, "%s", blob_sql_text(&sql));
  if( (flags & C_ALL) && (flags & C_MTIME) ){
    db_bind_int(&q, ":vid", db_lget_int("checkout", 0));
  }
  db_step(&q);
  db_finalize(&q);
  /* SQLITE BUG WORKAROUND??? */
#endif

  /* Append an ORDER BY clause then compile the query. */
  blob_append_sql(&sql, " ORDER BY pathname");
  db_prepare(&q, "%s", blob_sql_text(&sql));
  blob_reset(&sql);
  blob_reset(&where);








|
|
|
|
|
|
<
<
<
<
<
<
<







171
172
173
174
175
176
177
178
179
180
181
182
183







184
185
186
187
188
189
190
      " SELECT pathname, %s, %s, 0, 0, 0, 0, 0, 0"
      " FROM sfile WHERE pathname NOT IN (%s)%s",
      flags & C_MTIME ? "datetime(mtime, 'unixepoch', toLocal())" : "''",
      flags & C_SIZE  ? "size" : "0",
      fossil_all_reserved_names(0), blob_sql_text(&where));
  }

  /* Pre-create the "ok" temporary table so the checkin_mtime() SQL function
   * does not lead to SQLITE_ABORT_ROLLBACK during execution of the OP_OpenRead
   * SQLite opcode.  checkin_mtime() calls mtime_of_manifest_file() which
   * creates a temporary table if it doesn't already exist, thus invalidating
   * the prepared statement in the middle of its execution. */
  db_multi_exec("CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)");








  /* Append an ORDER BY clause then compile the query. */
  blob_append_sql(&sql, " ORDER BY pathname");
  db_prepare(&q, "%s", blob_sql_text(&sql));
  blob_reset(&sql);
  blob_reset(&where);

Changes to src/descendants.c.

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  i64 *pMTime    /* Write result here */
){
  static int prevVid = -1;
  static Stmt q;

  if( prevVid!=vid ){
    prevVid = vid;
    db_multi_exec("DROP TABLE IF EXISTS temp.ok;"
                  "CREATE TEMP TABLE ok(x INTEGER PRIMARY KEY);");
    compute_ancestors(vid, 100000000, 1);
  }
  db_static_prepare(&q,
    "SELECT (max(event.mtime)-2440587.5)*86400 FROM mlink, event"
    " WHERE mlink.mid=event.objid"
    "   AND +mlink.mid IN ok"
    "   AND mlink.fid=:fid");







|
|







214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  i64 *pMTime    /* Write result here */
){
  static int prevVid = -1;
  static Stmt q;

  if( prevVid!=vid ){
    prevVid = vid;
    db_multi_exec("CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY);"
                  "DELETE FROM ok;");
    compute_ancestors(vid, 100000000, 1);
  }
  db_static_prepare(&q,
    "SELECT (max(event.mtime)-2440587.5)*86400 FROM mlink, event"
    " WHERE mlink.mid=event.objid"
    "   AND +mlink.mid IN ok"
    "   AND mlink.fid=:fid");