@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update PhabricatorLiskDAO::chunkSQL() for new %Q semantics

Summary:
Ref T13217. This method is slightly tricky:

- We can't safely return a string: return an array instead.
- It no longer makes sense to accept glue. All callers use `', '` as glue anyway, so hard-code that.

Then convert all callsites.

Test Plan: Browsed around, saw fewer "unsafe" errors in error log.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13217

Differential Revision: https://secure.phabricator.com/D19784

+59 -60
+1 -1
resources/sql/autopatches/20140805.boardcol.2.php
··· 45 45 queryfx( 46 46 $conn_w, 47 47 'INSERT INTO %T (boardPHID, columnPHID, objectPHID, sequence) 48 - VALUES %Q', 48 + VALUES %LQ', 49 49 id(new PhabricatorProjectColumnPosition())->getTableName(), 50 50 $chunk); 51 51 }
+2 -2
resources/sql/patches/20130820.file-mailkey-populate.php
··· 22 22 } 23 23 24 24 if ($sql) { 25 - foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $chunk) { 25 + foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 26 26 queryfx( 27 27 $conn_w, 28 28 'INSERT INTO %T 29 29 (id, mailKey, phid, byteSize, storageEngine, storageFormat, 30 - storageHandle, dateCreated, dateModified, metadata) VALUES %Q '. 30 + storageHandle, dateCreated, dateModified, metadata) VALUES %LQ '. 31 31 'ON DUPLICATE KEY UPDATE mailKey = VALUES(mailKey)', 32 32 $table_name, 33 33 $chunk);
+2 -2
resources/sql/patches/20131106.diffphid.2.mig.php
··· 34 34 continue; 35 35 } 36 36 37 - foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $sql_chunk) { 37 + foreach (PhabricatorLiskDAO::chunkSQL($sql) as $sql_chunk) { 38 38 queryfx( 39 39 $conn_w, 40 - 'INSERT IGNORE INTO %T (id, phid) VALUES %Q 40 + 'INSERT IGNORE INTO %T (id, phid) VALUES %LQ 41 41 ON DUPLICATE KEY UPDATE phid = VALUES(phid)', 42 42 $diff_table->getTableName(), 43 43 $sql_chunk);
+1 -1
src/applications/cache/PhabricatorKeyValueDatabaseCache.php
··· 38 38 $conn_w, 39 39 'INSERT INTO %T 40 40 (cacheKeyHash, cacheKey, cacheFormat, cacheData, 41 - cacheCreated, cacheExpires) VALUES %Q 41 + cacheCreated, cacheExpires) VALUES %LQ 42 42 ON DUPLICATE KEY UPDATE 43 43 cacheKey = VALUES(cacheKey), 44 44 cacheFormat = VALUES(cacheFormat),
+1 -1
src/applications/calendar/notifications/PhabricatorCalendarNotificationEngine.php
··· 245 245 $conn, 246 246 'INSERT IGNORE INTO %T 247 247 (eventPHID, targetPHID, utcInitialEpoch, didNotifyEpoch) 248 - VALUES %Q', 248 + VALUES %LQ', 249 249 $table->getTableName(), 250 250 $chunk); 251 251 }
+2 -2
src/applications/diffusion/conduit/DiffusionUpdateCoverageConduitAPIMethod.php
··· 106 106 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 107 107 queryfx( 108 108 $conn, 109 - 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q'. 110 - ' ON DUPLICATE KEY UPDATE coverage=VALUES(coverage)', 109 + 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %LQ'. 110 + ' ON DUPLICATE KEY UPDATE coverage = VALUES(coverage)', 111 111 $table_name, 112 112 $chunk); 113 113 }
+2 -2
src/applications/diviner/publisher/DivinerLivePublisher.php
··· 101 101 $strings[] = qsprintf($conn_w, '%s', $hash); 102 102 } 103 103 104 - foreach (PhabricatorLiskDAO::chunkSQL($strings, ', ') as $chunk) { 104 + foreach (PhabricatorLiskDAO::chunkSQL($strings) as $chunk) { 105 105 queryfx( 106 106 $conn_w, 107 107 'UPDATE %T SET graphHash = NULL, nodeHash = NULL 108 - WHERE graphHash IN (%Q)', 108 + WHERE graphHash IN (%LQ)', 109 109 $symbol_table->getTableName(), 110 110 $chunk); 111 111 }
+1 -1
src/applications/fact/daemon/PhabricatorFactDaemon.php
··· 189 189 $conn, 190 190 'INSERT INTO %T 191 191 (keyID, objectID, dimensionID, value, epoch) 192 - VALUES %Q', 192 + VALUES %LQ', 193 193 $table_name, 194 194 $chunk); 195 195 }
+1 -1
src/applications/fact/storage/PhabricatorFactDimension.php
··· 75 75 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 76 76 queryfx( 77 77 $conn, 78 - 'INSERT IGNORE INTO %T (%C) VALUES %Q', 78 + 'INSERT IGNORE INTO %T (%C) VALUES %LQ', 79 79 $this->getTableName(), 80 80 $column, 81 81 $chunk);
+1 -1
src/applications/maniphest/editor/ManiphestTransactionEditor.php
··· 531 531 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 532 532 queryfx( 533 533 $conn, 534 - 'INSERT INTO %T (id, %Q, subpriority) VALUES %Q 534 + 'INSERT INTO %T (id, %Q, subpriority) VALUES %LQ 535 535 ON DUPLICATE KEY UPDATE subpriority = VALUES(subpriority)', 536 536 $task->getTableName(), 537 537 implode(', ', array_keys($extra_columns)),
+1 -1
src/applications/people/storage/PhabricatorUserCache.php
··· 85 85 queryfx( 86 86 $conn_w, 87 87 'INSERT INTO %T (userPHID, cacheIndex, cacheKey, cacheData, cacheType) 88 - VALUES %Q 88 + VALUES %LQ 89 89 ON DUPLICATE KEY UPDATE 90 90 cacheData = VALUES(cacheData), 91 91 cacheType = VALUES(cacheType)',
+1 -1
src/applications/project/storage/PhabricatorProject.php
··· 467 467 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 468 468 queryfx( 469 469 $conn_w, 470 - 'INSERT INTO %T (projectID, token) VALUES %Q', 470 + 'INSERT INTO %T (projectID, token) VALUES %LQ', 471 471 $table, 472 472 $chunk); 473 473 }
+2 -2
src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php
··· 161 161 foreach (PhabricatorLiskDAO::chunkSQL($delete_sql) as $chunk) { 162 162 queryfx( 163 163 $conn_w, 164 - 'DELETE FROM %T WHERE childCommitID IN (%Q)', 164 + 'DELETE FROM %T WHERE childCommitID IN (%LQ)', 165 165 PhabricatorRepository::TABLE_PARENTS, 166 166 $chunk); 167 167 } ··· 169 169 foreach (PhabricatorLiskDAO::chunkSQL($insert_sql) as $chunk) { 170 170 queryfx( 171 171 $conn_w, 172 - 'INSERT INTO %T (childCommitID, parentCommitID) VALUES %Q', 172 + 'INSERT INTO %T (childCommitID, parentCommitID) VALUES %LQ', 173 173 PhabricatorRepository::TABLE_PARENTS, 174 174 $chunk); 175 175 }
+1 -1
src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
··· 151 151 'INSERT INTO %T 152 152 (repositoryID, pathID, commitID, targetPathID, targetCommitID, 153 153 changeType, fileType, isDirect, commitSequence) 154 - VALUES %Q', 154 + VALUES %LQ', 155 155 PhabricatorRepository::TABLE_PATHCHANGE, 156 156 $chunk); 157 157 }
+1 -1
src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php
··· 201 201 foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { 202 202 queryfx( 203 203 $conn, 204 - 'INSERT INTO %T (documentID, ngram) VALUES %Q', 204 + 'INSERT INTO %T (documentID, ngram) VALUES %LQ', 205 205 $engine->getNgramsTableName(), 206 206 $chunk); 207 207 }
+1 -1
src/applications/search/management/PhabricatorSearchManagementNgramsWorkflow.php
··· 123 123 queryfx( 124 124 $conn, 125 125 'INSERT IGNORE INTO %T (ngram, needsCollection) 126 - VALUES %Q', 126 + VALUES %LQ', 127 127 $engine->getCommonNgramsTableName(), 128 128 $chunk); 129 129 }
+1 -1
src/applications/system/engine/PhabricatorSystemActionEngine.php
··· 153 153 queryfx( 154 154 $conn_w, 155 155 'INSERT INTO %T (actorHash, actorIdentity, action, score, epoch) 156 - VALUES %Q', 156 + VALUES %LQ', 157 157 $log->getTableName(), 158 158 $chunk); 159 159 }
+1 -1
src/infrastructure/customfield/field/PhabricatorCustomFieldList.php
··· 303 303 foreach (PhabricatorLiskDAO::chunkSQL($sql_list) as $chunk) { 304 304 queryfx( 305 305 $conn_w, 306 - 'INSERT INTO %T (objectPHID, indexKey, indexValue) VALUES %Q', 306 + 'INSERT INTO %T (objectPHID, indexKey, indexValue) VALUES %LQ', 307 307 $table, 308 308 $chunk); 309 309 }
+12 -12
src/infrastructure/storage/__tests__/QueryFormattingTestCase.php
··· 7 7 8 8 $this->assertEqual( 9 9 'NULL', 10 - qsprintf($conn, '%nd', null)); 10 + (string)qsprintf($conn, '%nd', null)); 11 11 12 12 $this->assertEqual( 13 13 '0', 14 - qsprintf($conn, '%nd', 0)); 14 + (string)qsprintf($conn, '%nd', 0)); 15 15 16 16 $this->assertEqual( 17 17 '0', 18 - qsprintf($conn, '%d', 0)); 18 + (string)qsprintf($conn, '%d', 0)); 19 19 20 20 $raised = null; 21 21 try { ··· 29 29 30 30 $this->assertEqual( 31 31 "'<S>'", 32 - qsprintf($conn, '%s', null)); 32 + (string)qsprintf($conn, '%s', null)); 33 33 34 34 $this->assertEqual( 35 35 'NULL', 36 - qsprintf($conn, '%ns', null)); 36 + (string)qsprintf($conn, '%ns', null)); 37 37 38 38 $this->assertEqual( 39 39 "'<S>', '<S>'", 40 - qsprintf($conn, '%Ls', array('x', 'y'))); 40 + (string)qsprintf($conn, '%Ls', array('x', 'y'))); 41 41 42 42 $this->assertEqual( 43 43 "'<B>'", 44 - qsprintf($conn, '%B', null)); 44 + (string)qsprintf($conn, '%B', null)); 45 45 46 46 $this->assertEqual( 47 47 'NULL', 48 - qsprintf($conn, '%nB', null)); 48 + (string)qsprintf($conn, '%nB', null)); 49 49 50 50 $this->assertEqual( 51 51 "'<B>', '<B>'", 52 - qsprintf($conn, '%LB', array('x', 'y'))); 52 + (string)qsprintf($conn, '%LB', array('x', 'y'))); 53 53 54 54 $this->assertEqual( 55 55 '<C>', 56 - qsprintf($conn, '%T', 'x')); 56 + (string)qsprintf($conn, '%T', 'x')); 57 57 58 58 $this->assertEqual( 59 59 '<C>', 60 - qsprintf($conn, '%C', 'y')); 60 + (string)qsprintf($conn, '%C', 'y')); 61 61 62 62 $this->assertEqual( 63 63 '<C>.<C>', 64 - qsprintf($conn, '%R', new AphrontDatabaseTableRef('x', 'y'))); 64 + (string)qsprintf($conn, '%R', new AphrontDatabaseTableRef('x', 'y'))); 65 65 66 66 } 67 67
+7 -10
src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
··· 196 196 * INSERT, previously built with @{function:qsprintf}) into chunks which will 197 197 * fit under the MySQL 'max_allowed_packet' limit. 198 198 * 199 - * Chunks are glued together with `$glue`, by default ", ". 200 - * 201 199 * If a statement is too large to fit within the limit, it is broken into 202 200 * its own chunk (but might fail when the query executes). 203 201 */ 204 202 public static function chunkSQL( 205 203 array $fragments, 206 - $glue = ', ', 207 204 $limit = null) { 208 205 209 206 if ($limit === null) { ··· 216 213 217 214 $chunk = array(); 218 215 $len = 0; 219 - $glue_len = strlen($glue); 216 + $glue_len = strlen(', '); 220 217 foreach ($fragments as $fragment) { 221 - $this_len = strlen($fragment); 218 + if ($fragment instanceof PhutilQueryString) { 219 + $this_len = strlen($fragment->getUnmaskedString()); 220 + } else { 221 + $this_len = strlen($fragment); 222 + } 222 223 223 224 if ($chunk) { 224 225 // Chunks after the first also imply glue. ··· 232 233 if ($chunk) { 233 234 $result[] = $chunk; 234 235 } 235 - $len = strlen($fragment); 236 + $len = ($this_len - $glue_len); 236 237 $chunk = array($fragment); 237 238 } 238 239 } 239 240 240 241 if ($chunk) { 241 242 $result[] = $chunk; 242 - } 243 - 244 - foreach ($result as $key => $fragment_list) { 245 - $result[$key] = implode($glue, $fragment_list); 246 243 } 247 244 248 245 return $result;
+17 -15
src/infrastructure/storage/lisk/__tests__/LiskChunkTestCase.php
··· 15 15 16 16 $this->assertEqual( 17 17 array( 18 - 'aa', 19 - 'bb', 20 - 'ccc', 21 - 'dd', 22 - 'e', 18 + array('a'), 19 + array('a'), 20 + array('b'), 21 + array('b'), 22 + array('ccc'), 23 + array('dd'), 24 + array('e'), 23 25 ), 24 - PhabricatorLiskDAO::chunkSQL($fragments, '', 2)); 26 + PhabricatorLiskDAO::chunkSQL($fragments, 2)); 25 27 26 28 27 29 $fragments = array( ··· 37 39 38 40 $this->assertEqual( 39 41 array( 40 - 'a, a, a', 41 - 'XX, a, a', 42 - 'a, a', 42 + array('a', 'a', 'a'), 43 + array('XX', 'a', 'a'), 44 + array('a', 'a'), 43 45 ), 44 - PhabricatorLiskDAO::chunkSQL($fragments, ', ', 8)); 46 + PhabricatorLiskDAO::chunkSQL($fragments, 8)); 45 47 46 48 47 49 $fragments = array( ··· 55 57 56 58 $this->assertEqual( 57 59 array( 58 - 'xxxxxxxxxx', 59 - 'yyyyyyyyyy', 60 - 'a, b, c', 61 - 'zzzzzzzzzz', 60 + array('xxxxxxxxxx'), 61 + array('yyyyyyyyyy'), 62 + array('a', 'b', 'c'), 63 + array('zzzzzzzzzz'), 62 64 ), 63 - PhabricatorLiskDAO::chunkSQL($fragments, ', ', 8)); 65 + PhabricatorLiskDAO::chunkSQL($fragments, 8)); 64 66 } 65 67 66 68 }