184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
pqueue_insert(&queue, pid, -mtime, 0);
}
}
db_reset(&q);
}
bag_clear(&seen);
pqueue_clear(&queue);
db_finalize(&ins);
db_finalize(&q);
}
/*
** Load the record ID rid and up to N-1 closest descendants into
** the "ok" table.
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
pqueue_insert(&queue, pid, -mtime, 0);
}
}
db_reset(&q);
}
bag_clear(&seen);
pqueue_clear(&queue);
db_finalize(&ins);
db_finalize(&q);
}
/*
** Compute up to N direct ancestors (merge ancestors do not count)
** for the check-in rid and put them in a table named "ancestor".
** Label each generation with consecutive integers going backwards
** in time such that rid has the smallest generation number and the oldest
** direct ancestor as the largest generation number.
*/
void compute_direct_ancestors(int rid, int N){
Stmt ins;
Stmt q;
int gen = 0;
db_multi_exec(
"CREATE TEMP TABLE ancestor(rid INTEGER, generation INTEGER PRIMARY KEY);"
"INSERT INTO ancestor VALUES(%d, 0);", rid
);
db_prepare(&ins, "INSERT INTO ancestor VALUES(:rid, :gen)");
db_prepare(&q,
"SELECT pid FROM plink"
" WHERE cid=:rid AND isprim"
);
while( (N--)>0 ){
db_bind_int(&q, ":rid", rid);
if( db_step(&q)!=SQLITE_ROW ) break;
rid = db_column_int(&q, 0);
db_reset(&q);
gen++;
db_bind_int(&ins, ":rid", rid);
db_bind_int(&ins, ":gen", gen);
db_step(&ins);
db_reset(&ins);
}
db_finalize(&ins);
db_finalize(&q);
}
/*
** Load the record ID rid and up to N-1 closest descendants into
** the "ok" table.
|