~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_wc/wc-queries.sql

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
-- STMT_SELECT_BASE_CHILDREN_INFO
74
74
SELECT local_relpath, nodes.repos_id, nodes.repos_path, presence, kind,
 
75
  revision, depth, file_external
 
76
FROM nodes
 
77
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = 0
 
78
 
 
79
-- STMT_SELECT_BASE_CHILDREN_INFO_LOCK
 
80
SELECT local_relpath, nodes.repos_id, nodes.repos_path, presence, kind,
75
81
  revision, depth, file_external,
76
82
  lock_token, lock_owner, lock_comment, lock_date
77
83
FROM nodes
79
85
  AND nodes.repos_path = lock.repos_relpath
80
86
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = 0
81
87
 
 
88
 
82
89
-- STMT_SELECT_WORKING_NODE
83
90
SELECT op_depth, presence, kind, checksum, translated_size,
84
91
  changed_revision, changed_date, changed_author, depth, symlink_target,
92
99
-- STMT_SELECT_DEPTH_NODE
93
100
SELECT repos_id, repos_path, presence, kind, revision, checksum,
94
101
  translated_size, changed_revision, changed_date, changed_author, depth,
95
 
  symlink_target, last_mod_time, properties
 
102
  symlink_target, properties, moved_to, moved_here
96
103
FROM nodes
97
104
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
98
105
 
118
125
-- STMT_SELECT_NODE_CHILDREN_INFO
119
126
/* Getting rows in an advantageous order using
120
127
     ORDER BY local_relpath, op_depth DESC
121
 
   turns out to be slower than getting rows in a random order and making the
122
 
   C code handle it. */
 
128
   doesn't work as the index is created without the DESC keyword.
 
129
   Using both local_relpath and op_depth descending does work without any
 
130
   performance penalty. */
123
131
SELECT op_depth, nodes.repos_id, nodes.repos_path, presence, kind, revision,
124
132
  checksum, translated_size, changed_revision, changed_date, changed_author,
125
133
  depth, symlink_target, last_mod_time, properties, lock_token, lock_owner,
128
136
LEFT OUTER JOIN lock ON nodes.repos_id = lock.repos_id
129
137
  AND nodes.repos_path = lock.repos_relpath AND op_depth = 0
130
138
WHERE wc_id = ?1 AND parent_relpath = ?2
 
139
ORDER BY local_relpath DESC, op_depth DESC
 
140
 
 
141
-- STMT_SELECT_BASE_NODE_CHILDREN_INFO
 
142
/* See above re: result ordering. The results of this query must be in
 
143
the same order as returned by STMT_SELECT_NODE_CHILDREN_INFO, because
 
144
read_children_info expects them to be. */
 
145
SELECT op_depth, nodes.repos_id, nodes.repos_path, presence, kind, revision,
 
146
  checksum, translated_size, changed_revision, changed_date, changed_author,
 
147
  depth, symlink_target, last_mod_time, properties, lock_token, lock_owner,
 
148
  lock_comment, lock_date, local_relpath, moved_here, moved_to, file_external
 
149
FROM nodes
 
150
LEFT OUTER JOIN lock ON nodes.repos_id = lock.repos_id
 
151
  AND nodes.repos_path = lock.repos_relpath AND op_depth = 0
 
152
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = 0
 
153
ORDER BY local_relpath DESC
131
154
 
132
155
-- STMT_SELECT_NODE_CHILDREN_WALKER_INFO
133
156
SELECT local_relpath, op_depth, presence, kind
134
157
FROM nodes_current
135
158
WHERE wc_id = ?1 AND parent_relpath = ?2
 
159
ORDER BY local_relpath
136
160
 
137
161
-- STMT_SELECT_ACTUAL_CHILDREN_INFO
138
162
SELECT local_relpath, changelist, properties, conflict_data
161
185
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14,
162
186
        ?15, ?16, ?17, ?18, ?19, ?20, ?21, ?22, ?23)
163
187
 
164
 
SELECT local_relpath, kind FROM nodes n
165
 
WHERE wc_id = ?1 AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
166
 
  AND op_depth = 0
167
 
  AND presence in (MAP_NORMAL, MAP_INCOMPLETE)
168
 
  AND NOT EXISTS(SELECT 1 FROM NODES w
169
 
                 WHERE w.wc_id = ?1 AND w.local_relpath = n.local_relpath
170
 
                   AND op_depth > 0)
171
 
ORDER BY local_relpath DESC
172
 
 
173
188
-- STMT_SELECT_WORKING_PRESENT
174
189
SELECT local_relpath, kind, checksum, translated_size, last_mod_time
175
190
FROM nodes n
210
224
 
211
225
-- STMT_DELETE_WORKING_BASE_DELETE
212
226
DELETE FROM nodes
 
227
WHERE wc_id = ?1 AND local_relpath = ?2
 
228
  AND presence = MAP_BASE_DELETED
 
229
  AND op_depth > ?3
 
230
  AND op_depth = (SELECT MIN(op_depth) FROM nodes n
 
231
                    WHERE n.wc_id = ?1
 
232
                      AND n.local_relpath = nodes.local_relpath
 
233
                      AND op_depth > ?3)
 
234
 
 
235
-- STMT_DELETE_WORKING_BASE_DELETE_RECURSIVE
 
