Changeset 1624 for trunk/admin/include/functions.php
- Timestamp:
- Dec 2, 2006, 12:31:19 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r1605 r1624 258 258 pwg_query($query); 259 259 260 // deletion of computed cache data linked to the user 261 $query = ' 262 DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.' 263 WHERE user_id = '.$user_id.' 264 ;'; 265 pwg_query($query); 266 260 267 // deletion of phpwebgallery specific informations 261 268 $query = ' … … 515 522 function mass_inserts($table_name, $dbfields, $datas) 516 523 { 517 // inserts all found categories 518 $query = ' 519 INSERT INTO '.$table_name.' 520 ('.implode(',', $dbfields).') 521 VALUES'; 522 foreach ($datas as $insert_id => $insert) 523 { 524 $query.= ' 525 '; 526 if ($insert_id > 0) 527 { 528 $query.= ','; 529 } 530 $query.= '('; 531 foreach ($dbfields as $field_id => $dbfield) 532 { 533 if ($field_id > 0) 524 if (count($datas) != 0) 525 { 526 // inserts all found categories 527 $query = ' 528 INSERT INTO '.$table_name.' 529 ('.implode(',', $dbfields).') 530 VALUES'; 531 foreach ($datas as $insert_id => $insert) 532 { 533 $query.= ' 534 '; 535 if ($insert_id > 0) 534 536 { 535 537 $query.= ','; 536 538 } 537 538 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')539 $query.= '('; 540 foreach ($dbfields as $field_id => $dbfield) 539 541 { 540 $query.= 'NULL'; 542 if ($field_id > 0) 543 { 544 $query.= ','; 545 } 546 547 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 548 { 549 $query.= 'NULL'; 550 } 551 else 552 { 553 $query.= "'".$insert[$dbfield]."'"; 554 } 541 555 } 542 else 543 { 544 $query.= "'".$insert[$dbfield]."'"; 545 } 546 } 547 $query.=')'; 548 } 549 $query.= ' 550 ;'; 551 pwg_query($query); 556 $query.=')'; 557 } 558 $query.= ' 559 ;'; 560 pwg_query($query); 561 } 552 562 } 553 563 … … 562 572 function mass_updates($tablename, $dbfields, $datas) 563 573 { 564 // depending on the MySQL version, we use the multi table update or N 565 // update queries 566 $query = 'SELECT VERSION() AS version;'; 567 list($mysql_version) = mysql_fetch_array(pwg_query($query)); 568 if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0) 569 { 570 // MySQL is prior to version 4.0.4, multi table update feature is not 571 // available 572 foreach ($datas as $data) 573 { 574 if (count($datas) != 0) 575 { 576 // depending on the MySQL version, we use the multi table update or N 577 // update queries 578 $query = 'SELECT VERSION() AS version;'; 579 list($mysql_version) = mysql_fetch_array(pwg_query($query)); 580 if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0) 581 { 582 // MySQL is prior to version 4.0.4, multi table update feature is not 583 // available 584 foreach ($datas as $data) 585 { 586 $query = ' 587 UPDATE '.$tablename.' 588 SET '; 589 $is_first = true; 590 foreach ($dbfields['update'] as $num => $key) 591 { 592 if (!$is_first) 593 { 594 $query.= ",\n "; 595 } 596 $query.= $key.' = '; 597 if (isset($data[$key]) and $data[$key] != '') 598 { 599 $query.= '\''.$data[$key].'\''; 600 } 601 else 602 { 603 $query.= 'NULL'; 604 } 605 $is_first = false; 606 } 607 $query.= ' 608 WHERE '; 609 foreach ($dbfields['primary'] as $num => $key) 610 { 611 if ($num > 1) 612 { 613 $query.= ' AND '; 614 } 615 $query.= $key.' = \''.$data[$key].'\''; 616 } 617 $query.= ' 618 ;'; 619 pwg_query($query); 620 } 621 } 622 else 623 { 624 // creation of the temporary table 574 625 $query = ' 575 UPDATE '.$tablename.' 576 SET '; 577 $is_first = true; 578 foreach ($dbfields['update'] as $num => $key) 626 SHOW FULL COLUMNS FROM '.$tablename.' 627 ;'; 628 $result = pwg_query($query); 629 $columns = array(); 630 $all_fields = array_merge($dbfields['primary'], $dbfields['update']); 631 while ($row = mysql_fetch_array($result)) 579 632 { 580 if ( !$is_first)633 if (in_array($row['Field'], $all_fields)) 581 634 { 582 $query.= ",\n "; 635 $column = $row['Field']; 636 $column.= ' '.$row['Type']; 637 if (!isset($row['Null']) or $row['Null'] == '') 638 { 639 $column.= ' NOT NULL'; 640 } 641 if (isset($row['Default'])) 642 { 643 $column.= " default '".$row['Default']."'"; 644 } 645 if (isset($row['Collation']) and $row['Collation'] != 'NULL') 646 { 647 $column.= " collate '".$row['Collation']."'"; 648 } 649 array_push($columns, $column); 583 650 } 584 $query.= $key.' = ';585 if (isset($data[$key]) and $data[$key] != '')586 {587 $query.= '\''.$data[$key].'\'';588 }589 else590 {591 $query.= 'NULL';592 }593 $is_first = false;594 651 } 595 $query.= ' 596 WHERE '; 597 foreach ($dbfields['primary'] as $num => $key) 598 { 599 if ($num > 1) 600 { 601 $query.= ' AND '; 602 } 603 $query.= $key.' = \''.$data[$key].'\''; 604 } 605 $query.= ' 652 653 $temporary_tablename = $tablename.'_'.micro_seconds(); 654 655 $query = ' 656 CREATE TABLE '.$temporary_tablename.' 657 ( 658 '.implode(",\n", $columns).', 659 PRIMARY KEY ('.implode(',', $dbfields['primary']).') 660 ) 606 661 ;'; 607 662 pwg_query($query); 608 } 609 } 610 else 611 { 612 // creation of the temporary table 613 $query = ' 614 SHOW FULL COLUMNS FROM '.$tablename.' 615 ;'; 616 $result = pwg_query($query); 617 $columns = array(); 618 $all_fields = array_merge($dbfields['primary'], $dbfields['update']); 619 while ($row = mysql_fetch_array($result)) 620 { 621 if (in_array($row['Field'], $all_fields)) 622 { 623 $column = $row['Field']; 624 $column.= ' '.$row['Type']; 625 if (!isset($row['Null']) or $row['Null'] == '') 626 { 627 $column.= ' NOT NULL'; 628 } 629 if (isset($row['Default'])) 630 { 631 $column.= " default '".$row['Default']."'"; 632 } 633 if (isset($row['Collation']) and $row['Collation'] != 'NULL') 634 { 635 $column.= " collate '".$row['Collation']."'"; 636 } 637 array_push($columns, $column); 638 } 639 } 640 641 $temporary_tablename = $tablename.'_'.micro_seconds(); 642 643 $query = ' 644 CREATE TABLE '.$temporary_tablename.' 645 ( 646 '.implode(",\n", $columns).', 647 PRIMARY KEY ('.implode(',', $dbfields['primary']).') 648 ) 649 ;'; 650 pwg_query($query); 651 mass_inserts($temporary_tablename, $all_fields, $datas); 652 // update of images table by joining with temporary table 653 $query = ' 654 UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 655 SET '. 656 implode( 657 "\n , ", 658 array_map( 659 create_function('$s', 'return "t1.$s = t2.$s";'), 660 $dbfields['update'] 661 ) 662 ).' 663 WHERE '. 664 implode( 665 "\n AND ", 666 array_map( 667 create_function('$s', 'return "t1.$s = t2.$s";'), 668 $dbfields['primary'] 669 ) 670 ).' 671 ;'; 672 pwg_query($query); 673 $query = ' 674 DROP TABLE '.$temporary_tablename.' 675 ;'; 676 pwg_query($query); 663 mass_inserts($temporary_tablename, $all_fields, $datas); 664 // update of images table by joining with temporary table 665 $query = ' 666 UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 667 SET '. 668 implode( 669 "\n , ", 670 array_map( 671 create_function('$s', 'return "t1.$s = t2.$s";'), 672 $dbfields['update'] 673 ) 674 ).' 675 WHERE '. 676 implode( 677 "\n AND ", 678 array_map( 679 create_function('$s', 'return "t1.$s = t2.$s";'), 680 $dbfields['primary'] 681 ) 682 ).' 683 ;'; 684 pwg_query($query); 685 $query = ' 686 DROP TABLE '.$temporary_tablename.' 687 ;'; 688 pwg_query($query); 689 } 677 690 } 678 691 } … … 1160 1173 USER_ACCESS_TABLE, 1161 1174 USER_CACHE_TABLE, 1175 USER_CACHE_CATEGORIES_TABLE, 1162 1176 USER_GROUP_TABLE 1163 1177 );
Note: See TracChangeset
for help on using the changeset viewer.