Changeset 11991
- Timestamp:
- Aug 24, 2011, 9:50:54 PM (13 years ago)
- Location:
- trunk/include/dblayer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/dblayer/functions_mysql.inc.php
r11485 r11991 351 351 * 352 352 * @param string table_name 353 * @param array dbfields354 * @param array data353 * @param array set_fields 354 * @param array where_fields 355 355 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 356 356 * @return void 357 357 */ 358 function single_update($tablename, $dbfields, $data, $flags=0) 359 { 360 if (count($data) == 0) 358 function single_update($tablename, $set_fields, $where_fields, $flags=0) 359 { 360 if (count($set_fields) == 0) 361 { 361 362 return; 363 } 362 364 363 365 $query = ' … … 365 367 SET '; 366 368 $is_first = true; 367 foreach ($ dbfields['update'] as $key)369 foreach ($set_fields as $key => $value) 368 370 { 369 371 $separator = $is_first ? '' : ",\n "; 370 372 371 if (isset($ data[$key]) and $data[$key]!= '')372 { 373 $query.= $separator.$key.' = \''.$ data[$key].'\'';373 if (isset($value) and $value != '') 374 { 375 $query.= $separator.$key.' = \''.$value.'\''; 374 376 } 375 377 else … … 386 388 WHERE '; 387 389 $is_first = true; 388 foreach ($ dbfields['primary'] as $key)390 foreach ($where_fields as $key => $value) 389 391 { 390 392 if (!$is_first) … … 392 394 $query.= ' AND '; 393 395 } 394 if ( isset($ data[$key]) )395 { 396 $query.= $key.' = \''.$ data[$key].'\'';396 if ( isset($value) ) 397 { 398 $query.= $key.' = \''.$value.'\''; 397 399 } 398 400 else … … 472 474 473 475 /** 474 * inserts on line in a table476 * inserts one line in a table 475 477 * 476 478 * @param string table_name … … 479 481 * @return void 480 482 */ 481 function single_insert($table_name, $d bfields, $insert)482 { 483 if (count($ insert) != 0)483 function single_insert($table_name, $data) 484 { 485 if (count($data) != 0) 484 486 { 485 487 $query = ' 486 488 INSERT INTO '.$table_name.' 487 ('.implode(',', $dbfields).')489 ('.implode(',', array_keys($data)).') 488 490 VALUES'; 489 491 490 492 $query .= '('; 491 foreach ($dbfields as $field_id => $dbfield) 492 { 493 if ($field_id > 0) 493 $is_first = true; 494 foreach ($data as $key => $value) 495 { 496 if (!$is_first) 494 497 { 495 498 $query .= ','; 496 499 } 497 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 500 else 501 { 502 $is_first = false; 503 } 504 505 if ($value === '') 498 506 { 499 507 $query .= 'NULL'; … … 501 509 else 502 510 { 503 $query .= "'".$ insert[$dbfield]."'";511 $query .= "'".$value."'"; 504 512 } 505 513 } -
trunk/include/dblayer/functions_pdo-sqlite.inc.php
r11485 r11991 316 316 317 317 /** 318 * updates on line in a table318 * updates one line in a table 319 319 * 320 320 * @param string table_name 321 * @param array dbfields322 * @param array data321 * @param array set_fields 322 * @param array where_fields 323 323 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 324 324 * @return void 325 325 */ 326 function single_update($tablename, $dbfields, $data, $flags=0) 327 { 328 if (count($data) == 0) 326 function single_update($tablename, $set_fields, $where_fields, $flags=0) 327 { 328 if (count($set_fields) == 0) 329 { 329 330 return; 331 } 330 332 331 333 $query = ' … … 333 335 SET '; 334 336 $is_first = true; 335 foreach ($ dbfields['update'] as $key)337 foreach ($set_fields as $key => $value) 336 338 { 337 339 $separator = $is_first ? '' : ",\n "; 338 339 if (isset($ data[$key]) and $data[$key]!= '')340 { 341 $query.= $separator.$key.' = \''.$ data[$key].'\'';340 341 if (isset($value) and $value != '') 342 { 343 $query.= $separator.$key.' = \''.$value.'\''; 342 344 } 343 345 else … … 354 356 WHERE '; 355 357 $is_first = true; 356 foreach ($ dbfields['primary'] as $key)358 foreach ($where_fields as $key => $value) 357 359 { 358 360 if (!$is_first) … … 360 362 $query.= ' AND '; 361 363 } 362 if ( isset($ data[$key]) )363 { 364 $query.= $key.' = \''.$ data[$key].'\'';364 if ( isset($value) ) 365 { 366 $query.= $key.' = \''.$value.'\''; 365 367 } 366 368 else … … 373 375 } 374 376 } 375 376 377 377 378 /** … … 446 447 * @return void 447 448 */ 448 function single_insert($table_name, $d bfields, $insert)449 { 450 if (count($ insert) != 0)449 function single_insert($table_name, $data) 450 { 451 if (count($data) != 0) 451 452 { 452 453 $query = ' 453 454 INSERT INTO '.$table_name.' 454 ('.implode(',', $dbfields).')455 ('.implode(',', array_keys($data)).') 455 456 VALUES'; 456 457 457 458 $query .= '('; 458 foreach ($dbfields as $field_id => $dbfield) 459 { 460 if ($field_id > 0) 459 $is_first = true; 460 foreach ($data as $key => $value) 461 { 462 if (!$is_first) 461 463 { 462 464 $query .= ','; 463 465 } 464 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 466 else 467 { 468 $is_first = false; 469 } 470 471 if ($value === '') 465 472 { 466 473 $query .= 'NULL'; … … 468 475 else 469 476 { 470 $query .= "'".$ insert[$dbfield]."'";477 $query .= "'".$value."'"; 471 478 } 472 479 } -
trunk/include/dblayer/functions_pgsql.inc.php
r11485 r11991 427 427 428 428 /** 429 * updates on line in a table429 * updates one line in a table 430 430 * 431 431 * @param string table_name 432 * @param array dbfields433 * @param array data432 * @param array set_fields 433 * @param array where_fields 434 434 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 435 435 * @return void 436 436 */ 437 function single_update($tablename, $dbfields, $data, $flags=0) 438 { 439 if (count($data) == 0) 437 function single_update($tablename, $set_fields, $where_fields, $flags=0) 438 { 439 if (count($set_fields) == 0) 440 { 440 441 return; 442 } 441 443 442 444 $query = ' … … 444 446 SET '; 445 447 $is_first = true; 446 foreach ($ dbfields['update'] as $key)448 foreach ($set_fields as $key => $value) 447 449 { 448 450 $separator = $is_first ? '' : ",\n "; 449 451 450 if (isset($ data[$key]) and $data[$key]!= '')451 { 452 $query.= $separator.$key.' = \''.$ data[$key].'\'';452 if (isset($value) and $value != '') 453 { 454 $query.= $separator.$key.' = \''.$value.'\''; 453 455 } 454 456 else … … 465 467 WHERE '; 466 468 $is_first = true; 467 foreach ($ dbfields['primary'] as $key)469 foreach ($where_fields as $key => $value) 468 470 { 469 471 if (!$is_first) … … 471 473 $query.= ' AND '; 472 474 } 473 if ( isset($ data[$key]) )474 { 475 $query.= $key.' = \''.$ data[$key].'\'';475 if ( isset($value) ) 476 { 477 $query.= $key.' = \''.$value.'\''; 476 478 } 477 479 else … … 482 484 } 483 485 pwg_query($query); 484 } 486 } 485 487 } 486 488 … … 549 551 550 552 /** 551 * inserts on line in a table553 * inserts one line in a table 552 554 * 553 555 * @param string table_name … … 556 558 * @return void 557 559 */ 558 function single_insert($table_name, $d bfields, $insert)559 { 560 if (count($ insert) != 0)560 function single_insert($table_name, $data) 561 { 562 if (count($data) != 0) 561 563 { 562 564 $query = ' 563 565 INSERT INTO '.$table_name.' 564 ('.implode(',', $dbfields).')566 ('.implode(',', array_keys($data)).') 565 567 VALUES'; 566 568 567 569 $query .= '('; 568 foreach ($dbfields as $field_id => $dbfield) 569 { 570 if ($field_id > 0) 570 $is_first = true; 571 foreach ($data as $key => $value) 572 { 573 if (!$is_first) 571 574 { 572 575 $query .= ','; 573 576 } 574 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 577 else 578 { 579 $is_first = false; 580 } 581 582 if ($value === '') 575 583 { 576 584 $query .= 'NULL'; … … 578 586 else 579 587 { 580 $query .= "'".$ insert[$dbfield]."'";588 $query .= "'".$value."'"; 581 589 } 582 590 } -
trunk/include/dblayer/functions_sqlite.inc.php
r11925 r11991 328 328 329 329 /** 330 * updates on line in a table330 * updates one line in a table 331 331 * 332 332 * @param string table_name 333 * @param array dbfields334 * @param array data333 * @param array set_fields 334 * @param array where_fields 335 335 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones 336 336 * @return void 337 337 */ 338 function single_update($tablename, $dbfields, $data, $flags=0) 339 { 340 if (count($data) == 0) 338 function single_update($tablename, $set_fields, $where_fields, $flags=0) 339 { 340 if (count($set_fields) == 0) 341 { 341 342 return; 343 } 342 344 343 345 $query = ' … … 345 347 SET '; 346 348 $is_first = true; 347 foreach ($ dbfields['update'] as $key)349 foreach ($set_fields as $key => $value) 348 350 { 349 351 $separator = $is_first ? '' : ",\n "; 350 351 if (isset($ data[$key]) and $data[$key]!= '')352 { 353 $query.= $separator.$key.' = \''.$ data[$key].'\'';352 353 if (isset($value) and $value != '') 354 { 355 $query.= $separator.$key.' = \''.$value.'\''; 354 356 } 355 357 else … … 366 368 WHERE '; 367 369 $is_first = true; 368 foreach ($ dbfields['primary'] as $key)370 foreach ($where_fields as $key => $value) 369 371 { 370 372 if (!$is_first) … … 372 374 $query.= ' AND '; 373 375 } 374 if ( isset($ data[$key]) )375 { 376 $query.= $key.' = \''.$ data[$key].'\'';376 if ( isset($value) ) 377 { 378 $query.= $key.' = \''.$value.'\''; 377 379 } 378 380 else … … 385 387 } 386 388 } 387 388 389 389 390 /** … … 458 459 * @return void 459 460 */ 460 function single_insert($table_name, $d bfields, $insert)461 { 462 if (count($ insert) != 0)461 function single_insert($table_name, $data) 462 { 463 if (count($data) != 0) 463 464 { 464 465 $query = ' 465 466 INSERT INTO '.$table_name.' 466 ('.implode(',', $dbfields).')467 ('.implode(',', array_keys($data)).') 467 468 VALUES'; 468 469 469 470 $query .= '('; 470 foreach ($dbfields as $field_id => $dbfield) 471 { 472 if ($field_id > 0) 471 $is_first = true; 472 foreach ($data as $key => $value) 473 { 474 if (!$is_first) 473 475 { 474 476 $query .= ','; 475 477 } 476 if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') 478 else 479 { 480 $is_first = false; 481 } 482 483 if ($value === '') 477 484 { 478 485 $query .= 'NULL'; … … 480 487 else 481 488 { 482 $query .= "'".$ insert[$dbfield]."'";489 $query .= "'".$value."'"; 483 490 } 484 491 }
Note: See TracChangeset
for help on using the changeset viewer.