236
DELETE FROM nodes
213
237
WHERE wc_id = ?1 AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
214
238
  AND presence = MAP_BASE_DELETED
215
 
  AND op_depth > 0
 
239
  AND op_depth > ?3
216
240
  AND op_depth = (SELECT MIN(op_depth) FROM nodes n
217
241
                    WHERE n.wc_id = ?1
218
242
                      AND n.local_relpath = nodes.local_relpath
219
 
                      AND op_depth > 0)
 
243
                      AND op_depth > ?3)
220
244
 
221
245
-- STMT_DELETE_WORKING_RECURSIVE
222
246
DELETE FROM nodes
225
249
 
226
250
-- STMT_DELETE_BASE_RECURSIVE
227
251
DELETE FROM nodes
228
 
WHERE wc_id = ?1 AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
 
252
WHERE wc_id = ?1 AND (local_relpath = ?2 
 
253
                      OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
229
254
  AND op_depth = 0
230
255
 
231
256
-- STMT_DELETE_WORKING_OP_DEPTH
232
257
DELETE FROM nodes
233
 
WHERE wc_id = ?1 
234
 
  AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
235
 
  AND op_depth = ?3
236
 
 
237
 
DELETE FROM nodes
238
 
WHERE wc_id = ?1 
239
 
  AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
240
 
  AND op_depth > ?3
241
 
 
242
 
SELECT local_relpath
243
 
FROM nodes
244
258
WHERE wc_id = ?1
245
259
  AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
246
260
  AND op_depth = ?3
247
261
 
 
262
/* Full layer replacement check code for handling moves
 
263
The op_root must exist (or there is no layer to replace) and an op-root
 
264
   always has presence 'normal' */
 
265
-- STMT_SELECT_LAYER_FOR_REPLACE
 
266
SELECT s.local_relpath, s.kind,
 
267
  RELPATH_SKIP_JOIN(?2, ?4, s.local_relpath) drp, 'normal'
 
268
FROM nodes s
 
269
WHERE s.wc_id = ?1 AND s.local_relpath = ?2 AND s.op_depth = ?3
 
270
UNION ALL
 
271
SELECT s.local_relpath, s.kind,
 
272
  RELPATH_SKIP_JOIN(?2, ?4, s.local_relpath) drp, d.presence
 
273
FROM nodes s
 
274
LEFT OUTER JOIN nodes d ON d.wc_id= ?1 AND d.op_depth = ?5
 
275
     AND d.local_relpath = drp
 
276
WHERE s.wc_id = ?1
 
277
  AND IS_STRICT_DESCENDANT_OF(s.local_relpath, ?2)
 
278
  AND s.op_depth = ?3
 
279
ORDER BY s.local_relpath
 
280
 
 
281
-- STMT_SELECT_DESCENDANTS_OP_DEPTH_RV
248
282
SELECT local_relpath, kind
249
283
FROM nodes
250
284
WHERE wc_id = ?1
251
285
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
252
286
  AND op_depth = ?3
 
287
  AND presence in (MAP_NORMAL, MAP_INCOMPLETE)
253
288
ORDER BY local_relpath DESC
254
289
 
255
290
-- STMT_COPY_NODE_MOVE
262
294
    changed_author, checksum, properties, translated_size, last_mod_time,
263
295
    symlink_target, moved_here, moved_to )
264
296
SELECT
265
 
    wc_id, ?4 /*local_relpath */, ?5 /*op_depth*/, ?6 /* parent_relpath */,
266
 
    repos_id,
267
 
    repos_path, revision, presence, depth, kind, changed_revision,
268
 
    changed_date, changed_author, checksum, properties, translated_size,
269
 
    last_mod_time, symlink_target, 1,
270
 
    (SELECT dst.moved_to FROM nodes AS dst
271
 
                         WHERE dst.wc_id = ?1
272
 
                         AND dst.local_relpath = ?4
273
 
                         AND dst.op_depth = ?5)
274
 
FROM nodes
275
 
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
 
297
    s.wc_id, ?4 /*local_relpath */, ?5 /*op_depth*/, ?6 /* parent_relpath */,
 
298
    s.repos_id,
 
299
    s.repos_path, s.revision, s.presence, s.depth, s.kind, s.changed_revision,
 
300
    s.changed_date, s.changed_author, s.checksum, s.properties,
 
301
    CASE WHEN d.checksum=s.checksum THEN d.translated_size END,
 
302
    CASE WHEN d.checksum=s.checksum THEN d.last_mod_time END,
 
303
    s.symlink_target, 1, d.moved_to
 
304
FROM nodes s
 
305
LEFT JOIN nodes d ON d.wc_id=?1 AND d.local_relpath=?4 AND d.op_depth=?5
 
306
WHERE s.wc_id = ?1 AND s.local_relpath = ?2 AND s.op_depth = ?3
 
307
 
 
308
-- STMT_SELECT_NO_LONGER_MOVED_RV
 
309
SELECT d.local_relpath, RELPATH_SKIP_JOIN(?2, ?4, d.local_relpath) srp,
 
310
       b.presence, b.op_depth
 
311
FROM nodes d
 
312
LEFT OUTER JOIN nodes b ON b.wc_id = ?1 AND b.local_relpath = d.local_relpath
 
