- Timestamp:
- Jun 22, 2011, 5:56:19 PM (13 years ago)
- Location:
- trunk/include/dblayer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/dblayer/functions_mysql.inc.php
r11364 r11485 220 220 if (count($datas) == 0) 221 221 return; 222 222 223 // depending on the MySQL version, we use the multi table update or N update queries 223 224 if (count($datas) < 10) … … 233 234 $separator = $is_first ? '' : ",\n "; 234 235 235 if (isset($data[$key]) and $data[$key] != ='')236 if (isset($data[$key]) and $data[$key] != '') 236 237 { 237 238 $query.= $separator.$key.' = \''.$data[$key].'\''; … … 239 240 else 240 241 { 241 if ( $flags & MASS_UPDATES_SKIP_EMPTY )242 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 242 243 continue; // next field 243 244 $query.= "$separator$key = NULL"; … … 346 347 } 347 348 349 /** 350 * updates one line in a table 351 * 352 * @param string table_name 353 * @param array dbfields 354 * @param array data 355 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 356 * @return void 357 */ 358 function single_update($tablename, $dbfields, $data, $flags=0) 359 { 360 if (count($data) == 0) 361 return; 362 363 $query = ' 364 UPDATE '.$tablename.' 365 SET '; 366 $is_first = true; 367 foreach ($dbfields['update'] as $key) 368 { 369 $separator = $is_first ? '' : ",\n "; 370 371 if (isset($data[$key]) and $data[$key] != '') 372 { 373 $query.= $separator.$key.' = \''.$data[$key].'\''; 374 } 375 else 376 { 377 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 378 continue; // next field 379 $query.= "$separator$key = NULL"; 380 } 381 $is_first = false; 382 } 383 if (!$is_first) 384 {// only if one field at least updated 385 $query.= ' 386 WHERE '; 387 $is_first = true; 388 foreach ($dbfields['primary'] as $key) 389 { 390 if (!$is_first) 391 { 392 $query.= ' AND '; 393 } 394 if ( isset($data[$key]) ) 395 { 396 $query.= $key.' = \''.$data[$key].'\''; 397 } 398 else 399 { 400 $query.= $key.' IS NULL'; 401 } 402 $is_first = false; 403 } 404 pwg_query($query); 405 } 406 } 407 348 408 349 409 /** … … 412 472 413 473 /** 474 * inserts on line in a table 475 * 476 * @param string table_name 477 * @param array dbfields 478 * @param array insert 479 * @return void 480 */ 481 function single_insert($table_name, $dbfields, $insert) 482 { 483 if (count($insert) != 0) 484 { 485 $query = ' 486 INSERT INTO '.$table_name.' 487 ('.implode(',', $dbfields).') 488 VALUES'; 489 490 $query .= '('; 491 foreach ($dbfields as $field_id => $dbfield) 492 { 493 if ($field_id > 0) 494 { 495 $query .= ','; 496 } 497 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 498 { 499 $query .= 'NULL'; 500 } 501 else 502 { 503 $query .= "'".$insert[$dbfield]."'"; 504 } 505 } 506 $query .= ')'; 507 508 pwg_query($query); 509 } 510 } 511 512 /** 414 513 * Do maintenance on all PWG tables 415 514 * -
trunk/include/dblayer/functions_pdo-sqlite.inc.php
r8728 r11485 279 279 if (isset($data[$key]) and $data[$key] != '') 280 280 { 281 281 $query.= $separator.$key.' = \''.$data[$key].'\''; 282 282 } 283 283 else 284 284 { 285 if ($flags & MASS_UPDATES_SKIP_EMPTY )286 287 285 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 286 continue; // next field 287 $query.= "$separator$key = NULL"; 288 288 } 289 289 $is_first = false; … … 296 296 foreach ($dbfields['primary'] as $key) 297 297 { 298 298 if (!$is_first) 299 299 { 300 301 302 300 $query.= ' AND '; 301 } 302 if ( isset($data[$key]) ) 303 303 { 304 305 306 304 $query.= $key.' = \''.$data[$key].'\''; 305 } 306 else 307 307 { 308 309 310 308 $query.= $key.' IS NULL'; 309 } 310 $is_first = false; 311 311 } 312 312 pwg_query($query); 313 313 } 314 } 315 } 316 317 /** 318 * updates on line in a table 319 * 320 * @param string table_name 321 * @param array dbfields 322 * @param array data 323 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 324 * @return void 325 */ 326 function single_update($tablename, $dbfields, $data, $flags=0) 327 { 328 if (count($data) == 0) 329 return; 330 331 $query = ' 332 UPDATE '.$tablename.' 333 SET '; 334 $is_first = true; 335 foreach ($dbfields['update'] as $key) 336 { 337 $separator = $is_first ? '' : ",\n "; 338 339 if (isset($data[$key]) and $data[$key] != '') 340 { 341 $query.= $separator.$key.' = \''.$data[$key].'\''; 342 } 343 else 344 { 345 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 346 continue; // next field 347 $query.= "$separator$key = NULL"; 348 } 349 $is_first = false; 350 } 351 if (!$is_first) 352 {// only if one field at least updated 353 $query.= ' 354 WHERE '; 355 $is_first = true; 356 foreach ($dbfields['primary'] as $key) 357 { 358 if (!$is_first) 359 { 360 $query.= ' AND '; 361 } 362 if ( isset($data[$key]) ) 363 { 364 $query.= $key.' = \''.$data[$key].'\''; 365 } 366 else 367 { 368 $query.= $key.' IS NULL'; 369 } 370 $is_first = false; 371 } 372 pwg_query($query); 314 373 } 315 374 } … … 324 383 * @return void 325 384 */ 326 327 385 function mass_inserts($table_name, $dbfields, $datas) 328 386 { … … 381 439 382 440 /** 441 * inserts one line in a table 442 * 443 * @param string table_name 444 * @param array dbfields 445 * @param array insert 446 * @return void 447 */ 448 function single_insert($table_name, $dbfields, $insert) 449 { 450 if (count($insert) != 0) 451 { 452 $query = ' 453 INSERT INTO '.$table_name.' 454 ('.implode(',', $dbfields).') 455 VALUES'; 456 457 $query .= '('; 458 foreach ($dbfields as $field_id => $dbfield) 459 { 460 if ($field_id > 0) 461 { 462 $query .= ','; 463 } 464 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 465 { 466 $query .= 'NULL'; 467 } 468 else 469 { 470 $query .= "'".$insert[$dbfield]."'"; 471 } 472 } 473 $query .= ')'; 474 475 pwg_query($query); 476 } 477 } 478 479 /** 383 480 * Do maintenance on all PWG tables 384 481 * -
trunk/include/dblayer/functions_pgsql.inc.php
r10431 r11485 356 356 else 357 357 { 358 if ( $flags & MASS_UPDATES_SKIP_EMPTY )358 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 359 359 continue; // next field 360 360 $query.= "$separator$key = NULL"; … … 426 426 } 427 427 428 /** 429 * updates on line in a table 430 * 431 * @param string table_name 432 * @param array dbfields 433 * @param array data 434 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 435 * @return void 436 */ 437 function single_update($tablename, $dbfields, $data, $flags=0) 438 { 439 if (count($data) == 0) 440 return; 441 442 $query = ' 443 UPDATE '.$tablename.' 444 SET '; 445 $is_first = true; 446 foreach ($dbfields['update'] as $key) 447 { 448 $separator = $is_first ? '' : ",\n "; 449 450 if (isset($data[$key]) and $data[$key] != '') 451 { 452 $query.= $separator.$key.' = \''.$data[$key].'\''; 453 } 454 else 455 { 456 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 457 continue; // next field 458 $query.= "$separator$key = NULL"; 459 } 460 $is_first = false; 461 } 462 if (!$is_first) 463 {// only if one field at least updated 464 $query.= ' 465 WHERE '; 466 $is_first = true; 467 foreach ($dbfields['primary'] as $key) 468 { 469 if (!$is_first) 470 { 471 $query.= ' AND '; 472 } 473 if ( isset($data[$key]) ) 474 { 475 $query.= $key.' = \''.$data[$key].'\''; 476 } 477 else 478 { 479 $query.= $key.' IS NULL'; 480 } 481 $is_first = false; 482 } 483 pwg_query($query); 484 } 485 } 428 486 429 487 /** … … 435 493 * @return void 436 494 */ 437 438 495 function mass_inserts($table_name, $dbfields, $datas) 439 496 { … … 492 549 493 550 /** 551 * inserts on line in a table 552 * 553 * @param string table_name 554 * @param array dbfields 555 * @param array insert 556 * @return void 557 */ 558 function single_insert($table_name, $dbfields, $insert) 559 { 560 if (count($insert) != 0) 561 { 562 $query = ' 563 INSERT INTO '.$table_name.' 564 ('.implode(',', $dbfields).') 565 VALUES'; 566 567 $query .= '('; 568 foreach ($dbfields as $field_id => $dbfield) 569 { 570 if ($field_id > 0) 571 { 572 $query .= ','; 573 } 574 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 575 { 576 $query .= 'NULL'; 577 } 578 else 579 { 580 $query .= "'".$insert[$dbfield]."'"; 581 } 582 } 583 $query .= ')'; 584 585 pwg_query($query); 586 } 587 } 588 589 /** 494 590 * Do maintenance on all PWG tables 495 591 * -
trunk/include/dblayer/functions_sqlite.inc.php
r8728 r11485 291 291 if (isset($data[$key]) and $data[$key] != '') 292 292 { 293 293 $query.= $separator.$key.' = \''.$data[$key].'\''; 294 294 } 295 295 else 296 296 { 297 if ($flags & MASS_UPDATES_SKIP_EMPTY )298 299 297 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 298 continue; // next field 299 $query.= "$separator$key = NULL"; 300 300 } 301 301 $is_first = false; … … 308 308 foreach ($dbfields['primary'] as $key) 309 309 { 310 310 if (!$is_first) 311 311 { 312 313 314 312 $query.= ' AND '; 313 } 314 if ( isset($data[$key]) ) 315 315 { 316 317 318 316 $query.= $key.' = \''.$data[$key].'\''; 317 } 318 else 319 319 { 320 321 322 320 $query.= $key.' IS NULL'; 321 } 322 $is_first = false; 323 323 } 324 324 pwg_query($query); 325 325 } 326 } 327 } 328 329 /** 330 * updates on line in a table 331 * 332 * @param string table_name 333 * @param array dbfields 334 * @param array data 335 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 336 * @return void 337 */ 338 function single_update($tablename, $dbfields, $data, $flags=0) 339 { 340 if (count($data) == 0) 341 return; 342 343 $query = ' 344 UPDATE '.$tablename.' 345 SET '; 346 $is_first = true; 347 foreach ($dbfields['update'] as $key) 348 { 349 $separator = $is_first ? '' : ",\n "; 350 351 if (isset($data[$key]) and $data[$key] != '') 352 { 353 $query.= $separator.$key.' = \''.$data[$key].'\''; 354 } 355 else 356 { 357 if ( $flags & MASS_UPDATES_SKIP_EMPTY ) 358 continue; // next field 359 $query.= "$separator$key = NULL"; 360 } 361 $is_first = false; 362 } 363 if (!$is_first) 364 {// only if one field at least updated 365 $query.= ' 366 WHERE '; 367 $is_first = true; 368 foreach ($dbfields['primary'] as $key) 369 { 370 if (!$is_first) 371 { 372 $query.= ' AND '; 373 } 374 if ( isset($data[$key]) ) 375 { 376 $query.= $key.' = \''.$data[$key].'\''; 377 } 378 else 379 { 380 $query.= $key.' IS NULL'; 381 } 382 $is_first = false; 383 } 384 pwg_query($query); 326 385 } 327 386 } … … 336 395 * @return void 337 396 */ 338 339 397 function mass_inserts($table_name, $dbfields, $datas) 340 398 { … … 393 451 394 452 /** 453 * inserts one line in a table 454 * 455 * @param string table_name 456 * @param array dbfields 457 * @param array insert 458 * @return void 459 */ 460 function single_insert($table_name, $dbfields, $insert) 461 { 462 if (count($insert) != 0) 463 { 464 $query = ' 465 INSERT INTO '.$table_name.' 466 ('.implode(',', $dbfields).') 467 VALUES'; 468 469 $query .= '('; 470 foreach ($dbfields as $field_id => $dbfield) 471 { 472 if ($field_id > 0) 473 { 474 $query .= ','; 475 } 476 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 477 { 478 $query .= 'NULL'; 479 } 480 else 481 { 482 $query .= "'".$insert[$dbfield]."'"; 483 } 484 } 485 $query .= ')'; 486 487 pwg_query($query); 488 } 489 } 490 491 /** 395 492 * Do maintenance on all PWG tables 396 493 *
Note: See TracChangeset
for help on using the changeset viewer.