Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Inna konstrukcja zapytania UPDATE?
Forum PHP.pl > Forum > Bazy danych > MySQL
assasin
Witam mam około 2 tysiące takich rekordów:)

  1. INSERT INTO `quest_template` VALUES ('66634', 'tekst1, 'tekst2', 'tekst3', 'Tekst4.', 'Tekst4?', '0');


I mam pytanie jak to najprościej/najszybciej przerobić te zapytania tak aby nie dodawały mi rakordu o id 66634 do tabel... itp tylko aktualizował rekord o ID 66634 wyłącznie tabele

`Title` text,
`Details` text,
`Objectives` text,
`OfferRewardText` text,
`RequestItemsText` text,
`EndText` text,

Ja sam wymyśliłem coś takiego:


  1. UPDATE `quest_template` SET `title`='tekst1, `details`='tekst2' (itd...) WHERE `id`=66634;


Musiał bym edytować około 2 tysiące rekordów ręcznie... zajęło by mi to około tydzień;/


Tabela na której chce przeprowadzić operacje wygląda tak:

  1. CREATE TABLE `quest_template` (
  2. `entry` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  3. `Method` tinyint(3) UNSIGNED NOT NULL DEFAULT '2',
  4. `ZoneOrSort` smallint(6) NOT NULL DEFAULT '0',
  5. `SkillOrClass` smallint(6) NOT NULL DEFAULT '0',
  6. `MinLevel` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  7. `QuestLevel` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  8. `Type` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  9. `RequiredRaces` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  10. `RequiredSkillValue` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  11. `RepObjectiveFaction` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  12. `RepObjectiveValue` mediumint(9) NOT NULL DEFAULT '0',
  13. `RequiredMinRepFaction` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  14. `RequiredMinRepValue` mediumint(9) NOT NULL DEFAULT '0',
  15. `RequiredMaxRepFaction` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  16. `RequiredMaxRepValue` mediumint(9) NOT NULL DEFAULT '0',
  17. `SuggestedPlayers` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  18. `LimitTime` int(10) UNSIGNED NOT NULL DEFAULT '0',
  19. `QuestFlags` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  20. `SpecialFlags` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  21. `CharTitleId` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  22. `PrevQuestId` mediumint(9) NOT NULL DEFAULT '0',
  23. `NextQuestId` mediumint(9) NOT NULL DEFAULT '0',
  24. `ExclusiveGroup` mediumint(9) NOT NULL DEFAULT '0',
  25. `NextQuestInChain` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  26. `SrcItemId` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  27. `SrcItemCount` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  28. `SrcSpell` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  29. `Title` text,
  30. `Details` text,
  31. `Objectives` text,
  32. `OfferRewardText` text,
  33. `RequestItemsText` text,
  34. `EndText` text,
  35. `ObjectiveText1` text,
  36. `ObjectiveText2` text,
  37. `ObjectiveText3` text,
  38. `ObjectiveText4` text,
  39. `ReqItemId1` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  40. `ReqItemId2` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  41. `ReqItemId3` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  42. `ReqItemId4` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  43. `ReqItemCount1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  44. `ReqItemCount2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  45. `ReqItemCount3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  46. `ReqItemCount4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  47. `ReqSourceId1` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  48. `ReqSourceId2` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  49. `ReqSourceId3` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  50. `ReqSourceId4` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  51. `ReqSourceCount1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  52. `ReqSourceCount2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  53. `ReqSourceCount3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  54. `ReqSourceCount4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  55. `ReqSourceRef1` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  56. `ReqSourceRef2` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  57. `ReqSourceRef3` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  58. `ReqSourceRef4` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  59. `ReqCreatureOrGOId1` mediumint(9) NOT NULL DEFAULT '0',
  60. `ReqCreatureOrGOId2` mediumint(9) NOT NULL DEFAULT '0',
  61. `ReqCreatureOrGOId3` mediumint(9) NOT NULL DEFAULT '0',
  62. `ReqCreatureOrGOId4` mediumint(9) NOT NULL DEFAULT '0',
  63. `ReqCreatureOrGOCount1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  64. `ReqCreatureOrGOCount2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  65. `ReqCreatureOrGOCount3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  66. `ReqCreatureOrGOCount4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  67. `ReqSpellCast1` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  68. `ReqSpellCast2` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  69. `ReqSpellCast3` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  70. `ReqSpellCast4` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  71. `RewChoiceItemId1` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  72. `RewChoiceItemId2` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  73. `RewChoiceItemId3` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  74. `RewChoiceItemId4` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  75. `RewChoiceItemId5` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  76. `RewChoiceItemId6` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  77. `RewChoiceItemCount1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  78. `RewChoiceItemCount2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  79. `RewChoiceItemCount3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  80. `RewChoiceItemCount4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  81. `RewChoiceItemCount5` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  82. `RewChoiceItemCount6` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  83. `RewItemId1` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  84. `RewItemId2` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  85. `RewItemId3` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  86. `RewItemId4` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  87. `RewItemCount1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  88. `RewItemCount2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  89. `RewItemCount3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  90. `RewItemCount4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  91. `RewRepFaction1` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'faction id from Faction.dbc in this case',
  92. `RewRepFaction2` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'faction id from Faction.dbc in this case',
  93. `RewRepFaction3` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'faction id from Faction.dbc in this case',
  94. `RewRepFaction4` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'faction id from Faction.dbc in this case',
  95. `RewRepFaction5` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'faction id from Faction.dbc in this case',
  96. `RewRepValue1` mediumint(9) NOT NULL DEFAULT '0',
  97. `RewRepValue2` mediumint(9) NOT NULL DEFAULT '0',
  98. `RewRepValue3` mediumint(9) NOT NULL DEFAULT '0',
  99. `RewRepValue4` mediumint(9) NOT NULL DEFAULT '0',
  100. `RewRepValue5` mediumint(9) NOT NULL DEFAULT '0',
  101. `RewHonorableKills` mediumint(9) UNSIGNED NOT NULL DEFAULT '0',
  102. `RewOrReqMoney` int(11) NOT NULL DEFAULT '0',
  103. `RewMoneyMaxLevel` int(10) UNSIGNED NOT NULL DEFAULT '0',
  104. `RewSpell` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  105. `RewSpellCast` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  106. `RewMailTemplateId` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  107. `RewMailDelaySecs` int(11) UNSIGNED NOT NULL DEFAULT '0',
  108. `PointMapId` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  109. `PointX` float NOT NULL DEFAULT '0',
  110. `PointY` float NOT NULL DEFAULT '0',
  111. `PointOpt` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  112. `DetailsEmote1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  113. `DetailsEmote2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  114. `DetailsEmote3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  115. `DetailsEmote4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  116. `IncompleteEmote` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  117. `CompleteEmote` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  118. `OfferRewardEmote1` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  119. `OfferRewardEmote2` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  120. `OfferRewardEmote3` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  121. `OfferRewardEmote4` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  122. `StartScript` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  123. `CompleteScript` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  124. PRIMARY KEY (`entry`)
  125. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Quest System';



Musiał bym edytować około 2 tysiące rekordów ręcznie... zajęło by mi to około tydzień;/
erix
UNIQUE?

Cytat
Musiał bym edytować około 2 tysiące rekordów ręcznie... zajęło by mi to około tydzień;/

Wyrażeniami regularnymi, etc?
assasin
No zapytania wyglądają tak:
  1. INSERT INTO `quest_template` VALUES ('114', 'The Escape', 'Zanies eliksir niewidzialnosci do mlodej Maybell. Powinno dzialac wystarczajaco dlugo aby mogla spotkac sie z Tommy Joe.', 'Zanies Invisibility Liquor do Maybell Maclure.', 'Ojej! Czuje sie winna niesluchajac mojej rodziny, ale moje uczucie do Tommy Joe jest zbyt silne aby je zignorowac.$b$bDziekuje ci, $N. Wypije ten eliksir jak tylko bende miala okazje i wymkne sie spotkac z moja miloscia.$b$bA dla ciebie... prosze wez to.', 'Dostarczyles moj list do Tommy Joe? Co powiedzial?', '0');
  2. INSERT INTO `quest_template` VALUES ('62', 'The Fargodeep Mine', 'Kopalnia w Northshire nie jest jedyna która ma problemy! Doniesiono mi ze Fargodeep Mine w Elwynn także stała sie siedziba Kobolds.$B$B Zwiedź kopalnie i potwierdź te pogłoski, następnie wróć do mnie. Kopalnie znajduje sie na południe od Goldshire, pomiędzy farmami Stonefield i Maclure.', 'Zwiedź Fargodeep Mine, następnie powróć do Marshal Dughan w Goldshire.', 'To są złe nowiny. Co będzie następne, smoki?!? Będziemy musieli zwiększyć liczbę patroli w pobliżu kopalni. Dziękuje za twój wysiłek, $N. Aha poczekaj chwilkę... Możliwe ze mam dla ciebie następne zadanie.', 'Co masz mi do powiedzenia, $N? Byleś już w Fargodeep Mine?', '0');
  3. INSERT INTO `quest_template` VALUES ('60', 'Kobold Candles', 'Witaj, $ggood sir:my lady;! Masz wolna chwilke?$B$BMoj brat i ja prowadzimy apteke w Stormwind, a ja jestem tutaj aby zbierac duze swiece dla ich wosku. Moglbys mi pomoc?$B$BMozesz zdobyc Large Candles z koboldow, a chodza pogloski ze w kopalniach Elwynn az roi sie od koboldow... Fargodeep Mine na poludniu i Jasperlode Mine na wschodzie. Sugeruje szukad Large Candles w ktoryms z tych miejsc.', 'Przynies 8 Large Candles do William Pestle w Goldshire.', 'Byles zajety polowaniem na koboldy, nieprawdaz? Dziekuje za swieczki, $N, a oto twoje wynagrodzenie...', 'Masz juz te sweczki?', '0');
  4. INSERT INTO `quest_template` VALUES ('87', 'Goldtooth', 'Bawilem sie nieopodal Fargodep Mine ,i myslalem ze upadl mi i...to znaczy ,widzialem naszyjnik starszej pani.\r\nNie pytaj mnie jak on sie tam dostal..to nie bylem ja!!!!$B$B\r\nZreszta niewazne ,zobaczylem tego wielkiego ,kobolda ze zlotym zebem ktory podnosil naszyjnik i zniknal w kopalni.\r\nProsze udaj sie tam, znajdz tego kobolda i odbierz mu ten naszyjnik.Przysiegam ze on bedzie go mial...', 'Przynies naszyjnik cioci Bernice Stonfield na Stonefield FArm.', 'Oh!!!Znalazles go! Dziekuje CI bardzo!!\r\n$B$B wez to.Nalezy do mojego meza ktory zawsze powtarza? ze przynosi szczescie.', 'Kogo ja widze! Czy znalazles moj naszyjnik?', '0');
  5. INSERT INTO `quest_template` VALUES ('129', 'A Free Lunch', 'Wyswiadczylbys mi przysluge? Przygotowalam posilek dla straznika Parkera, ale on wyszedl na patrol...Jest duzym, silnym straznikiem ze Stormwind, ktory potrafi zadbac o siebie, ale dla mnie jest tam zbyt niebezpiecznie.$B$B jesli zamiast mnie zaniesiesz mu jego obiad dam Ci darmowy posilek! Parker patroluje odcinek drogi prowadzacej do Duskwood.', 'Zanies Parker\'s lunch do Guard Parker. Patroluje droge prowadzacado Darkshire.', 'Dzieki, przyda mi sie jakis posilek. Strzeznie Lakeshire przed orkami i gnolami to ciezka praca!', 'Darcy przyslala mi posilek, nie prawdaz? Ma takie dobre serce. Dobra...wiec gdzie on jest!', '0');


To tylko 5 a ja mam ich 2 tysiące;/
wojckr
Może jakoś tak:

  1. $src= 'plik.txt'; //ścieżka do pliku z INSERTami
  2. $inserty=file($src); //każdy INSERT w array
  3. $updates=array();
  4. $i=0;
  5. foreach ($inserty as $insert) {
  6. $insert=str_replace('INSERT INTO `quest_template` VALUES (','',$insert); //utnie początek zapytania
  7. $insert=preg_replace('/;)\z/','',$insert); //utnie koniec zapytania
  8. //$insert zawiera teraz coś na kształt "'66634', 'tekst1', 'tekst2', 'tekst3', 'Tekst4.', 'Tekst4?', '0'"
  9. $wartosci=explode('\', \'',$insert); //np. $wartosci=array('66634', 'tekst1', 'tekst2', 'tekst3', 'Tekst4.', 'Tekst4?', '0'); explode przy użyciu '\', \'' jeśli wiadomo, ze w jakiejś wartości do update'u nie ma takiego tekstu
  10. $updates[$i]='UPDATE `quest_template` SET ';
  11.  
  12. foreach ($wartosci as $i2=>$wartosc) {
  13. if ($i2==1) { //zamiast tego może być switch
  14. $updates[$i].=' `title` = `'.$wartosc.'` ,'; //cudzysłów ` dla pól tekstowych
  15. } elseif ($i2==2) {
  16. ........
  17. } elseif (......) {
  18. ....... //z ostatniej wartości trzeba usunąć cudzysłów prosty z końca: $wartosc=rtrim($wartosc,'\'');
  19. }
  20. }
  21.  
  22. $updates[$i]=rtrim($updates[$i],','); //ucięcie ostatniego przecinka
  23.  
  24. $updates[$i].=' WHERE id = `'.ltrim($wartosci[0],'\'').'`';
  25.  
  26. $i++;
  27. }
  28.  
  29. //$updates zawiera teraz zapytania UPDATE


Kod napisałem na szybko, więc ciekawe, czy działa.
assasin
Hmm tam gdzie są kropki mam coś wpisaćbiggrin.gif w lini 17 18 19.?
Bo:

Parse error: syntax error, unexpected '.' in C:\xampp\htdocs\1.php on line 17
erix
Forum, to nie parser.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.