313
            AND b.op_depth = (SELECT MAX(x.op_depth) FROM nodes x
 
314
                              WHERE x.wc_id = ?1
 
315
                                AND x.local_relpath = b.local_relpath
 
316
                                AND x.op_depth < ?3)
 
317
WHERE d.wc_id = ?1
 
318
  AND IS_STRICT_DESCENDANT_OF(d.local_relpath, ?2)
 
319
  AND d.op_depth = ?3
 
320
  AND NOT EXISTS(SELECT * FROM nodes s
 
321
                 WHERE s.wc_id = ?1
 
322
                   AND s.local_relpath = srp
 
323
                   AND s.op_depth = ?5)
 
324
ORDER BY d.local_relpath DESC
276
325
 
277
326
-- STMT_SELECT_OP_DEPTH_CHILDREN
278
327
SELECT local_relpath, kind FROM nodes
279
 
WHERE wc_id = ?1 
 
328
WHERE wc_id = ?1
280
329
  AND parent_relpath = ?2
281
330
  AND op_depth = ?3
282
331
  AND presence != MAP_BASE_DELETED
283
332
  AND file_external is NULL
 
333
ORDER BY local_relpath
 
334
 
 
335
-- STMT_SELECT_OP_DEPTH_CHILDREN_EXISTS
 
336
SELECT local_relpath, kind FROM nodes
 
337
WHERE wc_id = ?1
 
338
  AND parent_relpath = ?2
 
339
  AND op_depth = ?3
 
340
  AND presence IN (MAP_NORMAL, MAP_INCOMPLETE)
 
341
ORDER BY local_relpath
284
342
 
285
343
/* Used by non-recursive revert to detect higher level children, and
286
344
   actual-only rows that would be left orphans, if the revert
288
346
-- STMT_SELECT_GE_OP_DEPTH_CHILDREN
289
347
SELECT 1 FROM nodes
290
348
WHERE wc_id = ?1 AND parent_relpath = ?2
291
 
  AND (op_depth > ?3 OR (op_depth = ?3 AND presence != MAP_BASE_DELETED))
 
349
  AND (op_depth > ?3 OR (op_depth = ?3
 
350
                         AND presence IN (MAP_NORMAL, MAP_INCOMPLETE)))
292
351
UNION ALL
293
352
SELECT 1 FROM ACTUAL_NODE a
294
353
WHERE wc_id = ?1 AND parent_relpath = ?2
318
377
-- STMT_COMMIT_DESCENDANTS_TO_BASE
319
378
UPDATE NODES SET op_depth = 0,
320
379
                 repos_id = ?4,
321
 
                 repos_path = ?5 || SUBSTR(local_relpath, LENGTH(?2)+1),
 
380
                 repos_path = RELPATH_SKIP_JOIN(?2, ?5, local_relpath),
322
381
                 revision = ?6,
323
382
                 dav_cache = NULL,
324
383
                 moved_here = NULL,
 
384
                 moved_to = NULL,
325
385
                 presence = CASE presence
326
386
                              WHEN MAP_NORMAL THEN MAP_NORMAL
327
387
                              WHEN MAP_EXCLUDED THEN MAP_EXCLUDED
334
394
-- STMT_SELECT_NODE_CHILDREN
335
395
/* Return all paths that are children of the directory (?1, ?2) in any
336
396
   op-depth, including children of any underlying, replaced directories. */
337
 
SELECT local_relpath FROM nodes
 
397
SELECT DISTINCT local_relpath FROM nodes
338
398
WHERE wc_id = ?1 AND parent_relpath = ?2
 
399
ORDER BY local_relpath
339
400
 
340
401
-- STMT_SELECT_WORKING_CHILDREN
341
402
/* Return all paths that are children of the working version of the
342
403
   directory (?1, ?2).  A given path is not included just because it is a
343
404
   child of an underlying (replaced) directory, it has to be in the
344
405
   working version of the directory. */
345
 
SELECT local_relpath FROM nodes
 
406
SELECT DISTINCT local_relpath FROM nodes
346
407
WHERE wc_id = ?1 AND parent_relpath = ?2
347
408
  AND (op_depth > (SELECT MAX(op_depth) FROM nodes
348
409
                   WHERE wc_id = ?1 AND local_relpath = ?2)
349
410
       OR
350
411
       (op_depth = (SELECT MAX(op_depth) FROM nodes
351
412
                    WHERE wc_id = ?1 AND local_relpath = ?2)
352
 
        AND presence != MAP_BASE_DELETED))
 
413
        AND presence IN (MAP_NORMAL, MAP_INCOMPLETE)))
 
414
ORDER BY local_relpath
 
415
 
 
416
-- STMT_SELECT_BASE_NOT_PRESENT_CHILDREN
 
417
SELECT local_relpath FROM nodes
 
418
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = 0
 
419
  AND presence = MAP_NOT_PRESENT
 
420
ORDER BY local_relpath
353
421
 
354
422
-- STMT_SELECT_NODE_PROPS
355
423
SELECT properties, presence FROM nodes
396
464
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = 0
397
465
 
398
466
-- STMT_SELECT_DELETION_INFO
399
 
SELECT (SELECT b.presence FROM nodes AS b
400
 
         WHERE b.wc_id = ?1 AND b.local_relpath = ?2 AND b.op_depth = 0),
401
 
       work.presence, work.op_depth
402
 
FROM nodes_current AS work
403
 
WHERE work.wc_id = ?1 AND work.local_relpath = ?2 AND work.op_depth > 0
404
 
LIMIT 1
405
 
 
406
 
/* ### FIXME.  moved.moved_to IS NOT NULL works when there is
407
 
 only one move but we need something else when there are several. */
408
 
SELECT (SELECT b.presence FROM nodes AS b
409
 
         WHERE b.wc_id = ?1 AND b.local_relpath = ?2 AND b.op_depth = 0),
410
 
       work.presence, work.op_depth, moved.moved_to
411
 
FROM nodes_current AS work
412
 
LEFT OUTER JOIN nodes AS moved 
413
 
  ON moved.wc_id = work.wc_id
414
 
 AND moved.local_relpath = work.local_relpath
415
 
 AND moved.moved_to IS NOT NULL
416
 
WHERE work.wc_id = ?1 AND work.local_relpath = ?2 AND work.op_depth > 0
 
467
SELECT b.presence, w.presence, w.op_depth, w.moved_to
 
468
FROM nodes w
 
469
LEFT JOIN nodes b ON b.wc_id = ?1 AND b.local_relpath = ?2 AND b.op_depth = 0
 
470
WHERE w.wc_id = ?1 AND w.local_relpath = ?2
 
471
  AND w.op_depth = (SELECT MAX(op_depth) FROM nodes d
 
472
                    WHERE d.wc_id = ?1 AND d.local_relpath = ?2
 
473
                      AND d.op_depth > 0)
417
474
LIMIT 1
418
475
 
419
476
-- STMT_SELECT_MOVED_TO_NODE
424
480
ORDER BY op_depth DESC
425
481
 
426
482
-- STMT_SELECT_OP_DEPTH_MOVED_TO
427
 
SELECT op_depth, moved_to, repos_path, revision
 
483
SELECT op_depth, moved_to
428
484
FROM nodes
429
 
WHERE wc_id = ?1 AND local_relpath = ?2
430
 
 AND op_depth <= (SELECT MIN(op_depth) FROM nodes
431
 
                  WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth > ?3)
432
 
ORDER BY op_depth DESC
 
485
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth > ?3
 
486
  AND EXISTS(SELECT * from nodes
 
487
             WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
 
488
             AND presence IN (MAP_NORMAL, MAP_INCOMPLETE))
 
489
ORDER BY op_depth ASC
 
490
LIMIT 1
433
491
 
434
492
-- STMT_SELECT_MOVED_TO
435
493
SELECT moved_to
436
494
FROM nodes
437
495
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
438
496
 
439
 
SELECT moved_here, presence, repos_path, revision
440
 
FROM nodes
441
 
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth >= ?3
442
 
ORDER BY op_depth
443
 
 
444
497
-- STMT_SELECT_MOVED_BACK
445
498
SELECT u.local_relpath,
446
499
       u.presence, u.repos_id, u.repos_path, u.revision,
467
519
  AND IS_STRICT_DESCENDANT_OF(u.local_relpath, ?2)
468
520
  AND u.op_depth = ?4
469
521
 
470
 
DELETE FROM nodes
471
 
WHERE wc_id = ?1
472
 
  AND (local_relpath = ?2
473
 
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
474
 
  AND op_depth = ?3
475
 
 
476
522
-- STMT_DELETE_LOCK
477
523
DELETE FROM lock
478
524
WHERE repos_id = ?1 AND repos_relpath = ?2
498
543
WHERE (wc_id = ?1 AND local_relpath = ?2 AND repos_id = ?3)
499
544
   OR (wc_id = ?1 AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
500
545
       AND repos_id = ?3)
501
 
 
 
546
 
502
547
 
503
548
-- STMT_UPDATE_LOCK_REPOS_ID
504
549
UPDATE lock SET repos_id = ?2
677
722
SELECT wc_id, local_relpath, parent_relpath
678
723
FROM targets_list
679
724
 
 
725
-- STMT_INSERT_ACTUAL_EMPTIES_FILES
 
726
INSERT OR IGNORE INTO actual_node (
 
727
     wc_id, local_relpath, parent_relpath)
 
728
SELECT wc_id, local_relpath, parent_relpath
 
729
FROM targets_list
 
730
WHERE kind=MAP_FILE
 
731
 
680
732
-- STMT_DELETE_ACTUAL_EMPTY
681
733
DELETE FROM actual_node
682
734
WHERE wc_id = ?1 AND local_relpath = ?2
691
743
-- STMT_DELETE_ACTUAL_EMPTIES
692
744
DELETE FROM actual_node
693
745
WHERE wc_id = ?1
694
 
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
 
746
  AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
695
747
  AND properties IS NULL
696
748
  AND conflict_data IS NULL
697
749
  AND changelist IS NULL
755
807
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
756
808
  AND (changelist IS NULL
757
809
       OR NOT EXISTS (SELECT 1 FROM nodes_current c
758
 
                      WHERE c.wc_id = ?1 
 
810
                      WHERE c.wc_id = ?1
759
811
                        AND c.local_relpath = actual_node.local_relpath
760
812
                        AND c.kind = MAP_FILE))
761
813
 
770
822
    right_checksum = NULL
771
823
WHERE wc_id = ?1 AND local_relpath = ?2
772
824
 
 
825
-- STMT_CLEAR_ACTUAL_NODE_LEAVING_CONFLICT
 
826
UPDATE actual_node
 
827
SET properties = NULL,
 
828
    text_mod = NULL,
 
829
    tree_conflict_data = NULL,
 
830
    older_checksum = NULL,
 
831
    left_checksum = NULL,
 
832
    right_checksum = NULL,
 
833
    changelist = NULL
 
834
WHERE wc_id = ?1 AND local_relpath = ?2
 
835
 
773
836
-- STMT_CLEAR_ACTUAL_NODE_LEAVING_CHANGELIST_RECURSIVE
774
837
UPDATE actual_node
775
838
SET properties = NULL,
787
850
UPDATE nodes SET depth = ?3
788
851
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = 0
789
852
  AND kind=MAP_DIR
 
853
  AND presence IN (MAP_NORMAL, MAP_INCOMPLETE)
790
854
 
791
855
-- STMT_UPDATE_NODE_BASE_PRESENCE
792
856
UPDATE nodes SET presence = ?3
891
955
WHERE wc_id = ?1
892
956
  AND IS_STRICT_DESCENDANT_OF(local_dir_relpath, ?2)
893
957
 
 
958
-- STMT_FIND_CONFLICT_DESCENDANT
 
959
SELECT 1 FROM actual_node
 
960
WHERE wc_id = ?1
 
961
  AND local_relpath > (?2 || '/')
 
962
  AND local_relpath < (?2 || '0') /* '0' = ascii('/') +1 */
 
963
  AND conflict_data IS NOT NULL
 
964
LIMIT 1
 
965
 
894
966
-- STMT_DELETE_WC_LOCK_ORPHAN
895
967
DELETE FROM wc_lock
896
968
WHERE wc_id = ?1 AND local_dir_relpath = ?2
924
996
            AND op_depth = 0))
925
997
 
926
998
-- STMT_INSTALL_WORKING_NODE_FOR_DELETE
927
 
INSERT OR REPLACE INTO nodes (
 
999
INSERT INTO nodes (
928
1000
    wc_id, local_relpath, op_depth,
929
1001
    parent_relpath, presence, kind)
930
1002
VALUES(?1, ?2, ?3, ?4, MAP_BASE_DELETED, ?5)
931
1003
 
932
 
DELETE FROM nodes
933
 
 WHERE wc_id = ?1
934
 
   AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
935
 
   AND op_depth = ?3
936
 
   AND NOT EXISTS (SELECT 1 FROM nodes n
937
 
                    WHERE n.wc_id = ?1
938
 
                    AND n.local_relpath = nodes.local_relpath
939
 
                    AND n.op_depth = ?4
940
 
                    AND n.presence IN (MAP_NORMAL, MAP_INCOMPLETE))
941
 
 
942
1004
-- STMT_REPLACE_WITH_BASE_DELETED
943
1005
INSERT OR REPLACE INTO nodes (wc_id, local_relpath, op_depth, parent_relpath,
944
1006
                              kind, moved_to, presence)
947
1008
       kind, moved_to, MAP_BASE_DELETED
948
1009
  FROM nodes
949
1010
 WHERE wc_id = ?1
950
 
   AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
 
1011
   AND local_relpath = ?2
951
1012
   AND op_depth = ?3
952
1013
 
953
 
/* If this query is updated, STMT_INSERT_DELETE_LIST should too. */
 
1014
/* If this query is updated, STMT_INSERT_DELETE_LIST should too.
 
1015
   Use UNION ALL instead of a simple 'OR' to avoid creating a temp table */
954
1016
-- STMT_INSERT_DELETE_FROM_NODE_RECURSIVE
955
1017
INSERT INTO nodes (
956
1018
    wc_id, local_relpath, op_depth, parent_relpath, presence, kind)
957
1019
SELECT wc_id, local_relpath, ?4 /*op_depth*/, parent_relpath, MAP_BASE_DELETED,
958
1020
       kind
959
1021
FROM nodes
 
1022
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
 
1023
UNION ALL
 
1024
SELECT wc_id, local_relpath, ?4 /*op_depth*/, parent_relpath, MAP_BASE_DELETED,
 
1025
       kind
 
1026
FROM nodes
960
1027
WHERE wc_id = ?1
961
 
  AND (local_relpath = ?2
962
 
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
 
1028
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
963
1029
  AND op_depth = ?3
964
1030
  AND presence NOT IN (MAP_BASE_DELETED, MAP_NOT_PRESENT, MAP_EXCLUDED, MAP_SERVER_EXCLUDED)
965
1031
  AND file_external IS NULL
 
1032
ORDER BY local_relpath
966
1033
 
967
1034
-- STMT_INSERT_WORKING_NODE_FROM_BASE_COPY
968
 
INSERT INTO nodes (
 
1035
INSERT OR REPLACE INTO nodes (
969
1036
    wc_id, local_relpath, op_depth, parent_relpath, repos_id, repos_path,
970
1037
    revision, presence, depth, kind, changed_revision, changed_date,
971
1038
    changed_author, checksum, properties, translated_size, last_mod_time,
972
 
    symlink_target )
 
1039
    symlink_target, moved_to )
973
1040
SELECT wc_id, local_relpath, ?3 /*op_depth*/, parent_relpath, repos_id,
974
1041
    repos_path, revision, presence, depth, kind, changed_revision,
975
1042
    changed_date, changed_author, checksum, properties, translated_size,
976
 
    last_mod_time, symlink_target
 
1043
    last_mod_time, symlink_target,
 
1044
    (SELECT moved_to FROM nodes
 
1045
     WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3) moved_to
977
1046
FROM nodes
978
1047
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = 0
979
1048
 
992
1061
 AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
993
1062
 AND op_depth = ?3
994
1063
 
995
 
UPDATE nodes SET op_depth = ?4, moved_here = NULL
996
 
WHERE wc_id = ?1
997
 
 AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
998
 
 AND op_depth = ?3
 
1064
/* Duplicated SELECT body to avoid creating temporary table */
 
1065
-- STMT_COPY_OP_DEPTH_RECURSIVE
 
1066
INSERT INTO nodes (
 
1067
    wc_id, local_relpath, op_depth, parent_relpath, repos_id, repos_path,
 
1068
    revision, presence, depth, kind, changed_revision, changed_date,
 
1069
    changed_author, checksum, properties, translated_size, last_mod_time,
 
1070
    symlink_target, moved_here, moved_to )
 
1071
SELECT
 
1072
    wc_id, local_relpath, ?4, parent_relpath, repos_id,
 
1073
    repos_path, revision, presence, depth, kind, changed_revision,
 
1074
    changed_date, changed_author, checksum, properties, translated_size,
 
1075
    last_mod_time, symlink_target, NULL, NULL
 
1076
FROM nodes
 
1077
WHERE wc_id = ?1 AND op_depth = ?3 AND local_relpath = ?2
 
1078
UNION ALL
 
1079
SELECT
 
1080
    wc_id, local_relpath, ?4, parent_relpath, repos_id,
 
1081
    repos_path, revision, presence, depth, kind, changed_revision,
 
1082
    changed_date, changed_author, checksum, properties, translated_size,
 
1083
    last_mod_time, symlink_target, NULL, NULL
 
1084
FROM nodes
 
1085
WHERE wc_id = ?1 AND op_depth = ?3
 
1086
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
 
1087
ORDER BY local_relpath
999
1088
 
1000
1089
-- STMT_DOES_NODE_EXIST
1001
1090
SELECT 1 FROM nodes WHERE wc_id = ?1 AND local_relpath = ?2
1213
1301
 
1214
1302
/* these are used in upgrade.c  */
1215
1303
 
1216
 
UPDATE actual_node SET conflict_data = ?3
1217
 
WHERE wc_id = ?1 AND local_relpath = ?2
1218
 
 
1219
 
INSERT INTO actual_node (wc_id, local_relpath, conflict_data, parent_relpath)
1220
 
VALUES (?1, ?2, ?3, ?4)
1221
 
 
1222
1304
-- STMT_SELECT_ALL_FILES
1223
1305
SELECT local_relpath FROM nodes_current
1224
1306
WHERE wc_id = ?1 AND parent_relpath = ?2 AND kind = MAP_FILE
1333
1413
                            WHERE n.wc_id = OLD.wc_id
1334
1414
                              AND n.local_relpath = OLD.local_relpath)
1335
1415
            THEN 1
1336
 
            ELSE NULL
1337
 
          END;
 
1416
          END notify
 
1417
   WHERE OLD.conflict_data IS NOT NULL
 
1418
      OR notify IS NOT NULL;
1338
1419
END;
1339
1420
DROP TRIGGER IF EXISTS   trigger_revert_list_actual_update;
1340
1421
CREATE TEMPORARY TRIGGER trigger_revert_list_actual_update
1350
1431
                            WHERE n.wc_id = OLD.wc_id
1351
1432
                              AND n.local_relpath = OLD.local_relpath)
1352
1433
            THEN 1
1353
 
            ELSE NULL
1354
 
          END;
 
1434
          END notify
 
1435
   WHERE OLD.conflict_data IS NOT NULL
 
1436
      OR notify IS NOT NULL;
1355
1437
END
1356
1438
 
1357
1439
-- STMT_DROP_REVERT_LIST_TRIGGERS
1377
1459
DELETE FROM revert_list WHERE local_relpath = ?1
1378
1460
 
1379
1461
-- STMT_SELECT_REVERT_LIST_RECURSIVE
1380
 
SELECT DISTINCT local_relpath
1381
 
FROM revert_list
1382
 
WHERE (local_relpath = ?1
1383
 
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?1))
1384
 
  AND (notify OR actual = 0)
1385
 
ORDER BY local_relpath
 
1462
SELECT p.local_relpath, n.kind, a.notify, a.kind
 
1463
FROM (SELECT DISTINCT local_relpath
 
1464
      FROM revert_list
 
1465
      WHERE (local_relpath = ?1
 
1466
        OR IS_STRICT_DESCENDANT_OF(local_relpath, ?1))) p
 
1467
 
 
1468
LEFT JOIN revert_list n ON n.local_relpath=p.local_relpath AND n.actual=0
 
1469
LEFT JOIN revert_list a ON a.local_relpath=p.local_relpath AND a.actual=1
 
1470
ORDER BY p.local_relpath
1386
1471
 
1387
1472
-- STMT_DELETE_REVERT_LIST_RECURSIVE
1388
1473
DELETE FROM revert_list
1404
1489
   A subquery is used instead of nodes_current to avoid a table scan */
1405
1490
-- STMT_INSERT_DELETE_LIST
1406
1491
INSERT INTO delete_list(local_relpath)
 
1492
SELECT ?2
 
1493
UNION ALL
1407
1494
SELECT local_relpath FROM nodes AS n
1408
1495
WHERE wc_id = ?1
1409
 
  AND (local_relpath = ?2
1410
 
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
 
1496
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
1411
1497
  AND op_depth >= ?3
1412
1498
  AND op_depth = (SELECT MAX(s.op_depth) FROM nodes AS s
1413
1499
                  WHERE s.wc_id = ?1
1414
1500
                    AND s.local_relpath = n.local_relpath)
1415
1501
  AND presence NOT IN (MAP_BASE_DELETED, MAP_NOT_PRESENT, MAP_EXCLUDED, MAP_SERVER_EXCLUDED)
1416
1502
  AND file_external IS NULL
 
1503
ORDER by local_relpath
1417
1504
 
1418
1505
-- STMT_SELECT_DELETE_LIST
1419
1506
SELECT local_relpath FROM delete_list
1429
1516
   ### working copies. queries, etc will need to be adjusted.  */
1430
1517
  local_relpath TEXT PRIMARY KEY NOT NULL UNIQUE,
1431
1518
  action INTEGER NOT NULL,
1432
 
  kind  INTEGER NOT NULL,
 
1519
  kind TEXT NOT NULL,
1433
1520
  content_state INTEGER NOT NULL,
1434
1521
  prop_state  INTEGER NOT NULL
1435
1522
  )
1447
1534
-- STMT_FINALIZE_UPDATE_MOVE
1448
1535
DROP TABLE IF EXISTS update_move_list
1449
1536
 
 
1537
-- STMT_MOVE_NOTIFY_TO_REVERT
 
1538
INSERT INTO revert_list (local_relpath, notify, kind, actual)
 
1539
       SELECT local_relpath, 2, kind, 1 FROM update_move_list;
 
1540
DROP TABLE update_move_list
 
1541
 
1450
1542
/* ------------------------------------------------------------------------- */
1451
1543
 
1452
1544
/* Queries for revision status. */
1499
1591
  AND repos_path IS NOT RELPATH_SKIP_JOIN(?2, ?3, local_relpath)
1500
1592
LIMIT 1
1501
1593
 
1502
 
SELECT local_relpath, translated_size, last_mod_time FROM nodes AS n
1503
 
WHERE wc_id = ?1
1504
 
  AND (local_relpath = ?2
1505
 
       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
1506
 
  AND op_depth = 0
1507
 
  AND kind=MAP_FILE
1508
 
  AND presence=MAP_NORMAL
1509
 
  AND file_external IS NULL
1510
 
 
1511
1594
-- STMT_SELECT_MOVED_FROM_RELPATH
1512
1595
SELECT local_relpath, op_depth FROM nodes
1513
1596
WHERE wc_id = ?1 AND moved_to = ?2 AND op_depth > 0
1571
1653
 WHERE wc_id = ?1
1572
1654
   AND IS_STRICT_DESCENDANT_OF(moved_to, ?2)
1573
1655
 
1574
 
 
1575
 
/* This statement returns pairs of move-roots below the path ?2 in WC_ID ?1,
1576
 
 * where the source of the move is within the subtree rooted at path ?2, and
1577
 
 * the destination of the move is outside the subtree rooted at path ?2. */
1578
 
SELECT local_relpath, moved_to, op_depth FROM nodes
1579
 
WHERE wc_id = ?1
1580
 
  AND (local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
1581
 
  AND moved_to IS NOT NULL
1582
 
  AND NOT IS_STRICT_DESCENDANT_OF(moved_to, ?2)
1583
 
  AND op_depth >= (SELECT MAX(op_depth) FROM nodes o
1584
 
                    WHERE o.wc_id = ?1
1585
 
                      AND o.local_relpath = ?2)
1586
 
 
1587
1656
-- STMT_SELECT_MOVED_PAIR3
1588
 
SELECT local_relpath, moved_to, op_depth, kind FROM nodes
1589
 
WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth > ?3
1590
 
  AND moved_to IS NOT NULL
 
1657
SELECT n.local_relpath, d.moved_to, d.op_depth, n.kind
 
1658
FROM nodes n
 
1659
JOIN nodes d ON d.wc_id = ?1 AND d.local_relpath = n.local_relpath
 
1660
 AND d.op_depth = (SELECT MIN(dd.op_depth)
 
1661
                    FROM nodes dd
 
1662
                    WHERE dd.wc_id = ?1
 
1663
                      AND dd.local_relpath = d.local_relpath
 
1664
                      AND dd.op_depth > ?3)
 
1665
WHERE n.wc_id = ?1 AND n.local_relpath = ?2 AND n.op_depth = ?3
 
1666
  AND d.moved_to IS NOT NULL
1591
1667
UNION ALL
1592
 
SELECT local_relpath, moved_to, op_depth, kind FROM nodes
1593
 
WHERE wc_id = ?1
1594
 
  AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
1595
 
  AND op_depth > ?3
1596
 
  AND moved_to IS NOT NULL
1597
 
ORDER BY local_relpath, op_depth
 
1668
SELECT n.local_relpath, d.moved_to, d.op_depth, n.kind
 
1669
FROM nodes n
 
1670
JOIN nodes d ON d.wc_id = ?1 AND d.local_relpath = n.local_relpath
 
1671
 AND d.op_depth = (SELECT MIN(dd.op_depth)
 
1672
                    FROM nodes dd
 
1673
                    WHERE dd.wc_id = ?1
 
1674
                      AND dd.local_relpath = d.local_relpath
 
1675
                      AND dd.op_depth > ?3)
 
1676
WHERE n.wc_id = ?1 AND IS_STRICT_DESCENDANT_OF(n.local_relpath, ?2)
 
1677
  AND n.op_depth = ?3
 
1678
  AND d.moved_to IS NOT NULL
 
1679
ORDER BY n.local_relpath
1598
1680
 
1599
1681
-- STMT_SELECT_MOVED_OUTSIDE
1600
1682
SELECT local_relpath, moved_to, op_depth FROM nodes
1605
1686
  AND moved_to IS NOT NULL
1606
1687
  AND NOT IS_STRICT_DESCENDANT_OF(moved_to, ?2)
1607
1688
 
1608
 
SELECT n.local_relpath, n.moved_to,
1609
 
       (SELECT o.repos_path FROM nodes AS o
1610
 
        WHERE o.wc_id = n.wc_id
1611
 
          AND o.local_relpath = n.local_relpath
1612
 
          AND o.op_depth < ?3 ORDER BY o.op_depth DESC LIMIT 1)
1613
 
FROM nodes AS n
1614
 
WHERE n.wc_id = ?1
1615
 
  AND IS_STRICT_DESCENDANT_OF(n.local_relpath, ?2)
1616
 
  AND n.op_depth = ?3
1617
 
  AND n.moved_to IS NOT NULL
1618
 
 
1619
 
SELECT n.local_relpath, h.moved_to
1620
 
FROM nodes n, nodes h
1621
 
WHERE n.wc_id = ?1
1622
 
  AND h.wc_id = ?1
1623
 
  AND IS_STRICT_DESCENDANT_OF(n.local_relpath, ?2)
1624
 
  AND h.local_relpath = n.local_relpath
1625
 
  AND n.op_depth = ?3
1626
 
  AND h.op_depth = (SELECT MIN(o.op_depth)
1627
 
                    FROM nodes o
1628
 
                    WHERE o.wc_id = ?1
1629
 
                      AND o.local_relpath = n.local_relpath
1630
 
                      AND o.op_depth > ?3)
1631
 
  AND h.moved_to IS NOT NULL
 
1689
-- STMT_SELECT_MOVED_DESCENDANTS_SRC
 
1690
SELECT s.op_depth, n.local_relpath, n.kind, n.repos_path, s.moved_to
 
1691
FROM nodes n
 
1692
JOIN nodes s ON s.wc_id = n.wc_id AND s.local_relpath = n.local_relpath
 
1693
 AND s.op_depth = (SELECT MIN(d.op_depth)
 
1694
                    FROM nodes d
 
1695
                    WHERE d.wc_id = ?1
 
1696
                      AND d.local_relpath = s.local_relpath
 
1697
                      AND d.op_depth > ?3)
 
1698
WHERE n.wc_id = ?1 AND n.op_depth = ?3
 
1699
  AND (n.local_relpath = ?2 OR IS_STRICT_DESCENDANT_OF(n.local_relpath, ?2))
 
1700
  AND s.moved_to IS NOT NULL
1632
1701
 
1633
1702
-- STMT_COMMIT_UPDATE_ORIGIN
1634
 
/* Note that the only reason this SUBSTR() trick is valid is that you
1635
 
   can move neither the working copy nor the repository root.
1636
 
 
1637
 
   SUBSTR(local_relpath, LENGTH(?2)+1) includes the '/' of the path */
1638
1703
UPDATE nodes SET repos_id = ?4,
1639
 
                 repos_path = ?5 || SUBSTR(local_relpath, LENGTH(?2)+1),
 
1704
                 repos_path = RELPATH_SKIP_JOIN(?2, ?5, local_relpath),
1640
1705
                 revision = ?6
1641
1706
WHERE wc_id = ?1
1642
1707
  AND (local_relpath = ?2
1658
1721
 
1659
1722
-- STMT_SELECT_HAS_NON_FILE_CHILDREN
1660
1723
SELECT 1 FROM nodes
1661
 
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = 0 AND kind != MAP_FILE
 
1724
WHERE wc_id = ?1 AND parent_relpath = ?2 AND op_depth = ?3 AND kind != MAP_FILE
 
1725
LIMIT 1
1662
1726
 
1663
1727
-- STMT_SELECT_HAS_GRANDCHILDREN
1664
1728
SELECT 1 FROM nodes
1665
1729
WHERE wc_id = ?1
1666
1730
  AND IS_STRICT_DESCENDANT_OF(parent_relpath, ?2)
1667
 
  AND op_depth = 0
 
1731
  AND op_depth = ?3
1668
1732
  AND file_external IS NULL
 
1733
LIMIT 1
1669
1734
 
1670
1735
/* ------------------------------------------------------------------------- */
1671
1736